Skip to content

Commit

Permalink
- Remove more Python 2 support code
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Nov 3, 2019
1 parent 9103f0d commit 06d940f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 64 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst
5.0a1 (unreleased)
------------------

- Remove more Python 2 support code
(`#692 <https://github.com/zopefoundation/Zope/issues/692>`_)

- Move retried request delay handling out of ``supports_retry``
(`#474 <https://github.com/zopefoundation/Zope/issues/474>`_)

Expand Down
5 changes: 1 addition & 4 deletions src/OFS/History.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
"""Object Histories
"""

try:
from html import escape
except ImportError:
from cgi import escape
import difflib
from html import escape
from struct import pack
from struct import unpack

Expand Down
4 changes: 0 additions & 4 deletions src/OFS/ObjectManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,6 @@ def __iter__(self):
def __len__(self):
return len(self.objectIds())

def __nonzero__(self):
# Py2
return self.__bool__()

def __bool__(self):
return True

Expand Down
7 changes: 0 additions & 7 deletions src/OFS/absoluteurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
##############################################################################

from six.moves.urllib.parse import quote
from six.moves.urllib.parse import unquote

from Acquisition import aq_parent
from OFS.interfaces import ITraversable
Expand All @@ -35,9 +34,6 @@ class AbsoluteURL(BrowserView):
all the methods that it uses yet.
"""

def __unicode__(self):
return unquote(self.__str__()).decode('utf-8')

def __str__(self):
context = self.context
request = self.request
Expand Down Expand Up @@ -93,9 +89,6 @@ class OFSTraversableAbsoluteURL(BrowserView):
"""An absolute_url adapter for OFS.Traversable subclasses
"""

def __unicode__(self):
return unquote(self.__str__()).decode('utf-8')

def __str__(self):
return self.context.absolute_url()

Expand Down
2 changes: 0 additions & 2 deletions src/Products/Five/tests/test_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
"""Test the basic ZCML directives
"""

from __future__ import absolute_import


def test_directives():
"""
Expand Down
2 changes: 0 additions & 2 deletions src/Products/Five/tests/test_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
##############################################################################
"""Size adapters for testing
"""
from __future__ import absolute_import

from zope.interface import implementer
from zope.size.interfaces import ISized

Expand Down
45 changes: 20 additions & 25 deletions src/ZPublisher/tests/test_xmlrpc.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import unittest
import xmlrpc.client

from DateTime import DateTime


try:
import xmlrpc.client as xmlrpclib
except ImportError:
import xmlrpclib


class FauxResponse(object):

def __init__(self):
Expand Down Expand Up @@ -49,7 +44,7 @@ def test_setBody(self):
body_str = faux._body
self.assertEqual(type(body_str), type(''))

as_set, method = xmlrpclib.loads(body_str)
as_set, method = xmlrpc.client.loads(body_str)
as_set = as_set[0]

