Use six.moves.xmlrpc.client instead of xmlrpclib

The module is renamed to xmlrpc.client in Python 3.

Reviewed-By: David Kupka <dkupka@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Petr Viktorin 2015-09-14 13:22:38 +02:00 committed by Jan Cholasta
parent 70b37a956c
commit ad2bc94725
9 changed files with 44 additions and 37 deletions

View File

@ -43,7 +43,7 @@ from ipapython.ipa_log_manager import *
from ipapython.dn import DN
from ipapython.config import IPAOptionParser
from ipaclient import ipadiscovery
from xmlrpclib import MAXINT
from six.moves.xmlrpc_client import MAXINT
from ipaplatform.paths import paths
# dict of command name and tuples of min/max num of args needed

View File

@ -103,7 +103,7 @@ import re
import decimal
import base64
import datetime
from xmlrpclib import MAXINT, MININT
from six.moves.xmlrpc_client import MAXINT, MININT
from types import NoneType
import encodings.idna

View File

@ -21,11 +21,11 @@
"""
RPC client and shared RPC client/server functionality.
This module adds some additional functionality on top of the ``xmlrpclib``
module in the Python standard library. For documentation on the
``xmlrpclib`` module, see:
This module adds some additional functionality on top of the ``xmlrpc.client``
module in the Python standard library (``xmlrpclib`` in Python 2).
For documentation on the ``xmlrpclib`` module, see:
http://docs.python.org/library/xmlrpclib.html
http://docs.python.org/2/library/xmlrpclib.html
Also see the `ipaserver.rpcserver` module.
"""
@ -39,8 +39,6 @@ import locale
import base64
import json
import socket
from xmlrpclib import (Binary, Fault, DateTime, dumps, loads, ServerProxy,
Transport, ProtocolError, MININT, MAXINT)
import gssapi
from dns import resolver, rdatatype
@ -71,6 +69,16 @@ from ipapython.dn import DN
from ipalib.capabilities import VERSION_WITHOUT_CAPABILITIES
from ipalib import api
# The XMLRPC client is in "six.moves.xmlrpc_client", but pylint
# cannot handle that
try:
from xmlrpclib import (Binary, Fault, DateTime, dumps, loads, ServerProxy,
Transport, ProtocolError, MININT, MAXINT)
except ImportError:
from xmlrpc.client import (Binary, Fault, DateTime, dumps, loads, ServerProxy,
Transport, ProtocolError, MININT, MAXINT)
if six.PY3:
unicode = str
@ -138,16 +146,16 @@ def delete_persistent_client_session_data(principal):
def xml_wrap(value, version):
"""
Wrap all ``str`` in ``xmlrpclib.Binary``.
Wrap all ``str`` in ``xmlrpc.client.Binary``.
Because ``xmlrpclib.dumps()`` will itself convert all ``unicode`` instances
Because ``xmlrpc.client.dumps()`` will itself convert all ``unicode`` instances
into UTF-8 encoded ``str`` instances, we don't do it here.
So in total, when encoding data for an XML-RPC packet, the following
transformations occur:
* All ``str`` instances are treated as binary data and are wrapped in
an ``xmlrpclib.Binary()`` instance.
an ``xmlrpc.client.Binary()`` instance.
* Only ``unicode`` instances are treated as character data. They get
converted to UTF-8 encoded ``str`` instances (although as mentioned,
@ -173,7 +181,7 @@ def xml_wrap(value, version):
if isinstance(value, DN):
return str(value)
# Encode datetime.datetime objects as xmlrpclib.DateTime objects
# Encode datetime.datetime objects as xmlrpc.client.DateTime objects
if isinstance(value, datetime.datetime):
if capabilities.client_has_capability(version, 'datetime_values'):
return DateTime(value)
@ -197,7 +205,7 @@ def xml_unwrap(value, encoding='UTF-8'):
When decoding data from an XML-RPC packet, the following transformations
occur:
* The binary payloads of all ``xmlrpclib.Binary`` instances are
* The binary payloads of all ``xmlrpc.client.Binary`` instances are
returned as ``str`` instances.
* All ``str`` instances are treated as UTF-8 encoded Unicode strings.
@ -235,16 +243,16 @@ def xml_dumps(params, version, methodname=None, methodresponse=False,
Encode an XML-RPC data packet, transparently wraping ``params``.
This function will wrap ``params`` using `xml_wrap()` and will
then encode the XML-RPC data packet using ``xmlrpclib.dumps()`` (from the
then encode the XML-RPC data packet using ``xmlrpc.client.dumps()`` (from the
Python standard library).
For documentation on the ``xmlrpclib.dumps()`` function, see:
For documentation on the ``xmlrpc.client.dumps()`` function, see:
http://docs.python.org/library/xmlrpclib.html#convenience-functions
http://docs.python.org/library/xmlrpc.client.html#convenience-functions
Also see `xml_loads()`.
:param params: A ``tuple`` or an ``xmlrpclib.Fault`` instance.
:param params: A ``tuple`` or an ``xmlrpc.client.Fault`` instance.
:param methodname: The name of the method to call if this is a request.
:param methodresponse: Set this to ``True`` if this is a response.
:param encoding: The Unicode encoding to use (defaults to ``'UTF-8'``).
@ -366,9 +374,9 @@ def xml_loads(data, encoding='UTF-8'):
Decode the XML-RPC packet in ``data``, transparently unwrapping its params.
This function will decode the XML-RPC packet in ``data`` using
``xmlrpclib.loads()`` (from the Python standard library). If ``data``
contains a fault, ``xmlrpclib.loads()`` will itself raise an
``xmlrpclib.Fault`` exception.
``xmlrpc.client.loads()`` (from the Python standard library). If ``data``
contains a fault, ``xmlrpc.client.loads()`` will itself raise an
``xmlrpc.client.Fault`` exception.
Assuming an exception is not raised, this function will then unwrap the
params in ``data`` using `xml_unwrap()`. Finally, a
@ -376,9 +384,9 @@ def xml_loads(data, encoding='UTF-8'):
and the name of the method being called. If the packet contains no method
name, ``methodname`` will be ``None``.
For documentation on the ``xmlrpclib.loads()`` function, see:
For documentation on the ``xmlrpc.client.loads()`` function, see:
http://docs.python.org/library/xmlrpclib.html#convenience-functions
http://docs.python.org/2/library/xmlrpclib.html#convenience-functions
Also see `xml_dumps()`.
@ -603,7 +611,7 @@ class KerbTransport(SSLTransport):
return True
def single_request(self, host, handler, request_body, verbose=0):
# Based on xmlrpclib.Transport.single_request
# Based on xmlrpc.lient.Transport.single_request
try:
h = SSLTransport.make_connection(self, host)
if verbose:
@ -1032,7 +1040,7 @@ class JSONServerProxy(object):
self.__verbose = verbose
# FIXME: Some of our code requires ServerProxy internals.
# But, xmlrpclib.ServerProxy's _ServerProxy__transport can be accessed
# But, xmlrpc.client.ServerProxy's _ServerProxy__transport can be accessed
# by calling serverproxy('transport')
self._ServerProxy__transport = transport

View File

@ -49,7 +49,7 @@ the relevant RFC's as well as actual practice in the field. However
cookielib.py is tighly integrated with urllib2 and it's not possible
to use most of the features of cookielib without simultaneously using
urllib2. Unfortunataely we only use httplib because of our dependency
on xmlrpclib. Without urllib2 cookielib is a non-starter.
on xmlrpc.client. Without urllib2 cookielib is a non-starter.
This module is a minimal implementation of Netscape cookies which
works equally well on either the client or server side. It's API is

View File

@ -31,7 +31,6 @@ import socket
import struct
from types import *
import re
import xmlrpclib
import datetime
import netaddr
import time

View File

@ -296,14 +296,14 @@ class NSSConnection(httplib.HTTPConnection, NSSAddressFamilyFallback):
raise e
class NSSHTTPS(httplib.HTTP):
# We would like to use HTTP 1.1 not the older HTTP 1.0 but xmlrpclib
# We would like to use HTTP 1.1 not the older HTTP 1.0 but xmlrpc.client
# and httplib do not play well together. httplib when the protocol
# is 1.1 will add a host header in the request. But xmlrpclib
# is 1.1 will add a host header in the request. But xmlrpc.client
# always adds a host header irregardless of the HTTP protocol
# version. That means the request ends up with 2 host headers,
# but Apache freaks out if it sees 2 host headers, a known Apache
# issue. httplib has a mechanism to skip adding the host header
# (i.e. skip_host in HTTPConnection.putrequest()) but xmlrpclib
# (i.e. skip_host in HTTPConnection.putrequest()) but xmlrpc.client
# doesn't use it. Oh well, back to 1.0 :-(
#
#_http_vsn = 11

View File

@ -24,7 +24,7 @@ Also see the `ipalib.rpc` module.
"""
from xml.sax.saxutils import escape
from xmlrpclib import Fault
from six.moves.xmlrpc_client import Fault
import os
import datetime
import json

View File

@ -31,7 +31,7 @@ import sys
from types import NoneType
from decimal import Decimal
from inspect import isclass
from xmlrpclib import MAXINT, MININT
from six.moves.xmlrpc_client import MAXINT, MININT
import six

View File

@ -22,7 +22,7 @@ Test the `ipalib.rpc` module.
"""
from __future__ import print_function
from xmlrpclib import Binary, Fault, dumps, loads
from six.moves.xmlrpc_client import Binary, Fault, dumps, loads
import nose
import six
@ -58,10 +58,10 @@ def test_round_trip():
"""
Test `ipalib.rpc.xml_wrap` and `ipalib.rpc.xml_unwrap`.
This tests the two functions together with ``xmlrpclib.dumps()`` and
``xmlrpclib.loads()`` in a full wrap/dumps/loads/unwrap round trip.
This tests the two functions together with ``xmlrpc.client.dumps()`` and
``xmlrpc.client.loads()`` in a full wrap/dumps/loads/unwrap round trip.
"""
# We first test that our assumptions about xmlrpclib module in the Python
# We first test that our assumptions about xmlrpc.client module in the Python
# standard library are correct:
assert_equal(dump_n_load(utf8_bytes), unicode_str)
assert_equal(dump_n_load(unicode_str), unicode_str)
@ -75,9 +75,9 @@ def test_round_trip():
# Now we test our wrap and unwrap methods in combination with dumps, loads:
# All str should come back str (because they get wrapped in
# xmlrpclib.Binary(). All unicode should come back unicode because str
# xmlrpc.client.Binary(). All unicode should come back unicode because str
# explicity get decoded by rpc.xml_unwrap() if they weren't already
# decoded by xmlrpclib.loads().
# decoded by xmlrpc.client.loads().
assert_equal(round_trip(utf8_bytes), utf8_bytes)
assert_equal(round_trip(unicode_str), unicode_str)
assert_equal(round_trip(binary_bytes), binary_bytes)