[Checkins] SVN: zope.publisher/branches/py3/ Checkpoint of my porting efforts. I am done for today.
Marius Gedminas
marius at gedmin.as
Fri Feb 15 07:46:29 UTC 2013
On Thu, Feb 14, 2013 at 10:45:23PM -0500, Stephen Richter wrote:
> Log message for revision 129426:
> Checkpoint of my porting efforts. I am done for today.
> Modified: zope.publisher/branches/py3/buildout.cfg
> ===================================================================
> --- zope.publisher/branches/py3/buildout.cfg 2013-02-15 03:41:08 UTC (rev 129425)
> +++ zope.publisher/branches/py3/buildout.cfg 2013-02-15 03:45:22 UTC (rev 129426)
> @@ -1,5 +1,6 @@
> [buildout]
> develop = .
> + ../zope.i18n
(to be removed before merging back to trunk)
> Modified: zope.publisher/branches/py3/src/zope/publisher/browser.py
> ===================================================================
> --- zope.publisher/branches/py3/src/zope/publisher/browser.py 2013-02-15 03:41:08 UTC (rev 129425)
> +++ zope.publisher/branches/py3/src/zope/publisher/browser.py 2013-02-15 03:45:22 UTC (rev 129426)
> @@ -51,9 +50,14 @@
> from zope.publisher.skinnable import setDefaultSkin #BBB import
> from zope.publisher.skinnable import applySkin #BBB import
> from zope.publisher.skinnable import SkinChangedEvent #BBB import
> +import six
>
> +try:
> + from cStringIO import StringIO as BytesIO
> +except ImportError:
> + from io import BytesIO
>
> -__ArrayTypes = (ListType, TupleType)
> +__ArrayTypes = (list, type)
I think you meant 'tuple'.
> Modified: zope.publisher/branches/py3/src/zope/publisher/http.py
> ===================================================================
> --- zope.publisher/branches/py3/src/zope/publisher/http.py 2013-02-15 03:41:08 UTC (rev 129425)
> +++ zope.publisher/branches/py3/src/zope/publisher/http.py 2013-02-15 03:45:22 UTC (rev 129426)
> @@ -349,10 +369,10 @@
> get_env = self._environ.get
> # Get base info first. This isn't likely to cause
> # errors and might be useful to error handlers.
> - script = get_env('SCRIPT_NAME', '').strip()
> + script = get_env('SCRIPT_NAME', b'').strip()
I thought the WSGI environment is supposed to contain native strings:
http://www.python.org/dev/peps/pep-3333/#a-note-on-string-types
> # _script and the other _names are meant for URL construction
> - self._app_names = filter(None, script.split('/'))
> + self._app_names = list(filter(None, script.split(b'/')))
>
> # get server URL and store it too, since we are already looking it up
> server_url = get_env('SERVER_URL', None)
> @@ -361,11 +381,11 @@
> else:
> server_url = self.__deduceServerURL()
>
> - if server_url.endswith('/'):
> + if server_url.endswith(b'/'):
> server_url = server_url[:-1]
>
> # strip off leading /'s of script
> - while script.startswith('/'):
> + while script.startswith(b'/'):
> script = script[1:]
>
> self._app_server = server_url
> @@ -373,13 +393,13 @@
> def __deduceServerURL(self):
> environ = self._environ
>
> - if (environ.get('HTTPS', '').lower() == "on" or
> - environ.get('SERVER_PORT_SECURE') == "1"):
> + if (environ.get('HTTPS', '').lower() == b"on" or
> + environ.get('SERVER_PORT_SECURE') == b"1"):
> protocol = 'https'
> else:
> protocol = 'http'
>
> - if environ.has_key('HTTP_HOST'):
> + if 'HTTP_HOST' in environ:
> host = environ['HTTP_HOST'].strip()
> hostname, port = urllib.splitport(host)
> else:
> @@ -401,8 +421,8 @@
>
> # ignore cookies on a CookieError
> try:
> - c = Cookie.SimpleCookie(text)
> - except Cookie.CookieError, e:
> + c = cookies.SimpleCookie(text)
> + except cookies.CookieError as e:
> eventlog.warn(e)
> return result
>
> @@ -489,9 +509,9 @@
>
> def _authUserPW(self):
> 'See IHTTPCredentials'
> - if self._auth and self._auth.lower().startswith('basic '):
> + if self._auth and self._auth.lower().startswith(b'basic '):
> encoded = self._auth.split(None, 1)[-1]
> - name, password = encoded.decode("base64").split(':', 1)
> + name, password = base64.decode(encoded).split(':', 1)
> return name, password
>
> def unauthorized(self, challenge):
> @@ -833,7 +853,7 @@
> Calls self.setBody() with an error response.
> """
> t, v = exc_info[:2]
> - if isinstance(t, (types.ClassType, type)):
> + if isinstance(t, (type, type)):
No need to repeat yourself. ;)
Hm, doesn't this break Python 2.6? Exceptions can be old-style classes in 2.6.
Use six.class_types perhaps?
> Modified: zope.publisher/branches/py3/src/zope/publisher/tests/test_http.py
> ===================================================================
> --- zope.publisher/branches/py3/src/zope/publisher/tests/test_http.py 2013-02-15 03:41:08 UTC (rev 129425)
> +++ zope.publisher/branches/py3/src/zope/publisher/tests/test_http.py 2013-02-15 03:45:22 UTC (rev 129426)
> @@ -162,26 +170,26 @@
> def read(self, size=-1):
> if size == -1:
> raise ServerHung
> - return 'a'*size
> + return b'a'*size
>
> - stream = HTTPInputStream(NonClosingStream(), {'CONTENT_LENGTH': '10'})
> - self.assertEquals(stream.getCacheStream().read(), 'aaaaaaaaaa')
> + stream = HTTPInputStream(NonClosingStream(), {'CONTENT_LENGTH': b'10'})
> + self.assertEquals(stream.getCacheStream().read(), b'aaaaaaaaaa')
> stream = HTTPInputStream(NonClosingStream(), {})
> self.assertRaises(ServerHung, stream.getCacheStream)
>
> class HTTPTests(unittest.TestCase):
>
> _testEnv = {
> - 'PATH_INFO': '/folder/item',
> - 'a': '5',
> - 'b': 6,
> - 'SERVER_URL': 'http://foobar.com',
> - 'HTTP_HOST': 'foobar.com',
> - 'CONTENT_LENGTH': '0',
> - 'HTTP_AUTHORIZATION': 'Should be in accessible',
> - 'GATEWAY_INTERFACE': 'TestFooInterface/1.0',
> - 'HTTP_OFF_THE_WALL': "Spam 'n eggs",
> - 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1, UTF-8;q=0.66, UTF-16;q=0.33',
> + 'PATH_INFO': b'/folder/item',
> + 'a': b'5',
> + 'b': 6,
> + 'SERVER_URL': b'http://foobar.com',
> + 'HTTP_HOST': b'foobar.com',
> + 'CONTENT_LENGTH': b'0',
> + 'HTTP_AUTHORIZATION': b'Should be in accessible',
> + 'GATEWAY_INTERFACE': b'TestFooInterface/1.0',
> + 'HTTP_OFF_THE_WALL': b"Spam 'n eggs",
> + 'HTTP_ACCEPT_CHARSET': b'ISO-8859-1, UTF-8;q=0.66, UTF-16;q=0.33',
These ought to be strings, not bytestrings, AFAIU.
(Elsewhere too.)
Marius Gedminas
--
No sane person should use frame buffers if they have the choice.
-- Linus Torvalds on lkml
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://mail.zope.org/pipermail/checkins/attachments/20130215/8844c571/attachment.sig>
More information about the checkins
mailing list