Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 280f219

Browse files
committed
Merge pull request #123 from Lukasa/framingbreakout
Breakout
2 parents d12cb83 + ea348ec commit 280f219

File tree

402 files changed

+147
-1651493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

402 files changed

+147
-1651493
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ omit =
33
hyper/compat.py
44
hyper/httplib_compat.py
55
hyper/ssl_compat.py
6-
hyper/http20/hpack_compat.py
6+
hyper/packages/*

conftest.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

hyper/http20/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
from ..common.exceptions import ConnectionResetError
1010
from ..common.bufsocket import BufferedSocket
1111
from ..common.headers import HTTPHeaderMap
12-
from .hpack_compat import Encoder, Decoder
13-
from .stream import Stream
14-
from .frame import (
12+
from ..packages.hyperframe.frame import (
1513
FRAMES, DataFrame, HeadersFrame, PushPromiseFrame, RstStreamFrame,
1614
SettingsFrame, Frame, WindowUpdateFrame, GoAwayFrame, PingFrame,
1715
BlockedFrame
1816
)
17+
from ..packages.hpack.hpack_compat import Encoder, Decoder
18+
from .stream import Stream
1919
from .response import HTTP20Response, HTTP20Push
2020
from .window import FlowControlManager
2121
from .exceptions import ConnectionError

hyper/http20/stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
the stream by the endpoint that initiated the stream.
1515
"""
1616
from ..common.headers import HTTPHeaderMap
17-
from .exceptions import ProtocolError
18-
from .frame import (
17+
from ..packages.hyperframe.frame import (
1918
FRAME_MAX_LEN, FRAMES, HeadersFrame, DataFrame, PushPromiseFrame,
2019
WindowUpdateFrame, ContinuationFrame, BlockedFrame
2120
)
21+
from .exceptions import ProtocolError
2222
from .util import h2_safe_headers
2323
import collections
2424
import logging

hyper/packages/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
hyper/packages
4+
~~~~~~~~~~~~~~
5+
6+
This module contains external packages that are vendored into hyper.
7+
"""

hyper/packages/hpack/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
hpack
4+
~~~~~
5+
6+
HTTP/2 header encoding for Python.
7+
"""
8+
__version__ = '1.0.0'

hyper/packages/hpack/compat.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
hpack/compat
4+
~~~~~~~~~~~~
5+
6+
Normalizes the Python 2/3 API for internal use.
7+
"""
8+
import sys
9+
10+
11+
_ver = sys.version_info
12+
is_py2 = _ver[0] == 2
13+
is_py3 = _ver[0] == 3
14+
15+
if is_py2:
16+
def to_byte(char):
17+
return ord(char)
18+
19+
def decode_hex(b):
20+
return b.decode('hex')
21+
22+
unicode = unicode
23+
bytes = str
24+
25+
elif is_py3:
26+
def to_byte(char):
27+
return char
28+
29+
def decode_hex(b):
30+
return bytes.fromhex(b)
31+
32+
unicode = str
33+
bytes = bytes

hyper/packages/hpack/exceptions.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
hyper/http20/exceptions
4+
~~~~~~~~~~~~~~~~~~~~~~~
5+
6+
This defines exceptions used in the HTTP/2 portion of hyper.
7+
"""
8+
9+
class HTTP20Error(Exception):
10+
"""
11+
The base class for all of ``hyper``'s HTTP/2-related exceptions.
12+
"""
13+
pass
14+
15+
16+
class HPACKEncodingError(HTTP20Error):
17+
"""
18+
An error has been encountered while performing HPACK encoding.
19+
"""
20+
pass
21+
22+
23+
class HPACKDecodingError(HTTP20Error):
24+
"""
25+
An error has been encountered while performing HPACK decoding.
26+
"""
27+
pass
28+
29+
30+
class ConnectionError(HTTP20Error):
31+
"""
32+
The remote party signalled an error affecting the entire HTTP/2
33+
connection, and the connection has been closed.
34+
"""
35+
pass
36+
37+
38+
class ProtocolError(HTTP20Error):
39+
"""
40+
The remote party violated the HTTP/2 protocol.
41+
"""
42+
pass

hyper/http20/hpack.py renamed to hyper/packages/hpack/hpack.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
hyper/http20/hpack
4-
~~~~~~~~~~~~~~~~~~
3+
hpack/hpack
4+
~~~~~~~~~~~
55
66
Implements the HPACK header compression algorithm as detailed by the IETF.
7-
8-
Implements the version dated July 31, 2014.
97
"""
108
import collections
119
import logging
1210

13-
from ..compat import to_byte
11+
from .compat import to_byte
1412
from .huffman import HuffmanDecoder, HuffmanEncoder
15-
from hyper.http20.huffman_constants import (
13+
from .huffman_constants import (
1614
REQUEST_CODES, REQUEST_CODES_LENGTH
1715
)
18-
from .exceptions import HPACKEncodingError
1916

2017
log = logging.getLogger(__name__)
2118

@@ -79,7 +76,7 @@ def _to_bytes(string):
7976
"""
8077
Convert string to bytes.
8178
"""
82-
if not isinstance(string, (str, bytes)):
79+
if not isinstance(string, (str, bytes)): # pragma: no cover
8380
string = str(string)
8481

8582
return string if isinstance(string, bytes) else string.encode('utf-8')

hyper/http20/hpack_compat.py renamed to hyper/packages/hpack/hpack_compat.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
hyper/http20/hpack_compat
4-
~~~~~~~~~~~~~~~~~~~~~~~~~
3+
hpack/hpack_compat
4+
~~~~~~~~~~~~~~~~~~
55
66
Provides an abstraction layer over two HPACK implementations.
77
8-
Hyper has a pure-Python greenfield HPACK implementation that can be used on
9-
all Python platforms. However, this implementation is both slower and more
8+
This module has a pure-Python greenfield HPACK implementation that can be used
9+
on all Python platforms. However, this implementation is both slower and more
1010
memory-hungry than could be achieved with a C-language version. Additionally,
1111
nghttp2's HPACK implementation currently achieves better compression ratios
1212
than hyper's in almost all benchmarks.
1313
14-
For those who care about efficiency and speed in HPACK, hyper allows you to
15-
use nghttp2's HPACK implementation instead of hyper's. This module detects
14+
For those who care about efficiency and speed in HPACK, this module allows you
15+
to use nghttp2's HPACK implementation instead of ours. This module detects
1616
whether the nghttp2 bindings are installed, and if they are it wraps them in
17-
a hyper-compatible API and uses them instead of its own. If not, it falls back
18-
to hyper's built-in Python bindings.
17+
a hpack-compatible API and uses them instead of its own. If not, it falls back
18+
to the built-in Python bindings.
1919
"""
2020
import logging
2121
from .hpack import _to_bytes
@@ -29,7 +29,7 @@
2929
log.debug("Using nghttp2's HPACK implementation.")
3030
except ImportError:
3131
USE_NGHTTP2 = False
32-
log.debug("Using hyper's pure-Python HPACK implementation.")
32+
log.debug("Using our pure-Python HPACK implementation.")
3333

3434
if USE_NGHTTP2:
3535
class Encoder(object):

0 commit comments

Comments
 (0)