summaryrefslogtreecommitdiff
path: root/msgpack
diff options
context:
space:
mode:
Diffstat (limited to 'msgpack')
-rw-r--r--msgpack/__init__.py5
-rw-r--r--msgpack/_packer.pyx5
-rw-r--r--msgpack/buff_converter.h20
-rw-r--r--msgpack/fallback.py5
-rw-r--r--msgpack/unpack.h4
5 files changed, 6 insertions, 33 deletions
diff --git a/msgpack/__init__.py b/msgpack/__init__.py
index 4ad9c1a..4112a16 100644
--- a/msgpack/__init__.py
+++ b/msgpack/__init__.py
@@ -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:
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx
index 2f4d120..e620914 100644
--- a/msgpack/_packer.pyx
+++ b/msgpack/_packer.pyx
@@ -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
diff --git a/msgpack/buff_converter.h b/msgpack/buff_converter.h
index bc7227a..86b4196 100644
--- a/msgpack/buff_converter.h
+++ b/msgpack/buff_converter.h
@@ -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
diff --git a/msgpack/fallback.py b/msgpack/fallback.py
index 3836e83..1ed6e77 100644
--- a/msgpack/fallback.py
+++ b/msgpack/fallback.py
@@ -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
diff --git a/msgpack/unpack.h b/msgpack/unpack.h
index 85dbbed..bbce91c 100644
--- a/msgpack/unpack.h
+++ b/msgpack/unpack.h
@@ -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;