Skip to content

Commit

Permalink
Remove deprecated python bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Dec 26, 2022
1 parent 2c62572 commit b4cb3b0
Show file tree
Hide file tree
Showing 29 changed files with 14 additions and 3,648 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -54,4 +54,3 @@ _VC_ROOT/
.depend.MSVC
*.pyd
*.egg-info/
python/nghttp2.c
40 changes: 5 additions & 35 deletions CMakeLists.txt
Expand Up @@ -52,9 +52,8 @@ endif()

include(GNUInstallDirs)

# For Python bindings and documentation
# (Must be called before PythonLibs for matching versions.)
find_package(PythonInterp)
# For documentation
find_package(Python3 COMPONENTS Interpreter)

# Auto-detection of features that can be toggled
find_package(OpenSSL 1.0.1)
Expand Down Expand Up @@ -84,13 +83,6 @@ set(ENABLE_HPACK_TOOLS_DEFAULT ${JANSSON_FOUND})
# 2.0.8 is required because we use evconnlistener_set_error_cb()
find_package(Libevent 2.0.8 COMPONENTS core extra openssl)
set(ENABLE_EXAMPLES_DEFAULT ${LIBEVENT_OPENSSL_FOUND})
find_package(Cython)
find_package(PythonLibs)
if(CYTHON_FOUND AND PYTHONLIBS_FOUND)
set(ENABLE_PYTHON_BINDINGS_DEFAULT ON)
else()
set(ENABLE_PYTHON_BINDINGS_DEFAULT OFF)
endif()

find_package(LibXml2 2.6.26)
set(WITH_LIBXML2_DEFAULT ${LIBXML2_FOUND})
Expand All @@ -99,8 +91,7 @@ set(WITH_JEMALLOC_DEFAULT ${JEMALLOC_FOUND})

include(CMakeOptions.txt)

if(ENABLE_LIB_ONLY AND (ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_EXAMPLES OR
ENABLE_PYTHON_BINDINGS))
if(ENABLE_LIB_ONLY AND (ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_EXAMPLES))
# Remember when disabled options are disabled for later diagnostics.
set(ENABLE_LIB_ONLY_DISABLED_OTHERS 1)
else()
Expand All @@ -110,7 +101,6 @@ if(ENABLE_LIB_ONLY)
set(ENABLE_APP OFF)
set(ENABLE_HPACK_TOOLS OFF)
set(ENABLE_EXAMPLES OFF)
set(ENABLE_PYTHON_BINDINGS OFF)
endif()

# Do not disable assertions based on CMAKE_BUILD_TYPE.
Expand Down Expand Up @@ -156,20 +146,6 @@ cmake_pop_check_state()
# Additional libraries required for programs under src directory.
set(APP_LIBRARIES)

if(ENABLE_PYTHON_BINDINGS)
if(NOT (CYTHON_FOUND AND PYTHONLIBS_FOUND))
message(FATAL_ERROR "python bindings were requested "
"(ENABLE_PYTHON_BINDINGS=1) but dependencies are not met.")
endif()
if(NOT PYTHON_VERSION_STRING STREQUAL PYTHONLIBS_VERSION_STRING)
message(FATAL_ERROR
"Python executable and library must have the same version!"
" Found Python ${PYTHON_VERSION_STRING} and"
" PythonLibs ${PYTHONLIBS_VERSION_STRING}"
)
endif()
endif()