self.assertIsNone(method)
Expand All @@ -62,7 +57,7 @@ def test_nil(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
self.assertIs(data[0]['public'], None)

def test_instance(self):
Expand All @@ -72,7 +67,7 @@ def test_instance(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0]
self.assertEqual(data, {'public': 'def'})

Expand All @@ -84,7 +79,7 @@ def test_instanceattribute(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0]['public']
self.assertEqual(data, {'public': 'def'})

Expand All @@ -95,7 +90,7 @@ def test_instanceattribute_recursive(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0]['public']['public']
self.assertEqual(data, {'public': 'def'})

Expand All @@ -107,7 +102,7 @@ def test_instance_in_list(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0][0]
self.assertEqual(data, {'public': 'def'})

Expand All @@ -119,7 +114,7 @@ def test_instance_in_dict(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0]['faux']
self.assertEqual(data, {'public': 'def'})

Expand All @@ -129,9 +124,9 @@ def test_zopedatetimeinstance(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0]
self.assertTrue(isinstance(data, xmlrpclib.DateTime))
self.assertTrue(isinstance(data, xmlrpc.client.DateTime))
self.assertEqual(data.value, u'2006-05-24T07:00:00+00:00')

def test_zopedatetimeattribute(self):
Expand All @@ -140,9 +135,9 @@ def test_zopedatetimeattribute(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0]['public']
self.assertTrue(isinstance(data, xmlrpclib.DateTime))
self.assertTrue(isinstance(data, xmlrpc.client.DateTime))
self.assertEqual(data.value, u'2006-05-24T07:00:00+00:00')

def test_zopedatetimeattribute_recursive(self):
Expand All @@ -152,9 +147,9 @@ def test_zopedatetimeattribute_recursive(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0]['public']['public']
self.assertTrue(isinstance(data, xmlrpclib.DateTime))
self.assertTrue(isinstance(data, xmlrpc.client.DateTime))
self.assertEqual(data.value, u'2006-05-24T07:00:00+00:00')

def test_zopedatetimeinstance_in_list(self):
Expand All @@ -163,9 +158,9 @@ def test_zopedatetimeinstance_in_list(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0][0]
self.assertTrue(isinstance(data, xmlrpclib.DateTime))
self.assertTrue(isinstance(data, xmlrpc.client.DateTime))
self.assertEqual(data.value, u'2006-05-24T07:00:00+00:00')

def test_zopedatetimeinstance_in_dict(self):
Expand All @@ -174,9 +169,9 @@ def test_zopedatetimeinstance_in_dict(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0]['date']
self.assertTrue(isinstance(data, xmlrpclib.DateTime))
self.assertTrue(isinstance(data, xmlrpc.client.DateTime))
self.assertEqual(data.value, u'2006-05-24T07:00:00+00:00')

def test_functionattribute(self):
Expand All @@ -189,7 +184,7 @@ def foo():
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
func = xmlrpclib.loads(faux._body)
func = xmlrpc.client.loads(faux._body)
self.assertEqual(func, (({'public': {}},), None))

def test_emptystringattribute(self):
Expand All @@ -200,6 +195,6 @@ def test_emptystringattribute(self):
faux = FauxResponse()
response = self._makeOne(faux)
response.setBody(body)
data, method = xmlrpclib.loads(faux._body)
data, method = xmlrpc.client.loads(faux._body)
data = data[0]
self.assertEqual(data, {'': True})
30 changes: 10 additions & 20 deletions src/ZPublisher/xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import re
import sys
import xmlrpc.client

from App.config import getConfiguration
# Make DateTime.DateTime marshallable via XML-RPC
Expand All @@ -30,13 +31,7 @@
from ZODB.POSException import ConflictError


try:
import xmlrpc.client as xmlrpclib
except ImportError:
import xmlrpclib


WRAPPERS = xmlrpclib.WRAPPERS + (DateTime, )
WRAPPERS = xmlrpc.client.WRAPPERS + (DateTime, )


def dump_instance(self, value, write):
Expand All @@ -57,13 +52,8 @@ def dump_instance(self, value, write):

# Override the standard marshaller for object instances
# to skip private attributes.
try:
from types import InstanceType
xmlrpclib.Marshaller.dispatch[InstanceType] = dump_instance # py2
except ImportError:
xmlrpclib.Marshaller.dispatch['_arbitrary_instance'] = dump_instance # py3

xmlrpclib.Marshaller.dispatch[DateTime] = dump_instance
xmlrpc.client.Marshaller.dispatch['_arbitrary_instance'] = dump_instance
xmlrpc.client.Marshaller.dispatch[DateTime] = dump_instance


def parse_input(data):
Expand All @@ -87,7 +77,7 @@ def parse_input(data):
# the function should return:
#
# ('examples.getStateName', (41,))
params, method = xmlrpclib.loads(data)
params, method = xmlrpc.client.loads(data)
# Translate '.' to '/' in meth to represent object traversal.
method = method.replace('.', '/')
return method, params
Expand Down Expand Up @@ -147,18 +137,18 @@ def __delattr__(self, name):
return delattr(self._real, name)

def setBody(self, body, title='', is_error=0, bogus_str_search=None):
if isinstance(body, xmlrpclib.Fault):
if isinstance(body, xmlrpc.client.Fault):
# Convert Fault object to XML-RPC response.
body = xmlrpclib.dumps(body, methodresponse=1, allow_none=True)
body = xmlrpc.client.dumps(body, methodresponse=1, allow_none=True)
else:
# Marshall our body as an XML-RPC response. Strings will be sent
# strings, integers as integers, etc. We do *not* convert
# everything to a string first.
# Previously this had special handling if the response
# was a Python None. This is now patched in xmlrpclib to
# was a Python None. This is now patched in xmlrpc.client to
# allow Nones nested inside data structures too.
try:
body = xmlrpclib.dumps(
body = xmlrpc.client.dumps(
(body,), methodresponse=1, allow_none=True)
except ConflictError:
raise
Expand Down Expand Up @@ -186,7 +176,7 @@ def exception(self, fatal=0, info=None,
return self._real.exception(fatal=fatal, info=info)

# Create an appropriate Fault object. Containing error information
Fault = xmlrpclib.Fault
Fault = xmlrpc.client.Fault
f = None
try:
# Strip HTML tags from the error value
Expand Down

0 comments on commit 06d940f

Please sign in to comment.