aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
Diffstat (limited to 'netlib')
-rw-r--r--netlib/http2/__init__.py1
-rw-r--r--netlib/http2/frame.py55
-rw-r--r--netlib/http_cookies.py8
-rw-r--r--netlib/http_uastrings.py24
-rw-r--r--netlib/tcp.py8
-rw-r--r--netlib/utils.py2
-rw-r--r--netlib/websockets.py16
7 files changed, 56 insertions, 58 deletions
diff --git a/netlib/http2/__init__.py b/netlib/http2/__init__.py
index 92897b5d..5acf7696 100644
--- a/netlib/http2/__init__.py
+++ b/netlib/http2/__init__.py
@@ -1,3 +1,2 @@
-
from frame import *
from protocol import *
diff --git a/netlib/http2/frame.py b/netlib/http2/frame.py
index 98ced904..b4783a02 100644
--- a/netlib/http2/frame.py
+++ b/netlib/http2/frame.py
@@ -1,6 +1,5 @@
import sys
import struct
-from functools import reduce
from hpack.hpack import Encoder, Decoder
from .. import utils
@@ -52,7 +51,7 @@ class Frame(object):
self.stream_id = stream_id
@classmethod
- def _check_frame_size(self, length, state):
+ def _check_frame_size(cls, length, state):
if state:
settings = state.http2_settings
else:
@@ -67,7 +66,7 @@ class Frame(object):
length, max_frame_size))
@classmethod
- def from_file(self, fp, state=None):
+ def from_file(cls, fp, state=None):
"""
read a HTTP/2 frame sent by a server or client
fp is a "file like" object that could be backed by a network
@@ -83,7 +82,7 @@ class Frame(object):
if raw_header[:4] == b'HTTP': # pragma no cover
print >> sys.stderr, "WARNING: This looks like an HTTP/1 connection!"
- self._check_frame_size(length, state)
+ cls._check_frame_size(length, state)
payload = fp.safe_read(length)
return FRAMES[fields[2]].from_bytes(
@@ -143,10 +142,10 @@ class DataFrame(Frame):
self.pad_length = pad_length
@classmethod
- def from_bytes(self, state, length, flags, stream_id, payload):
- f = self(state=state, length=length, flags=flags, stream_id=stream_id)
+ def from_bytes(cls, state, length, flags, stream_id, payload):
+ f = cls(state=state, length=length, flags=flags, stream_id=stream_id)
- if f.flags & self.FLAG_PADDED:
+ if f.flags & Frame.FLAG_PADDED:
f.pad_length = struct.unpack('!B', payload[0])[0]
f.payload = payload[1:-f.pad_length]
else:
@@ -201,16 +200,16 @@ class HeadersFrame(Frame):
self.weight = weight
@classmethod
- def from_bytes(self, state, length, flags, stream_id, payload):
- f = self(state=state, length=length, flags=flags, stream_id=stream_id)
+ def from_bytes(cls, state, length, flags, stream_id, payload):
+ f = cls(state=state, length=length, flags=flags, stream_id=stream_id)
- if f.flags & self.FLAG_PADDED:
+ if f.flags & Frame.FLAG_PADDED:
f.pad_length = struct.unpack('!B', payload[0])[0]
f.header_block_fragment = payload[1:-f.pad_length]
else:
f.header_block_fragment = payload[0:]
- if f.flags & self.FLAG_PRIORITY:
+ if f.flags & Frame.FLAG_PRIORITY:
f.stream_dependency, f.weight = struct.unpack(
'!LB', f.header_block_fragment[:5])
f.exclusive = bool(f.stream_dependency >> 31)
@@ -276,8 +275,8 @@ class PriorityFrame(Frame):
self.weight = weight
@classmethod
- def from_bytes(self, state, length, flags, stream_id, payload):
- f = self(state=state, length=length, flags=flags, stream_id=stream_id)
+ def from_bytes(cls, state, length, flags, stream_id, payload):
+ f = cls(state=state, length=length, flags=flags, stream_id=stream_id)
f.stream_dependency, f.weight = struct.unpack('!LB', payload)
f.exclusive = bool(f.stream_dependency >> 31)
@@ -322,8 +321,8 @@ class RstStreamFrame(Frame):
self.error_code = error_code
@classmethod
- def from_bytes(self, state, length, flags, stream_id, payload):
- f = self(state=state, length=length, flags=flags, stream_id=stream_id)
+ def from_bytes(cls, state, length, flags, stream_id, payload):
+ f = cls(state=state, length=length, flags=flags, stream_id=stream_id)
f.error_code = struct.unpack('!L', payload)[0]
return f
@@ -366,8 +365,8 @@ class SettingsFrame(Frame):
self.settings = settings
@classmethod
- def from_bytes(self, state, length, flags, stream_id, payload):
- f = self(state=state, length=length, flags=flags, stream_id=stream_id)
+ def from_bytes(cls, state, length, flags, stream_id, payload):
+ f = cls(state=state, length=length, flags=flags, stream_id=stream_id)
for i in xrange(0, len(payload), 6):
identifier, value = struct.unpack("!HL", payload[i:i + 6])
@@ -417,10 +416,10 @@ class PushPromiseFrame(Frame):
self.header_block_fragment = header_block_fragment
@classmethod
- def from_bytes(self, state, length, flags, stream_id, payload):
- f = self(state=state, length=length, flags=flags, stream_id=stream_id)
+ def from_bytes(cls, state, length, flags, stream_id, payload):
+ f = cls(state=state, length=length, flags=flags, stream_id=stream_id)
- if f.flags & self.FLAG_PADDED:
+ if f.flags & Frame.FLAG_PADDED:
f.pad_length, f.promised_stream = struct.unpack('!BL', payload[:5])
f.header_block_fragment = payload[5:-f.pad_length]
else:
@@ -480,8 +479,8 @@ class PingFrame(Frame):
self.payload = payload
@classmethod
- def from_bytes(self, state, length, flags, stream_id, payload):
- f = self(state=state, length=length, flags=flags, stream_id=stream_id)
+ def from_bytes(cls, state, length, flags, stream_id, payload):
+ f = cls(state=state, length=length, flags=flags, stream_id=stream_id)
f.payload = payload
return f
@@ -517,8 +516,8 @@ class GoAwayFrame(Frame):
self.data = data
@classmethod
- def from_bytes(self, state, length, flags, stream_id, payload):
- f = self(state=state, length=length, flags=flags, stream_id=stream_id)
+ def from_bytes(cls, state, length, flags, stream_id, payload):
+ f = cls(state=state, length=length, flags=flags, stream_id=stream_id)
f.last_stream, f.error_code = struct.unpack("!LL", payload[:8])
f.last_stream &= 0x7FFFFFFF
@@ -558,8 +557,8 @@ class WindowUpdateFrame(Frame):
self.window_size_increment = window_size_increment
@classmethod
- def from_bytes(self, state, length, flags, stream_id, payload):
- f = self(state=state, length=length, flags=flags, stream_id=stream_id)
+ def from_bytes(cls, state, length, flags, stream_id, payload):
+ f = cls(state=state, length=length, flags=flags, stream_id=stream_id)
f.window_size_increment = struct.unpack("!L", payload)[0]
f.window_size_increment &= 0x7FFFFFFF
@@ -592,8 +591,8 @@ class ContinuationFrame(Frame):
self.header_block_fragment = header_block_fragment
@classmethod
- def from_bytes(self, state, length, flags, stream_id, payload):
- f = self(state=state, length=length, flags=flags, stream_id=stream_id)
+ def from_bytes(cls, state, length, flags, stream_id, payload):
+ f = cls(state=state, length=length, flags=flags, stream_id=stream_id)
f.header_block_fragment = payload
return f
diff --git a/netlib/http_cookies.py b/netlib/http_cookies.py
index 5cb39e5c..b7311714 100644
--- a/netlib/http_cookies.py
+++ b/netlib/http_cookies.py
@@ -158,7 +158,7 @@ def _parse_set_cookie_pairs(s):
return pairs
-def parse_set_cookie_header(str):
+def parse_set_cookie_header(line):
"""
Parse a Set-Cookie header value
@@ -166,7 +166,7 @@ def parse_set_cookie_header(str):
ODictCaseless set of attributes. No attempt is made to parse attribute
values - they are treated purely as strings.
"""
- pairs = _parse_set_cookie_pairs(str)
+ pairs = _parse_set_cookie_pairs(line)
if pairs:
return pairs[0][0], pairs[0][1], odict.ODictCaseless(pairs[1:])
@@ -180,12 +180,12 @@ def format_set_cookie_header(name, value, attrs):
return _format_set_cookie_pairs(pairs)
-def parse_cookie_header(str):
+def parse_cookie_header(line):
"""
Parse a Cookie header value.
Returns a (possibly empty) ODict object.
"""
- pairs, off = _read_pairs(str)
+ pairs, off = _read_pairs(line)
return odict.ODict(pairs)
diff --git a/netlib/http_uastrings.py b/netlib/http_uastrings.py
index d9869531..c1ef557c 100644
--- a/netlib/http_uastrings.py
+++ b/netlib/http_uastrings.py
@@ -5,40 +5,42 @@ from __future__ import (absolute_import, print_function, division)
kept reasonably current to reflect common usage.
"""
+# pylint: line-too-long
+
# A collection of (name, shortcut, string) tuples.
UASTRINGS = [
("android",
"a",
- "Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Nexus 7 Build/JRO03D) AFL/01.04.02"),
+ "Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Nexus 7 Build/JRO03D) AFL/01.04.02"), # noqa
("blackberry",
"l",
- "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+"),
+ "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+"), # noqa
("bingbot",
"b",
- "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"),
+ "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"), # noqa
("chrome",
"c",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1"),
+ "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1"), # noqa
("firefox",
"f",
- "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1"),
+ "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1"), # noqa
("googlebot",
"g",
- "Googlebot/2.1 (+http://www.googlebot.com/bot.html)"),
+ "Googlebot/2.1 (+http://www.googlebot.com/bot.html)"), # noqa
("ie9",
"i",
- "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))"),
+ "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))"), # noqa
("ipad",
"p",
- "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3"),
+ "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3"), # noqa
("iphone",
"h",
- "Mozilla/5.0 (iPhone; CPU iPhone OS 4_2_1 like Mac OS X) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5",
- ),
+ "Mozilla/5.0 (iPhone; CPU iPhone OS 4_2_1 like Mac OS X) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5"), # noqa
("safari",
"s",
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10")]
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10"), # noqa
+]
def get_by_shortcut(s):
diff --git a/netlib/tcp.py b/netlib/tcp.py
index cafc3ed9..a1d1fe62 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -292,7 +292,7 @@ def close_socket(sock):
"""
try:
# We already indicate that we close our end.
- # may raise "Transport endpoint is not connected" on Linux
+ # may raise "Transport endpoint is not connected" on Linux
sock.shutdown(socket.SHUT_WR)
# Section 4.2.2.13 of RFC 1122 tells us that a close() with any pending
@@ -363,10 +363,6 @@ class _Connection(object):
except SSL.Error:
pass
- """
- Creates an SSL Context.
- """
-
def _create_ssl_context(self,
method=SSLv23_METHOD,
options=(SSL.OP_NO_SSLv2 | SSL.OP_NO_SSLv3 | SSL.OP_CIPHER_SERVER_PREFERENCE | SSL.OP_NO_COMPRESSION),
@@ -378,6 +374,8 @@ class _Connection(object):
alpn_select=None,
):
"""
+ Creates an SSL Context.
+
:param method: One of SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, TLSv1_METHOD, TLSv1_1_METHOD, or TLSv1_2_METHOD
:param options: A bit field consisting of OpenSSL.SSL.OP_* values
:param verify_options: A bit field consisting of OpenSSL.SSL.VERIFY_* values
diff --git a/netlib/utils.py b/netlib/utils.py
index 9c5404e6..ac42bd53 100644
--- a/netlib/utils.py
+++ b/netlib/utils.py
@@ -67,7 +67,7 @@ def getbit(byte, offset):
return True
-class BiDi:
+class BiDi(object):
"""
A wee utility class for keeping bi-directional mappings, like field
diff --git a/netlib/websockets.py b/netlib/websockets.py
index 346adf1b..c45db4df 100644
--- a/netlib/websockets.py
+++ b/netlib/websockets.py
@@ -35,7 +35,7 @@ OPCODE = utils.BiDi(
)
-class Masker:
+class Masker(object):
"""
Data sent from the server must be masked to prevent malicious clients
@@ -94,15 +94,15 @@ def server_handshake_headers(key):
)
-def make_length_code(len):
+def make_length_code(length):
"""
A websockets frame contains an initial length_code, and an optional
extended length code to represent the actual length if length code is
larger than 125
"""
- if len <= 125:
- return len
- elif len >= 126 and len <= 65535:
+ if length <= 125:
+ return length
+ elif length >= 126 and length <= 65535:
return 126
else:
return 127
@@ -129,7 +129,7 @@ def create_server_nonce(client_nonce):
DEFAULT = object()
-class FrameHeader:
+class FrameHeader(object):
def __init__(
self,
@@ -216,7 +216,7 @@ class FrameHeader:
return b
@classmethod
- def from_file(klass, fp):
+ def from_file(cls, fp):
"""
read a websockets frame header
"""
@@ -248,7 +248,7 @@ class FrameHeader:
else:
masking_key = None
- return klass(
+ return cls(
fin=fin,
rsv1=rsv1,
rsv2=rsv2,