summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2013-10-17 08:44:25 +0900
committerINADA Naoki <songofacandy@gmail.com>2013-10-17 08:44:25 +0900
commit171c5381135bdfc6db154100ad5a9913955408a7 (patch)
treeea47f538fd263e11e2a077e7ce56a170cd8ce55f
parentda12e177a31445492795f4003bbe0328645325b2 (diff)
downloadmsgpack-python-171c5381135bdfc6db154100ad5a9913955408a7.tar.gz
refactoring.
-rw-r--r--msgpack/__init__.py22
-rw-r--r--msgpack/_packer.pyx27
-rw-r--r--msgpack/fallback.py17
3 files changed, 21 insertions, 45 deletions
diff --git a/msgpack/__init__.py b/msgpack/__init__.py
index 77f6b81..5ce531e 100644
--- a/msgpack/__init__.py
+++ b/msgpack/__init__.py
@@ -4,14 +4,32 @@ from msgpack.exceptions import *
import os
if os.environ.get('MSGPACK_PUREPYTHON'):
- from msgpack.fallback import pack, packb, Packer, unpack, unpackb, Unpacker
+ from msgpack.fallback import Packer, unpack, unpackb, Unpacker
else:
try:
- from msgpack._packer import pack, packb, Packer
+ from msgpack._packer import Packer
from msgpack._unpacker import unpack, unpackb, Unpacker
except ImportError:
from msgpack.fallback import pack, packb, Packer, unpack, unpackb, Unpacker
+
+def pack(o, stream, **kwargs):
+ """
+ Pack object `o` and write it to `stream`
+
+ See :class:`Packer` for options.
+ """
+ packer = Packer(**kwargs)
+ stream.write(packer.pack(o))
+
+def packb(o, **kwargs):
+ """
+ Pack object `o` and return packed bytes
+
+ See :class:`Packer` for options.
+ """
+ return Packer(**kwargs).pack(o)
+
# alias for compatibility to simplejson/marshal/pickle.
load = unpack
loads = unpackb
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx
index b9ae505..7082445 100644
--- a/msgpack/_packer.pyx
+++ b/msgpack/_packer.pyx
@@ -13,6 +13,7 @@ cdef extern from "pack.h":
char* buf
size_t length
size_t buf_size
+ bint use_bin_type
int msgpack_pack_int(msgpack_packer* pk, int d)
int msgpack_pack_nil(msgpack_packer* pk)
@@ -68,7 +69,6 @@ cdef class Packer(object):
cdef char *encoding
cdef char *unicode_errors
cdef bool use_float
- cdef bool use_bin_type
cdef bint autoreset
def __cinit__(self):
@@ -254,28 +254,3 @@ cdef class Packer(object):
def bytes(self):
"""Return buffer content."""
return PyBytes_FromStringAndSize(self.pk.buf, self.pk.length)
-
-
-def pack(object o, object stream,
- default=None, str encoding='utf-8', str unicode_errors='strict',
- bint use_single_float=False, bint use_bin_type=False):
- """
- pack an object `o` and write it to stream)
-
- See :class:`Packer` for options.
- """
- packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors,
- use_single_float=use_single_float, use_bin_type=use_bin_type)
- stream.write(packer.pack(o))
-
-def packb(object o,
- default=None, str encoding='utf-8', str unicode_errors='strict',
- bint use_single_float=False, bint use_bin_type=False):
- """
- pack o and return packed bytes
-
- See :class:`Packer` for options.
- """
- packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors,
- use_single_float=use_single_float, use_bin_type=use_bin_type)
- return packer.pack(o)
diff --git a/msgpack/fallback.py b/msgpack/fallback.py
index 8f9d646..3bf0489 100644
--- a/msgpack/fallback.py
+++ b/msgpack/fallback.py
@@ -60,23 +60,6 @@ TYPE_RAW = 3
DEFAULT_RECURSE_LIMIT=511
-def pack(o, stream, **kwargs):
- """
- Pack object `o` and write it to `stream`
-
- See :class:`Packer` for options.
- """
- packer = Packer(**kwargs)
- stream.write(packer.pack(o))
-
-def packb(o, **kwargs):
- """
- Pack object `o` and return packed bytes
-
- See :class:`Packer` for options.
- """
- return Packer(**kwargs).pack(o)
-
def unpack(stream, **kwargs):
"""
Unpack an object from `stream`.