mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-21 12:05:03 +00:00
Futurize part of port to Python 3.
This commit is contained in:
parent
60a1a24423
commit
bb7d31c5e4
@ -22,6 +22,7 @@ PORTED_MODULES = [
|
||||
"allmydata.util.humanreadable",
|
||||
"allmydata.util.mathutil",
|
||||
"allmydata.util.namespace",
|
||||
"allmydata.util.netstring",
|
||||
"allmydata.util.pollmixin",
|
||||
"allmydata.util._python3",
|
||||
]
|
||||
|
@ -1,5 +1,20 @@
|
||||
"""
|
||||
Netstring encoding and decoding.
|
||||
|
||||
Ported to Python 3.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
from past.builtins import long
|
||||
|
||||
|
||||
def netstring(s):
|
||||
assert isinstance(s, bytes), s # no unicode here
|
||||
return b"%d:%s," % (len(s), s,)
|
||||
@ -13,9 +28,9 @@ def split_netstring(data, numstrings,
|
||||
byte which was not consumed (the 'required_trailer', if any, counts as
|
||||
consumed). If 'required_trailer' is not None, throw ValueError if leftover
|
||||
data does not exactly equal 'required_trailer'."""
|
||||
assert type(data) == bytes
|
||||
assert type(required_trailer) in (type(None), bytes)
|
||||
assert type(position) in (int, long), (repr(position), type(position))
|
||||
assert isinstance(data, bytes)
|
||||
assert required_trailer is None or isinstance(required_trailer, bytes)
|
||||
assert isinstance(position, (int, long)), (repr(position), type(position))
|
||||
elements = []
|
||||
assert numstrings >= 0
|
||||
while position < len(data):
|
||||
|
Loading…
Reference in New Issue
Block a user