Merge pull request #443 from nicksay/py-2-package-structure

Python: Create native brotli module and move extension to _brotli
This commit is contained in:
Eugene Kliuchnikov 2016-10-17 17:40:32 +02:00 committed by GitHub
commit d60aa23116
3 changed files with 40 additions and 10 deletions

View File

@ -244,7 +244,7 @@ static PyObject* brotli_decompress(PyObject *self, PyObject *args, PyObject *key
} else {
PyErr_SetString(BrotliError, "BrotliDecompress failed");
}
BrotliDecoderDestroyInstance(state);
delete[] buffer;
@ -257,18 +257,16 @@ static PyMethodDef brotli_methods[] = {
{NULL, NULL, 0, NULL}
};
PyDoc_STRVAR(brotli__doc__,
"The functions in this module allow compression and decompression using the\n"
"Brotli library.\n\n");
PyDoc_STRVAR(brotli__doc__, "Implementation module for the Brotli library.");
#if PY_MAJOR_VERSION >= 3
#define INIT_BROTLI PyInit_brotli
#define INIT_BROTLI PyInit__brotli
#define CREATE_BROTLI PyModule_Create(&brotli_module)
#define RETURN_BROTLI return m
static struct PyModuleDef brotli_module = {
PyModuleDef_HEAD_INIT,
"brotli",
"_brotli",
brotli__doc__,
0,
brotli_methods,
@ -277,8 +275,8 @@ static struct PyModuleDef brotli_module = {
NULL
};
#else
#define INIT_BROTLI initbrotli
#define CREATE_BROTLI Py_InitModule3("brotli", brotli_methods, brotli__doc__)
#define INIT_BROTLI init_brotli
#define CREATE_BROTLI Py_InitModule3("_brotli", brotli_methods, brotli__doc__)
#define RETURN_BROTLI return
#endif

26
python/brotli.py Normal file
View File

@ -0,0 +1,26 @@
# Copyright 2016 The Brotli Authors. All rights reserved.
#
# Distributed under MIT license.
# See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
"""Functions to compress and decompress data using the Brotli library."""
import _brotli
# The library version.
__version__ = _brotli.__version__
# The compression mode.
MODE_GENERIC = _brotli.MODE_GENERIC
MODE_TEXT = _brotli.MODE_TEXT
MODE_FONT = _brotli.MODE_FONT
# Compress a byte string.
compress = _brotli.compress
# Decompress a compressed byte string.
decompress = _brotli.decompress
# Raised if compression or decompression fails.
error = _brotli.error

View File

@ -174,11 +174,15 @@ CLASSIFIERS = [
'Topic :: Utilities',
]
PACKAGE_DIR = {'': 'python'}
PY_MODULES = ['brotli']
EXT_MODULES = [
Extension(
'brotli',
'_brotli',
sources=[
'python/brotlimodule.cc',
'python/_brotli.cc',
'common/dictionary.c',
'dec/bit_reader.c',
'dec/decode.c',
@ -268,5 +272,7 @@ setup(
license=LICENSE,
platforms=PLATFORMS,
classifiers=CLASSIFIERS,
package_dir=PACKAGE_DIR,
py_modules=PY_MODULES,
ext_modules=EXT_MODULES,
cmdclass=CMD_CLASS)