mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Closes #13297: use bytes type to send and receive binary data through XMLRPC.
This commit is contained in:
parent
1d8f3f451c
commit
6166519d2b
4 changed files with 132 additions and 48 deletions
|
@ -8,7 +8,7 @@
|
|||
|
||||
|
||||
.. XXX Not everything is documented yet. It might be good to describe
|
||||
Marshaller, Unmarshaller, getparser, dumps, loads, and Transport.
|
||||
Marshaller, Unmarshaller, getparser and Transport.
|
||||
|
||||
**Source code:** :source:`Lib/xmlrpc/client.py`
|
||||
|
||||
|
@ -21,7 +21,12 @@ supports writing XML-RPC client code; it handles all the details of translating
|
|||
between conformable Python objects and XML on the wire.
|
||||
|
||||
|
||||
.. class:: ServerProxy(uri, transport=None, encoding=None, verbose=False, allow_none=False, use_datetime=False)
|
||||
.. class:: ServerProxy(uri, transport=None, encoding=None, verbose=False, \
|
||||
allow_none=False, use_datetime=False, \
|
||||
use_builtin_types=False)
|
||||
|
||||
.. versionchanged:: 3.3
|
||||
The *use_builtin_types* flag was added.
|
||||
|
||||
A :class:`ServerProxy` instance is an object that manages communication with a
|
||||
remote XML-RPC server. The required first argument is a URI (Uniform Resource
|
||||
|
@ -34,9 +39,13 @@ between conformable Python objects and XML on the wire.
|
|||
XML; the default behaviour is for ``None`` to raise a :exc:`TypeError`. This is
|
||||
a commonly-used extension to the XML-RPC specification, but isn't supported by
|
||||
all clients and servers; see http://ontosys.com/xml-rpc/extensions.php for a
|
||||
description. The *use_datetime* flag can be used to cause date/time values to
|
||||
be presented as :class:`datetime.datetime` objects; this is false by default.
|
||||
:class:`datetime.datetime` objects may be passed to calls.
|
||||
description. The *use_builtin_types* flag can be used to cause date/time values
|
||||
to be presented as :class:`datetime.datetime` objects and binary data to be
|
||||
presented as :class:`bytes` objects; this flag is false by default.
|
||||
:class:`datetime.datetime` and :class:`bytes` objects may be passed to calls.
|
||||
|
||||
The obsolete *use_datetime* flag is similar to *use_builtin_types* but it
|
||||
applies only to date/time values.
|
||||
|
||||
Both the HTTP and HTTPS transports support the URL syntax extension for HTTP
|
||||
Basic Authentication: ``http://user:pass@host:port/path``. The ``user:pass``
|
||||
|
@ -78,12 +87,12 @@ between conformable Python objects and XML on the wire.
|
|||
| | only their *__dict__* attribute is |
|
||||
| | transmitted. |
|
||||
+---------------------------------+---------------------------------------------+
|
||||
| :const:`dates` | in seconds since the epoch (pass in an |
|
||||
| | instance of the :class:`DateTime` class) or |
|
||||
| :const:`dates` | In seconds since the epoch. Pass in an |
|
||||
| | instance of the :class:`DateTime` class or |
|
||||
| | a :class:`datetime.datetime` instance. |
|
||||
+---------------------------------+---------------------------------------------+
|
||||
| :const:`binary data` | pass in an instance of the :class:`Binary` |
|
||||
| | wrapper class |
|
||||
| :const:`binary data` | Pass in an instance of the :class:`Binary` |
|
||||
| | wrapper class or a :class:`bytes` instance. |
|
||||
+---------------------------------+---------------------------------------------+
|
||||
|
||||
This is the full set of data types supported by XML-RPC. Method calls may also
|
||||
|
@ -98,8 +107,9 @@ between conformable Python objects and XML on the wire.
|
|||
ensure that the string is free of characters that aren't allowed in XML, such as
|
||||
the control characters with ASCII values between 0 and 31 (except, of course,
|
||||
tab, newline and carriage return); failing to do this will result in an XML-RPC
|
||||
request that isn't well-formed XML. If you have to pass arbitrary strings via
|
||||
XML-RPC, use the :class:`Binary` wrapper class described below.
|
||||
request that isn't well-formed XML. If you have to pass arbitrary bytes
|
||||
via XML-RPC, use the :class:`bytes` class or the class:`Binary` wrapper class
|
||||
described below.
|
||||
|
||||
:class:`Server` is retained as an alias for :class:`ServerProxy` for backwards
|
||||
compatibility. New code should use :class:`ServerProxy`.
|
||||
|
@ -249,7 +259,7 @@ The client code for the preceding server::
|
|||
Binary Objects
|
||||
--------------
|
||||
|
||||
This class may be initialized from string data (which may include NULs). The
|
||||
This class may be initialized from bytes data (which may include NULs). The
|
||||
primary access to the content of a :class:`Binary` object is provided by an
|
||||
attribute:
|
||||
|
||||
|
@ -257,15 +267,15 @@ attribute:
|
|||
.. attribute:: Binary.data
|
||||
|
||||
The binary data encapsulated by the :class:`Binary` instance. The data is
|
||||
provided as an 8-bit string.
|
||||
provided as a :class:`bytes` object.
|
||||
|
||||
:class:`Binary` objects have the following methods, supported mainly for
|
||||
internal use by the marshalling/unmarshalling code:
|
||||
|
||||
|
||||
.. method:: Binary.decode(string)
|
||||
.. method:: Binary.decode(bytes)
|
||||
|
||||
Accept a base64 string and decode it as the instance's new data.
|
||||
Accept a base64 :class:`bytes` object and decode it as the instance's new data.
|
||||
|
||||
|
||||
.. method:: Binary.encode(out)
|
||||
|
@ -471,14 +481,21 @@ Convenience Functions
|
|||
it via an extension, provide a true value for *allow_none*.
|
||||
|
||||
|
||||
.. function:: loads(data, use_datetime=False)
|
||||
.. function:: loads(data, use_datetime=False, use_builtin_types=False)
|
||||
|
||||
Convert an XML-RPC request or response into Python objects, a ``(params,
|
||||
methodname)``. *params* is a tuple of argument; *methodname* is a string, or
|
||||
``None`` if no method name is present in the packet. If the XML-RPC packet
|
||||
represents a fault condition, this function will raise a :exc:`Fault` exception.
|
||||
The *use_datetime* flag can be used to cause date/time values to be presented as
|
||||
:class:`datetime.datetime` objects; this is false by default.
|
||||
The *use_builtin_types* flag can be used to cause date/time values to be
|
||||
presented as :class:`datetime.datetime` objects and binary data to be
|
||||
presented as :class:`bytes` objects; this flag is false by default.
|
||||
|
||||
The obsolete *use_datetime* flag is similar to *use_builtin_types* but it
|
||||
applies only to date/time values.
|
||||
|
||||
.. versionchanged:: 3.3
|
||||
The *use_builtin_types* flag was added.
|
||||
|
||||
|
||||
.. _xmlrpc-client-example:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue