More type annotations.

This commit is contained in:
Itamar Turner-Trauring 2021-02-22 10:09:16 -05:00
parent 595ce94f2b
commit c26d94b9b3

View File

@ -14,14 +14,19 @@ if PY2:
from past.builtins import long
try:
from typing import Optional, Tuple, List
except ImportError:
pass
def netstring(s):
def netstring(s): # type: (bytes) -> bytes
assert isinstance(s, bytes), s # no unicode here
return b"%d:%s," % (len(s), s,)
def split_netstring(data, numstrings,
position=0,
required_trailer=None):
required_trailer=None): # type (bytes, init, int, Optional[bytes]) -> Tuple[List[bytes], int]
"""like string.split(), but extracts netstrings. Ignore all bytes of data
before the 'position' byte. Return a tuple of (list of elements (numstrings
in length), new position index). The new position index points to the first