[Checkins] SVN: zope.publisher/branches/py3-attempt2/src/zope/publisher/ Adding py3 compatibility, fixing tests
Andrey Lebedev
cvs-admin at zope.org
Wed Feb 20 08:35:05 UTC 2013
Log message for revision 129520:
Adding py3 compatibility, fixing tests
Changed:
A zope.publisher/branches/py3-attempt2/src/zope/publisher/_compat.py
U zope.publisher/branches/py3-attempt2/src/zope/publisher/configure.zcml
U zope.publisher/branches/py3-attempt2/src/zope/publisher/testing.py
U zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.py
U zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.txt
-=-
Added: zope.publisher/branches/py3-attempt2/src/zope/publisher/_compat.py
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/_compat.py (rev 0)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/_compat.py 2013-02-20 08:35:05 UTC (rev 129520)
@@ -0,0 +1,31 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Compatibility module for xmlrpclib
+
+This module unifies namespace for xmlrpclib, that changed its name in
+python-3.x (became xmlrpc.client).
+
+The intention is to let xmlrpclib names to be importable from zcml.
+"""
+import sys
+PYTHON2 = sys.version_info[0] == 2
+PYTHON3 = sys.version_info[0] == 3
+
+if PYTHON2:
+ _u = unicode
+ from xmlrpclib import *
+else:
+ _u = str
+ from xmlrpc.client import *
+
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/configure.zcml
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/configure.zcml 2013-02-20 05:35:41 UTC (rev 129519)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/configure.zcml 2013-02-20 08:35:05 UTC (rev 129520)
@@ -61,15 +61,15 @@
provides="zope.i18n.interfaces.IModifiableUserPreferredLanguages"
/>
- <class class="xmlrpclib.Binary">
+ <class class="._compat.Binary">
<allow attributes="data encode decode" />
</class>
- <class class="xmlrpclib.Fault">
+ <class class="._compat.Fault">
<allow attributes="faultCode faultString" />
</class>
- <class class="xmlrpclib.DateTime">
+ <class class="._compat.DateTime">
<allow attributes="value" />
</class>
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/testing.py
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/testing.py 2013-02-20 05:35:41 UTC (rev 129519)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/testing.py 2013-02-20 08:35:05 UTC (rev 129520)
@@ -12,7 +12,6 @@
#
##############################################################################
-import sys
import re
import contextlib
import zope.publisher.browser
@@ -20,17 +19,14 @@
import zope.security.testing
from zope.testing import renormalizing
-PY2 = sys.version_info[0] == 2
+from zope.publisher._compat import PYTHON2
-if PY2:
- _u = unicode
- import doctest
+if PYTHON2:
rules = [(re.compile("b('.*?')"), r"\1"),
(re.compile('b(".*?")'), r"\1"),
]
output_checker = renormalizing.RENormalizing(rules)
else:
- _u = str
rules = [(re.compile("u('.*?')"), r"\1"),
(re.compile('u(".*?")'), r"\1"),
(re.compile("b('.*?')"), r"\1"),
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.py
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.py 2013-02-20 05:35:41 UTC (rev 129519)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.py 2013-02-20 08:35:05 UTC (rev 129520)
@@ -202,7 +202,7 @@
"""Pre-marshaller for list"""
def __call__(self):
- return map(premarshal, self.data)
+ return [premarshal(x) for x in self.data]
@zope.component.adapter(tuple)
class TuplePreMarshaller(ListPreMarshaller):
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.txt
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.txt 2013-02-20 05:35:41 UTC (rev 129519)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.txt 2013-02-20 08:35:05 UTC (rev 129520)
@@ -38,10 +38,18 @@
So xmlrpclib will be happy. :)
+Import xmlrpclib depending on current python interpreter version
+
+ >>> import sys
+ >>> if sys.version_info[0] == 2:
+ ... import xmlrpclib
+ ... else:
+ ... import xmlrpc.client as xmlrpclib
+
+
We can also use premarshal to strip proxies off of Fault objects.
We have to make a security declaration first though:
- >>> import xmlrpclib
>>> fault = xmlrpclib.Fault(1, 'waaa')
>>> proxied_fault = ProxyFactory(fault)
>>> stripped_fault = premarshal(proxied_fault)
@@ -51,7 +59,7 @@
Standard python datetime objects are also handled:
>>> import datetime
- >>> sample = datetime.datetime(2006,06,17,21,41,00)
+ >>> sample = datetime.datetime(2006,6,17,21,41,00)
>>> stripped_date = premarshal(sample)
>>> isinstance(stripped_date, datetime.datetime)
False
@@ -61,8 +69,7 @@
We can also use premarshal to strip proxies off of Binary objects.
We have to make a security declaration first though:
- >>> import xmlrpclib
- >>> binary = xmlrpclib.Binary('foobar')
+ >>> binary = xmlrpclib.Binary(b'foobar')
>>> proxied_binary = ProxyFactory(binary)
>>> stripped_binary = premarshal(proxied_binary)
>>> type(stripped_binary) is Proxy
More information about the checkins
mailing list