Opened 21 months ago

Last modified 13 months ago

#6178 enhancement new

Port twisted.web.util to Python 3

Reported by: itamar Owned by:
Priority: lowest Milestone: Python-3.x
Component: core Keywords:
Cc: Branch:
Author: Launchpad Bug:

Description

twisted.web.util should run on Python 3.

Change History (3)

comment:1 Changed 13 months ago by nott_

  • Owner set to nott_

comment:2 Changed 13 months ago by nott_

  • Owner nott_ deleted

comment:3 Changed 13 months ago by ihrachyshka

This will probably require changing filepath.py to expose unicode strings instead of bytes. F.e. if I try to import the module in Python3.3, I get the following:

import twisted.web.util

Traceback (most recent call last):

File "<stdin>", line 1, in <module>
File "./twisted/web/util.py", line 362, in <module>

class FailureElement(Element):

File "./twisted/web/util.py", line 372, in FailureElement

loader = XMLFile(getModule(name).filePath.sibling("failure.xhtml"))

File "./twisted/python/filepath.py", line 408, in sibling

return self.parent().child(path)

File "./twisted/python/filepath.py", line 679, in child

if self.sep in norm:

TypeError: 'in <string>' requires string as left operand, not bytes

If I try to pass bytes string to sibling(), I get another error:

import twisted.web.util

Traceback (most recent call last):

File "<stdin>", line 1, in <module>
File "./twisted/web/util.py", line 362, in <module>

class FailureElement(Element):

File "./twisted/web/util.py", line 372, in FailureElement

loader = XMLFile(getModule(name).filePath.sibling(b"failure.xhtml"))

File "./twisted/python/filepath.py", line 408, in sibling

return self.parent().child(path)

File "./twisted/python/filepath.py", line 681, in child

newpath = abspath(joinpath(self.path, norm))

File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/posixpath.py", line 92, in join

"components.") from None

TypeError: Can't mix strings and bytes in path components.

It looks like filepath object is instantiated via unicode module path, while we try to use paths as if they are bytes. Looks like the ticket to handle first is: #5203

Note: See TracTickets for help on using tickets.