Skip to content

Commit

Permalink
Upgrade msgpack to 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ichard26 committed Dec 7, 2024
1 parent dc6c4f3 commit c0900b8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 63 deletions.
1 change: 1 addition & 0 deletions news/msgpack.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade msgpack to 1.1.0
16 changes: 8 additions & 8 deletions src/pip/_vendor/msgpack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from .exceptions import *
from .ext import ExtType, Timestamp

# ruff: noqa: F401
import os

from .exceptions import * # noqa: F403
from .ext import ExtType, Timestamp

version = (1, 0, 8)
__version__ = "1.0.8"
version = (1, 1, 0)
__version__ = "1.1.0"


if os.environ.get("MSGPACK_PUREPYTHON"):
from .fallback import Packer, unpackb, Unpacker
from .fallback import Packer, Unpacker, unpackb
else:
try:
from ._cmsgpack import Packer, unpackb, Unpacker
from ._cmsgpack import Packer, Unpacker, unpackb
except ImportError:
from .fallback import Packer, unpackb, Unpacker
from .fallback import Packer, Unpacker, unpackb


def pack(o, stream, **kwargs):
Expand Down
8 changes: 5 additions & 3 deletions src/pip/_vendor/msgpack/ext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import namedtuple
import datetime
import struct
from collections import namedtuple


class ExtType(namedtuple("ExtType", "code data")):
Expand Down Expand Up @@ -157,12 +157,14 @@ def to_datetime(self):
:rtype: `datetime.datetime`
"""
utc = datetime.timezone.utc
return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(seconds=self.to_unix())
return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(
seconds=self.seconds, microseconds=self.nanoseconds // 1000
)

@staticmethod
def from_datetime(dt):
"""Create a Timestamp from datetime with tzinfo.
:rtype: Timestamp
"""
return Timestamp.from_unix(dt.timestamp())
return Timestamp(seconds=int(dt.timestamp()), nanoseconds=dt.microsecond * 1000)
80 changes: 29 additions & 51 deletions src/pip/_vendor/msgpack/fallback.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
"""Fallback pure Python implementation of msgpack"""
from datetime import datetime as _DateTime
import sys
import struct

import struct
import sys
from datetime import datetime as _DateTime

if hasattr(sys, "pypy_version_info"):
# StringIO is slow on PyPy, StringIO is faster. However: PyPy's own
# StringBuilder is fastest.
from __pypy__ import newlist_hint
from __pypy__.builders import BytesBuilder

try:
from __pypy__.builders import BytesBuilder as StringBuilder
except ImportError:
from __pypy__.builders import StringBuilder
USING_STRINGBUILDER = True
_USING_STRINGBUILDER = True

class StringIO:
class BytesIO:
def __init__(self, s=b""):
if s:
self.builder = StringBuilder(len(s))
self.builder = BytesBuilder(len(s))
self.builder.append(s)
else:
self.builder = StringBuilder()
self.builder = BytesBuilder()

def write(self, s):
if isinstance(s, memoryview):
Expand All @@ -34,17 +29,17 @@ def getvalue(self):
return self.builder.build()

else:
USING_STRINGBUILDER = False
from io import BytesIO as StringIO
from io import BytesIO

newlist_hint = lambda size: []
_USING_STRINGBUILDER = False

def newlist_hint(size):
return []

from .exceptions import BufferFull, OutOfData, ExtraData, FormatError, StackError

from .exceptions import BufferFull, ExtraData, FormatError, OutOfData, StackError
from .ext import ExtType, Timestamp


EX_SKIP = 0
EX_CONSTRUCT = 1
EX_READ_ARRAY_HEADER = 2
Expand Down Expand Up @@ -231,6 +226,7 @@ class Unpacker:
def __init__(
self,
file_like=None,
*,
read_size=0,
use_list=True,
raw=False,
Expand Down Expand Up @@ -333,6 +329,7 @@ def feed(self, next_bytes):

# Use extend here: INPLACE_ADD += doesn't reliably typecast memoryview in jython
self._buffer.extend(view)
view.release()

def _consume(self):
"""Gets rid of the used parts of the buffer."""
Expand Down Expand Up @@ -649,50 +646,31 @@ class Packer:
The error handler for encoding unicode. (default: 'strict')
DO NOT USE THIS!! This option is kept for very specific usage.
Example of streaming deserialize from file-like object::
unpacker = Unpacker(file_like)
for o in unpacker:
process(o)
Example of streaming deserialize from socket::
unpacker = Unpacker()
while True:
buf = sock.recv(1024**2)
if not buf:
break
unpacker.feed(buf)
for o in unpacker:
process(o)
Raises ``ExtraData`` when *packed* contains extra bytes.
Raises ``OutOfData`` when *packed* is incomplete.
Raises ``FormatError`` when *packed* is not valid msgpack.
Raises ``StackError`` when *packed* contains too nested.
Other exceptions can be raised during unpacking.
:param int buf_size:
Internal buffer size. This option is used only for C implementation.
"""

def __init__(
self,
*,
default=None,
use_single_float=False,
autoreset=True,
use_bin_type=True,
strict_types=False,
datetime=False,
unicode_errors=None,
buf_size=None,
):
self._strict_types = strict_types
self._use_float = use_single_float
self._autoreset = autoreset
self._use_bin_type = use_bin_type
self._buffer = StringIO()
self._buffer = BytesIO()
self._datetime = bool(datetime)
self._unicode_errors = unicode_errors or "strict"
if default is not None:
if not callable(default):
raise TypeError("default must be callable")
if default is not None and not callable(default):
raise TypeError("default must be callable")
self._default = default

def _pack(
Expand Down Expand Up @@ -823,18 +801,18 @@ def pack(self, obj):
try:
self._pack(obj)
except:
self._buffer = StringIO() # force reset
self._buffer = BytesIO() # force reset
raise
if self._autoreset:
ret = self._buffer.getvalue()
self._buffer = StringIO()
self._buffer = BytesIO()
return ret

def pack_map_pairs(self, pairs):
self._pack_map_pairs(len(pairs), pairs)
if self._autoreset:
ret = self._buffer.getvalue()
self._buffer = StringIO()
self._buffer = BytesIO()
return ret

def pack_array_header(self, n):
Expand All @@ -843,7 +821,7 @@ def pack_array_header(self, n):
self._pack_array_header(n)
if self._autoreset:
ret = self._buffer.getvalue()
self._buffer = StringIO()
self._buffer = BytesIO()
return ret

def pack_map_header(self, n):
Expand All @@ -852,7 +830,7 @@ def pack_map_header(self, n):
self._pack_map_header(n)
if self._autoreset:
ret = self._buffer.getvalue()
self._buffer = StringIO()
self._buffer = BytesIO()
return ret

def pack_ext_type(self, typecode, data):
Expand Down Expand Up @@ -941,11 +919,11 @@ def reset(self):
This method is useful only when autoreset=False.
"""
self._buffer = StringIO()
self._buffer = BytesIO()

def getbuffer(self):
"""Return view of internal buffer."""
if USING_STRINGBUILDER:
if _USING_STRINGBUILDER:
return memoryview(self.bytes())
else:
return self._buffer.getbuffer()
2 changes: 1 addition & 1 deletion src/pip/_vendor/vendor.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CacheControl==0.14.1
distlib==0.3.9
distro==1.9.0
msgpack==1.0.8
msgpack==1.1.0
packaging==24.1
platformdirs==4.2.2
pyproject-hooks==1.0.0
Expand Down

0 comments on commit c0900b8

Please sign in to comment.