Add raw_as_bytes option to Unpacker. (#265)

This commit is contained in:
INADA Naoki 2018-01-11 17:02:41 +09:00 committed by GitHub
parent 50ea49c86f
commit 5534d0c7af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 199 additions and 93 deletions

View file

@ -20,9 +20,10 @@
#include "unpack_define.h"
typedef struct unpack_user {
int use_list;
PyObject *object_hook;
bool use_list;
bool raw_as_bytes;
bool has_pairs_hook;
PyObject *object_hook;
PyObject *list_hook;
PyObject *ext_hook;
const char *encoding;
@ -225,10 +226,13 @@ static inline int unpack_callback_raw(unpack_user* u, const char* b, const char*
}
PyObject *py;
if(u->encoding) {
if (u->encoding) {
py = PyUnicode_Decode(p, l, u->encoding, u->unicode_errors);
} else {
} else if (u->raw_as_bytes) {
py = PyBytes_FromStringAndSize(p, l);
} else {
py = PyUnicode_DecodeUTF8(p, l, NULL);
}
if (!py)
return -1;