Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
xmlrpc.client.SafeTransport Class Reference

Standard transport class for XML-RPC over HTTPS. More...

Inheritance diagram for xmlrpc.client.SafeTransport:
Inheritance graph
[legend]
Collaboration diagram for xmlrpc.client.SafeTransport:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def make_connection
 Connect to server.
def request
 Send a complete request, and parse the response.
def single_request
def getparser
 Create parser.
def get_host_info
 Get authorization info from host parameter Host may be a string, or a (host, x509-dict) tuple; if a string, it is checked for a "user:pw@host" format, and a "Basic Authentication" header is added if appropriate.
def close
 Clear any cached connection object.
def send_request
 Send HTTP request.
def send_headers
 Send request headers.
def send_content
 Send request body.
def parse_response
 Parse response.

Public Attributes

 verbose

Static Public Attributes

string user_agent = "xmlrpclib.py/%s (by www.pythonware.com)"
 accept_gzip_encoding = True
 encode_threshold = None

Private Attributes

 _connection

Detailed Description

Standard transport class for XML-RPC over HTTPS.

Handles an HTTPS transaction to an XML-RPC server.

Definition at line 1328 of file client.py.


Member Function Documentation

def xmlrpc.client.Transport.close (   self) [inherited]

Clear any cached connection object.

Used in the event of socket errors.

Definition at line 1233 of file client.py.

01233 
01234     def close(self):
01235         if self._connection[1]:
01236             self._connection[1].close()
01237             self._connection = (None, None)

Here is the caller graph for this function:

def xmlrpc.client.Transport.get_host_info (   self,
  host 
) [inherited]

Get authorization info from host parameter Host may be a string, or a (host, x509-dict) tuple; if a string, it is checked for a "user:pw@host" format, and a "Basic Authentication" header is added if appropriate.

Parameters:
hostHost descriptor (URL or (URL, x509 info) tuple).
Returns:
A 3-tuple containing (actual host, extra headers, x509 info). The header and x509 fields may be None.

Definition at line 1191 of file client.py.

01191 
01192     def get_host_info(self, host):
01193 
01194         x509 = {}
01195         if isinstance(host, tuple):
01196             host, x509 = host
01197 
01198         import urllib.parse
01199         auth, host = urllib.parse.splituser(host)
01200 
01201         if auth:
01202             import base64
01203             auth = urllib.parse.unquote_to_bytes(auth)
01204             auth = base64.encodebytes(auth).decode("utf-8")
01205             auth = "".join(auth.split()) # get rid of whitespace
01206             extra_headers = [
01207                 ("Authorization", "Basic " + auth)
01208                 ]
01209         else:
01210             extra_headers = []
01211 
01212         return host, extra_headers, x509

Here is the call graph for this function:

Here is the caller graph for this function:

def xmlrpc.client.Transport.getparser (   self) [inherited]

Create parser.

Returns:
A 2-tuple containing a parser and a unmarshaller.

Definition at line 1177 of file client.py.

01177 
01178     def getparser(self):
01179         # get parser and unmarshaller
01180         return getparser(use_datetime=self._use_datetime)

Here is the caller graph for this function:

def xmlrpc.client.SafeTransport.make_connection (   self,
  host 
)

Connect to server.

Parameters:
hostTarget host.
Returns:
An HTTPConnection object

Reimplemented from xmlrpc.client.Transport.

Definition at line 1333 of file client.py.

01333 
01334     def make_connection(self, host):
01335         if self._connection and host == self._connection[0]:
01336             return self._connection[1]
01337 
01338         if not hasattr(http.client, "HTTPSConnection"):
01339             raise NotImplementedError(
01340             "your version of http.client doesn't support HTTPS")
01341         # create a HTTPS connection object from a host descriptor
01342         # host may be a string, or a (host, x509-dict) tuple
01343         chost, self._extra_headers, x509 = self.get_host_info(host)
01344         self._connection = host, http.client.HTTPSConnection(chost,
01345             None, **(x509 or {}))
01346         return self._connection[1]

Here is the call graph for this function:

def xmlrpc.client.Transport.parse_response (   self,
  response 
) [inherited]

Parse response.

Parameters:
fileStream.
Returns:
Response tuple and target method.

Definition at line 1298 of file client.py.

01298 
01299     def parse_response(self, response):
01300         # read response data from httpresponse, and parse it
01301         # Check for new http response object, otherwise it is a file object.
01302         if hasattr(response, 'getheader'):
01303             if response.getheader("Content-Encoding", "") == "gzip":
01304                 stream = GzipDecodedResponse(response)
01305             else:
01306                 stream = response
01307         else:
01308             stream = response
01309 
01310         p, u = self.getparser()
01311 
01312         while 1:
01313             data = stream.read(1024)
01314             if not data:
01315                 break
01316             if self.verbose:
01317                 print("body:", repr(data))
01318             p.feed(data)
01319 
01320         if stream is not response:
01321             stream.close()
01322         p.close()
01323 
01324         return u.close()

