@@ -32,6 +32,12 @@ def __init__(self, host, port=None, **kwargs):
3232
3333 Most of the standard library's arguments to the constructor are
3434 irrelevant for HTTP/2.0 or not supported by hyper.
35+
36+ :param host: The host to connect to. This may be an IP address or a
37+ hostname, and optionally may include a port: for example,
38+ ``'twitter.com'``, ``'twitter.com:443'`` or ``'127.0.0.1'``.
39+ :param port: (optional) The port to connect to. If not provided and one
40+ also isn't provided in the ``host`` parameter, defaults to 443.
3541 """
3642 if port is None :
3743 try :
@@ -78,7 +84,12 @@ def request(self, method, url, body=None, headers={}):
7884 encodings, pass a bytes object. The Content-Length header is set to the
7985 length of the body field.
8086
81- Returns a stream ID for the request.
87+ :returns: A stream ID for the request.
88+ :param method: The request method, e.g. ``'GET'``.
89+ :param url: The URL to contact, e.g. ``'/path/segment'``.
90+ :param body: (optional) The request body to send. Must be a bytestring
91+ or a file-like object.
92+ :param headers: (optional) The headers to send on the request.
8293 """
8394 stream_id = self .putrequest (method , url )
8495
@@ -100,6 +111,10 @@ def getresponse(self, stream_id=None):
100111 the request whose response you want. Returns a HTTPResponse instance.
101112 If you pass no stream_id, you will receive the oldest HTTPResponse
102113 still outstanding.
114+
115+ :param stream_id: (optional) The stream ID of the request for which to
116+ get a response.
117+ :returns: A HTTP response object.
103118 """
104119 stream = (self .streams [stream_id ] if stream_id is not None
105120 else self .recent_stream )
@@ -109,6 +124,8 @@ def connect(self):
109124 """
110125 Connect to the server specified when the object was created. This is a
111126 no-op if we're already connected.
127+
128+ :returns: Nothing.
112129 """
113130 if self ._sock is None :
114131 sock = socket .create_connection ((self .host , self .port ), 5 )
@@ -131,6 +148,8 @@ def connect(self):
131148 def close (self ):
132149 """
133150 Close the connection to the server.
151+
152+ :returns: Nothing.
134153 """
135154 # Todo: we should actually clean ourselves up if possible by sending
136155 # GoAway frames and closing all outstanding streams. For now this will
@@ -144,6 +163,10 @@ def putrequest(self, method, selector, **kwargs):
144163 This should be the first call for sending a given HTTP request to a
145164 server. It returns a stream ID for the given connection that should be
146165 passed to all subsequent request building calls.
166+
167+ :param method: The request method, e.g. ``'GET'``.
168+ :param selector: The path selector.
169+ :returns: A stream ID for the request.
147170 """
148171 # Create a new stream.
149172 s = self ._new_stream ()
@@ -170,6 +193,12 @@ def putheader(self, header, argument, stream_id=None):
170193 Unlike the httplib version of this function, this version does not
171194 actually send anything when called. Instead, it queues the headers up
172195 to be sent when you call ``endheaders``.
196+
197+ :param header: The name of the header.
198+ :param argument: The value of the header.
199+ :param stream_id: (optional) The stream ID of the request to add the
200+ header to.
201+ :returns: Nothing.
173202 """
174203 stream = (self .streams [stream_id ] if stream_id is not None
175204 else self .recent_stream )
@@ -186,6 +215,15 @@ def endheaders(self, message_body=None, final=False, stream_id=None):
186215 ``final`` argument is set to True, the stream will also immediately
187216 be closed: otherwise, the stream will be left open and subsequent calls
188217 to ``send()`` will be required.
218+
219+ :param message_body: (optional) The body to send. May not be provided
220+ assuming that ``send()`` will be called.
221+ :param final: (optional) If the ``message_body`` parameter is provided,
222+ should be set to ``True`` if no further data will be provided via
223+ calls to ``send()``.
224+ :param stream_id: (optional) The stream ID of the request to finish
225+ sending the headers on.
226+ :returns: Nothing.
189227 """
190228 self .connect ()
191229
@@ -208,6 +246,13 @@ def send(self, data, final=False, stream_id=None):
208246 (excluding the normal HTTP/2.0 flow control rules). If this is the last
209247 data that will be sent as part of this request, the ``final`` argument
210248 should be set to ``True``. This will cause the stream to be closed.
249+
250+ :param data: The data to send.
251+ :param final: (optional) Whether this is the last bit of data to be
252+ sent on this request.
253+ :param stream_id: (optional) The stream ID of the request to send the
254+ data on.
255+ :returns: Nothing.
211256 """
212257 stream = (self .streams [stream_id ] if stream_id is not None
213258 else self .recent_stream )
0 commit comments