summaryrefslogtreecommitdiff
path: root/msgpack/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'msgpack/__init__.py')
-rw-r--r--msgpack/__init__.py22
1 files changed, 20 insertions, 2 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