[Checkins] SVN: zope.publisher/branches/py3-attempt2/src/zope/publisher/ All tests pass
Andrey Lebedev
cvs-admin at zope.org
Thu Feb 21 10:39:33 UTC 2013
Log message for revision 129560:
All tests pass
Changed:
U zope.publisher/branches/py3-attempt2/src/zope/publisher/base.py
U zope.publisher/branches/py3-attempt2/src/zope/publisher/principallogging.py
U zope.publisher/branches/py3-attempt2/src/zope/publisher/skinnable.txt
U zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_skinnable.py
U zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_xmlrpcrequest.py
U zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_zcml.py
U zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.py
-=-
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/base.py
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/base.py 2013-02-21 10:03:21 UTC (rev 129559)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/base.py 2013-02-21 10:39:33 UTC (rev 129560)
@@ -28,6 +28,8 @@
from zope.publisher.interfaces import IRequest, IResponse, IDebugFlags
from zope.publisher.publish import mapply
+from zope.publisher._compat import PYTHON2
+
_marker = object()
@implementer(IResponse)
@@ -50,7 +52,9 @@
def handleException(self, exc_info):
'See IPublisherResponse'
- f = BytesIO()
+ # We want exception to be formatted to native strings. Pick
+ # respective io class depending on python version.
+ f = BytesIO() if PYTHON2 else StringIO()
print_exception(
exc_info[0], exc_info[1], exc_info[2], 100, f)
self.setResult(f.getvalue())
@@ -398,7 +402,7 @@
environ['PATH_INFO'] = path
if body_instream is None:
- body_instream = BytesIO('')
+ body_instream = BytesIO(b'')
super(TestRequest, self).__init__(body_instream, environ)
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/principallogging.py
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/principallogging.py 2013-02-21 10:03:21 UTC (rev 129559)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/principallogging.py 2013-02-21 10:39:33 UTC (rev 129560)
@@ -30,4 +30,5 @@
self.principal = principal
def getLogMessage(self):
- return self.principal.id.encode('ascii', 'backslashreplace')
+ pid = self.principal.id
+ return pid.encode('ascii', 'backslashreplace').decode('latin1')
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/skinnable.txt
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/skinnable.txt 2013-02-21 10:03:21 UTC (rev 129559)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/skinnable.txt 2013-02-21 10:39:33 UTC (rev 129560)
@@ -88,8 +88,8 @@
Now our request provides IJSONRequest because it implement that interface:
- >>> from StringIO import StringIO
- >>> request = JSONRequest(StringIO(''), {})
+ >>> from io import BytesIO
+ >>> request = JSONRequest(BytesIO(b''), {})
>>> IJSONRequest.providedBy(request)
True
@@ -160,7 +160,7 @@
>>> sm = zope.component.getSiteManager()
>>> sm.registerAdapter(
... IJSONDefaultLayer, (IJSONRequest,), IDefaultSkin, name='default')
- >>> request = JSONRequest(StringIO(''), {})
+ >>> request = JSONRequest(BytesIO(b''), {})
>>> IJSONDefaultLayer.providedBy(request)
False
>>> setDefaultSkin(request)
@@ -210,7 +210,7 @@
setDefaultSkin uses the custom layer interface instead of IJSONDefaultLayer:
- >>> request = JSONRequest(StringIO(''), {})
+ >>> request = JSONRequest(BytesIO(b''), {})
>>> IMySkin.providedBy(request)
False
@@ -229,7 +229,7 @@
method are replaced by the applied layer/skin interface. This is important
for our retry pattern which will ensure that we start with a clean request:
- >>> request = JSONRequest(StringIO(''), {})
+ >>> request = JSONRequest(BytesIO(b''), {})
>>> class IFoo(Interface):
... pass
@@ -261,7 +261,7 @@
Let's start with a fresh request:
- >>> request = JSONRequest(StringIO(''), {})
+ >>> request = JSONRequest(BytesIO(b''), {})
Now we can apply the SkinA:
@@ -287,7 +287,7 @@
If we set a default skin and later apply a custom skin, the default skin get
removed at the time the applySkin get called within a new ISkinType:
- >>> request = JSONRequest(StringIO(''), {})
+ >>> request = JSONRequest(BytesIO(b''), {})
Note, that our IMySkin is the default skin for IJSONRequest. We can aprove that
by lookup an IDefaultSkin interface for our request:
@@ -319,12 +319,17 @@
SkinChangedEvent
----------------
+We will use python-3 style print function, so we import it from the
+future:
+
+ >>> from __future__ import print_function
+
Changing the skin on a request triggers the ISkinChangedEvent event:
>>> import zope.component
>>> from zope.publisher.interfaces import ISkinChangedEvent
>>> def receiveSkinEvent(event):
- ... print "Notified SkinEvent for:", event.request.__class__.__name__
+ ... print("Notified SkinEvent for: %s" % event.request.__class__.__name__)
>>> zope.component.provideHandler(receiveSkinEvent, (ISkinChangedEvent,))
>>> applySkin(request, ISkinA)
Notified SkinEvent for: JSONRequest
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_skinnable.py
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_skinnable.py 2013-02-21 10:03:21 UTC (rev 129559)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_skinnable.py 2013-02-21 10:39:33 UTC (rev 129560)
@@ -14,9 +14,12 @@
##############################################################################
"""HTTP Publisher Tests
"""
+import re
import unittest
import doctest
+
import zope.testing
+from zope.testing.renormalizing import RENormalizing
def cleanUp(test):
@@ -24,9 +27,14 @@
def test_suite():
+ checker = RENormalizing([
+ # Python 3 includes module name in exceptions
+ (re.compile(r"__builtin__"), "builtins"),
+ ])
+
return unittest.TestSuite(
doctest.DocFileSuite('../skinnable.txt',
- setUp=cleanUp, tearDown=cleanUp))
+ setUp=cleanUp, tearDown=cleanUp, checker=checker))
if __name__ == '__main__':
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_xmlrpcrequest.py
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_xmlrpcrequest.py 2013-02-21 10:03:21 UTC (rev 129559)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_xmlrpcrequest.py 2013-02-21 10:39:33 UTC (rev 129560)
@@ -39,7 +39,7 @@
XMLRPCRequest.__init__(self, *args, **kw)
-xmlrpc_call = '''<?xml version='1.0'?>
+xmlrpc_call = b'''<?xml version='1.0'?>
<methodCall>
<methodName>action</methodName>
<params>
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_zcml.py
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_zcml.py 2013-02-21 10:03:21 UTC (rev 129559)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/tests/test_zcml.py 2013-02-21 10:39:33 UTC (rev 129560)
@@ -59,6 +59,10 @@
%s
</configure>"""
+def templated(contents):
+ body = template % contents
+ return BytesIO(body.encode('latin-1'))
+
class Test(cleanup.CleanUp, unittest.TestCase):
def setUp(self):
@@ -68,13 +72,13 @@
def testDefaultView(self):
self.assertTrue(
component.queryMultiAdapter((ob, request), IDefaultViewName) is None)
- xmlconfig(BytesIO(template % (
+ xmlconfig(templated(
'''
<browser:defaultView
name="test"
for="zope.publisher.tests.test_zcml.IOb" />
'''
- )))
+ ))
self.assertEqual(getDefaultViewName(ob, request), 'test')
@@ -88,7 +92,7 @@
component.queryMultiAdapter((ob, request2), IDefaultViewName),
None)
- xmlconfig(BytesIO(template % (
+ xmlconfig(templated(
'''
<browser:defaultView
for="zope.publisher.tests.test_zcml.IOb"
@@ -100,7 +104,7 @@
name="test2"
/>
'''
- )))
+ ))
self.assertEqual(
zope.publisher.defaultview.getDefaultViewName(ob, request2),
@@ -114,14 +118,14 @@
component.queryMultiAdapter((ob, request), IDefaultViewName),
None)
- xmlconfig(BytesIO(template % (
+ xmlconfig(templated(
'''
<browser:defaultView
for="zope.publisher.tests.test_zcml.Ob"
name="test"
/>
'''
- )))
+ ))
self.assertEqual(
zope.publisher.defaultview.getDefaultViewName(ob, request),
@@ -134,7 +138,7 @@
None)
XMLConfig('meta.zcml', component)()
- xmlconfig(BytesIO(template % (
+ xmlconfig(templated(
'''
<interface
interface="
@@ -156,7 +160,7 @@
factory="zope.publisher.tests.test_zcml.V2"
/>
'''
- )))
+ ))
# Simulate Zope Publication behavior in beforeTraversal()
adapters = component.getSiteManager().adapters
Modified: zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.py
===================================================================
--- zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.py 2013-02-21 10:03:21 UTC (rev 129559)
+++ zope.publisher/branches/py3-attempt2/src/zope/publisher/xmlrpc.py 2013-02-21 10:39:33 UTC (rev 129560)
@@ -51,7 +51,7 @@
# Using lines() does not work as Twisted's BufferedStream sends back
# an empty stream here for read() (bug). Using readlines() does not
# work with paster.httpserver. However, readline() works fine.
- lines = ''
+ lines = b''
while True:
line = self._body_instream.readline()
if not line:
More information about the checkins
mailing list