diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-10-16 21:17:39 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-10-16 21:17:39 -0700 |
commit | 9389601025415c47d5efaa6ac371ddca6d543f48 (patch) | |
tree | 7a2fa561d702425ccec7edbc5a35108523e3f33d /mitmproxy/contrib | |
parent | ae3ff8ee1edc646e7a640219df1a312c27f7c339 (diff) | |
parent | 5a07892bfc58472c1b651f66deaf03176bfe79df (diff) | |
download | mitmproxy-9389601025415c47d5efaa6ac371ddca6d543f48.tar.gz mitmproxy-9389601025415c47d5efaa6ac371ddca6d543f48.tar.bz2 mitmproxy-9389601025415c47d5efaa6ac371ddca6d543f48.zip |
Merge branch 'such-types'
Diffstat (limited to 'mitmproxy/contrib')
-rw-r--r-- | mitmproxy/contrib/tnetstring.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/mitmproxy/contrib/tnetstring.py b/mitmproxy/contrib/tnetstring.py index 22ecab65..95157475 100644 --- a/mitmproxy/contrib/tnetstring.py +++ b/mitmproxy/contrib/tnetstring.py @@ -41,13 +41,12 @@ all other strings are returned as plain bytes. """ import collections -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. """ @@ -59,8 +58,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. @@ -68,8 +66,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. @@ -152,16 +149,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 @@ -188,8 +183,14 @@ def load(file_handle): return parse(data_type, data) +<<<<<<< HEAD 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) +>>>>>>> such-types if data_type == ord(b','): return data if data_type == ord(b';'): @@ -231,8 +232,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 |