aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
Diffstat (limited to 'netlib')
-rw-r--r--netlib/http_cookies.py24
-rw-r--r--netlib/websockets.py50
2 files changed, 37 insertions, 37 deletions
diff --git a/netlib/http_cookies.py b/netlib/http_cookies.py
index dab95ed0..8e245891 100644
--- a/netlib/http_cookies.py
+++ b/netlib/http_cookies.py
@@ -1,18 +1,18 @@
"""
A flexible module for cookie parsing and manipulation.
-This module differs from usual standards-compliant cookie modules in a number of
-ways. We try to be as permissive as possible, and to retain even mal-formed
+This module differs from usual standards-compliant cookie modules in a number
+of ways. We try to be as permissive as possible, and to retain even mal-formed
information. Duplicate cookies are preserved in parsing, and can be set in
formatting. We do attempt to escape and quote values where needed, but will not
reject data that violate the specs.
Parsing accepts the formats in RFC6265 and partially RFC2109 and RFC2965. We do
-not parse the comma-separated variant of Set-Cookie that allows multiple cookies
-to be set in a single header. Technically this should be feasible, but it turns
-out that violations of RFC6265 that makes the parsing problem indeterminate are
-much more common than genuine occurences of the multi-cookie variants.
-Serialization follows RFC6265.
+not parse the comma-separated variant of Set-Cookie that allows multiple
+cookies to be set in a single header. Technically this should be feasible, but
+it turns out that violations of RFC6265 that makes the parsing problem
+indeterminate are much more common than genuine occurences of the multi-cookie
+variants. Serialization follows RFC6265.
http://tools.ietf.org/html/rfc6265
http://tools.ietf.org/html/rfc2109
@@ -32,11 +32,11 @@ def _read_until(s, start, term):
Read until one of the characters in term is reached.
"""
if start == len(s):
- return "", start+1
+ return "", start + 1
for i in range(start, len(s)):
if s[i] in term:
return s[start:i], i
- return s[start:i+1], i+1
+ return s[start:i + 1], i + 1
def _read_token(s, start):
@@ -59,7 +59,7 @@ def _read_quoted_string(s, start):
escaping = False
ret = []
# Skip the first quote
- for i in range(start+1, len(s)):
+ for i in range(start + 1, len(s)):
if escaping:
ret.append(s[i])
escaping = False
@@ -70,7 +70,7 @@ def _read_quoted_string(s, start):
pass
else:
ret.append(s[i])
- return "".join(ret), i+1
+ return "".join(ret), i + 1
def _read_value(s, start, delims):
@@ -103,7 +103,7 @@ def _read_pairs(s, off=0, specials=()):
rhs = None
if off < len(s):
if s[off] == "=":
- rhs, off = _read_value(s, off+1, ";")
+ rhs, off = _read_value(s, off + 1, ";")
vals.append([lhs, rhs])
off += 1
if not off < len(s):
diff --git a/netlib/websockets.py b/netlib/websockets.py
index 5b9d8fbd..f2d467a5 100644
--- a/netlib/websockets.py
+++ b/netlib/websockets.py
@@ -67,23 +67,23 @@ class Frame(object):
mask_bit, # decimal integer 1 or 0
payload_length_code, # decimal integer 1 - 127
decoded_payload, # bytestring
- rsv1 = 0, # decimal integer 1 or 0
- rsv2 = 0, # decimal integer 1 or 0
- rsv3 = 0, # decimal integer 1 or 0
- payload = None, # bytestring
- masking_key = None, # 32 bit byte string
+ rsv1 = 0, # decimal integer 1 or 0
+ rsv2 = 0, # decimal integer 1 or 0
+ rsv3 = 0, # decimal integer 1 or 0
+ payload = None, # bytestring
+ masking_key = None, # 32 bit byte string
actual_payload_length = None, # any decimal integer
):
- self.fin = fin
- self.rsv1 = rsv1
- self.rsv2 = rsv2
- self.rsv3 = rsv3
- self.opcode = opcode
- self.mask_bit = mask_bit
- self.payload_length_code = payload_length_code
- self.masking_key = masking_key
- self.payload = payload
- self.decoded_payload = decoded_payload
+ self.fin = fin
+ self.rsv1 = rsv1
+ self.rsv2 = rsv2
+ self.rsv3 = rsv3
+ self.opcode = opcode
+ self.mask_bit = mask_bit
+ self.payload_length_code = payload_length_code
+ self.masking_key = masking_key
+ self.payload = payload
+ self.decoded_payload = decoded_payload
self.actual_payload_length = actual_payload_length
@classmethod
@@ -162,7 +162,7 @@ class Frame(object):
"""
Construct a websocket frame from an in-memory bytestring
to construct a frame from a stream of bytes, use from_file() directly
- """
+ """
return cls.from_file(io.BytesIO(bytestring))
def safe_to_bytes(self):
@@ -206,7 +206,7 @@ class Frame(object):
# '!H' pack as 16 bit unsigned short
# add 2 byte extended payload length
bytes += struct.pack('!H', self.actual_payload_length)
- elif self.actual_payload_length < CONST.MAX_64_BIT_INT:
+ elif self.actual_payload_length < CONST.MAX_64_BIT_INT:
# '!Q' = pack as 64 bit unsigned long long
# add 8 bytes extended payload length
bytes += struct.pack('!Q', self.actual_payload_length)
@@ -225,10 +225,10 @@ class Frame(object):
def from_file(cls, reader):
"""
read a websockets frame sent by a server or client
-
- reader is a "file like" object that could be backed by a network stream or a disk
- or an in memory stream reader
- """
+
+ reader is a "file like" object that could be backed by a network
+ stream or a disk or an in memory stream reader
+ """
first_byte = utils.bytes_to_int(reader.read(1))
second_byte = utils.bytes_to_int(reader.read(1))
@@ -336,7 +336,7 @@ def create_server_handshake(key):
headers = [
('Connection', 'Upgrade'),
('Upgrade', 'websocket'),
- ('Sec-WebSocket-Accept', create_server_nounce(key))
+ ('Sec-WebSocket-Accept', create_server_nonce(key))
]
request = "HTTP/1.1 101 Switching Protocols"
return build_handshake(headers, request)
@@ -406,11 +406,11 @@ def headers_from_http_message(http_message):
)
-def create_server_nounce(client_nounce):
+def create_server_nonce(client_nonce):
return base64.b64encode(
- hashlib.sha1(client_nounce + websockets_magic).hexdigest().decode('hex')
+ hashlib.sha1(client_nonce + websockets_magic).hexdigest().decode('hex')
)
-def create_client_nounce():
+def create_client_nonce():
return base64.b64encode(os.urandom(16)).decode('utf-8')