mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-11-07 13:01:01 +00:00
Merge remote-tracking branch 'origin/master' into skip
This commit is contained in:
commit
032df6f2d9
5 changed files with 33 additions and 25 deletions
|
|
@ -1,6 +1,11 @@
|
||||||
0.2.2
|
0.2.2
|
||||||
=======
|
=======
|
||||||
:release date: NOT RELEASED YET
|
:release date: 2012-09-21
|
||||||
|
|
||||||
|
Changes
|
||||||
|
-------
|
||||||
|
* Add ``use_single_float`` option to ``Packer``. When it is true, packs float
|
||||||
|
object in single precision format.
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
-----------
|
-----------
|
||||||
|
|
@ -8,6 +13,8 @@ Bugs fixed
|
||||||
``unpack()`` doesn't control gc now instead of restoring gc state collectly.
|
``unpack()`` doesn't control gc now instead of restoring gc state collectly.
|
||||||
User can control gc state when gc cause performance issue.
|
User can control gc state when gc cause performance issue.
|
||||||
|
|
||||||
|
* ``Unpacker``'s ``read_size`` option didn't used.
|
||||||
|
|
||||||
0.2.1
|
0.2.1
|
||||||
=======
|
=======
|
||||||
:release date: 2012-08-20
|
:release date: 2012-08-20
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,8 @@ cdef class Packer(object):
|
||||||
self.pk.buf_size = buf_size
|
self.pk.buf_size = buf_size
|
||||||
self.pk.length = 0
|
self.pk.length = 0
|
||||||
|
|
||||||
def __init__(self, default=None, encoding='utf-8', unicode_errors='strict', use_float=False):
|
def __init__(self, default=None, encoding='utf-8', unicode_errors='strict', use_single_float=False):
|
||||||
self.use_float = use_float
|
self.use_float = use_single_float
|
||||||
if default is not None:
|
if default is not None:
|
||||||
if not PyCallable_Check(default):
|
if not PyCallable_Check(default):
|
||||||
raise TypeError("default must be a callable.")
|
raise TypeError("default must be a callable.")
|
||||||
|
|
@ -177,10 +177,11 @@ def pack(object o, object stream, default=None, encoding='utf-8', unicode_errors
|
||||||
packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors)
|
packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors)
|
||||||
stream.write(packer.pack(o))
|
stream.write(packer.pack(o))
|
||||||
|
|
||||||
def packb(object o, default=None, encoding='utf-8', unicode_errors='strict'):
|
def packb(object o, default=None, encoding='utf-8', unicode_errors='strict', use_single_float=False):
|
||||||
"""
|
"""
|
||||||
pack o and return packed bytes."""
|
pack o and return packed bytes."""
|
||||||
packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors)
|
packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors,
|
||||||
|
use_single_float=use_single_float)
|
||||||
return packer.pack(o)
|
return packer.pack(o)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -286,8 +287,8 @@ cdef class Unpacker(object):
|
||||||
|
|
||||||
`unicode_errors` is used for decoding bytes.
|
`unicode_errors` is used for decoding bytes.
|
||||||
|
|
||||||
`max_buffer_size` limits size of data waiting unpacked. 0 means unlimited
|
`max_buffer_size` limits size of data waiting unpacked.
|
||||||
(default).
|
0 means system's INT_MAX (default).
|
||||||
Raises `BufferFull` exception when it is insufficient.
|
Raises `BufferFull` exception when it is insufficient.
|
||||||
You shoud set this parameter when unpacking data from untrasted source.
|
You shoud set this parameter when unpacking data from untrasted source.
|
||||||
|
|
||||||
|
|
@ -340,11 +341,11 @@ cdef class Unpacker(object):
|
||||||
raise ValueError("`file_like.read` must be a callable.")
|
raise ValueError("`file_like.read` must be a callable.")
|
||||||
if not max_buffer_size:
|
if not max_buffer_size:
|
||||||
max_buffer_size = INT_MAX
|
max_buffer_size = INT_MAX
|
||||||
|
if read_size > max_buffer_size:
|
||||||
|
raise ValueError("read_size should be less or equal to max_buffer_size")
|
||||||
if not read_size:
|
if not read_size:
|
||||||
read_size = min(max_buffer_size, 1024**2)
|
read_size = min(max_buffer_size, 1024**2)
|
||||||
self.max_buffer_size = max_buffer_size
|
self.max_buffer_size = max_buffer_size
|
||||||
if read_size > max_buffer_size:
|
|
||||||
raise ValueError("read_size should be less or equal to max_buffer_size")
|
|
||||||
self.read_size = read_size
|
self.read_size = read_size
|
||||||
self.buf = <char*>malloc(read_size)
|
self.buf = <char*>malloc(read_size)
|
||||||
if self.buf == NULL:
|
if self.buf == NULL:
|
||||||
|
|
@ -427,16 +428,13 @@ cdef class Unpacker(object):
|
||||||
self.buf_size = buf_size
|
self.buf_size = buf_size
|
||||||
self.buf_tail = tail + _buf_len
|
self.buf_tail = tail + _buf_len
|
||||||
|
|
||||||
# prepare self.buf from file_like
|
cdef read_from_file(self):
|
||||||
cdef fill_buffer(self):
|
|
||||||
if self.file_like is not None:
|
|
||||||
next_bytes = self.file_like_read(
|
next_bytes = self.file_like_read(
|
||||||
max(self.read_size,
|
min(self.read_size,
|
||||||
self.max_buffer_size - (self.buf_tail - self.buf_head)
|
self.max_buffer_size - (self.buf_tail - self.buf_head)
|
||||||
))
|
))
|
||||||
if next_bytes:
|
if next_bytes:
|
||||||
self.append_buffer(PyBytes_AsString(next_bytes),
|
self.append_buffer(PyBytes_AsString(next_bytes), PyBytes_Size(next_bytes))
|
||||||
PyBytes_Size(next_bytes))
|
|
||||||
else:
|
else:
|
||||||
self.file_like = None
|
self.file_like = None
|
||||||
|
|
||||||
|
|
@ -448,7 +446,7 @@ cdef class Unpacker(object):
|
||||||
return
|
return
|
||||||
elif ret == 0:
|
elif ret == 0:
|
||||||
if self.file_like is not None:
|
if self.file_like is not None:
|
||||||
self.fill_buffer()
|
self.read_from_file()
|
||||||
continue
|
continue
|
||||||
raise StopIteration("No more unpack data.")
|
raise StopIteration("No more unpack data.")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
version = (0, 2, 1)
|
version = (0, 2, 2)
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -1,7 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
version = (0, 2, 1, 'dev1')
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
import struct
|
||||||
from nose import main
|
from nose import main
|
||||||
from nose.tools import *
|
from nose.tools import *
|
||||||
from nose.plugins.skip import SkipTest
|
from nose.plugins.skip import SkipTest
|
||||||
|
|
@ -86,5 +87,9 @@ def testDecodeBinary():
|
||||||
re = unpackb(packb("abc"), encoding=None)
|
re = unpackb(packb("abc"), encoding=None)
|
||||||
assert_equal(re, b"abc")
|
assert_equal(re, b"abc")
|
||||||
|
|
||||||
|
def testPackFloat():
|
||||||
|
assert_equal(packb(1.0, use_single_float=True), b'\xca' + struct.pack('>f', 1.0))
|
||||||
|
assert_equal(packb(1.0, use_single_float=False), b'\xcb' + struct.pack('>d', 1.0))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue