Skip to content

Commit 648e3d0

Browse files
committed
issue2551116 - difusedxml support - python2 fixups.
Make sure python2 code path sets client.defusedxml so the code can still run. Bomb tests fail under python2. So disable test under python 2. In the past it was due to string/byte type difference. Not worth fixing the tests since python 2 support dropped.
1 parent 13b7396 commit 648e3d0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

roundup/anypy/xmlrpc_.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
from xmlrpc import client, server
44
# If client.defusedxml == False, client.py will warn that
55
# xmlrpc is insecure and defusedxml should be installed.
6-
client.defusedxml=False
6+
client.defusedxml = False
77
try:
88
from defusedxml import xmlrpc
99
xmlrpc.monkey_patch()
1010
# figure out how to allow user to set xmlrpc.MAX_DATA = bytes
11-
client.defusedxml=True
11+
client.defusedxml = True
1212
except ImportError:
1313
# use regular xmlrpc with warnings
1414
pass
1515

16-
server.SimpleXMLRPCDispatcher
16+
server.SimpleXMLRPCDispatcher # noqa: B018
1717
except (ImportError, AttributeError):
1818
# Python 2.
1919
import SimpleXMLRPCServer as server
2020
import xmlrpclib as client # noqa: F401
21+
client.defusedxml = False

test/test_xmlrpc.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535

3636
skip_defusedxml_used = lambda func, *args, **kwargs: func
3737

38+
if sys.version_info[0] > 2:
39+
skip_python2 = lambda func, *args, **kwargs: func
40+
else:
41+
skip_python2 = mark_class(pytest.mark.skip(
42+
reason='Skipping test under python 2'))
43+
44+
3845
class XmlrpcTest(object):
3946

4047
backend = None
@@ -327,10 +334,12 @@ class S:
327334
for n, r in enumerate(result):
328335
self.assertEqual(r, results[n])
329336

337+
@skip_python2
330338
@skip_defusedxml
331339
def testDefusedXmlBomb(self):
332340
self.XmlBomb(expectIn=b"defusedxml.common.EntitiesForbidden")
333341

342+
@skip_python2
334343
@skip_defusedxml_used
335344
def testNonDefusedXmlBomb(self):
336345
self.XmlBomb(expectIn=b"1234567890"*511)

0 commit comments

Comments
 (0)