Skip to content

Commit ec3a7a0

Browse files
committed
Fixup examples to remove deprecated code
1 parent 51ec572 commit ec3a7a0

File tree

11 files changed

+34
-14
lines changed

11 files changed

+34
-14
lines changed

examples/asyncio/asyncio-server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import collections
2121
from typing import List, Tuple
2222

23+
from h2.config import H2Configuration
2324
from h2.connection import H2Connection
2425
from h2.events import (
2526
ConnectionTerminated, DataReceived, RequestReceived, StreamEnded
@@ -33,7 +34,8 @@
3334

3435
class H2Protocol(asyncio.Protocol):
3536
def __init__(self):
36-
self.conn = H2Connection(client_side=False)
37+
config = H2Configuration(client_side=False, header_encoding='utf-8')
38+
self.conn = H2Connection(config=config)
3739
self.transport = None
3840
self.stream_data = {}
3941

examples/asyncio/wsgi-server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import sys
6666
import threading
6767

68+
from h2.config import H2Configuration
6869
from h2.connection import H2Connection
6970
from h2.events import (
7071
DataReceived, RequestReceived, WindowUpdated, StreamEnded, StreamReset
@@ -86,8 +87,10 @@
8687

8788
class H2Protocol(asyncio.Protocol):
8889
def __init__(self):
90+
config = H2Configuration(client_side=False, header_encoding='utf-8')
91+
8992
# Our server-side state machine.
90-
self.conn = H2Connection(client_side=False)
93+
self.conn = H2Connection(config=config)
9194

9295
# The backing transport.
9396
self.transport = None

examples/curio/curio-server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from curio import Kernel, Event, spawn, socket, ssl
1616

17+
import h2.config
1718
import h2.connection
1819
import h2.events
1920

@@ -64,8 +65,11 @@ class H2Server:
6465
HTTP/1.1.
6566
"""
6667
def __init__(self, sock, root):
68+
config = h2.config.H2Configuration(
69+
client_side=False, header_encoding='utf-8'
70+
)
6771
self.sock = sock
68-
self.conn = h2.connection.H2Connection(client_side=False)
72+
self.conn = h2.connection.H2Connection(config=config)
6973
self.root = root
7074
self.flow_control_events = {}
7175

examples/eventlet/eventlet-server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import eventlet
1212

1313
from eventlet.green.OpenSSL import SSL, crypto
14+
from h2.config import H2Configuration
1415
from h2.connection import H2Connection
1516
from h2.events import RequestReceived, DataReceived
1617

@@ -20,8 +21,9 @@ class ConnectionManager(object):
2021
An object that manages a single HTTP/2 connection.
2122
"""
2223
def __init__(self, sock):
24+
config = H2Configuration(client_side=False)
2325
self.sock = sock
24-
self.conn = H2Connection(client_side=False)
26+
self.conn = H2Connection(config=config)
2527

2628
def run_forever(self):
2729
self.conn.initiate_connection()

examples/fragments/client_https_setup_fragment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def main():
9999
# Step 3: Wrap the connection in TLS and validate that we negotiated HTTP/2
100100
tls_connection = negotiate_tls(connection, context)
101101

102-
# Step 4: Create a server-side H2 connection.
103-
http2_connection = h2.connection.H2Connection(client_side=True)
102+
# Step 4: Create a client-side H2 connection.
103+
http2_connection = h2.connection.H2Connection()
104104

105105
# Step 5: Initiate the connection
106106
http2_connection.initiate_connection()

examples/fragments/server_https_setup_fragment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
This code requires Python 3.5 or later.
1515
"""
16+
import h2.config
1617
import h2.connection
1718
import socket
1819
import ssl
@@ -100,7 +101,8 @@ def main():
100101
tls_connection = negotiate_tls(connection, context)
101102

102103
# Step 4: Create a server-side H2 connection.
103-
http2_connection = h2.connection.H2Connection(client_side=False)
104+
config = h2.config.H2Configuration(client_side=False)
105+
http2_connection = h2.connection.H2Connection(config=config)
104106

105107
# Step 5: Initiate the connection
106108
http2_connection.initiate_connection()

examples/fragments/server_upgrade_fragment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
This code requires Python 3.5 or later.
1313
"""
14+
import h2.config
1415
import h2.connection
1516
import re
1617
import socket
@@ -81,7 +82,8 @@ def main():
8182

8283
# Step 3: Create a H2Connection object in server mode, and pass it the
8384
# value of the HTTP2-Settings header field.
84-
h2_connection = h2.connection.H2Connection(client_side=False)
85+
config = h2.config.H2Configuration(client_side=False)
86+
h2_connection = h2.connection.H2Connection(config=config)
8587
h2_connection.initiate_upgrade_connection(
8688
settings_header=settings_header_value
8789
)

examples/tornado/tornado-server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import tornado.iostream
1616
import tornado.tcpserver
1717

18+
from h2.config import H2Configuration
1819
from h2.connection import H2Connection
1920
from h2.events import RequestReceived, DataReceived
2021

@@ -42,7 +43,9 @@ class EchoHeadersHandler(object):
4243

4344
def __init__(self, stream):
4445
self.stream = stream
45-
self.conn = H2Connection(client_side=False)
46+
47+
config = H2Configuration(client_side=False)
48+
self.conn = H2Connection(config=config)
4649

4750
@tornado.gen.coroutine
4851
def handle(self):

examples/twisted/head_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def settingsAcked(self, event):
7575

7676
def handleResponse(self, response_headers, stream_id):
7777
for name, value in response_headers:
78-
print("%s: %s" % (name, value))
78+
print("%s: %s" % (name.decode('utf-8'), value.decode('utf-8')))
7979

8080
print("")
8181

examples/twisted/post_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def handleResponse(self, response_headers):
103103
Handle the response by printing the response headers.
104104
"""
105105
for name, value in response_headers:
106-
print("%s: %s" % (name, value))
106+
print("%s: %s" % (name.decode('utf-8'), value.decode('utf-8')))
107107

108108
print("")
109109

0 commit comments

Comments
 (0)