Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ omit =
hyper/compat.py
hyper/httplib_compat.py
hyper/ssl_compat.py
hyper/http20/hpack_compat.py
hyper/packages/*
46 changes: 0 additions & 46 deletions conftest.py

This file was deleted.

6 changes: 3 additions & 3 deletions hyper/http20/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from ..common.exceptions import ConnectionResetError
from ..common.bufsocket import BufferedSocket
from ..common.headers import HTTPHeaderMap
from .hpack_compat import Encoder, Decoder
from .stream import Stream
from .frame import (
from ..packages.hyperframe.frame import (
FRAMES, DataFrame, HeadersFrame, PushPromiseFrame, RstStreamFrame,
SettingsFrame, Frame, WindowUpdateFrame, GoAwayFrame, PingFrame,
BlockedFrame
)
from ..packages.hpack.hpack_compat import Encoder, Decoder
from .stream import Stream
from .response import HTTP20Response, HTTP20Push
from .window import FlowControlManager
from .exceptions import ConnectionError
Expand Down
4 changes: 2 additions & 2 deletions hyper/http20/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
the stream by the endpoint that initiated the stream.
"""
from ..common.headers import HTTPHeaderMap
from .exceptions import ProtocolError
from .frame import (
from ..packages.hyperframe.frame import (
FRAME_MAX_LEN, FRAMES, HeadersFrame, DataFrame, PushPromiseFrame,
WindowUpdateFrame, ContinuationFrame, BlockedFrame
)
from .exceptions import ProtocolError
from .util import h2_safe_headers
import collections
import logging
Expand Down
7 changes: 7 additions & 0 deletions hyper/packages/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
"""
hyper/packages
~~~~~~~~~~~~~~

This module contains external packages that are vendored into hyper.
"""
8 changes: 8 additions & 0 deletions hyper/packages/hpack/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
"""
hpack
~~~~~

HTTP/2 header encoding for Python.
"""
__version__ = '1.0.0'
33 changes: 33 additions & 0 deletions hyper/packages/hpack/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
"""
hpack/compat
~~~~~~~~~~~~

Normalizes the Python 2/3 API for internal use.
"""
import sys


_ver = sys.version_info
is_py2 = _ver[0] == 2
is_py3 = _ver[0] == 3

if is_py2:
def to_byte(char):
return ord(char)

def decode_hex(b):
return b.decode('hex')

unicode = unicode
bytes = str

elif is_py3:
def to_byte(char):
return char

def decode_hex(b):
return bytes.fromhex(b)

unicode = str
bytes = bytes
42 changes: 42 additions & 0 deletions hyper/packages/hpack/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
"""
hyper/http20/exceptions
~~~~~~~~~~~~~~~~~~~~~~~

This defines exceptions used in the HTTP/2 portion of hyper.
"""

class HTTP20Error(Exception):
"""
The base class for all of ``hyper``'s HTTP/2-related exceptions.
"""
pass


class HPACKEncodingError(HTTP20Error):
"""
An error has been encountered while performing HPACK encoding.
"""
pass


class HPACKDecodingError(HTTP20Error):
"""
An error has been encountered while performing HPACK decoding.
"""
pass


class ConnectionError(HTTP20Error):
"""
The remote party signalled an error affecting the entire HTTP/2
connection, and the connection has been closed.
"""
pass


class ProtocolError(HTTP20Error):
"""
The remote party violated the HTTP/2 protocol.
"""
pass
13 changes: 5 additions & 8 deletions hyper/http20/hpack.py → hyper/packages/hpack/hpack.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# -*- coding: utf-8 -*-
"""
hyper/http20/hpack
~~~~~~~~~~~~~~~~~~
hpack/hpack
~~~~~~~~~~~

Implements the HPACK header compression algorithm as detailed by the IETF.

Implements the version dated July 31, 2014.
"""
import collections
import logging

from ..compat import to_byte
from .compat import to_byte
from .huffman import HuffmanDecoder, HuffmanEncoder
from hyper.http20.huffman_constants import (
from .huffman_constants import (
REQUEST_CODES, REQUEST_CODES_LENGTH
)
from .exceptions import HPACKEncodingError

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -79,7 +76,7 @@ def _to_bytes(string):
"""
Convert string to bytes.
"""
if not isinstance(string, (str, bytes)):
if not isinstance(string, (str, bytes)): # pragma: no cover
string = str(string)

return string if isinstance(string, bytes) else string.encode('utf-8')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# -*- coding: utf-8 -*-
"""
hyper/http20/hpack_compat
~~~~~~~~~~~~~~~~~~~~~~~~~
hpack/hpack_compat
~~~~~~~~~~~~~~~~~~

Provides an abstraction layer over two HPACK implementations.

Hyper has a pure-Python greenfield HPACK implementation that can be used on
all Python platforms. However, this implementation is both slower and more
This module has a pure-Python greenfield HPACK implementation that can be used
on all Python platforms. However, this implementation is both slower and more
memory-hungry than could be achieved with a C-language version. Additionally,
nghttp2's HPACK implementation currently achieves better compression ratios
than hyper's in almost all benchmarks.

For those who care about efficiency and speed in HPACK, hyper allows you to
use nghttp2's HPACK implementation instead of hyper's. This module detects
For those who care about efficiency and speed in HPACK, this module allows you
to use nghttp2's HPACK implementation instead of ours. This module detects
whether the nghttp2 bindings are installed, and if they are it wraps them in
a hyper-compatible API and uses them instead of its own. If not, it falls back
to hyper's built-in Python bindings.
a hpack-compatible API and uses them instead of its own. If not, it falls back
to the built-in Python bindings.
"""
import logging
from .hpack import _to_bytes
Expand All @@ -29,7 +29,7 @@
log.debug("Using nghttp2's HPACK implementation.")
except ImportError:
USE_NGHTTP2 = False
log.debug("Using hyper's pure-Python HPACK implementation.")
log.debug("Using our pure-Python HPACK implementation.")

if USE_NGHTTP2:
class Encoder(object):
Expand Down
6 changes: 3 additions & 3 deletions hyper/http20/huffman.py → hyper/packages/hpack/huffman.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
"""
hyper/http20/huffman_decoder
~~~~~~~~~~~~~~~~~~~~~~~~~~~
hpack/huffman_decoder
~~~~~~~~~~~~~~~~~~~~~

An implementation of a bitwise prefix tree specially built for decoding
Huffman-coded content where we already know the Huffman table.
"""
from ..compat import to_byte, decode_hex
from .compat import to_byte, decode_hex
from .exceptions import HPACKDecodingError

def _pad_binary(bin_str, req_len=8):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
hyper/http20/huffman_constants
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hpack/huffman_constants
~~~~~~~~~~~~~~~~~~~~~~~

Defines the constant Huffman table. This takes up an upsetting amount of space,
but c'est la vie.
Expand Down
8 changes: 8 additions & 0 deletions hyper/packages/hyperframe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
"""
hyperframe
~~~~~~~~~~

A module for providing a pure-Python HTTP/2 framing layer.
"""
__version__ = '1.0.0'
5 changes: 3 additions & 2 deletions hyper/http20/frame.py → hyper/packages/hyperframe/frame.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
hyper/http20/frame
~~~~~~~~~~~~~~~~~~
hyperframe/frame
~~~~~~~~~~~~~~~~

Defines framing logic for HTTP/2. Provides both classes to represent framed
data and logic for aiding the connection when it comes to reading from the
Expand All @@ -13,6 +13,7 @@
# The maximum length of a frame. Some frames have shorter maximum lengths.
FRAME_MAX_LEN = (2 ** 14) - 1


class Frame(object):
"""
The base class for all HTTP/2 frames.
Expand Down
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ def resolve_install_requires():
return ['pyOpenSSL>=0.14']
return []

packages = ['hyper', 'hyper.http20', 'hyper.common', 'hyper.http11']
packages = [
'hyper',
'hyper.http20',
'hyper.common',
'hyper.http11',
'hyper.packages',
'hyper.packages.hpack',
'hyper.packages.hyperframe',
]

setup(
name='hyper',
Expand Down
6 changes: 3 additions & 3 deletions test/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from hyper import HTTP20Connection
from hyper.compat import ssl
from hyper.http11.connection import HTTP11Connection
from hyper.http20.hpack import Encoder
from hyper.http20.huffman import HuffmanEncoder
from hyper.http20.huffman_constants import (
from hyper.packages.hpack.hpack import Encoder
from hyper.packages.hpack.huffman import HuffmanEncoder
from hyper.packages.hpack.huffman_constants import (
REQUEST_CODES, REQUEST_CODES_LENGTH
)
from hyper.tls import NPN_PROTOCOL
Expand Down
59 changes: 0 additions & 59 deletions test/test_hpack_integration.py

This file was deleted.

Loading