diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-10-16 20:56:46 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-10-16 20:56:46 -0700 |
commit | 5a07892bfc58472c1b651f66deaf03176bfe79df (patch) | |
tree | 6b6a7f449721c3b3515c9ae36e5be03b610c7967 /mitmproxy/contrib | |
parent | 3fbce7e981cab5d20b3ef17a50f14b34e8c60fa3 (diff) | |
download | mitmproxy-5a07892bfc58472c1b651f66deaf03176bfe79df.tar.gz mitmproxy-5a07892bfc58472c1b651f66deaf03176bfe79df.tar.bz2 mitmproxy-5a07892bfc58472c1b651f66deaf03176bfe79df.zip |
py2--: inline type info
Diffstat (limited to 'mitmproxy/contrib')
-rw-r--r-- | mitmproxy/contrib/tnetstring.py | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/mitmproxy/contrib/tnetstring.py b/mitmproxy/contrib/tnetstring.py index f5e1d5c1..eead7021 100644 --- a/mitmproxy/contrib/tnetstring.py +++ b/mitmproxy/contrib/tnetstring.py @@ -42,13 +42,12 @@ all other strings are returned as plain bytes. import collections import six -from typing import io, Union, Tuple # noqa +from typing import io, Union, Tuple TSerializable = Union[None, bool, int, float, bytes, list, tuple, dict] -def dumps(value): - # type: (TSerializable) -> bytes +def dumps(value: TSerializable) -> bytes: """ This function dumps a python object as a tnetstring. """ @@ -60,8 +59,7 @@ def dumps(value): return b''.join(q) -def dump(value, file_handle): - # type: (TSerializable, io.BinaryIO) -> None +def dump(value: TSerializable, file_handle: io.BinaryIO) -> None: """ This function dumps a python object as a tnetstring and writes it to the given file. @@ -69,8 +67,7 @@ def dump(value, file_handle): file_handle.write(dumps(value)) -def _rdumpq(q, size, value): - # type: (collections.deque, int, TSerializable) -> int +def _rdumpq(q: collections.deque, size: int, value: TSerializable) -> int: """ Dump value as a tnetstring, to a deque instance, last chunks first. @@ -153,16 +150,14 @@ def _rdumpq(q, size, value): raise ValueError("unserializable object: {} ({})".format(value, type(value))) -def loads(string): - # type: (bytes) -> TSerializable +def loads(string: bytes) -> TSerializable: """ This function parses a tnetstring into a python object. """ return pop(string)[0] -def load(file_handle): - # type: (io.BinaryIO) -> TSerializable +def load(file_handle: io.BinaryIO) -> TSerializable: """load(file) -> object This function reads a tnetstring from a file and parses it into a @@ -189,8 +184,7 @@ def load(file_handle): return parse(data_type, data) -def parse(data_type, data): - # type: (int, bytes) -> TSerializable +def parse(data_type: int, data: bytes) -> TSerializable: if six.PY2: data_type = ord(data_type) if data_type == ord(b','): @@ -236,8 +230,7 @@ def parse(data_type, data): raise ValueError("unknown type tag: {}".format(data_type)) -def pop(data): - # type: (bytes) -> Tuple[TSerializable, bytes] +def pop(data: bytes) -> Tuple[TSerializable, bytes]: """ This function parses a tnetstring into a python object. It returns a tuple giving the parsed object and a string |