aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorEugene Kliuchnikov <eustas@google.com>2016-10-17 17:40:32 +0200
committerGitHub <noreply@github.com>2016-10-17 17:40:32 +0200
commitd60aa2311664f0ac35b6ed1a10a990658eba4b86 (patch)
tree484f9d48ca2447a9467ff285f659a7e4e526836e /python
parent4219fece592059522a1c800b3b16804d543f477e (diff)
parentf7b5b3dc2c69f2a71120e499949f9435ccdf4126 (diff)
downloadbrotli-d60aa2311664f0ac35b6ed1a10a990658eba4b86.zip
brotli-d60aa2311664f0ac35b6ed1a10a990658eba4b86.tar.gz
brotli-d60aa2311664f0ac35b6ed1a10a990658eba4b86.tar.bz2
Merge pull request #443 from nicksay/py-2-package-structure
Python: Create native brotli module and move extension to _brotli
Diffstat (limited to 'python')
-rw-r--r--python/_brotli.cc (renamed from python/brotlimodule.cc)14
-rw-r--r--python/brotli.py26
2 files changed, 32 insertions, 8 deletions
diff --git a/python/brotlimodule.cc b/python/_brotli.cc
index 1d3b208..27e8346 100644
--- a/python/brotlimodule.cc
+++ b/python/_brotli.cc
@@ -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
diff --git a/python/brotli.py b/python/brotli.py
new file mode 100644
index 0000000..b63e218
--- /dev/null
+++ b/python/brotli.py
@@ -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