Here is the call graph for this function:

def xmlrpc.client.Transport.request (   self,
  host,
  handler,
  request_body,
  verbose = False 
) [inherited]

Send a complete request, and parse the response.

Retry request if a cached connection has disconnected.

Parameters:
hostTarget host.
handlerTarget PRC handler.
request_bodyXML-RPC request body.
verboseDebugging flag.
Returns:
Parsed response.

Definition at line 1132 of file client.py.

01132 
01133     def request(self, host, handler, request_body, verbose=False):
01134         #retry request once if cached connection has gone cold
01135         for i in (0, 1):
01136             try:
01137                 return self.single_request(host, handler, request_body, verbose)
01138             except socket.error as e:
01139                 if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
01140                     raise
01141             except http.client.BadStatusLine: #close after we sent request
01142                 if i:
01143                     raise

Here is the call graph for this function:

def xmlrpc.client.Transport.send_content (   self,
  connection,
  request_body 
) [inherited]

Send request body.

This function provides a useful hook for subclassing

Parameters:
connectionhttpConnection.
request_bodyXML-RPC request body.

Definition at line 1281 of file client.py.

01281 
01282     def send_content(self, connection, request_body):
01283         #optionally encode the request
01284         if (self.encode_threshold is not None and
01285             self.encode_threshold < len(request_body) and
01286             gzip):
01287             connection.putheader("Content-Encoding", "gzip")
01288             request_body = gzip_encode(request_body)
01289 
01290         connection.putheader("Content-Length", str(len(request_body)))
01291         connection.endheaders(request_body)

Here is the call graph for this function:

Here is the caller graph for this function:

def xmlrpc.client.Transport.send_headers (   self,
  connection,
  headers 
) [inherited]

Send request headers.

This function provides a useful hook for subclassing

Parameters:
connectionhttpConnection.
headerslist of key,value pairs for HTTP headers

Definition at line 1270 of file client.py.

01270 
01271     def send_headers(self, connection, headers):
01272         for key, val in headers:
01273             connection.putheader(key, val)

Here is the caller graph for this function:

def xmlrpc.client.Transport.send_request (   self,
  host,
  handler,
  request_body,
  debug 
) [inherited]

Send HTTP request.

Parameters:
hostHost descriptor (URL or (URL, x509 info) tuple).
handlerTarger RPC handler (a path relative to host)
request_bodyThe XML-RPC request body
debugEnable debugging if debug is true.
Returns:
An HTTPConnection.

Definition at line 1247 of file client.py.

01247 
01248     def send_request(self, host, handler, request_body, debug):
01249         connection = self.make_connection(host)
01250         headers = self._extra_headers[:]
01251         if debug:
01252             connection.set_debuglevel(1)
01253         if self.accept_gzip_encoding and gzip:
01254             connection.putrequest("POST", handler, skip_accept_encoding=True)
01255             headers.append(("Accept-Encoding", "gzip"))
01256         else:
01257             connection.putrequest("POST", handler)
01258         headers.append(("Content-Type", "text/xml"))
01259         headers.append(("User-Agent", self.user_agent))
01260         self.send_headers(connection, headers)
01261         self.send_content(connection, request_body)
01262         return connection

Here is the call graph for this function:

Here is the caller graph for this function:

def xmlrpc.client.Transport.single_request (   self,
  host,
  handler,
  request_body,
  verbose = False 
) [inherited]

Definition at line 1144 of file client.py.

01144 
01145     def single_request(self, host, handler, request_body, verbose=False):
01146         # issue XML-RPC request
01147         try:
01148             http_conn = self.send_request(host, handler, request_body, verbose)
01149             resp = http_conn.getresponse()
01150             if resp.status == 200:
01151                 self.verbose = verbose
01152                 return self.parse_response(resp)
01153 
01154         except Fault:
01155             raise
01156         except Exception:
01157             #All unexpected errors leave connection in
01158             # a strange state, so we clear it.
01159             self.close()
01160             raise
01161 
01162         #We got an error response.
01163         #Discard any response data and raise exception
01164         if resp.getheader("content-length", ""):
01165             resp.read()
01166         raise ProtocolError(
01167             host + handler,
01168             resp.status, resp.reason,
01169             dict(resp.getheaders())
01170             )
01171 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from xmlrpc.client.Transport.

Definition at line 1343 of file client.py.

Definition at line 1110 of file client.py.

xmlrpc.client.Transport.encode_threshold = None [static, inherited]

Definition at line 1115 of file client.py.

string xmlrpc.client.Transport.user_agent = "xmlrpclib.py/%s (by www.pythonware.com)" [static, inherited]

Definition at line 1107 of file client.py.

Definition at line 1150 of file client.py.


The documentation for this class was generated from the following file: