Show More
@@ -32,37 +32,22 b' import sys' | |||||
32 | """Compatibility module across Python 2 and 3.""" |
|
32 | """Compatibility module across Python 2 and 3.""" | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | PYTHON2 = sys.version_info < (3, 0) |
|
|||
36 | PYTHON3 = sys.version_info >= (3, 0) |
|
35 | PYTHON3 = sys.version_info >= (3, 0) | |
37 |
|
36 | |||
38 | # This is adapted from https://bitbucket.org/gutworth/six, and used under the |
|
37 | # This is adapted from https://bitbucket.org/gutworth/six, and used under the | |
39 | # MIT license. See LICENSE for a full copyright notice. |
|
38 | # MIT license. See LICENSE for a full copyright notice. | |
40 | if PYTHON3: |
|
|||
41 |
|
||||
42 | def reraise(tp, value, tb=None): |
|
|||
43 | try: |
|
|||
44 | if value is None: |
|
|||
45 | value = tp() |
|
|||
46 | if value.__traceback__ is not tb: |
|
|||
47 | raise value.with_traceback(tb) |
|
|||
48 | raise value |
|
|||
49 | finally: |
|
|||
50 | value = None |
|
|||
51 | tb = None |
|
|||
52 |
|
39 | |||
53 |
|
40 | |||
54 | else: |
|
|||
55 | exec( |
|
|||
56 | """ |
|
|||
57 | def reraise(tp, value, tb=None): |
|
41 | def reraise(tp, value, tb=None): | |
58 | try: |
|
42 | try: | |
59 |
|
|
43 | if value is None: | |
|
44 | value = tp() | |||
|
45 | if value.__traceback__ is not tb: | |||
|
46 | raise value.with_traceback(tb) | |||
|
47 | raise value | |||
60 | finally: |
|
48 | finally: | |
|
49 | value = None | |||
61 | tb = None |
|
50 | tb = None | |
62 | """.strip() |
|
51 | ||
63 | ) |
|
|||
64 |
|
52 | |||
65 | if PYTHON3: |
|
53 | UNICODE = str | |
66 | UNICODE = str |
|
|||
67 | else: |
|
|||
68 | UNICODE = unicode # noqa: F821 We handled versioning above |
|
@@ -51,17 +51,15 b' BSER_TEMPLATE = b"\\x0b"' | |||||
51 | BSER_SKIP = b"\x0c" |
|
51 | BSER_SKIP = b"\x0c" | |
52 | BSER_UTF8STRING = b"\x0d" |
|
52 | BSER_UTF8STRING = b"\x0d" | |
53 |
|
53 | |||
54 | if compat.PYTHON3: |
|
54 | STRING_TYPES = (str, bytes) | |
55 | STRING_TYPES = (str, bytes) |
|
55 | unicode = str | |
56 | unicode = str |
|
56 | ||
57 |
|
57 | |||
58 |
|
|
58 | def tobytes(i): | |
59 |
|
|
59 | return str(i).encode("ascii") | |
60 |
|
60 | |||
61 | long = int |
|
61 | ||
62 | else: |
|
62 | long = int | |
63 | STRING_TYPES = (unicode, str) |
|
|||
64 | tobytes = bytes |
|
|||
65 |
|
63 | |||
66 | # Leave room for the serialization header, which includes |
|
64 | # Leave room for the serialization header, which includes | |
67 | # our overall length. To make things simpler, we'll use an |
|
65 | # our overall length. To make things simpler, we'll use an | |
@@ -87,7 +85,7 b' def _int_size(x):' | |||||
87 | def _buf_pos(buf, pos): |
|
85 | def _buf_pos(buf, pos): | |
88 | ret = buf[pos] |
|
86 | ret = buf[pos] | |
89 | # Normalize the return type to bytes |
|
87 | # Normalize the return type to bytes | |
90 |
if |
|
88 | if not isinstance(ret, bytes): | |
91 | ret = bytes((ret,)) |
|
89 | ret = bytes((ret,)) | |
92 | return ret |
|
90 | return ret | |
93 |
|
91 | |||
@@ -250,10 +248,7 b' class _bser_buffer:' | |||||
250 | else: |
|
248 | else: | |
251 | raise RuntimeError("Cannot represent this mapping value") |
|
249 | raise RuntimeError("Cannot represent this mapping value") | |
252 | self.wpos += needed |
|
250 | self.wpos += needed | |
253 | if compat.PYTHON3: |
|
251 | iteritems = val.items() | |
254 | iteritems = val.items() |
|
|||
255 | else: |
|
|||
256 | iteritems = val.iteritems() # noqa: B301 Checked version above |
|
|||
257 | for k, v in iteritems: |
|
252 | for k, v in iteritems: | |
258 | self.append_string(k) |
|
253 | self.append_string(k) | |
259 | self.append_recursive(v) |
|
254 | self.append_recursive(v) |
General Comments 0
You need to be logged in to leave comments.
Login now