8000 better packer docstring · loude/msgpack-python@3ce005c · GitHub
[go: up one dir, main page]

Skip to content < 8000 script crossorigin="anonymous" type="application/javascript" src="https://github.githubassets.com/assets/ui_packages_document-metadata_document-metadata_ts-ui_packages_hydro-analytics_hydro-analytic-f29230-07417997172c.js" defer="defer">

Commit 3ce005c

Browse files
committed
better packer docstring
1 parent 1e38bfa commit 3ce005c

File tree

5 files changed

+66
-19
lines changed

5 files changed

+66
-19
lines changed

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
.PHONY: test all python3
22

3-
all:
3+
all: cython
44
python setup.py build_ext -i -f
5-
python setup.py build sdist
65

7-
python3:
6+
doc-serve: all
7+
cd docs && make serve
8+
9+
cython:
10+
cython msgpack/*.pyx
11+
12+
python3: cython
813
python3 setup.py build_ext -i -f
9-
python3 setup.py build sdist
1014

1115
test:
1216
py.test test

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BUILDDIR = _build
1010
# Internal variables.
1111
PAPEROPT_a4 = -D latex_paper_size=a4
1212
PAPEROPT_letter = -D latex_paper_size=letter
13-
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
13+
ALLSPHINXOPTS = -E -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
1414
# the i18n builder cannot share the environment and doctrees with the others
1515
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
1616

docs/api.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ These exceptions are accessible via `msgpack` package.
3636
:undoc-members:
3737
:show-inheritance:
3838

39+
.. automodule:: msgpack.fallback
40+
:members:
41+
:undoc-members:
42+
:show-inheritance:
43+

msgpack/_packer.pyx

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,29 @@ cdef int DEFAULT_RECURSE_LIMIT=511
3939

4040

4141
cdef class Packer(object):
42-
"""MessagePack Packer
42+
"""
43+
MessagePack Packer
4344
44-
usage:
45+
usage::
4546
4647
packer = Packer()
4748
astream.write(packer.pack(a))
4849
astream.write(packer.pack(b))
4950
5051
Packer's constructor has some keyword arguments:
5152
52-
* *defaut* - Convert user type to builtin type that Packer supports.
53-
See also simplejson's document.
54-
* *encoding* - Convert unicode to bytes with this encoding. (default: 'utf-8')
55-
* *unicode_erros* - Error handler for encoding unicode. (default: 'strict')
56-
* *use_single_float* - Use single precision float type for float. (default: False)
57-
* *autoreset* - Reset buffer after each pack and return it's content as `bytes`. (default: True).
58-
If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.
53+
:param callable default:
54+
Convert user type to builtin type that Packer supports.
55+
See also simplejson's document.
56+
:param str encoding:
57+
Convert unicode to bytes with this encoding. (default: 'utf-8')
58+
:param str unicode_erros:
59+
Error handler for encoding unicode. (default: 'strict')
60+
:param bool use_single_float:
61+
Use single precision float type for float. (default: False)
62+
:param bool autoreset:
63+
Reset buffer after each pack and return it's content as `bytes`. (default: True).
64+
If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.
5965
"""
6066
cdef msgpack_packer pk
6167
cdef object _default
@@ -75,6 +81,8 @@ cdef class Packer(object):
7581
self.pk.length = 0
7682

7783
def __init__(self, default=None, encoding='utf-8', unicode_errors='strict', use_single_float=False, bint autoreset=1):
84+
"""
85+
"""
7886
self.use_float = use_single_float
7987
self.autoreset = autoreset
8088
if default is not None:
@@ -218,7 +226,7 @@ cdef class Packer(object):
218226
Pack *pairs* as msgpack map type.
219227
220228
*pairs* should sequence of pair.
221-
(`len(pairs)` and `for k, v in *pairs*:` should be supported.)
229+
(`len(pairs)` and `for k, v in pairs:` should be supported.)
222230
"""
223231
cdef int ret = msgpack_pack_map(&self.pk, len(pairs))
224232
if ret == 0:
@@ -245,15 +253,21 @@ cdef class Packer(object):
245253
return PyBytes_FromStringAndSize(self.pk.buf, self.pk.length)
246254

247255

248-
def pack(object o, object stream, default=None, encoding='utf-8', unicode_errors='strict'):
256+
def pack(object o, object stream, default=None, str encoding='utf-8', str unicode_errors='strict'):
257+
"""
258+
pack an object `o` and write it to stream)
259+
260+
See :class:`Packer` for options.
249261
"""
250-
pack an object `o` and write it to stream)."""
251262
packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors)
252263
stream.write(packer.pack(o))
253264

254-
def packb(object o, default=None, encoding='utf-8', unicode_errors='strict', use_single_float=False):
265+
def packb(object o, default=None, encoding='utf-8', str unicode_errors='strict', bint use_single_float=False):
266+
"""
267+
pack o and return packed bytes
268+
269+
See :class:`Packer` for options.
255270
"""
256-
pack o and return packed bytes."""
257271
packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors,
258272
use_single_float=use_single_float)
259273
return packer.pack(o)

msgpack/fallback.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,30 @@ def read_map_header(self, write_bytes=None):
423423

424424

425425
class Packer(object):
426+
"""
427+
MessagePack Packer
428+
429+
usage:
430+
431+
packer = Packer()
432+
astream.write(packer.pack(a))
433+
astream.write(packer.pack(b))
434+
435+
Packer's constructor has some keyword arguments:
436+
437+
:param callable default:
438+
Convert user type to builtin type that Packer supports.
439+
See also simplejson's document.
440+
:param str encoding:
441+
Convert unicode to bytes with this encoding. (default: 'utf-8')
442+
:param str unicode_erros:
443+
Error handler for encoding unicode. (default: 'strict')
444+
:param bool use_single_float:
445+
Use single precision float type for float. (default: False)
446+
:param bool autoreset:
447+
Reset buffer after each pack and return it's content as `bytes`. (default: True).
448+
If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.
449+
"""
426450
def __init__(self, default=None, encoding='utf-8', unicode_errors='strict',
427451
use_single_float=False, autoreset=True):
428452
self._use_float = use_single_float

0 commit comments

Comments
 (0)
0