| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -220,9 +220,9 @@ and `raw=True` options. | |||
| 220 | 220 | ||
| 221 | 221 | ```pycon | |
| 222 | 222 | >>> import msgpack | |
| 223 | - >>> msgpack.unpackb(msgpack.packb([b'spam', u'eggs'], use_bin_type=False), raw=True) | ||
| 223 | + >>> msgpack.unpackb(msgpack.packb([b'spam', 'eggs'], use_bin_type=False), raw=True) | ||
| 224 | 224 | [b'spam', b'eggs'] | |
| 225 | - >>> msgpack.unpackb(msgpack.packb([b'spam', u'eggs'], use_bin_type=True), raw=False) | ||
| 225 | + >>> msgpack.unpackb(msgpack.packb([b'spam', 'eggs'], use_bin_type=True), raw=False) | ||
| 226 | 226 | [b'spam', 'eggs'] | |
| 227 | 227 | ``` | |
| 228 | 228 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,8 +40,8 @@ | |||
| 40 | 40 | master_doc = "index" | |
| 41 | 41 | ||
| 42 | 42 | # General information about the project. | |
| 43 | - project = u"msgpack" | ||
| 44 | - copyright = u"Inada Naoki" | ||
| 43 | + project = "msgpack" | ||
| 44 | + copyright = "Inada Naoki" | ||
| 45 | 45 | ||
| 46 | 46 | # The version info for the project you're documenting, acts as replacement for | |
| 47 | 47 | # |version| and |release|, also used in various other places throughout the | |
@@ -181,7 +181,7 @@ | |||
| 181 | 181 | # Grouping the document tree into LaTeX files. List of tuples | |
| 182 | 182 | # (source start file, target name, title, author, documentclass [howto/manual]). | |
| 183 | 183 | latex_documents = [ | |
| 184 | - ("index", "msgpack.tex", u"msgpack Documentation", u"Author", "manual"), | ||
| 184 | + ("index", "msgpack.tex", "msgpack Documentation", "Author", "manual"), | ||
| 185 | 185 | ] | |
| 186 | 186 | ||
| 187 | 187 | # The name of an image file (relative to this directory) to place at the top of | |
@@ -209,7 +209,7 @@ | |||
| 209 | 209 | ||
| 210 | 210 | # One entry per manual page. List of tuples | |
| 211 | 211 | # (source start file, name, description, authors, manual section). | |
| 212 | - man_pages = [("index", "msgpack", u"msgpack Documentation", [u"Author"], 1)] | ||
| 212 | + man_pages = [("index", "msgpack", "msgpack Documentation", ["Author"], 1)] | ||
| 213 | 213 | ||
| 214 | 214 | # If true, show URL addresses after external links. | |
| 215 | 215 | # man_show_urls = False | |
@@ -224,8 +224,8 @@ | |||
| 224 | 224 | ( | |
| 225 | 225 | "index", | |
| 226 | 226 | "msgpack", | |
| 227 | - u"msgpack Documentation", | ||
| 228 | - u"Author", | ||
| 227 | + "msgpack Documentation", | ||
| 228 | + "Author", | ||
| 229 | 229 | "msgpack", | |
| 230 | 230 | "One line description of project.", | |
| 231 | 231 | "Miscellaneous", | |
@@ -245,10 +245,10 @@ | |||
| 245 | 245 | # -- Options for Epub output --------------------------------------------------- | |
| 246 | 246 | ||
| 247 | 247 | # Bibliographic Dublin Core info. | |
| 248 | - epub_title = u"msgpack" | ||
| 249 | - epub_author = u"Author" | ||
| 250 | - epub_publisher = u"Author" | ||
| 251 | - epub_copyright = u"2013, Author" | ||
| 248 | + epub_title = "msgpack" | ||
| 249 | + epub_author = "Author" | ||
| 250 | + epub_publisher = "Author" | ||
| 251 | + epub_copyright = "2013, Author" | ||
| 252 | 252 | ||
| 253 | 253 | # The language of the text. It defaults to the language option | |
| 254 | 254 | # or en if the language is not set. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ | |||
| 10 | 10 | __version__ = "1.0.5" | |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | - if os.environ.get("MSGPACK_PUREPYTHON") or sys.version_info[0] == 2: | ||
| 13 | + if os.environ.get("MSGPACK_PUREPYTHON"): | ||
| 14 | 14 | from .fallback import Packer, unpackb, Unpacker | |
| 15 | 15 | else: | |
| 16 | 16 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,7 +98,6 @@ cdef class Packer(object): | |||
| 98 | 98 | If set to true, datetime with tzinfo is packed into Timestamp type. | |
| 99 | 99 | Note that the tzinfo is stripped in the timestamp. | |
| 100 | 100 | You can get UTC datetime with `timestamp=3` option of the Unpacker. | |
| 101 | - (Python 2 is not supported). | ||
| 102 | 101 | ||
| 103 | 102 | :param str unicode_errors: | |
| 104 | 103 | The error handler for encoding unicode. (default: 'strict') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -236,7 +236,7 @@ cdef class Unpacker(object): | |||
| 236 | 236 | 0 - Timestamp | |
| 237 | 237 | 1 - float (Seconds from the EPOCH) | |
| 238 | 238 | 2 - int (Nanoseconds from the EPOCH) | |
| 239 | - 3 - datetime.datetime (UTC). Python 2 is not supported. | ||
| 239 | + 3 - datetime.datetime (UTC). | ||
| 240 | 240 | ||
| 241 | 241 | :param bool strict_map_key: | |
| 242 | 242 | If true (default), only str or bytes are accepted for map (dict) keys. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,19 +5,6 @@ | |||
| 5 | 5 | import struct | |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | - PY2 = sys.version_info[0] == 2 | ||
| 9 | - | ||
| 10 | - if PY2: | ||
| 11 | - int_types = (int, long) | ||
| 12 | - _utc = None | ||
| 13 | - else: | ||
| 14 | - int_types = int | ||
| 15 | - try: | ||
| 16 | - _utc = datetime.timezone.utc | ||
| 17 | - except AttributeError: | ||
| 18 | - _utc = datetime.timezone(datetime.timedelta(0)) | ||
| 19 | - | ||
| 20 | - | ||
| 21 | 8 | class ExtType(namedtuple("ExtType", "code data")): | |
| 22 | 9 | """ExtType represents ext type in msgpack.""" | |
| 23 | 10 | ||
@@ -55,9 +42,9 @@ def __init__(self, seconds, nanoseconds=0): | |||
| 55 | 42 | ||
| 56 | 43 | Note: Negative times (before the UNIX epoch) are represented as negative seconds + positive ns. | |
| 57 | 44 | """ | |
| 58 | - if not isinstance(seconds, int_types): | ||
| 45 | + if not isinstance(seconds, int): | ||
| 59 | 46 | raise TypeError("seconds must be an integer") | |
| 60 | - if not isinstance(nanoseconds, int_types): | ||
| 47 | + if not isinstance(nanoseconds, int): | ||
| 61 | 48 | raise TypeError("nanoseconds must be an integer") | |
| 62 | 49 | if not (0 <= nanoseconds < 10**9): | |
| 63 | 50 | raise ValueError( | |
@@ -174,20 +161,17 @@ def to_unix_nano(self): | |||
| 174 | 161 | def to_datetime(self): | |
| 175 | 162 | """Get the timestamp as a UTC datetime. | |
| 176 | 163 | ||
| 177 | - Python 2 is not supported. | ||
| 178 | - | ||
| 179 | 164 | :rtype: datetime. | |
| 180 | 165 | """ | |
| 181 | - return datetime.datetime.fromtimestamp(0, _utc) + datetime.timedelta( | ||
| 166 | + utc = datetime.timezone.utc | ||
| 167 | + return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta( | ||
| 182 | 168 | seconds=self.to_unix() | |
| 183 | 169 | ) | |
| 184 | 170 | ||
| 185 | 171 | @staticmethod | |
| 186 | 172 | def from_datetime(dt): | |
| 187 | 173 | """Create a Timestamp from datetime with tzinfo. | |
| 188 | 174 | ||
| 189 | - Python 2 is not supported. | ||
| 190 | - | ||
| 191 | 175 | :rtype: Timestamp | |
| 192 | 176 | """ | |
| 193 | 177 | return Timestamp.from_unix(dt.timestamp()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,22 +4,6 @@ | |||
| 4 | 4 | import struct | |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | - PY2 = sys.version_info[0] == 2 | ||
| 8 | - if PY2: | ||
| 9 | - int_types = (int, long) | ||
| 10 | - | ||
| 11 | - def dict_iteritems(d): | ||
| 12 | - return d.iteritems() | ||
| 13 | - | ||
| 14 | - else: | ||
| 15 | - int_types = int | ||
| 16 | - unicode = str | ||
| 17 | - xrange = range | ||
| 18 | - | ||
| 19 | - def dict_iteritems(d): | ||
| 20 | - return d.items() | ||
| 21 | - | ||
| 22 | - | ||
| 23 | 7 | if sys.version_info < (3, 5): | |
| 24 | 8 | # Ugly hack... | |
| 25 | 9 | RecursionError = RuntimeError | |
@@ -134,15 +118,6 @@ def unpackb(packed, **kwargs): | |||
| 134 | 118 | return ret | |
| 135 | 119 | ||
| 136 | 120 | ||
| 137 | - if sys.version_info < (2, 7, 6): | ||
| 138 | - | ||
| 139 | - def _unpack_from(f, b, o=0): | ||
| 140 | - """Explicit type cast for legacy struct.unpack_from""" | ||
| 141 | - return struct.unpack_from(f, bytes(b), o) | ||
| 142 | - | ||
| 143 | - else: | ||
| 144 | - _unpack_from = struct.unpack_from | ||
| 145 | - | ||
| 146 | 121 | _NO_FORMAT_USED = "" | |
| 147 | 122 | _MSGPACK_HEADERS = { | |
| 148 | 123 | 0xC4: (1, _NO_FORMAT_USED, TYPE_BIN), | |
@@ -202,7 +177,7 @@ class Unpacker(object): | |||
| 202 | 177 | 0 - Timestamp | |
| 203 | 178 | 1 - float (Seconds from the EPOCH) | |
| 204 | 179 | 2 - int (Nanoseconds from the EPOCH) | |
| 205 | - 3 - datetime.datetime (UTC). Python 2 is not supported. | ||
| 180 | + 3 - datetime.datetime (UTC). | ||
| 206 | 181 | ||
| 207 | 182 | :param bool strict_map_key: | |
| 208 | 183 | If true (default), only str or bytes are accepted for map (dict) keys. | |
@@ -477,7 +452,7 @@ def _read_header(self): | |||
| 477 | 452 | size, fmt, typ = _MSGPACK_HEADERS[b] | |
| 478 | 453 | self._reserve(size) | |
| 479 | 454 | if len(fmt) > 0: | |
| 480 | - n = _unpack_from(fmt, self._buffer, self._buff_i)[0] | ||
| 455 | + n = struct.unpack_from(fmt, self._buffer, self._buff_i)[0] | ||
| 481 | 456 | else: | |
| 482 | 457 | n = self._buffer[self._buff_i] | |
| 483 | 458 | self._buff_i += size | |
@@ -487,7 +462,7 @@ def _read_header(self): | |||
| 487 | 462 | elif 0xC7 <= b <= 0xC9: | |
| 488 | 463 | size, fmt, typ = _MSGPACK_HEADERS[b] | |
| 489 | 464 | self._reserve(size) | |
| 490 | - L, n = _unpack_from(fmt, self._buffer, self._buff_i) | ||
| 465 | + L, n = struct.unpack_from(fmt, self._buffer, self._buff_i) | ||
| 491 | 466 | self._buff_i += size | |
| 492 | 467 | if L > self._max_ext_len: | |
| 493 | 468 | raise ValueError("%s exceeds max_ext_len(%s)" % (L, self._max_ext_len)) | |
@@ -496,7 +471,7 @@ def _read_header(self): | |||
| 496 | 471 | size, fmt = _MSGPACK_HEADERS[b] | |
| 497 | 472 | self._reserve(size) | |
| 498 | 473 | if len(fmt) > 0: | |
| 499 | - obj = _unpack_from(fmt, self._buffer, self._buff_i)[0] | ||
| 474 | + obj = struct.unpack_from(fmt, self._buffer, self._buff_i)[0] | ||
| 500 | 475 | else: | |
| 501 | 476 | obj = self._buffer[self._buff_i] | |
| 502 | 477 | self._buff_i += size | |
@@ -507,13 +482,13 @@ def _read_header(self): | |||
| 507 | 482 | "%s exceeds max_ext_len(%s)" % (size, self._max_ext_len) | |
| 508 | 483 | ) | |
| 509 | 484 | self._reserve(size + 1) | |
| 510 | - n, obj = _unpack_from(fmt, self._buffer, self._buff_i) | ||
| 485 | + n, obj = struct.unpack_from(fmt, self._buffer, self._buff_i) | ||
| 511 | 486 | self._buff_i += size + 1 | |
| 512 | 487 | elif 0xD9 <= b <= 0xDB: | |
| 513 | 488 | size, fmt, typ = _MSGPACK_HEADERS[b] | |
| 514 | 489 | self._reserve(size) | |
| 515 | 490 | if len(fmt) > 0: | |
| 516 | - (n,) = _unpack_from(fmt, self._buffer, self._buff_i) | ||
| 491 | + (n,) = struct.unpack_from(fmt, self._buffer, self._buff_i) | ||
| 517 | 492 | else: | |
| 518 | 493 | n = self._buffer[self._buff_i] | |
| 519 | 494 | self._buff_i += size | |
@@ -523,7 +498,7 @@ def _read_header(self): | |||
| 523 | 498 | elif 0xDC <= b <= 0xDD: | |
| 524 | 499 | size, fmt, typ = _MSGPACK_HEADERS[b] | |
| 525 | 500 | self._reserve(size) | |
| 526 | - (n,) = _unpack_from(fmt, self._buffer, self._buff_i) | ||
| 501 | + (n,) = struct.unpack_from(fmt, self._buffer, self._buff_i) | ||
| 527 | 502 | self._buff_i += size | |
| 528 | 503 | if n > self._max_array_len: | |
| 529 | 504 | raise ValueError( | |
@@ -532,7 +507,7 @@ def _read_header(self): | |||
| 532 | 507 | elif 0xDE <= b <= 0xDF: | |
| 533 | 508 | size, fmt, typ = _MSGPACK_HEADERS[b] | |
| 534 | 509 | self._reserve(size) | |
| 535 | - (n,) = _unpack_from(fmt, self._buffer, self._buff_i) | ||
| 510 | + (n,) = struct.unpack_from(fmt, self._buffer, self._buff_i) | ||
| 536 | 511 | self._buff_i += size | |
| 537 | 512 | if n > self._max_map_len: | |
| 538 | 513 | raise ValueError("%s exceeds max_map_len(%s)" % (n, self._max_map_len)) | |
@@ -554,38 +529,38 @@ def _unpack(self, execute=EX_CONSTRUCT): | |||
| 554 | 529 | # TODO should we eliminate the recursion? | |
| 555 | 530 | if typ == TYPE_ARRAY: | |
| 556 | 531 | if execute == EX_SKIP: | |
| 557 | - for i in xrange(n): | ||
| 532 | + for i in range(n): | ||
| 558 | 533 | # TODO check whether we need to call `list_hook` | |
| 559 | 534 | self._unpack(EX_SKIP) | |
| 560 | 535 | return | |
| 561 | 536 | ret = newlist_hint(n) | |
| 562 | - for i in xrange(n): | ||
| 537 | + for i in range(n): | ||
| 563 | 538 | ret.append(self._unpack(EX_CONSTRUCT)) | |
| 564 | 539 | if self._list_hook is not None: | |
| 565 | 540 | ret = self._list_hook(ret) | |
| 566 | 541 | # TODO is the interaction between `list_hook` and `use_list` ok? | |
| 567 | 542 | return ret if self._use_list else tuple(ret) | |
| 568 | 543 | if typ == TYPE_MAP: | |
| 569 | 544 | if execute == EX_SKIP: | |
| 570 | - for i in xrange(n): | ||
| 545 | + for i in range(n): | ||
| 571 | 546 | # TODO check whether we need to call hooks | |
| 572 | 547 | self._unpack(EX_SKIP) | |
| 573 | 548 | self._unpack(EX_SKIP) | |
| 574 | 549 | return | |
| 575 | 550 | if self._object_pairs_hook is not None: | |
| 576 | 551 | ret = self._object_pairs_hook( | |
| 577 | 552 | (self._unpack(EX_CONSTRUCT), self._unpack(EX_CONSTRUCT)) | |
| 578 | - for _ in xrange(n) | ||
| 553 | + for _ in range(n) | ||
| 579 | 554 | ) | |
| 580 | 555 | else: | |
| 581 | 556 | ret = {} | |
| 582 | - for _ in xrange(n): | ||
| 557 | + for _ in range(n): | ||
| 583 | 558 | key = self._unpack(EX_CONSTRUCT) | |
| 584 | - if self._strict_map_key and type(key) not in (unicode, bytes): | ||
| 559 | + if self._strict_map_key and type(key) not in (str, bytes): | ||
| 585 | 560 | raise ValueError( | |
| 586 | 561 | "%s is not allowed for map key" % str(type(key)) | |
| 587 | 562 | ) | |
| 588 | - if not PY2 and type(key) is str: | ||
| 563 | + if type(key) is str: | ||
| 589 | 564 | key = sys.intern(key) | |
| 590 | 565 | ret[key] = self._unpack(EX_CONSTRUCT) | |
| 591 | 566 | if self._object_hook is not None: | |
@@ -698,7 +673,6 @@ class Packer(object): | |||
| 698 | 673 | If set to true, datetime with tzinfo is packed into Timestamp type. | |
| 699 | 674 | Note that the tzinfo is stripped in the timestamp. | |
| 700 | 675 | You can get UTC datetime with `timestamp=3` option of the Unpacker. | |
| 701 | - (Python 2 is not supported). | ||
| 702 | 676 | ||
| 703 | 677 | :param str unicode_errors: | |
| 704 | 678 | The error handler for encoding unicode. (default: 'strict') | |
@@ -743,8 +717,6 @@ def __init__( | |||
| 743 | 717 | self._autoreset = autoreset | |
| 744 | 718 | self._use_bin_type = use_bin_type | |
| 745 | 719 | self._buffer = StringIO() | |
| 746 | - if PY2 and datetime: | ||
| 747 | - raise ValueError("datetime is not supported in Python 2") | ||
| 748 | 720 | self._datetime = bool(datetime) | |
| 749 | 721 | self._unicode_errors = unicode_errors or "strict" | |
| 750 | 722 | if default is not None: | |
@@ -774,7 +746,7 @@ def _pack( | |||
| 774 | 746 | if obj: | |
| 775 | 747 | return self._buffer.write(b"\xc3") | |
| 776 | 748 | return self._buffer.write(b"\xc2") | |
| 777 | - if check(obj, int_types): | ||
| 749 | + if check(obj, int): | ||
| 778 | 750 | if 0 <= obj < 0x80: | |
| 779 | 751 | return self._buffer.write(struct.pack("B", obj)) | |
| 780 | 752 | if -0x20 <= obj < 0: | |
@@ -806,7 +778,7 @@ def _pack( | |||
| 806 | 778 | raise ValueError("%s is too large" % type(obj).__name__) | |
| 807 | 779 | self._pack_bin_header(n) | |
| 808 | 780 | return self._buffer.write(obj) | |
| 809 | - if check(obj, unicode): | ||
| 781 | + if check(obj, str): | ||
| 810 | 782 | obj = obj.encode("utf-8", self._unicode_errors) | |
| 811 | 783 | n = len(obj) | |
| 812 | 784 | if n >= 2**32: | |
@@ -855,13 +827,11 @@ def _pack( | |||
| 855 | 827 | if check(obj, list_types): | |
| 856 | 828 | n = len(obj) | |
| 857 | 829 | self._pack_array_header(n) | |
| 858 | - for i in xrange(n): | ||
| 830 | + for i in range(n): | ||
| 859 | 831 | self._pack(obj[i], nest_limit - 1) | |
| 860 | 832 | return | |
| 861 | 833 | if check(obj, dict): | |
| 862 | - return self._pack_map_pairs( | ||
| 863 | - len(obj), dict_iteritems(obj), nest_limit - 1 | ||
| 864 | - ) | ||
| 834 | + return self._pack_map_pairs(len(obj), obj.items(), nest_limit - 1) | ||
| 865 | 835 | ||
| 866 | 836 | if self._datetime and check(obj, _DateTime) and obj.tzinfo is not None: | |
| 867 | 837 | obj = Timestamp.from_datetime(obj) | |
@@ -1004,7 +974,7 @@ def reset(self): | |||
| 1004 | 974 | ||
| 1005 | 975 | def getbuffer(self): | |
| 1006 | 976 | """Return view of internal buffer.""" | |
| 1007 | - if USING_STRINGBUILDER or PY2: | ||
| 977 | + if USING_STRINGBUILDER: | ||
| 1008 | 978 | return memoryview(self.bytes()) | |
| 1009 | 979 | else: | |
| 1010 | 980 | return self._buffer.getbuffer() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,6 @@ | |||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | PYPY = hasattr(sys, "pypy_version_info") | |
| 13 | - PY2 = sys.version_info[0] == 2 | ||
| 14 | 13 | ||
| 15 | 14 | ||
| 16 | 15 | class NoCython(Exception): | |
@@ -79,7 +78,7 @@ def __init__(self, *args, **kwargs): | |||
| 79 | 78 | macros = [("__LITTLE_ENDIAN__", "1")] | |
| 80 | 79 | ||
| 81 | 80 | ext_modules = [] | |
| 82 | - if not PYPY and not PY2 and not os.environ.get("MSGPACK_PUREPYTHON"): | ||
| 81 | + if not PYPY and not os.environ.get("MSGPACK_PUREPYTHON"): | ||
| 83 | 82 | ext_modules.append( | |
| 84 | 83 | Extension( | |
| 85 | 84 | "msgpack._cmsgpack", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,6 @@ | |||
| 6 | 6 | from msgpack import packb, unpackb | |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | - @pytest.mark.skipif(sys.version_info[0] == 2, reason="Python 2 is not supported") | ||
| 10 | 9 | def test_unpack_buffer(): | |
| 11 | 10 | from array import array | |
| 12 | 11 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -134,4 +134,4 @@ def test_match(): | |||
| 134 | 134 | ||
| 135 | 135 | ||
| 136 | 136 | def test_unicode(): | |
| 137 | - assert unpackb(packb(u"foobar"), use_list=1) == u"foobar" | ||
| 137 | + assert unpackb(packb("foobar"), use_list=1) == "foobar" | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments