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

Commit 0eb717e

Browse files
committed
Better method names in HTTP/2.
1 parent 042bb84 commit 0eb717e

File tree

11 files changed

+41
-41
lines changed

11 files changed

+41
-41
lines changed

docs/source/advanced.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ you decide you want to avoid keeping the connection open, you can use the
1717

1818
with HTTP20Connection('twitter.com:443') as conn:
1919
conn.request('GET', '/')
20-
data = conn.getresponse().read()
20+
data = conn.get_response().read()
2121

2222
analyse(data)
2323

@@ -130,7 +130,7 @@ In order to receive pushed resources, the
130130
with ``enable_push=True``.
131131

132132
You may retrieve the push promises that the server has sent *so far* by calling
133-
:meth:`getpushes() <hyper.HTTP20Connection.getpushes>`, which returns a
133+
:meth:`get_pushes() <hyper.HTTP20Connection.get_pushes>`, which returns a
134134
generator that yields :class:`HTTP20Push <hyper.HTTP20Push>` objects. Note that
135135
this method is not idempotent; promises returned in one call will not be
136136
returned in subsequent calls. If ``capture_all=False`` is passed (the default),
@@ -143,11 +143,11 @@ the original response, or when also processing the original response in a
143143
separate thread (N.B. do not do this; ``hyper`` is not yet thread-safe)::
144144

145145
conn.request('GET', '/')
146-
response = conn.getresponse()
147-
for push in conn.getpushes(): # all pushes promised before response headers
146+
response = conn.get_response()
147+
for push in conn.get_pushes(): # all pushes promised before response headers
148148
print(push.path)
149149
conn.read()
150-
for push in conn.getpushes(): # all other pushes
150+
for push in conn.get_pushes(): # all other pushes
151151
print(push.path)
152152

153153
To cancel an in-progress pushed stream (for example, if the user already has

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ improved speed, lower bandwidth usage, better connection management, and more.
1818

1919
conn = HTTP20Connection('twitter.com:443')
2020
conn.request('GET', '/')
21-
resp = conn.getresponse()
21+
resp = conn.get_response()
2222

2323
print(resp.read())
2424

docs/source/quickstart.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Begin by getting the Twitter homepage::
6161
>>> c = HTTP20Connection('twitter.com:443')
6262
>>> c.request('GET', '/')
6363
1
64-
>>> resp = c.getresponse()
64+
>>> resp = c.get_response()
6565

6666
Used in this way, ``hyper`` behaves exactly like ``http.client``. You can make
6767
sequential requests using the exact same API you're accustomed to. The only
@@ -103,9 +103,9 @@ For example::
103103
>>> first = c.request('GET', '/')
104104
>>> second = c.request('GET', '/lukasaoz')
105105
>>> third = c.request('GET', '/about')
106-
>>> second_response = c.getresponse(second)
107-
>>> first_response = c.getresponse(first)
108-
>>> third_response = c.getresponse(third)
106+
>>> second_response = c.get_response(second)
107+
>>> first_response = c.get_response(first)
108+
>>> third_response = c.get_response(third)
109109

110110
``hyper`` will ensure that each response is matched to the correct request.
111111

hyper/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def get_content_type_and_charset(response):
216216
def request(args):
217217
conn = HTTP20Connection(args.url.host, args.url.port)
218218
conn.request(args.method, args.url.path, args.body, args.headers)
219-
response = conn.getresponse()
219+
response = conn.get_response()
220220
log.debug('Response Headers:\n%s', pformat(response.getheaders()))
221221
ctype, charset = get_content_type_and_charset(response)
222222
data = response.read().decode(charset)

hyper/contrib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def send(self, request, stream=False, **kwargs):
5858
request.body,
5959
request.headers
6060
)
61-
resp = conn.getresponse(stream_id)
61+
resp = conn.get_response(stream_id)
6262

6363
r = self.build_response(request, resp)
6464

hyper/http20/connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class HTTP20Connection(object):
5050
will be used.
5151
:param enable_push: (optional) Whether the server is allowed to push
5252
resources to the client (see
53-
:meth:`getpushes() <hyper.HTTP20Connection.getpushes>`).
53+
:meth:`get_pushes() <hyper.HTTP20Connection.get_pushes>`).
5454
"""
5555
def __init__(self, host, port=None, window_manager=None, enable_push=False,
5656
**kwargs):
@@ -156,7 +156,7 @@ def _get_stream(self, stream_id):
156156
return (self.streams[stream_id] if stream_id is not None
157157
else self.recent_stream)
158158

159-
def getresponse(self, stream_id=None):
159+
def get_response(self, stream_id=None):
160160
"""
161161
Should be called after a request is sent to get a response from the
162162
server. If sending multiple parallel requests, pass the stream ID of
@@ -172,7 +172,7 @@ def getresponse(self, stream_id=None):
172172
stream = self._get_stream(stream_id)
173173
return HTTP20Response(stream.getheaders(), stream)
174174

175-
def getpushes(self, stream_id=None, capture_all=False):
175+
def get_pushes(self, stream_id=None, capture_all=False):
176176
"""
177177
Returns a generator that yields push promises from the server. **Note
178178
that this method is not idempotent**: promises returned in one call
@@ -191,7 +191,7 @@ def getpushes(self, stream_id=None, capture_all=False):
191191
corresponding to the streams pushed by the server.
192192
"""
193193
stream = self._get_stream(stream_id)
194-
for promised_stream_id, headers in stream.getpushes(capture_all):
194+
for promised_stream_id, headers in stream.get_pushes(capture_all):
195195
yield HTTP20Push(
196196
HTTPHeaderMap(headers), self.streams[promised_stream_id]
197197
)

hyper/http20/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def __init__(self, request_headers, stream):
181181

182182
self._stream = stream
183183

184-
def getresponse(self):
184+
def get_response(self):
185185
"""
186186
Get the pushed response provided by the server.
187187

hyper/http20/stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def gettrailers(self):
324324

325325
return self.response_trailers
326326

327-
def getpushes(self, capture_all=False):
327+
def get_pushes(self, capture_all=False):
328328
"""
329329
Returns a generator that yields push promises from the server. Note that
330330
this method is not idempotent; promises returned in one call will not be

test/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, host, port):
5151
def request(self, method, path, body, headers):
5252
return method, path, body, headers
5353

54-
def getresponse(self):
54+
def get_response(self):
5555
return self.response
5656

5757

test/test_hyper.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,8 @@ def test_read_headers_out_of_order(self):
12131213
r1 = c.request('GET', '/a')
12141214
r3 = c.request('GET', '/b')
12151215

1216-
assert c.getresponse(r3).headers == HTTPHeaderMap([('content-type', 'baz/qux')])
1217-
assert c.getresponse(r1).headers == HTTPHeaderMap([('content-type', 'foo/bar')])
1216+
assert c.get_response(r3).headers == HTTPHeaderMap([('content-type', 'baz/qux')])
1217+
assert c.get_response(r1).headers == HTTPHeaderMap([('content-type', 'foo/bar')])
12181218

12191219
def test_headers_with_continuation(self):
12201220
e = Encoder()
@@ -1233,7 +1233,7 @@ def test_headers_with_continuation(self):
12331233
c._sock = sock
12341234
r = c.request('GET', '/')
12351235

1236-
assert set(c.getresponse(r).headers.iter_raw()) == set([(b'content-type', b'foo/bar'), (b'content-length', b'0')])
1236+
assert set(c.get_response(r).headers.iter_raw()) == set([(b'content-type', b'foo/bar'), (b'content-length', b'0')])
12371237

12381238
def test_receive_unexpected_frame(self):
12391239
# RST_STREAM frames are never defined on connections, so send one of
@@ -1275,7 +1275,7 @@ def test_window_increments_appropriately(self):
12751275
c.window_manager.window_size = 1000
12761276
c.window_manager.initial_window_size = 1000
12771277
c.request('GET', '/')
1278-
resp = c.getresponse()
1278+
resp = c.get_response()
12791279
resp.read()
12801280

12811281
queue = list(map(decode_frame, map(memoryview, sock.queue)))
@@ -1371,12 +1371,12 @@ def request(self):
13711371
self.conn.request('GET', '/')
13721372

13731373
def assert_response(self):
1374-
self.response = self.conn.getresponse()
1374+
self.response = self.conn.get_response()
13751375
assert self.response.status == 200
13761376
assert dict(self.response.headers) == {b'content-type': [b'text/html']}
13771377

