Skip to content

Commit e557e17

Browse files
committed
blacken
1 parent 6414069 commit e557e17

File tree

3 files changed

+245
-180
lines changed

3 files changed

+245
-180
lines changed

msgpack/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88

99

10-
if os.environ.get('MSGPACK_PUREPYTHON') or sys.version_info[0] == 2:
10+
if os.environ.get("MSGPACK_PUREPYTHON") or sys.version_info[0] == 2:
1111
from .fallback import Packer, unpackb, Unpacker
1212
else:
1313
try:

msgpack/ext.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
long = int
1010

1111

12-
class ExtType(namedtuple('ExtType', 'code data')):
12+
class ExtType(namedtuple("ExtType", "code data")):
1313
"""ExtType represents ext type in msgpack."""
14+
1415
def __new__(cls, code, data):
1516
if not isinstance(code, int):
1617
raise TypeError("code must be int")
@@ -29,6 +30,7 @@ class Timestamp(object):
2930
When built with Cython, msgpack uses C methods to pack and unpack `Timestamp`. When using pure-Python
3031
msgpack, :func:`to_bytes` and :func:`from_bytes` are used to pack and unpack `Timestamp`.
3132
"""
33+
3234
__slots__ = ["seconds", "nanoseconds"]
3335

3436
def __init__(self, seconds, nanoseconds=0):
@@ -50,9 +52,13 @@ def __init__(self, seconds, nanoseconds=0):
5052
raise TypeError("nanoseconds must be an integer")
5153
if nanoseconds:
5254
if nanoseconds < 0 or nanoseconds % 1 != 0 or nanoseconds > (1e9 - 1):
53-
raise ValueError("nanoseconds must be a non-negative integer less than 999999999.")
55+
raise ValueError(
56+
"nanoseconds must be a non-negative integer less than 999999999."
57+
)
5458
if not isinstance(seconds, (int, long)):
55-
raise ValueError("seconds must be an integer if also providing nanoseconds.")
59+
raise ValueError(
60+
"seconds must be an integer if also providing nanoseconds."
61+
)
5662
self.nanoseconds = nanoseconds
5763
else:
5864
# round helps with floating point issues
@@ -61,12 +67,16 @@ def __init__(self, seconds, nanoseconds=0):
6167

6268
def __repr__(self):
6369
"""String representation of Timestamp."""
64-
return "Timestamp(seconds={0}, nanoseconds={1})".format(self.seconds, self.nanoseconds)
70+
return "Timestamp(seconds={0}, nanoseconds={1})".format(
71+
self.seconds, self.nanoseconds
72+
)
6573

6674
def __eq__(self, other):
6775
"""Check for equality with another Timestamp object"""
6876
if type(other) is self.__class__:
69-
return self.seconds == other.seconds and self.nanoseconds == other.nanoseconds
77+
return (
78+
self.seconds == other.seconds and self.nanoseconds == other.nanoseconds
79+
)
7080
return False
7181

7282
def __ne__(self, other):
@@ -90,12 +100,14 @@ def from_bytes(b):
90100
nanoseconds = 0
91101
elif len(b) == 8:
92102
data64 = struct.unpack("!Q", b)[0]
93-
seconds = data64 & 0x00000003ffffffff
103+
seconds = data64 & 0x00000003FFFFFFFF
94104
nanoseconds = data64 >> 34
95105
elif len(b) == 12:
96106
nanoseconds, seconds = struct.unpack("!Iq", b)
97107
else:
98-
raise ValueError("Timestamp type can only be created from 32, 64, or 96-bit byte objects")
108+
raise ValueError(
109+
"Timestamp type can only be created from 32, 64, or 96-bit byte objects"
110+
)
99111
return Timestamp(seconds, nanoseconds)
100112

101113
def to_bytes(self):
@@ -108,7 +120,7 @@ def to_bytes(self):
108120
"""
109121
if (self.seconds >> 34) == 0: # seconds is non-negative and fits in 34 bits
110122
data64 = self.nanoseconds << 34 | self.seconds
111-
if data64 & 0xffffffff00000000 == 0:
123+
if data64 & 0xFFFFFFFF00000000 == 0:
112124
# nanoseconds is zero and seconds < 2**32, so timestamp 32
113125
data = struct.pack("!L", data64)
114126
else:
@@ -125,7 +137,7 @@ def to_float_s(self):
125137
:returns: posix timestamp
126138
:rtype: float
127139
"""
128-
return self.seconds + self.nanoseconds/1e9
140+
return self.seconds + self.nanoseconds / 1e9
129141

130142
def to_unix_ns(self):
131143
"""Get the timestamp as a unixtime in nanoseconds.

0 commit comments

Comments
 (0)