@@ -65,8 +65,8 @@ cdef class Packer(object):
6565 self .pk.buf_size = buf_size
6666 self .pk.length = 0
6767
68- def __init__ (self , default = None , encoding = ' utf-8' , unicode_errors = ' strict' , use_float = False ):
69- self .use_float = use_float
68+ def __init__ (self , default = None , encoding = ' utf-8' , unicode_errors = ' strict' , use_single_float = False ):
69+ self .use_float = use_single_float
7070 if default is not None :
7171 if not PyCallable_Check(default):
7272 raise TypeError (" default must be a callable." )
@@ -177,10 +177,11 @@ def pack(object o, object stream, default=None, encoding='utf-8', unicode_errors
177177 packer = Packer(default = default, encoding = encoding, unicode_errors = unicode_errors)
178178 stream.write(packer.pack(o))
179179
180- def packb (object o , default = None , encoding = ' utf-8' , unicode_errors = ' strict' ):
180+ def packb (object o , default = None , encoding = ' utf-8' , unicode_errors = ' strict' , use_single_float = False ):
181181 """
182182 pack o and return packed bytes."""
183- packer = Packer(default = default, encoding = encoding, unicode_errors = unicode_errors)
183+ packer = Packer(default = default, encoding = encoding, unicode_errors = unicode_errors,
184+ use_single_float = use_single_float)
184185 return packer.pack(o)
185186
186187
@@ -286,8 +287,8 @@ cdef class Unpacker(object):
286287
287288 `unicode_errors` is used for decoding bytes.
288289
289- `max_buffer_size` limits size of data waiting unpacked. 0 means unlimited
290- (default).
290+ `max_buffer_size` limits size of data waiting unpacked.
291+ 0 means system's INT_MAX (default).
291292 Raises `BufferFull` exception when it is insufficient.
292293 You shoud set this parameter when unpacking data from untrasted source.
293294
@@ -340,11 +341,11 @@ cdef class Unpacker(object):
340341 raise ValueError (" `file_like.read` must be a callable." )
341342 if not max_buffer_size:
342343 max_buffer_size = INT_MAX
344+ if read_size > max_buffer_size:
345+ raise ValueError (" read_size should be less or equal to max_buffer_size" )
343346 if not read_size:
344347 read_size = min (max_buffer_size, 1024 ** 2 )
345348 self .max_buffer_size = max_buffer_size
346- if read_size > max_buffer_size:
347- raise ValueError (" read_size should be less or equal to max_buffer_size" )
348349 self .read_size = read_size
349350 self .buf = < char * > malloc(read_size)
350351 if self .buf == NULL :
@@ -427,18 +428,15 @@ cdef class Unpacker(object):
427428 self .buf_size = buf_size
428429 self .buf_tail = tail + _buf_len
429430
430- # prepare self.buf from file_like
431- cdef fill_buffer(self ):
432- if self .file_like is not None :
433- next_bytes = self .file_like_read(
434- max (self .read_size,
435- self .max_buffer_size - (self .buf_tail - self .buf_head)
436- ))
437- if next_bytes:
438- self .append_buffer(PyBytes_AsString(next_bytes),
439- PyBytes_Size(next_bytes))
440- else :
441- self .file_like = None
431+ cdef read_from_file(self ):
432+ next_bytes = self .file_like_read(
433+ min (self .read_size,
434+ self .max_buffer_size - (self .buf_tail - self .buf_head)
435+ ))
436+ if next_bytes:
437+ self .append_buffer(PyBytes_AsString(next_bytes), PyBytes_Size(next_bytes))
438+ else :
439+ self .file_like = None
442440
443441 cpdef _unpack(self , bool construct):
444442 cdef int ret
@@ -448,7 +446,7 @@ cdef class Unpacker(object):
448446 return
449447 elif ret == 0 :
450448 if self .file_like is not None :
451- self .fill_buffer ()
449+ self .read_from_file ()
452450 continue
453451 raise StopIteration (" No more unpack data." )
454452 else :
0 commit comments