Back to index

python3.2  3.2.2
Classes | Functions | Variables
http.client Namespace Reference

Classes

class  HTTPMessage
class  HTTPResponse
class  HTTPConnection
class  HTTPSConnection
class  HTTPException
class  NotConnected
class  InvalidURL
class  UnknownProtocol
class  UnknownTransferEncoding
class  UnimplementedFileMode
class  IncompleteRead
class  ImproperConnectionState
class  CannotSendRequest
class  CannotSendHeader
class  ResponseNotReady
class  BadStatusLine
class  LineTooLong

Functions

def parse_headers

Variables

list __all__
int HTTP_PORT = 80
int HTTPS_PORT = 443
string _UNKNOWN = 'UNKNOWN'
string _CS_IDLE = 'Idle'
string _CS_REQ_STARTED = 'Request-started'
string _CS_REQ_SENT = 'Request-sent'
int CONTINUE = 100
int SWITCHING_PROTOCOLS = 101
int PROCESSING = 102
int OK = 200
int CREATED = 201
int ACCEPTED = 202
int NON_AUTHORITATIVE_INFORMATION = 203
int NO_CONTENT = 204
int RESET_CONTENT = 205
int PARTIAL_CONTENT = 206
int MULTI_STATUS = 207
int IM_USED = 226
int MULTIPLE_CHOICES = 300
int MOVED_PERMANENTLY = 301
int FOUND = 302
int SEE_OTHER = 303
int NOT_MODIFIED = 304
int USE_PROXY = 305
int TEMPORARY_REDIRECT = 307
int BAD_REQUEST = 400
int UNAUTHORIZED = 401
int PAYMENT_REQUIRED = 402
int FORBIDDEN = 403
int NOT_FOUND = 404
int METHOD_NOT_ALLOWED = 405
int NOT_ACCEPTABLE = 406
int PROXY_AUTHENTICATION_REQUIRED = 407
int REQUEST_TIMEOUT = 408
int CONFLICT = 409
int GONE = 410
int LENGTH_REQUIRED = 411
int PRECONDITION_FAILED = 412
int REQUEST_ENTITY_TOO_LARGE = 413
int REQUEST_URI_TOO_LONG = 414
int UNSUPPORTED_MEDIA_TYPE = 415
int REQUESTED_RANGE_NOT_SATISFIABLE = 416
int EXPECTATION_FAILED = 417
int UNPROCESSABLE_ENTITY = 422
int LOCKED = 423
int FAILED_DEPENDENCY = 424
int UPGRADE_REQUIRED = 426
int INTERNAL_SERVER_ERROR = 500
int NOT_IMPLEMENTED = 501
int BAD_GATEWAY = 502
int SERVICE_UNAVAILABLE = 503
int GATEWAY_TIMEOUT = 504
int HTTP_VERSION_NOT_SUPPORTED = 505
int INSUFFICIENT_STORAGE = 507
int NOT_EXTENDED = 510
dictionary responses
int MAXAMOUNT = 1048576
int _MAXLINE = 65536
tuple _strict_sentinel = object()
 error = HTTPException

Detailed Description

HTTP/1.1 client library

<intro stuff goes here>
<other stuff, too>

HTTPConnection goes through a number of "states", which define when a client
may legally make another request or fetch the response for a particular
request. This diagram details these state transitions:

(null)
  |
  | HTTPConnection()
  v
Idle
  |
  | putrequest()
  v
Request-started
  |
  | ( putheader() )*  endheaders()
  v
Request-sent
  |
  | response = getresponse()
  v
Unread-response   [Response-headers-read]
  |\____________________
  |                     |
  | response.read()     | putrequest()
  v                     v
Idle                  Req-started-unread-response
                 ______/|
               /        |
   response.read() |        | ( putheader() )*  endheaders()
               v        v
   Request-started    Req-sent-unread-response
                        |
                        | response.read()
                        v
                      Request-sent

This diagram presents the following rules:
  -- a second request may not be started until {response-headers-read}
  -- a response [object] cannot be retrieved until {request-sent}
  -- there is no differentiation between an unread response body and a
 partially read response body

Note: this enforcement is applied by the HTTPConnection class. The
  HTTPResponse class does not enforce this state machine, which
  implies sophisticated clients may accelerate the request/response
  pipeline. Caution should be taken, though: accelerating the states
  beyond the above pattern may imply knowledge of the server's
  connection-close behavior for certain requests. For example, it
  is impossible to tell whether the server will close the connection
  UNTIL the response headers have been read; this means that further
  requests cannot be placed into the pipeline until it is known that
  the server will NOT be closing the connection.

Logical State                  __state            __response
-------------                  -------            ----------
Idle                           _CS_IDLE           None
Request-started                _CS_REQ_STARTED    None
Request-sent                   _CS_REQ_SENT       None
Unread-response                _CS_IDLE           <response_class>
Req-started-unread-response    _CS_REQ_STARTED    <response_class>
Req-sent-unread-response       _CS_REQ_SENT       <response_class>

Function Documentation

def http.client.parse_headers (   fp,
  _class = HTTPMessage 
)
Parses only RFC2822 headers from a file pointer.

email Parser wants to see strings rather than bytes.
But a TextIOWrapper around self.rfile would buffer too many bytes
from the stream, bytes which we later need to read as bytes.
So we read the correct bytes here, as bytes, for email Parser
to parse.

Definition at line 240 of file client.py.

00240 
00241 def parse_headers(fp, _class=HTTPMessage):
00242     """Parses only RFC2822 headers from a file pointer.
00243 
00244     email Parser wants to see strings rather than bytes.
00245     But a TextIOWrapper around self.rfile would buffer too many bytes
00246     from the stream, bytes which we later need to read as bytes.
00247     So we read the correct bytes here, as bytes, for email Parser
00248     to parse.
00249 
00250     """
00251     headers = []
00252     while True:
00253         line = fp.readline(_MAXLINE + 1)
00254         if len(line) > _MAXLINE:
00255             raise LineTooLong("header line")
00256         headers.append(line)
00257         if line in (b'\r\n', b'\n', b''):
00258             break
00259     hstring = b''.join(headers).decode('iso-8859-1')
00260     return email.parser.Parser(_class=_class).parsestr(hstring)
00261 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 ["HTTPResponse", "HTTPConnection",
00002            "HTTPException", "NotConnected", "UnknownProtocol",
00003            "UnknownTransferEncoding", "UnimplementedFileMode",
00004            "IncompleteRead", "InvalidURL", "ImproperConnectionState",
00005            "CannotSendRequest", "CannotSendHeader", "ResponseNotReady",
00006            "BadStatusLine", "error", "responses"]

Definition at line 78 of file client.py.

Definition at line 91 of file client.py.

string http.client._CS_REQ_SENT = 'Request-sent'

Definition at line 93 of file client.py.

string http.client._CS_REQ_STARTED = 'Request-started'

Definition at line 92 of file client.py.

Definition at line 208 of file client.py.

Definition at line 262 of file client.py.

Definition at line 88 of file client.py.

Definition at line 104 of file client.py.

Definition at line 148 of file client.py.

Definition at line 122 of file client.py.

Definition at line 131 of file client.py.

Definition at line 97 of file client.py.

Definition at line 103 of file client.py.

Definition at line 1177 of file client.py.

Definition at line 139 of file client.py.

Definition at line 142 of file client.py.

Definition at line 125 of file client.py.

Definition at line 115 of file client.py.

Definition at line 150 of file client.py.

Definition at line 132 of file client.py.

Definition at line 85 of file client.py.

Definition at line 151 of file client.py.

Definition at line 86 of file client.py.

Definition at line 110 of file client.py.

Definition at line 152 of file client.py.

Definition at line 146 of file client.py.

Definition at line 133 of file client.py.

Definition at line 141 of file client.py.

Definition at line 205 of file client.py.

Definition at line 127 of file client.py.

Definition at line 114 of file client.py.

Definition at line 109 of file client.py.

Definition at line 113 of file client.py.

Definition at line 106 of file client.py.

Definition at line 105 of file client.py.

Definition at line 128 of file client.py.

Definition at line 153 of file client.py.

Definition at line 126 of file client.py.

Definition at line 147 of file client.py.

Definition at line 117 of file client.py.

Definition at line 102 of file client.py.

Definition at line 108 of file client.py.

Definition at line 124 of file client.py.

Definition at line 134 of file client.py.

Definition at line 99 of file client.py.

Definition at line 129 of file client.py.

Definition at line 135 of file client.py.

Definition at line 130 of file client.py.

Definition at line 136 of file client.py.

Definition at line 138 of file client.py.

Definition at line 107 of file client.py.

Definition at line 156 of file client.py.

Definition at line 116 of file client.py.

Definition at line 149 of file client.py.

Definition at line 98 of file client.py.

Definition at line 119 of file client.py.

Definition at line 123 of file client.py.

Definition at line 140 of file client.py.

Definition at line 137 of file client.py.

Definition at line 143 of file client.py.

Definition at line 118 of file client.py.