13781378
def assert_pushes(self):
1379-
self.pushes = list(self.conn.getpushes())
1379+
self.pushes = list(self.conn.get_pushes())
13801380
assert len(self.pushes) == 1
13811381
assert self.pushes[0].method == b'GET'
13821382
assert self.pushes[0].scheme == b'https'
@@ -1386,7 +1386,7 @@ def assert_pushes(self):
13861386
assert dict(self.pushes[0].request_headers) == expected_headers
13871387

13881388
def assert_push_response(self):
1389-
push_response = self.pushes[0].getresponse()
1389+
push_response = self.pushes[0].get_response()
13901390
assert push_response.status == 200
13911391
assert dict(push_response.headers) == {b'content-type': [b'application/javascript']}
13921392
assert push_response.read() == b'bar'
@@ -1399,7 +1399,7 @@ def test_promise_before_headers(self):
13991399
self.add_data_frame(2, b'bar', end_stream=True)
14001400

14011401
self.request()
1402-
assert len(list(self.conn.getpushes())) == 0
1402+
assert len(list(self.conn.get_pushes())) == 0
14031403
self.assert_response()
14041404
self.assert_pushes()
14051405
assert self.response.read() == b'foo'
@@ -1413,9 +1413,9 @@ def test_promise_after_headers(self):
14131413
self.add_data_frame(2, b'bar', end_stream=True)
14141414

14151415
self.request()
1416-
assert len(list(self.conn.getpushes())) == 0
1416+
assert len(list(self.conn.get_pushes())) == 0
14171417
self.assert_response()
1418-
assert len(list(self.conn.getpushes())) == 0
1418+
assert len(list(self.conn.get_pushes())) == 0
14191419
assert self.response.read() == b'foo'
14201420
self.assert_pushes()
14211421
self.assert_push_response()
@@ -1429,9 +1429,9 @@ def test_promise_after_data(self):
14291429
self.add_data_frame(2, b'bar', end_stream=True)
14301430

14311431
self.request()
1432-
assert len(list(self.conn.getpushes())) == 0
1432+
assert len(list(self.conn.get_pushes())) == 0
14331433
self.assert_response()
1434-
assert len(list(self.conn.getpushes())) == 0
1434+
assert len(list(self.conn.get_pushes())) == 0
14351435
assert self.response.read() == b'foo'
14361436
self.assert_pushes()
14371437
self.assert_push_response()
@@ -1447,13 +1447,13 @@ def test_capture_all_promises(self):
14471447
self.add_data_frame(2, b'one', end_stream=True)
14481448

14491449
self.request()
1450-
assert len(list(self.conn.getpushes())) == 0
1451-
pushes = list(self.conn.getpushes(capture_all=True))
1450+
assert len(list(self.conn.get_pushes())) == 0
1451+
pushes = list(self.conn.get_pushes(capture_all=True))
14521452
assert len(pushes) == 2
14531453
assert pushes[0].path == b'/one'
14541454
assert pushes[1].path == b'/two'
1455-
assert pushes[0].getresponse().read() == b'one'
1456-
assert pushes[1].getresponse().read() == b'two'
1455+
assert pushes[0].get_response().read() == b'one'
1456+
assert pushes[1].get_response().read() == b'two'
14571457
self.assert_response()
14581458
assert self.response.read() == b'foo'
14591459

@@ -1462,8 +1462,8 @@ def test_cancel_push(self):
14621462
self.add_headers_frame(1, [(':status', '200'), ('content-type', 'text/html')])
14631463

14641464
self.request()
1465-
self.conn.getresponse()
1466-
list(self.conn.getpushes())[0].cancel()
1465+
self.conn.get_response()
1466+
list(self.conn.get_pushes())[0].cancel()
14671467

14681468
f = RstStreamFrame(2)
14691469
f.error_code = 8
@@ -1475,7 +1475,7 @@ def test_reset_pushed_streams_when_push_disabled(self):
14751475

14761476
self.request()
14771477
self.conn._enable_push = False
1478-
self.conn.getresponse()
1478+
self.conn.get_response()
14791479

14801480
f = RstStreamFrame(2)
14811481
f.error_code = 7

0 commit comments

Comments
 (0)