mirror of
https://github.com/google/brotli.git
synced 2024-12-28 18:51:08 +00:00
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:
commit
d60aa23116
@ -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
26
python/brotli.py
Normal 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
|
10
setup.py
10
setup.py
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user