• 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.
192 # Indicates an HTTP-level protocol error. This is raised by the HTTP
216 # Indicates a broken XML-RPC response package. This exception is
217 # raised by the unmarshalling layer, if the XML-RPC response is
225 # Indicates an XML-RPC fault response package. This exception is
226 # raised by the unmarshalling layer, if the XML-RPC response contains
228 # generate a fault XML-RPC message.
230 # @param faultCode The XML-RPC fault code.
231 # @param faultString The XML-RPC fault string.
234 """Indicates an XML-RPC fault package."""
243 # --------------------------------------------------------------------
252 # Wrapper for XML-RPC DateTime values. This converts a time value to
253 # the format used by XML-RPC.
256 # format "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by
298 localtime integer value to generate 'dateTime.iso8601' XML-RPC
374 out.write("<value><dateTime.iso8601>")
375 out.write(self.value)
376 out.write("</dateTime.iso8601></value>\n")
389 # of binary data over XML-RPC, using BASE64 encoding.
391 # @param data An 8-bit string containing arbitrary data.
409 # @return Buffer contents, as an 8-bit string.
412 return str(self.data, "latin-1") # XXX encoding?!
423 out.write("<value><base64>\n")
425 out.write(encoded.decode('ascii'))
426 out.write("</base64></value>\n")
436 # --------------------------------------------------------------------
462 # --------------------------------------------------------------------
463 # XML-RPC marshalling and unmarshalling code
466 # XML-RPC marshaller.
468 # @param encoding Default encoding for 8-bit strings. The default
469 # value is None (interpreted as UTF-8).
473 """Generate an XML-RPC params chunk from a Python data structure.
477 to an XML-RPC params chunk. To write a fault response, pass a
495 write = out.append
499 write("<fault>\n")
502 write)
503 write("</fault>\n")
506 # FIXME: the xml-rpc specification allows us to leave out
511 write("<params>\n")
513 write("<param>\n")
514 dump(v, write)
515 write("</param>\n")
516 write("</params>\n")
520 def __dump(self, value, write): argument
527 # check if this class is a sub-class of a basic type,
529 # (e.g. a string sub-class)
533 # XXX(twouters): using "_arbitrary_instance" as key as a quick-fix
536 f(self, value, write)
538 def dump_nil (self, value, write): argument
541 write("<value><nil/></value>")
544 def dump_bool(self, value, write): argument
545 write("<value><boolean>")
546 write(value and "1" or "0")
547 write("</boolean></value>\n")
550 def dump_long(self, value, write): argument
552 raise OverflowError("int exceeds XML-RPC limits")
553 write("<value><int>")
554 write(str(int(value)))
555 write("</int></value>\n")
561 def dump_double(self, value, write): argument
562 write("<value><double>")
563 write(repr(value))
564 write("</double></value>\n")
567 def dump_unicode(self, value, write, escape=escape): argument
568 write("<value><string>")
569 write(escape(value))
570 write("</string></value>\n")
573 def dump_bytes(self, value, write): argument
574 write("<value><base64>\n")
576 write(encoded.decode('ascii'))
577 write("</base64></value>\n")
581 def dump_array(self, value, write): argument
587 write("<value><array><data>\n")
589 dump(v, write)
590 write("</data></array></value>\n")
595 def dump_struct(self, value, write, escape=escape): argument
601 write("<value><struct>\n")
603 write("<member>\n")
606 write("<name>%s</name>\n" % escape(k))
607 dump(v, write)
608 write("</member>\n")
609 write("</struct></value>\n")
613 def dump_datetime(self, value, write): argument
614 write("<value><dateTime.iso8601>")
615 write(_strftime(value))
616 write("</dateTime.iso8601></value>\n")
619 def dump_instance(self, value, write): argument
622 self.write = write
624 del self.write
627 self.dump_struct(value.__dict__, write)
630 # XXX(twouters): using "_arbitrary_instance" as key as a quick-fix
635 # XML-RPC unmarshaller.
640 """Unmarshal an XML-RPC response, based on incoming XML event
645 XML-RPC data without complaining (but not bogus XML).
658 self._encoding = "utf-8"
684 tag = tag.split(':')[-1]
703 f = self.dispatch[tag.split(':')[-1]]
719 f = self.dispatch[tag.split(':')[-1]]
861 """server -> an object used to boxcar method calls
894 # --------------------------------------------------------------------
906 """getparser() -> parser, unmarshaller
932 # Convert a Python tuple or a Fault instance to an XML-RPC packet.
946 """data [,options] -> marshalled data
948 Convert an argument tuple or a Fault instance to an XML-RPC
960 encoding: the packet encoding (default is UTF-8)
974 encoding = "utf-8"
983 if encoding != "utf-8":
986 xmlheader = "<?xml version='1.0'?>\n" # utf-8 is default
988 # standard XML-RPC wrappings
1011 # Convert an XML-RPC packet to a Python object. If the XML-RPC packet
1014 # @param data An XML-RPC packet, given as an 8-bit string.
1020 """data -> unmarshalled data, method name
1022 Convert an XML-RPC packet to unmarshalled data plus a method
1025 If the XML-RPC packet represents a fault condition, this function
1035 # Content-Encoding: gzip
1042 """data -> gzip encoded data
1050 gzf.write(data)
1055 # Content-Encoding: gzip
1066 """gzip encoded data -> unencoded data
1085 # Return a decoded file-like object for the gzip encoding
1089 # @return a file-like object that the decoded data can be read() from
1092 """a file-like object to decode a response encoded with the gzip
1110 # --------------------------------------------------------------------
1114 # some magic to bind an XML-RPC method to an RPC server.
1125 # Standard transport class for XML-RPC over HTTP.
1131 """Handles an HTTP transaction to an XML-RPC server."""
1134 user_agent = "Python-xmlrpc/%s" % __version__
1156 # @param host Target host.
1158 # @param request_body XML-RPC request body.
1162 def request(self, host, handler, request_body, verbose=False): argument
1166 return self.single_request(host, handler, request_body, verbose)
1175 def single_request(self, host, handler, request_body, verbose=False): argument
1176 # issue XML-RPC request
1178 http_conn = self.send_request(host, handler, request_body, verbose)
1194 if resp.getheader("content-length", ""):
1197 host + handler,
1206 # @return A 2-tuple containing a parser and an unmarshaller.
1214 # Get authorization info from host parameter
1215 # Host may be a string, or a (host, x509-dict) tuple; if a string,
1216 # it is checked for a "user:pw@host" format, and a "Basic
1219 # @param host Host descriptor (URL or (URL, x509 info) tuple).
1220 # @return A 3-tuple containing (actual host, extra headers,
1223 def get_host_info(self, host): argument
1226 if isinstance(host, tuple):
1227 host, x509 = host
1229 auth, host = urllib.parse._splituser(host)
1233 auth = base64.encodebytes(auth).decode("utf-8")
1241 return host, extra_headers, x509
1246 # @param host Target host.
1249 def make_connection(self, host): argument
1251 #HTTP/1.1 keep-alive.
1252 if self._connection and host == self._connection[0]:
1254 # create a HTTP connection object from a host descriptor
1255 chost, self._extra_headers, x509 = self.get_host_info(host)
1256 self._connection = host, http.client.HTTPConnection(chost)
1264 host, connection = self._connection
1272 # @param host Host descriptor (URL or (URL, x509 info) tuple).
1273 # @param handler Target RPC handler (a path relative to host)
1274 # @param request_body The XML-RPC request body
1278 def send_request(self, host, handler, request_body, debug): argument
1279 connection = self.make_connection(host)
1285 headers.append(("Accept-Encoding", "gzip"))
1288 headers.append(("Content-Type", "text/xml"))
1289 headers.append(("User-Agent", self.user_agent))
1310 # @param request_body XML-RPC request body.
1317 connection.putheader("Content-Encoding", "gzip")
1320 connection.putheader("Content-Length", str(len(request_body)))
1333 if response.getheader("Content-Encoding", "") == "gzip":
1357 # Standard transport class for XML-RPC over HTTPS.
1360 """Handles an HTTPS transaction to an XML-RPC server."""
1371 def make_connection(self, host): argument
1372 if self._connection and host == self._connection[0]:
1378 # create a HTTPS connection object from a host descriptor
1379 # host may be a string, or a (host, x509-dict) tuple
1380 chost, self._extra_headers, x509 = self.get_host_info(host)
1381 self._connection = host, http.client.HTTPSConnection(chost,
1387 # to an XML-RPC server.
1396 # @keyparam encoding The default encoding used for 8-bit strings
1397 # (default is UTF-8).
1403 """uri [,options] -> a logical connection to an XML-RPC server
1406 scheme://host/target.
1418 encoding: the request encoding (default is UTF-8)
1420 All 8-bit strings passed to the server proxy are assumed to use
1432 raise OSError("unsupported XML-RPC protocol")
1451 self.__encoding = encoding or 'utf-8'
1486 # note: to call a remote object with a non-standard name, use
1487 # result getattr(server, "strange-python-name")(args)
1509 # --------------------------------------------------------------------
1514 # simple test program (from the XML-RPC specification)