Skip to content

Commit b28816e

Browse files
committed
Upgrade msgpack to 1.0.8
1 parent f325211 commit b28816e

File tree

5 files changed

+64
-149
lines changed

5 files changed

+64
-149
lines changed

news/msgpack.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade msgpack to 1.0.8

src/pip/_vendor/msgpack/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
# coding: utf-8
21
from .exceptions import *
32
from .ext import ExtType, Timestamp
43

54
import os
6-
import sys
75

86

9-
version = (1, 0, 5)
10-
__version__ = "1.0.5"
7+
version = (1, 0, 8)
8+
__version__ = "1.0.8"
119

1210

13-
if os.environ.get("MSGPACK_PUREPYTHON") or sys.version_info[0] == 2:
11+
if os.environ.get("MSGPACK_PUREPYTHON"):
1412
from .fallback import Packer, unpackb, Unpacker
1513
else:
1614
try:

src/pip/_vendor/msgpack/ext.py

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
# coding: utf-8
21
from collections import namedtuple
32
import datetime
4-
import sys
53
import struct
64

75

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-
216
class ExtType(namedtuple("ExtType", "code data")):
227
"""ExtType represents ext type in msgpack."""
238

@@ -28,14 +13,15 @@ def __new__(cls, code, data):
2813
raise TypeError("data must be bytes")
2914
if not 0 <= code <= 127:
3015
raise ValueError("code must be 0~127")
31-
return super(ExtType, cls).__new__(cls, code, data)
16+
return super().__new__(cls, code, data)
3217

3318

34-
class Timestamp(object):
19+
class Timestamp:
3520
"""Timestamp represents the Timestamp extension type in msgpack.
3621
37-
When built with Cython, msgpack uses C methods to pack and unpack `Timestamp`. When using pure-Python
38-
msgpack, :func:`to_bytes` and :func:`from_bytes` are used to pack and unpack `Timestamp`.
22+
When built with Cython, msgpack uses C methods to pack and unpack `Timestamp`.
23+
When using pure-Python msgpack, :func:`to_bytes` and :func:`from_bytes` are used to pack and
24+
unpack `Timestamp`.
3925
4026
This class is immutable: Do not override seconds and nanoseconds.
4127
"""
@@ -53,31 +39,25 @@ def __init__(self, seconds, nanoseconds=0):
5339
Number of nanoseconds to add to `seconds` to get fractional time.
5440
Maximum is 999_999_999. Default is 0.
5541
56-
Note: Negative times (before the UNIX epoch) are represented as negative seconds + positive ns.
42+
Note: Negative times (before the UNIX epoch) are represented as neg. seconds + pos. ns.
5743
"""
58-
if not isinstance(seconds, int_types):
44+
if not isinstance(seconds, int):
5945
raise TypeError("seconds must be an integer")
60-
if not isinstance(nanoseconds, int_types):
46+
if not isinstance(nanoseconds, int):
6147
raise TypeError("nanoseconds must be an integer")
6248
if not (0 <= nanoseconds < 10**9):
63-
raise ValueError(
64-
"nanoseconds must be a non-negative integer less than 999999999."
65-
)
49+
raise ValueError("nanoseconds must be a non-negative integer less than 999999999.")
6650
self.seconds = seconds
6751
self.nanoseconds = nanoseconds
6852

6953
def __repr__(self):
7054
"""String representation of Timestamp."""
71-
return "Timestamp(seconds={0}, nanoseconds={1})".format(
72-
self.seconds, self.nanoseconds
73-
)
55+
return f"Timestamp(seconds={self.seconds}, nanoseconds={self.nanoseconds})"
7456

7557
def __eq__(self, other):
7658
"""Check for equality with another Timestamp object"""
7759
if type(other) is self.__class__:
78-
return (
79-
self.seconds == other.seconds and self.nanoseconds == other.nanoseconds
80-
)
60+
return self.seconds == other.seconds and self.nanoseconds == other.nanoseconds
8161
return False
8262

8363
def __ne__(self, other):
@@ -140,7 +120,7 @@ def from_unix(unix_sec):
140120
"""Create a Timestamp from posix timestamp in seconds.
141121
142122
:param unix_float: Posix timestamp in seconds.
143-
:type unix_float: int or float.
123+
:type unix_float: int or float
144124
"""
145125
seconds = int(unix_sec // 1)
146126
nanoseconds = int((unix_sec % 1) * 10**9)
@@ -174,20 +154,15 @@ def to_unix_nano(self):
174154
def to_datetime(self):
175155
"""Get the timestamp as a UTC datetime.
176156
177-
Python 2 is not supported.
178-
179-
:rtype: datetime.
157+
:rtype: `datetime.datetime`
180158
"""
181-
return datetime.datetime.fromtimestamp(0, _utc) + datetime.timedelta(
182-
seconds=self.to_unix()
183-
)
159+
utc = datetime.timezone.utc
160+
return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(seconds=self.to_unix())
184161

185162
@staticmethod
186163
def from_datetime(dt):
187164
"""Create a Timestamp from datetime with tzinfo.
188165
189-
Python 2 is not supported.
190-
191166
:rtype: Timestamp
192167
"""
193168
return Timestamp.from_unix(dt.timestamp())

0 commit comments

Comments
 (0)