set(CMAKE_THREAD_PREFER_PTHREAD 1)
find_package(Threads)
if(CMAKE_USE_PTHREADS_INIT)
Expand Down Expand Up @@ -463,7 +439,6 @@ set(sbindir "${CMAKE_INSTALL_FULL_SBINDIR}")
foreach(name
lib/libnghttp2.pc
lib/includes/nghttp2/nghttp2ver.h
python/setup.py
integration-tests/config.go
integration-tests/setenv
doc/conf.py
Expand All @@ -474,7 +449,6 @@ foreach(name
doc/tutorial-hpack.rst
doc/nghttpx-howto.rst
doc/h2load-howto.rst
doc/python-apiref.rst
doc/building-android-binary.rst
doc/nghttp2.h.rst
doc/nghttp2ver.h.rst
Expand Down Expand Up @@ -502,7 +476,6 @@ add_subdirectory(third-party)
add_subdirectory(src)
#add_subdirectory(src/includes)
add_subdirectory(examples)
add_subdirectory(python)
add_subdirectory(tests)
#add_subdirectory(tests/testdata)
add_subdirectory(integration-tests)
Expand Down Expand Up @@ -530,10 +503,8 @@ message(STATUS "summary of build options:
WARNCFLAGS: ${WARNCFLAGS}
CXX1XCXXFLAGS: ${CXX1XCXXFLAGS}
Python:
Python: ${PYTHON_EXECUTABLE}
PYTHON_VERSION: ${PYTHON_VERSION_STRING}
Library version:${PYTHONLIBS_VERSION_STRING}
Cython: ${CYTHON_EXECUTABLE}
Python: ${Python3_EXECUTABLE}
Python3_VERSION: ${Python3_VERSION}
Test:
CUnit: ${HAVE_CUNIT} (LIBS='${CUNIT_LIBRARIES}')
Failmalloc: ${ENABLE_FAILMALLOC}
Expand All @@ -559,7 +530,6 @@ message(STATUS "summary of build options:
Applications: ${ENABLE_APP}
HPACK tools: ${ENABLE_HPACK_TOOLS}
Examples: ${ENABLE_EXAMPLES}
Python bindings:${ENABLE_PYTHON_BINDINGS}
Threading: ${ENABLE_THREADS}
HTTP/3(EXPERIMENTAL): ${ENABLE_HTTP3}
")
Expand Down
4 changes: 1 addition & 3 deletions CMakeOptions.txt
Expand Up @@ -9,10 +9,8 @@ option(ENABLE_HPACK_TOOLS "Build HPACK tools"
${ENABLE_HPACK_TOOLS_DEFAULT})
option(ENABLE_EXAMPLES "Build examples"
${ENABLE_EXAMPLES_DEFAULT})
option(ENABLE_PYTHON_BINDINGS "Build Python bindings"
${ENABLE_PYTHON_BINDINGS_DEFAULT})
option(ENABLE_FAILMALLOC "Build failmalloc test program" ON)
option(ENABLE_LIB_ONLY "Build libnghttp2 only. This is a short hand for -DENABLE_APP=0 -DENABLE_EXAMPLES=0 -DENABLE_HPACK_TOOLS=0 -DENABLE_PYTHON_BINDINGS=0")
option(ENABLE_LIB_ONLY "Build libnghttp2 only. This is a short hand for -DENABLE_APP=0 -DENABLE_EXAMPLES=0 -DENABLE_HPACK_TOOLS=0")
option(ENABLE_STATIC_LIB "Build libnghttp2 in static mode also")
option(ENABLE_SHARED_LIB "Build libnghttp2 as a shared library" ON)
option(ENABLE_STATIC_CRT "Build libnghttp2 against the MS LIBCMT[d]")
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile.android
Expand Up @@ -33,7 +33,7 @@ RUN apt-get update && \
apt-get install -y unzip make binutils autoconf \
automake autotools-dev libtool pkg-config git \
curl dpkg-dev libxml2-dev genisoimage libc6-i386 \
lib32stdc++6 python3 && \
lib32stdc++6 && \
rm -rf /var/cache/apt/*

# Download NDK
Expand Down Expand Up @@ -112,7 +112,6 @@ RUN autoreconf -i && \
--host=$TARGET \
--build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
--without-libxml2 \
--disable-python-bindings \
--disable-examples \
--disable-threads \
CPPFLAGS="-fPIE -I$PREFIX/include" \
Expand Down
8 changes: 1 addition & 7 deletions Makefile.am
Expand Up @@ -20,14 +20,9 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SUBDIRS = lib third-party src bpf examples python tests integration-tests \
SUBDIRS = lib third-party src bpf examples tests integration-tests \
doc contrib script

# Now with python setuptools, make uninstall will leave many files we
# cannot easily remove (e.g., easy-install.pth). Disable it for
# distcheck rule.
AM_DISTCHECK_CONFIGURE_FLAGS = --disable-python-bindings

ACLOCAL_AMFLAGS = -I m4

dist_doc_DATA = README.rst
Expand All @@ -42,7 +37,6 @@ EXTRA_DIST = nghttpx.conf.sample proxy.pac.sample android-config android-env \
cmake/FindLibev.cmake \
cmake/FindCUnit.cmake \
cmake/Version.cmake \
cmake/FindCython.cmake \
cmake/FindLibevent.cmake \
cmake/FindJansson.cmake \
cmake/FindLibcares.cmake \
Expand Down
125 changes: 0 additions & 125 deletions README.rst
Expand Up @@ -103,12 +103,6 @@ To mitigate heap fragmentation in long running server programs
Alpine Linux currently does not support malloc replacement
due to musl limitations. See details in issue `#762 <https://github.com/nghttp2/nghttp2/issues/762>`_.

The Python bindings (deprecated) require the following packages:

* cython >= 0.19
* python >= 3.8
* python-setuptools

To enable mruby support for nghttpx, `mruby
<https://github.com/mruby/mruby>`_ is required. We need to build
mruby with C++ ABI explicitly turned on, and probably need other
Expand Down Expand Up @@ -400,7 +394,6 @@ Build nghttp2:
$ git submodule update --init
$ autoreconf -i
$ ./configure --with-mruby --with-neverbleed --enable-http3 --with-libbpf \
--disable-python-bindings \
CC=clang-14 CXX=clang++-14 \
PKG_CONFIG_PATH="$PWD/../openssl/build/lib/pkgconfig:$PWD/../nghttp3/build/lib/pkgconfig:$PWD/../ngtcp2/build/lib/pkgconfig:$PWD/../libbpf/build/lib64/pkgconfig" \
LDFLAGS="$LDFLAGS -Wl,-rpath,$PWD/../openssl/build/lib -Wl,-rpath,$PWD/../libbpf/build/lib64"
Expand Down Expand Up @@ -1425,124 +1418,6 @@ associated value includes the state of the dynamic header table after the
corresponding header set was processed. The format is the same as
``deflatehd``.

Python bindings
---------------

Python bindings have been deprecated.

The ``python`` directory contains nghttp2 Python bindings. The
bindings currently provide HPACK compressor and decompressor classes
and an HTTP/2 server.

The extension module is called ``nghttp2``.

``make`` will build the bindings and target Python version is
determined by the ``configure`` script. If the detected Python version is not
what you expect, specify a path to Python executable in a ``PYTHON``
variable as an argument to configure script (e.g., ``./configure
PYTHON=/usr/bin/python3.8``).

The following example code illustrates basic usage of the HPACK compressor
and decompressor in Python:

.. code-block:: python
import binascii
import nghttp2
deflater = nghttp2.HDDeflater()
inflater = nghttp2.HDInflater()
data = deflater.deflate([(b'foo', b'bar'),
(b'baz', b'buz')])
print(binascii.b2a_hex(data))
hdrs = inflater.inflate(data)
print(hdrs)
The ``nghttp2.HTTP2Server`` class builds on top of the asyncio event
loop. On construction, *RequestHandlerClass* must be given, which
must be a subclass of ``nghttp2.BaseRequestHandler`` class.

The ``BaseRequestHandler`` class is used to handle the HTTP/2 stream.
By default, it does nothing. It must be subclassed to handle each
event callback method.

The first callback method invoked is ``on_headers()``. It is called
when HEADERS frame, which includes the request header fields, has arrived.

If the request has a request body, ``on_data(data)`` is invoked for each
chunk of received data.

Once the entire request is received, ``on_request_done()`` is invoked.

When the stream is closed, ``on_close(error_code)`` is called.

The application can send a response using ``send_response()`` method.
It can be used in ``on_headers()``, ``on_data()`` or
``on_request_done()``.

The application can push resources using the ``push()`` method. It must be
used before the ``send_response()`` call.

The following instance variables are available:

client_address
Contains a tuple of the form (host, port) referring to the
client's address.

stream_id
Stream ID of this stream.

scheme
Scheme of the request URI. This is a value of :scheme header
field.

method
Method of this stream. This is a value of :method header field.

host
This is a value of :authority or host header field.

path
This is a value of :path header field.

The following example illustrates the HTTP2Server and
BaseRequestHandler usage:

.. code-block:: python
#!/usr/bin/env python3
import io, ssl
import nghttp2
class Handler(nghttp2.BaseRequestHandler):
def on_headers(self):
self.push(path='/css/bootstrap.css',
request_headers = [('content-length', '3')],
status=200,
body='foo')
self.push(path='/js/bootstrap.js',
method='GET',
request_headers = [('content-length', '10')],
status=200,
body='foobarbuzz')
self.send_response(status=200,
headers = [('content-type', 'text/plain')],
body=io.BytesIO(b'nghttp2-python FTW'))
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ctx.options = ssl.OP_ALL | ssl.OP_NO_SSLv2
ctx.load_cert_chain('server.crt', 'server.key')
# give None to ssl to make the server non-SSL/TLS
server = nghttp2.HTTP2Server(('127.0.0.1', 8443), Handler, ssl=ctx)
server.serve_forever()
Contribution
------------

Expand Down
1 change: 0 additions & 1 deletion android-config
Expand Up @@ -30,7 +30,6 @@
--host=$TARGET \
--build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
--without-libxml2 \
--disable-python-bindings \
--disable-examples \
--disable-threads \
CPPFLAGS="-fPIE -I$PREFIX/include" \
Expand Down
44 changes: 0 additions & 44 deletions cmake/FindCython.cmake

This file was deleted.

0 comments on commit b4cb3b0

Please sign in to comment.