summaryrefslogtreecommitdiff
path: root/msgpack/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'msgpack/__init__.py')
-rw-r--r--msgpack/__init__.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/msgpack/__init__.py b/msgpack/__init__.py
index 77f6b81..79107b6 100644
--- a/msgpack/__init__.py
+++ b/msgpack/__init__.py
@@ -2,15 +2,37 @@
from msgpack._version import version
from msgpack.exceptions import *
+from collections import namedtuple
+
+ExtType = namedtuple('ExtType', 'code data')
+
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
+ from msgpack.fallback import 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