mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-12-08 06:09:49 +00:00
Drop python2 support (#519)
The PR removes python2 references and cases. Close #518 Co-authored-by: Inada Naoki <songofacandy@gmail.com>
This commit is contained in:
parent
45f848695c
commit
feec06206c
17 changed files with 58 additions and 143 deletions
|
|
@ -5,19 +5,6 @@ import sys
|
|||
import struct
|
||||
|
||||
|
||||
PY2 = sys.version_info[0] == 2
|
||||
|
||||
if PY2:
|
||||
int_types = (int, long)
|
||||
_utc = None
|
||||
else:
|
||||
int_types = int
|
||||
try:
|
||||
_utc = datetime.timezone.utc
|
||||
except AttributeError:
|
||||
_utc = datetime.timezone(datetime.timedelta(0))
|
||||
|
||||
|
||||
class ExtType(namedtuple("ExtType", "code data")):
|
||||
"""ExtType represents ext type in msgpack."""
|
||||
|
||||
|
|
@ -55,9 +42,9 @@ class Timestamp(object):
|
|||
|
||||
Note: Negative times (before the UNIX epoch) are represented as negative seconds + positive ns.
|
||||
"""
|
||||
if not isinstance(seconds, int_types):
|
||||
if not isinstance(seconds, int):
|
||||
raise TypeError("seconds must be an integer")
|
||||
if not isinstance(nanoseconds, int_types):
|
||||
if not isinstance(nanoseconds, int):
|
||||
raise TypeError("nanoseconds must be an integer")
|
||||
if not (0 <= nanoseconds < 10**9):
|
||||
raise ValueError(
|
||||
|
|
@ -174,11 +161,10 @@ class Timestamp(object):
|
|||
def to_datetime(self):
|
||||
"""Get the timestamp as a UTC datetime.
|
||||
|
||||
Python 2 is not supported.
|
||||
|
||||
:rtype: datetime.
|
||||
"""
|
||||
return datetime.datetime.fromtimestamp(0, _utc) + datetime.timedelta(
|
||||
utc = datetime.timezone.utc
|
||||
return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(
|
||||
seconds=self.to_unix()
|
||||
)
|
||||
|
||||
|
|
@ -186,8 +172,6 @@ class Timestamp(object):
|
|||
def from_datetime(dt):
|
||||
"""Create a Timestamp from datetime with tzinfo.
|
||||
|
||||
Python 2 is not supported.
|
||||
|
||||
:rtype: Timestamp
|
||||
"""
|
||||
return Timestamp.from_unix(dt.timestamp())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue