@@ -28,14 +28,14 @@ Install
2828PyPy
2929^^^^
3030
31- msgpack-python provides pure python implementation. PyPy can use this.
31+ msgpack-python provides a pure Python implementation. PyPy can use this.
3232
3333Windows
3434^^^^^^^
3535
36- When you can't use binary distribution, you need to install Visual Studio
36+ When you can't use a binary distribution, you need to install Visual Studio
3737or Windows SDK on Windows.
38- Without extension, using pure python implementation on CPython runs slowly.
38+ Without extension, using pure Python implementation on CPython runs slowly.
3939
4040For Python 2.7, `Microsoft Visual C++ Compiler for Python 2.7 <https://www.microsoft.com/en-us/download/details.aspx?id=44266 >`_
4141is recommended solution.
@@ -51,11 +51,11 @@ One-shot pack & unpack
5151^^^^^^^^^^^^^^^^^^^^^^
5252
5353Use ``packb `` for packing and ``unpackb `` for unpacking.
54- msgpack provides ``dumps `` and ``loads `` as alias for compatibility with
54+ msgpack provides ``dumps `` and ``loads `` as an alias for compatibility with
5555``json `` and ``pickle ``.
5656
57- ``pack `` and ``dump `` packs to file-like object.
58- ``unpack `` and ``load `` unpacks from file-like object.
57+ ``pack `` and ``dump `` packs to a file-like object.
58+ ``unpack `` and ``load `` unpacks from a file-like object.
5959
6060.. code-block :: pycon
6161
@@ -65,14 +65,15 @@ msgpack provides ``dumps`` and ``loads`` as alias for compatibility with
6565 >>> msgpack.unpackb(_)
6666 [1, 2, 3]
6767
68- ``unpack `` unpacks msgpack's array to Python's list, but can unpack to tuple:
68+ ``unpack `` unpacks msgpack's array to Python's list, but can also unpack to tuple:
6969
7070.. code-block :: pycon
7171
7272 >>> msgpack.unpackb(b'\x93\x01\x02\x03', use_list=False)
7373 (1, 2, 3)
7474
75- You should always pass the ``use_list `` keyword argument. See performance issues relating to `use_list option `_ below.
75+ You should always specify the ``use_list `` keyword argument for backward compatibility.
76+ See performance issues relating to `use_list option `_ below.
7677
7778Read the docstring for other options.
7879
@@ -198,29 +199,43 @@ Notes
198199string and binary type
199200^^^^^^^^^^^^^^^^^^^^^^
200201
201- In old days, msgpack doesn 't distinguish string and binary types like Python 1.
202- The type for represent string and binary types is named **raw **.
202+ Early versions of msgpack didn 't distinguish string and binary types ( like Python 1) .
203+ The type for representing both string and binary types was named **raw **.
203204
204- msgpack can distinguish string and binary type for now. But it is not like Python 2.
205- Python 2 added unicode string. But msgpack renamed **raw ** to **str ** and added **bin ** type.
206- It is because keep compatibility with data created by old libs. **raw ** was used for text more than binary.
205+ For backward compatibility reasons, msgpack-python will still default all
206+ strings to byte strings, unless you specify the `use_bin_type=True ` option in
207+ the packer. If you do so, it will use a non-standard type called **bin ** to
208+ serialize byte arrays, and **raw ** becomes to mean **str **. If you want to
209+ distinguish **bin ** and **raw ** in the unpacker, specify `encoding='utf-8' `.
207210
208- Currently, while msgpack-python supports new **bin ** type, default setting doesn't use it and
209- decodes **raw ** as `bytes ` instead of `unicode ` (`str ` in Python 3).
211+ Note that Python 2 defaults to byte-arrays over Unicode strings:
210212
211- You can change this by using `use_bin_type=True ` option in Packer and `encoding="utf-8" ` option in Unpacker.
213+ .. code-block :: pycon
214+
215+ >>> import msgpack
216+ >>> msgpack.unpackb(msgpack.packb([b'spam', u'eggs']))
217+ ['spam', 'eggs']
218+ >>> msgpack.unpackb(msgpack.packb([b'spam', u'eggs'], use_bin_type=True),
219+ encoding='utf-8')
220+ ['spam', u'eggs']
221+
222+ This is the same code in Python 3 (same behaviour, but Python 3 has a
223+ different default):
212224
213225.. code-block :: pycon
214226
215227 >>> import msgpack
216- >>> packed = msgpack.packb([b'spam', u'egg'], use_bin_type=True)
217- >>> msgpack.unpackb(packed, encoding='utf-8')
218- ['spam', u'egg']
228+ >>> msgpack.unpackb(msgpack.packb([b'spam', u'eggs']))
229+ [b'spam', b'eggs']
230+ >>> msgpack.unpackb(msgpack.packb([b'spam', u'eggs'], use_bin_type=True),
231+ encoding='utf-8')
232+ [b'spam', 'eggs']
233+
219234
220235 ext type
221236^^^^^^^^
222237
223- To use **ext ** type, pass ``msgpack.ExtType `` object to packer.
238+ To use the **ext ** type, pass ``msgpack.ExtType `` object to packer.
224239
225240.. code-block :: pycon
226241
@@ -234,7 +249,7 @@ You can use it with ``default`` and ``ext_hook``. See below.
234249Note for msgpack-python 0.2.x users
235250^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
236251
237- The msgpack-python 0.3 have some incompatible changes.
252+ The msgpack-python release 0.3 has some incompatible changes.
238253
239254The default value of ``use_list `` keyword argument is ``True `` from 0.3.
240255You should pass the argument explicitly for backward compatibility.
0 commit comments