Drop Python 2 support from _cmsgpack (#376)

This commit is contained in:
Inada Naoki 2019-11-28 20:23:34 +09:00 committed by GitHub
parent b458e9a6a2
commit 891f2d8743
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 55 deletions

View file

@ -2,6 +2,8 @@
from ._version import version
from .exceptions import *
import os
import sys
from collections import namedtuple
@ -17,8 +19,7 @@ class ExtType(namedtuple('ExtType', 'code data')):
return super(ExtType, cls).__new__(cls, code, data)
import os
if os.environ.get('MSGPACK_PUREPYTHON'):
if os.environ.get('MSGPACK_PUREPYTHON') or sys.version_info[0] == 2:
from .fallback import Packer, unpackb, Unpacker
else:
try:

View file

@ -130,10 +130,7 @@ cdef class Packer(object):
self._bencoding = encoding
if encoding is None:
if PY_MAJOR_VERSION < 3:
self.encoding = 'utf-8'
else:
self.encoding = NULL
self.encoding = 'utf-8'
else:
self.encoding = self._bencoding

View file

@ -1,28 +1,8 @@
#include "Python.h"
/* cython does not support this preprocessor check => write it in raw C */
#if PY_MAJOR_VERSION == 2
static PyObject *
buff_to_buff(char *buff, Py_ssize_t size)
{
return PyBuffer_FromMemory(buff, size);
}
#elif (PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION >= 3)
static PyObject *
buff_to_buff(char *buff, Py_ssize_t size)
{
return PyMemoryView_FromMemory(buff, size, PyBUF_READ);
}
#else
static PyObject *
buff_to_buff(char *buff, Py_ssize_t size)
{
Py_buffer pybuf;
if (PyBuffer_FillInfo(&pybuf, NULL, buff, size, 1, PyBUF_FULL_RO) == -1) {
return NULL;
}
return PyMemoryView_FromBuffer(&pybuf);
}
#endif

View file

@ -5,13 +5,12 @@ import struct
import warnings
if sys.version_info[0] == 2:
PY2 = True
PY2 = sys.version_info[0] == 2
if PY2:
int_types = (int, long)
def dict_iteritems(d):
return d.iteritems()
else:
PY2 = False
int_types = int
unicode = str
xrange = range

View file

@ -273,11 +273,7 @@ static inline int unpack_callback_ext(unpack_user* u, const char* base, const ch
return -1;
}
// length also includes the typecode, so the actual data is length-1
#if PY_MAJOR_VERSION == 2
py = PyObject_CallFunction(u->ext_hook, "(is#)", (int)typecode, pos, (Py_ssize_t)length-1);
#else
py = PyObject_CallFunction(u->ext_hook, "(iy#)", (int)typecode, pos, (Py_ssize_t)length-1);
#endif
if (!py)
return -1;
*o = py;