• Home
  • Raw
  • Download

Lines Matching +full:write +full:- +full:host

2 # XML-RPC CLIENT LIBRARY
5 # an XML-RPC client interface for Python.
8 # implement XML-RPC servers.
14 # 1999-01-14 fl Created
15 # 1999-01-15 fl Changed dateTime to use localtime
16 # 1999-01-16 fl Added Binary/base64 element, default to RPC2 service
17 # 1999-01-19 fl Fixed array data element (from Skip Montanaro)
18 # 1999-01-21 fl Fixed dateTime constructor, etc.
19 # 1999-02-02 fl Added fault handling, handle empty sequences, etc.
20 # 1999-02-10 fl Fixed problem with empty responses (from Skip Montanaro)
21 # 1999-06-20 fl Speed improvements, pluggable parsers/transports (0.9.8)
22 # 2000-11-28 fl Changed boolean to check the truth value of its argument
23 # 2001-02-24 fl Added encoding/Unicode/SafeTransport patches
24 # 2001-02-26 fl Added compare support to wrappers (0.9.9/1.0b1)
25 # 2001-03-28 fl Make sure response tuple is a singleton
26 # 2001-03-29 fl Don't require empty params element (from Nicholas Riley)
27 # 2001-06-10 fl Folded in _xmlrpclib accelerator support (1.0b2)
28 # 2001-08-20 fl Base xmlrpclib.Error on built-in Exception (from Paul Prescod)
29 # 2001-09-03 fl Allow Transport subclass to override getparser
30 # 2001-09-10 fl Lazy import of urllib, cgi, xmllib (20x import speedup)
31 # 2001-10-01 fl Remove containers from memo cache when done with them
32 # 2001-10-01 fl Use faster escape method (80% dumps speedup)
33 # 2001-10-02 fl More dumps microtuning
34 # 2001-10-04 fl Make sure import expat gets a parser (from Guido van Rossum)
35 # 2001-10-10 sm Allow long ints to be passed as ints if they don't overflow
36 # 2001-10-17 sm Test for int and long overflow (allows use on 64-bit systems)
37 # 2001-11-12 fl Use repr() to marshal doubles (from Paul Felix)
38 # 2002-03-17 fl Avoid buffered read when possible (from James Rucker)
39 # 2002-04-07 fl Added pythondoc comments
40 # 2002-04-16 fl Added __str__ methods to datetime/binary wrappers
41 # 2002-05-15 fl Added error constants (from Andrew Kuchling)
42 # 2002-06-27 fl Merged with Python CVS version
43 # 2002-10-22 fl Added basic authentication (based on code from Phillip Eby)
44 # 2003-01-22 sm Add support for the bool type
45 # 2003-02-27 gvr Remove apply calls
46 # 2003-04-24 sm Use cStringIO if available
47 # 2003-04-25 ak Add support for nil
48 # 2003-06-15 gn Add support for time.struct_time
49 # 2003-07-12 gp Correct marshalling of Faults
50 # 2003-10-31 mvl Add multicall support
51 # 2004-08-20 mvl Bump minimum supported Python version to 2.1
52 # 2014-12-02 ch/doko Add workaround for gzip bomb vulnerability
54 # Copyright (c) 1999-2002 by Secret Labs AB.
55 # Copyright (c) 1999-2002 by Fredrik Lundh.
60 # --------------------------------------------------------------------
61 # The XML-RPC client interface is
63 # Copyright (c) 1999-2002 by Secret Labs AB
64 # Copyright (c) 1999-2002 by Fredrik Lundh
80 # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
87 # --------------------------------------------------------------------
90 An XML-RPC client interface for Python.
93 implement XML-RPC servers.
100 Fault Indicates an XML-RPC fault package
104 ServerProxy Represents a logical connection to an XML-RPC server
109 XML-RPC value
112 Marshaller Generate an XML-RPC params chunk from a Python data structure
113 Unmarshaller Unmarshal an XML-RPC response from incoming XML event message
114 Transport Handles an HTTP transaction to an XML-RPC server
115 SafeTransport Handles an HTTPS transaction to an XML-RPC server
125 dumps Convert an argument tuple or a Fault instance to an XML-RPC
127 loads Convert an XML-RPC packet to unmarshalled data plus a method
146 # --------------------------------------------------------------------
154 # used in User-Agent header sent
158 MAXINT = 2**31-1
159 MININT = -2**31
161 # --------------------------------------------------------------------
163 # http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php)
166 PARSE_ERROR = -32700
167 SERVER_ERROR = -32600
168 APPLICATION_ERROR = -32500
169 SYSTEM_ERROR = -32400
170 TRANSPORT_ERROR = -32300
173 NOT_WELLFORMED_ERROR = -32700
174 UNSUPPORTED_ENCODING = -32701
175 INVALID_ENCODING_CHAR = -32702
176 INVALID_XMLRPC = -32600
177 METHOD_NOT_FOUND = -32601
178 INVALID_METHOD_PARAMS = -32602
179 INTERNAL_ERROR = -32603
181 # --------------------------------------------------------------------
185 # Base class for all kinds of client-side errors.
193 # Indicates an HTTP-level protocol error. This is raised by the HTTP
217 # Indicates a broken XML-RPC response package. This exception is
218 # raised by the unmarshalling layer, if the XML-RPC response is
226 # Indicates an XML-RPC fault response package. This exception is
227 # raised by the unmarshalling layer, if the XML-RPC response contains
229 # generate a fault XML-RPC message.
231 # @param faultCode The XML-RPC fault code.
232 # @param faultString The XML-RPC fault string.
235 """Indicates an XML-RPC fault package."""
244 # --------------------------------------------------------------------
253 # Wrapper for XML-RPC DateTime values. This converts a time value to
254 # the format used by XML-RPC.
257 # format "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by
293 localtime integer value to generate 'dateTime.iso8601' XML-RPC
362 out.write("<value><dateTime.iso8601>")
363 out.write(self.value)
364 out.write("</dateTime.iso8601></value>\n")
377 # of binary data over XML-RPC, using BASE64 encoding.
379 # @param data An 8-bit string containing arbitrary data.
397 # @return Buffer contents, as an 8-bit string.
400 return str(self.data, "latin-1") # XXX encoding?!
411 out.write("<value><base64>\n")
413 out.write(encoded.decode('ascii'))
414 out.write("</base64></value>\n")
424 # --------------------------------------------------------------------
450 # --------------------------------------------------------------------
451 # XML-RPC marshalling and unmarshalling code
454 # XML-RPC marshaller.
456 # @param encoding Default encoding for 8-bit strings. The default
457 # value is None (interpreted as UTF-8).
461 """Generate an XML-RPC params chunk from a Python data structure.
465 to an XML-RPC params chunk. To write a fault response, pass a
483 write = out.append
487 write("<fault>\n")
490 write)
491 write("</fault>\n")
494 # FIXME: the xml-rpc specification allows us to leave out
499 write("<params>\n")
501 write("<param>\n")
502 dump(v, write)
503 write("</param>\n")
504 write("</params>\n")
508 def __dump(self, value, write): argument
515 # check if this class is a sub-class of a basic type,
517 # (e.g. a string sub-class)
521 # XXX(twouters): using "_arbitrary_instance" as key as a quick-fix
524 f(self, value, write)
526 def dump_nil (self, value, write): argument
529 write("<value><nil/></value>")
532 def dump_bool(self, value, write): argument
533 write("<value><boolean>")
534 write(value and "1" or "0")
535 write("</boolean></value>\n")
538 def dump_long(self, value, write): argument
540 raise OverflowError("int exceeds XML-RPC limits")
541 write("<value><int>")
542 write(str(int(value)))
543 write("</int></value>\n")
549 def dump_double(self, value, write): argument
550 write("<value><double>")
551 write(repr(value))
552 write("</double></value>\n")
555 def dump_unicode(self, value, write, escape=escape): argument
556 write("<value><string>")
557 write(escape(value))
558 write("</string></value>\n")
561 def dump_bytes(self, value, write): argument
562 write("<value><base64>\n")
564 write(encoded.decode('ascii'))
565 write("</base64></value>\n")
569 def dump_array(self, value, write): argument
575 write("<value><array><data>\n")
577 dump(v, write)
578 write("</data></array></value>\n")
583 def dump_struct(self, value, write, escape=escape): argument
589 write("<value><struct>\n")
591 write("<member>\n")
594 write("<name>%s</name>\n" % escape(k))
595 dump(v, write)
596 write("</member>\n")
597 write("</struct></value>\n")
601 def dump_datetime(self, value, write): argument
602 write("<value><dateTime.iso8601>")
603 write(_strftime(value))
604 write("</dateTime.iso8601></value>\n")
607 def dump_instance(self, value, write): argument
610 self.write = write
612 del self.write
615 self.dump_struct(value.__dict__, write)
618 # XXX(twouters): using "_arbitrary_instance" as key as a quick-fix
623 # XML-RPC unmarshaller.
628 """Unmarshal an XML-RPC response, based on incoming XML event
633 XML-RPC data without complaining (but not bogus XML).
646 self._encoding = "utf-8"
672 tag = tag.split(':')[-1]
691 f = self.dispatch[tag.split(':')[-1]]
707 f = self.dispatch[tag.split(':')[-1]]
849 """server -> an object used to boxcar method calls
884 # --------------------------------------------------------------------
896 """getparser() -> parser, unmarshaller
922 # Convert a Python tuple or a Fault instance to an XML-RPC packet.
936 """data [,options] -> marshalled data
938 Convert an argument tuple or a Fault instance to an XML-RPC
950 encoding: the packet encoding (default is UTF-8)
964 encoding = "utf-8"
973 if encoding != "utf-8":
976 xmlheader = "<?xml version='1.0'?>\n" # utf-8 is default
978 # standard XML-RPC wrappings
1001 # Convert an XML-RPC packet to a Python object. If the XML-RPC packet
1004 # @param data An XML-RPC packet, given as an 8-bit string.
1010 """data -> unmarshalled data, method name
1012 Convert an XML-RPC packet to unmarshalled data plus a method
1015 If the XML-RPC packet represents a fault condition, this function
1025 # Content-Encoding: gzip
1032 """data -> gzip encoded data
1040 gzf.write(data)
1045 # Content-Encoding: gzip
1056 """gzip encoded data -> unencoded data
1075 # Return a decoded file-like object for the gzip encoding
1079 # @return a file-like object that the decoded data can be read() from
1082 """a file-like object to decode a response encoded with the gzip
1100 # --------------------------------------------------------------------
1104 # some magic to bind an XML-RPC method to an RPC server.
1115 # Standard transport class for XML-RPC over HTTP.
1121 """Handles an HTTP transaction to an XML-RPC server."""
1124 user_agent = "Python-xmlrpc/%s" % __version__
1144 # @param host Target host.
1146 # @param request_body XML-RPC request body.
1150 def request(self, host, handler, request_body, verbose=False): argument
1154 return self.single_request(host, handler, request_body, verbose)
1163 def single_request(self, host, handler, request_body, verbose=False): argument
1164 # issue XML-RPC request
1166 http_conn = self.send_request(host, handler, request_body, verbose)
1182 if resp.getheader("content-length", ""):
1185 host + handler,
1194 # @return A 2-tuple containing a parser and an unmarshaller.
1202 # Get authorization info from host parameter
1203 # Host may be a string, or a (host, x509-dict) tuple; if a string,
1204 # it is checked for a "user:pw@host" format, and a "Basic
1207 # @param host Host descriptor (URL or (URL, x509 info) tuple).
1208 # @return A 3-tuple containing (actual host, extra headers,
1211 def get_host_info(self, host): argument
1214 if isinstance(host, tuple):
1215 host, x509 = host
1217 auth, host = urllib.parse.splituser(host)
1221 auth = base64.encodebytes(auth).decode("utf-8")
1229 return host, extra_headers, x509
1234 # @param host Target host.
1237 def make_connection(self, host): argument
1239 #HTTP/1.1 keep-alive.
1240 if self._connection and host == self._connection[0]:
1242 # create a HTTP connection object from a host descriptor
1243 chost, self._extra_headers, x509 = self.get_host_info(host)
1244 self._connection = host, http.client.HTTPConnection(chost)
1252 host, connection = self._connection
1260 # @param host Host descriptor (URL or (URL, x509 info) tuple).
1261 # @param handler Target RPC handler (a path relative to host)
1262 # @param request_body The XML-RPC request body
1266 def send_request(self, host, handler, request_body, debug): argument
1267 connection = self.make_connection(host)
1273 headers.append(("Accept-Encoding", "gzip"))
1276 headers.append(("Content-Type", "text/xml"))
1277 headers.append(("User-Agent", self.user_agent))
1298 # @param request_body XML-RPC request body.
1305 connection.putheader("Content-Encoding", "gzip")
1308 connection.putheader("Content-Length", str(len(request_body)))
1321 if response.getheader("Content-Encoding", "") == "gzip":
1345 # Standard transport class for XML-RPC over HTTPS.
1348 """Handles an HTTPS transaction to an XML-RPC server."""
1357 def make_connection(self, host): argument
1358 if self._connection and host == self._connection[0]:
1364 # create a HTTPS connection object from a host descriptor
1365 # host may be a string, or a (host, x509-dict) tuple
1366 chost, self._extra_headers, x509 = self.get_host_info(host)
1367 self._connection = host, http.client.HTTPSConnection(chost,
1373 # to an XML-RPC server.
1382 # @keyparam encoding The default encoding used for 8-bit strings
1383 # (default is UTF-8).
1389 """uri [,options] -> a logical connection to an XML-RPC server
1392 scheme://host/target.
1404 encoding: the request encoding (default is UTF-8)
1406 All 8-bit strings passed to the server proxy are assumed to use
1418 raise OSError("unsupported XML-RPC protocol")
1435 self.__encoding = encoding or 'utf-8'
1472 # note: to call a remote object with a non-standard name, use
1473 # result getattr(server, "strange-python-name")(args)
1495 # --------------------------------------------------------------------
1500 # simple test program (from the XML-RPC specification)