diff options
author | Andrew Rabert <6550543+nvllsvm@users.noreply.github.com> | 2018-02-02 20:34:42 -0500 |
---|---|---|
committer | INADA Naoki <methane@users.noreply.github.com> | 2018-02-03 10:34:42 +0900 |
commit | a0ba076c3527bb474cd8ec820ae0fd6c8293d4af (patch) | |
tree | e2761d0cc2a67eb21f283eb1b2bb2956ce59df8c /msgpack | |
parent | 52fb85a2c5776590599df3a5839117b88bc49980 (diff) | |
download | msgpack-python-a0ba076c3527bb474cd8ec820ae0fd6c8293d4af.tar.gz |
Fix encoding and unicode_errors (#277)
Previously, unicode_errors was either set to NULL or to
the result of PyBytes_AsString. This restores that behavior while also
keeping the existing NULL default behavior.
Original defaults were restored to keep API compatibility until these
deprecated options are finally removed.
Diffstat (limited to 'msgpack')
-rw-r--r-- | msgpack/_packer.pyx | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx index 35e5a9d..c49e719 100644 --- a/msgpack/_packer.pyx +++ b/msgpack/_packer.pyx @@ -127,27 +127,26 @@ cdef class Packer(object): if not PyCallable_Check(default): raise TypeError("default must be a callable.") self._default = default - if encoding is None: - if unicode_errors is None: - self.encoding = NULL - self.unicode_errors = NULL - else: - self.encoding = "utf_8" - self.unicode_errors = unicode_errors + if encoding is None and unicode_errors is None: + self.encoding = NULL + self.unicode_errors = NULL else: - if isinstance(encoding, unicode): - self._bencoding = encoding.encode('ascii') + if encoding is None: + self.encoding = 'utf-8' else: - self._bencoding = encoding - self.encoding = PyBytes_AsString(self._bencoding) - if isinstance(unicode_errors, unicode): - self._berrors = unicode_errors.encode('ascii') + if isinstance(encoding, unicode): + self._bencoding = encoding.encode('ascii') + else: + self._bencoding = encoding + self.encoding = PyBytes_AsString(self._bencoding) + if unicode_errors is None: + self.unicode_errors = 'strict' else: - self._berrors = unicode_errors - if self._berrors is not None: + if isinstance(unicode_errors, unicode): + self._berrors = unicode_errors.encode('ascii') + else: + self._berrors = unicode_errors self.unicode_errors = PyBytes_AsString(self._berrors) - else: - self.unicode_errors = NULL def __dealloc__(self): PyMem_Free(self.pk.buf) |