msgpack.patch 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. diff --git a/src/pip/_vendor/msgpack/fallback.py b/msgpack/fallback.py
  2. index c0e5fd66..c8c8c78a 100644
  3. --- a/src/pip/_vendor/msgpack/fallback.py
  4. +++ b/src/pip/_vendor/msgpack/fallback.py
  5. @@ -234,6 +234,12 @@ def __init__(self, file_like=None, read_size=0, use_list=True, raw=True,
  6. #: array of bytes fed.
  7. self._buffer = bytearray()
  8. + # Some very old pythons don't support `struct.unpack_from()` with a
  9. + # `bytearray`. So we wrap it in a `buffer()` there.
  10. + if sys.version_info < (2, 7, 6):
  11. + self._buffer_view = buffer(self._buffer)
  12. + else:
  13. + self._buffer_view = self._buffer
  14. #: Which position we currently reads
  15. self._buff_i = 0
  16. @@ -388,7 +394,7 @@ def _read_header(self, execute=EX_CONSTRUCT):
  17. elif b == 0xc5:
  18. typ = TYPE_BIN
  19. self._reserve(2)
  20. - n = struct.unpack_from(">H", self._buffer, self._buff_i)[0]
  21. + n = struct.unpack_from(">H", self._buffer_view, self._buff_i)[0]
  22. self._buff_i += 2
  23. if n > self._max_bin_len:
  24. raise UnpackValueError("%s exceeds max_bin_len(%s)" % (n, self._max_bin_len))
  25. @@ -396,7 +402,7 @@ def _read_header(self, execute=EX_CONSTRUCT):
  26. elif b == 0xc6:
  27. typ = TYPE_BIN
  28. self._reserve(4)
  29. - n = struct.unpack_from(">I", self._buffer, self._buff_i)[0]
  30. + n = struct.unpack_from(">I", self._buffer_view, self._buff_i)[0]
  31. self._buff_i += 4
  32. if n > self._max_bin_len:
  33. raise UnpackValueError("%s exceeds max_bin_len(%s)" % (n, self._max_bin_len))
  34. @@ -404,7 +410,7 @@ def _read_header(self, execute=EX_CONSTRUCT):
  35. elif b == 0xc7: # ext 8
  36. typ = TYPE_EXT
  37. self._reserve(2)
  38. - L, n = struct.unpack_from('Bb', self._buffer, self._buff_i)
  39. + L, n = struct.unpack_from('Bb', self._buffer_view, self._buff_i)
  40. self._buff_i += 2
  41. if L > self._max_ext_len:
  42. raise UnpackValueError("%s exceeds max_ext_len(%s)" % (L, self._max_ext_len))
  43. @@ -412,7 +418,7 @@ def _read_header(self, execute=EX_CONSTRUCT):
  44. elif b == 0xc8: # ext 16
  45. typ = TYPE_EXT
  46. self._reserve(3)
  47. - L, n = struct.unpack_from('>Hb', self._buffer, self._buff_i)
  48. + L, n = struct.unpack_from('>Hb', self._buffer_view, self._buff_i)
  49. self._buff_i += 3
  50. if L > self._max_ext_len:
  51. raise UnpackValueError("%s exceeds max_ext_len(%s)" % (L, self._max_ext_len))
  52. @@ -420,18 +426,18 @@ def _read_header(self, execute=EX_CONSTRUCT):
  53. elif b == 0xc9: # ext 32
  54. typ = TYPE_EXT
  55. self._reserve(5)
  56. - L, n = struct.unpack_from('>Ib', self._buffer, self._buff_i)
  57. + L, n = struct.unpack_from('>Ib', self._buffer_view, self._buff_i)
  58. self._buff_i += 5
  59. if L > self._max_ext_len:
  60. raise UnpackValueError("%s exceeds max_ext_len(%s)" % (L, self._max_ext_len))
  61. obj = self._read(L)
  62. elif b == 0xca:
  63. self._reserve(4)
  64. - obj = struct.unpack_from(">f", self._buffer, self._buff_i)[0]
  65. + obj = struct.unpack_from(">f", self._buffer_view, self._buff_i)[0]
  66. self._buff_i += 4
  67. elif b == 0xcb:
  68. self._reserve(8)
  69. - obj = struct.unpack_from(">d", self._buffer, self._buff_i)[0]
  70. + obj = struct.unpack_from(">d", self._buffer_view, self._buff_i)[0]
  71. self._buff_i += 8
  72. elif b == 0xcc:
  73. self._reserve(1)
  74. @@ -439,66 +445,66 @@ def _read_header(self, execute=EX_CONSTRUCT):
  75. self._buff_i += 1
  76. elif b == 0xcd:
  77. self._reserve(2)
  78. - obj = struct.unpack_from(">H", self._buffer, self._buff_i)[0]
  79. + obj = struct.unpack_from(">H", self._buffer_view, self._buff_i)[0]
  80. self._buff_i += 2
  81. elif b == 0xce:
  82. self._reserve(4)
  83. - obj = struct.unpack_from(">I", self._buffer, self._buff_i)[0]
  84. + obj = struct.unpack_from(">I", self._buffer_view, self._buff_i)[0]
  85. self._buff_i += 4
  86. elif b == 0xcf:
  87. self._reserve(8)
  88. - obj = struct.unpack_from(">Q", self._buffer, self._buff_i)[0]
  89. + obj = struct.unpack_from(">Q", self._buffer_view, self._buff_i)[0]
  90. self._buff_i += 8
  91. elif b == 0xd0:
  92. self._reserve(1)
  93. - obj = struct.unpack_from("b", self._buffer, self._buff_i)[0]
  94. + obj = struct.unpack_from("b", self._buffer_view, self._buff_i)[0]
  95. self._buff_i += 1
  96. elif b == 0xd1:
  97. self._reserve(2)
  98. - obj = struct.unpack_from(">h", self._buffer, self._buff_i)[0]
  99. + obj = struct.unpack_from(">h", self._buffer_view, self._buff_i)[0]
  100. self._buff_i += 2
  101. elif b == 0xd2:
  102. self._reserve(4)
  103. - obj = struct.unpack_from(">i", self._buffer, self._buff_i)[0]
  104. + obj = struct.unpack_from(">i", self._buffer_view, self._buff_i)[0]
  105. self._buff_i += 4
  106. elif b == 0xd3:
  107. self._reserve(8)
  108. - obj = struct.unpack_from(">q", self._buffer, self._buff_i)[0]
  109. + obj = struct.unpack_from(">q", self._buffer_view, self._buff_i)[0]
  110. self._buff_i += 8
  111. elif b == 0xd4: # fixext 1
  112. typ = TYPE_EXT
  113. if self._max_ext_len < 1:
  114. raise UnpackValueError("%s exceeds max_ext_len(%s)" % (1, self._max_ext_len))
  115. self._reserve(2)
  116. - n, obj = struct.unpack_from("b1s", self._buffer, self._buff_i)
  117. + n, obj = struct.unpack_from("b1s", self._buffer_view, self._buff_i)
  118. self._buff_i += 2
  119. elif b == 0xd5: # fixext 2
  120. typ = TYPE_EXT
  121. if self._max_ext_len < 2:
  122. raise UnpackValueError("%s exceeds max_ext_len(%s)" % (2, self._max_ext_len))
  123. self._reserve(3)
  124. - n, obj = struct.unpack_from("b2s", self._buffer, self._buff_i)
  125. + n, obj = struct.unpack_from("b2s", self._buffer_view, self._buff_i)
  126. self._buff_i += 3
  127. elif b == 0xd6: # fixext 4
  128. typ = TYPE_EXT
  129. if self._max_ext_len < 4:
  130. raise UnpackValueError("%s exceeds max_ext_len(%s)" % (4, self._max_ext_len))
  131. self._reserve(5)
  132. - n, obj = struct.unpack_from("b4s", self._buffer, self._buff_i)
  133. + n, obj = struct.unpack_from("b4s", self._buffer_view, self._buff_i)
  134. self._buff_i += 5
  135. elif b == 0xd7: # fixext 8
  136. typ = TYPE_EXT
  137. if self._max_ext_len < 8:
  138. raise UnpackValueError("%s exceeds max_ext_len(%s)" % (8, self._max_ext_len))
  139. self._reserve(9)
  140. - n, obj = struct.unpack_from("b8s", self._buffer, self._buff_i)
  141. + n, obj = struct.unpack_from("b8s", self._buffer_view, self._buff_i)
  142. self._buff_i += 9
  143. elif b == 0xd8: # fixext 16
  144. typ = TYPE_EXT
  145. if self._max_ext_len < 16:
  146. raise UnpackValueError("%s exceeds max_ext_len(%s)" % (16, self._max_ext_len))
  147. self._reserve(17)
  148. - n, obj = struct.unpack_from("b16s", self._buffer, self._buff_i)
  149. + n, obj = struct.unpack_from("b16s", self._buffer_view, self._buff_i)
  150. self._buff_i += 17
  151. elif b == 0xd9:
  152. typ = TYPE_RAW
  153. @@ -511,7 +517,7 @@ def _read_header(self, execute=EX_CONSTRUCT):
  154. elif b == 0xda:
  155. typ = TYPE_RAW
  156. self._reserve(2)
  157. - n, = struct.unpack_from(">H", self._buffer, self._buff_i)
  158. + n, = struct.unpack_from(">H", self._buffer_view, self._buff_i)
  159. self._buff_i += 2
  160. if n > self._max_str_len:
  161. raise UnpackValueError("%s exceeds max_str_len(%s)", n, self._max_str_len)
  162. @@ -519,7 +525,7 @@ def _read_header(self, execute=EX_CONSTRUCT):
  163. elif b == 0xdb:
  164. typ = TYPE_RAW
  165. self._reserve(4)
  166. - n, = struct.unpack_from(">I", self._buffer, self._buff_i)
  167. + n, = struct.unpack_from(">I", self._buffer_view, self._buff_i)
  168. self._buff_i += 4
  169. if n > self._max_str_len:
  170. raise UnpackValueError("%s exceeds max_str_len(%s)", n, self._max_str_len)
  171. @@ -527,27 +533,27 @@ def _read_header(self, execute=EX_CONSTRUCT):
  172. elif b == 0xdc:
  173. typ = TYPE_ARRAY
  174. self._reserve(2)
  175. - n, = struct.unpack_from(">H", self._buffer, self._buff_i)
  176. + n, = struct.unpack_from(">H", self._buffer_view, self._buff_i)
  177. self._buff_i += 2
  178. if n > self._max_array_len:
  179. raise UnpackValueError("%s exceeds max_array_len(%s)", n, self._max_array_len)
  180. elif b == 0xdd:
  181. typ = TYPE_ARRAY
  182. self._reserve(4)
  183. - n, = struct.unpack_from(">I", self._buffer, self._buff_i)
  184. + n, = struct.unpack_from(">I", self._buffer_view, self._buff_i)
  185. self._buff_i += 4
  186. if n > self._max_array_len:
  187. raise UnpackValueError("%s exceeds max_array_len(%s)", n, self._max_array_len)
  188. elif b == 0xde:
  189. self._reserve(2)
  190. - n, = struct.unpack_from(">H", self._buffer, self._buff_i)
  191. + n, = struct.unpack_from(">H", self._buffer_view, self._buff_i)
  192. self._buff_i += 2
  193. if n > self._max_map_len:
  194. raise UnpackValueError("%s exceeds max_map_len(%s)", n, self._max_map_len)
  195. typ = TYPE_MAP
  196. elif b == 0xdf:
  197. self._reserve(4)
  198. - n, = struct.unpack_from(">I", self._buffer, self._buff_i)
  199. + n, = struct.unpack_from(">I", self._buffer_view, self._buff_i)
  200. self._buff_i += 4
  201. if n > self._max_map_len:
  202. raise UnpackValueError("%s exceeds max_map_len(%s)", n, self._max_map_len)