Skip to content

Commit

Permalink
Add support for Python3.2, and really test PyPy3.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jun 4, 2015
1 parent 26698a3 commit 8fa2fca
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 152 deletions.
23 changes: 14 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
language: python
sudo: false
python:
- 2.6
- 2.7
- 3.3
- 3.4
- pypy
- pypy3

env:
- TOXENV=py26
- TOXENV=py27
- TOXENV=py32
- TOXENV=py33
- TOXENV=py34
- TOXENV=pypy
- TOXENV=pypy3

install:
- pip install .
- travis_retry pip install tox

script:
- python setup.py test -q
- travis_retry tox

notifications:
email: false
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changes
4.2.1 (unreleased)
------------------

- TBD
- Add support for Python 3.2.

4.2.0 (2015-06-02)
------------------
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def read(*rnames):
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: CPython',
Expand Down
9 changes: 6 additions & 3 deletions src/zope/publisher/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
PYTHON3 = sys.version_info[0] == 3

if PYTHON2:
_u = unicode
def _u(s, encoding='unicode_escape'):
return unicode(s, encoding)
from xmlrpclib import *
import types
CLASS_TYPES = (type, types.ClassType)
else:
_u = str
def _u(s, encoding=None):
if encoding is None:
return s
return str(s, encoding)
CLASS_TYPES = (type,)
from xmlrpc.client import *

10 changes: 5 additions & 5 deletions src/zope/publisher/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,15 +877,15 @@ def handleException(self, exc_info):

def internalError(self):
'See IPublisherResponse'
self.setStatus(500, u"The engines can't take any more, Jim!")
self.setStatus(500, _u("The engines can't take any more, Jim!"))

def _html(self, title, content):
t = escape(title)
return (
u"<html><head><title>%s</title></head>\n"
u"<body><h2>%s</h2>\n"
u"%s\n"
u"</body></html>\n" %
_u("<html><head><title>%s</title></head>\n"
"<body><h2>%s</h2>\n"
"%s\n"
"</body></html>\n") %
(t, t, content)
)

Expand Down
5 changes: 2 additions & 3 deletions src/zope/publisher/httpresults.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ python-3.x:
... @zope.component.adapter(unicode, IHTTPRequest)
... def do_something_silly_to_unicode_results(val, request):
... request.response.setHeader('X-Silly', 'Yes')
... return (u'<html>\n<head>\n<title>raw</title>\n</head>\n<body>\n' +
... return (unicode('<html>\n<head>\n<title>raw</title>\n</head>\n<body>\n') +
... escape(val) + '\n</body>\n</html>')
...
>>> zope.component.provideAdapter(do_something_silly_to_unicode_results)
Expand All @@ -96,7 +96,7 @@ iterable that is chunked, (2) encode, and (3) set content-length.

>>> request = TestRequest()
>>> request.response.setHeader('content-type', 'text/html')
>>> request.response.setResult(u'<h1>Foo!</h1>')
>>> request.response.setResult(unicode('<h1>Foo!</h1>'))
>>> request.response.getHeader('x-silly')
'Yes'
>>> request.response.getHeader('content-type')
Expand Down Expand Up @@ -145,4 +145,3 @@ simplest way to do this, but any other IResult should work.
>>> request.response.setResult(DirectResult(('hi',)))
>>> tuple(request.response.consumeBodyIter())
('hi',)

28 changes: 14 additions & 14 deletions src/zope/publisher/interfaces/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from zope.publisher.interfaces import IResponse
from zope.publisher.interfaces import IView

from .._compat import _u

class IVirtualHostRequest(Interface):
"""The support for virtual hosts in Zope is very important.
Expand Down Expand Up @@ -282,7 +283,7 @@ def setAuthUserName(name):

class IResult(Interface):
"""An iterable that provides the body data of the response.
For simplicity, an adapter to this interface may in fact return any
iterable, without needing to strictly have the iterable provide
IResult.
Expand All @@ -303,14 +304,14 @@ class IResult(Interface):
per-character is wildly too small. Because this is such a common
case, if a string is used as an IResult then this is special-cased
to simply convert to a tuple of one value, the string.
Adaptation to this interface provides the opportunity for efficient file
delivery, pipelining hooks, and more.
"""

def __iter__():
"""iterate over the values that should be returned as the result.
See IHTTPResponse.setResult.
"""

Expand Down Expand Up @@ -428,18 +429,18 @@ def getCookie(name, default=None):

def setResult(result):
"""Sets response result value based on input.
Input is usually a unicode string, a string, None, or an object
that can be adapted to IResult with the request. The end result
is an iterable such as WSGI prefers, determined by following the
process described below.
Try to adapt the given input, with the request, to IResult
(found above in this file). If this fails, and the original
value was a string, use the string as the result; or if was
None, use an empty string as the result; and if it was anything
else, raise a TypeError.
If the result of the above (the adaptation or the default
handling of string and None) is unicode, encode it (to the
preferred encoding found by adapting the request to
Expand All @@ -449,14 +450,14 @@ def setResult(result):
the Content-Type header, if present. Otherwise (the end result
was not unicode) application is responsible for setting
Content-Type header encoding value as necessary.
If the result of the above is a string, set the Content-Length
header, and make the string be the single member of an iterable
such as a tuple (to send large chunks over the wire; see
discussion in the IResult interface). Otherwise (the end result
was not a string) application is responsible for setting
Content-Length header as necessary.
Set the result of all of the above as the response's result. If
the status has not been set, set it to 200 (OK). """

Expand All @@ -473,15 +474,15 @@ def consumeBodyIter():
Note that this function can be only requested once, since it is
constructed from the result.
"""

class IHTTPVirtualHostChangedEvent(Interface):
"""The host, port and/or the application path have changed.
The request referred to in this event implements at least the
The request referred to in this event implements at least the
IHTTPAppliationRequest interface.
"""
request = Attribute(u'The application request whose virtual host info has '
u'been altered')
request = Attribute(_u("The application request whose virtual host info has "
"been altered"))

class IHTTPException(Interface):
"""Marker interface for http exceptions views
Expand All @@ -507,4 +508,3 @@ def __init__(self, object, request):

def __str__(self):
return "%r, %r" % (self.object, self.request)

Loading

0 comments on commit 8fa2fca

Please sign in to comment.