[Twisted-Python] Python3: should paths be bytes or str?

Wolfgang Rohdewald wolfgang.kde at rohdewald.de
Mon Sep 8 03:20:05 MDT 2014


Am Montag, 8. September 2014, 02:14:10 schrieb exarkun at twistedmatrix.com:
> On 01:26 am, wolfgang.kde at rohdewald.de wrote:
> >The porting guide says
> >
> >No byte paths in sys.path.
> 
> What porting guide is that?

https://twistedmatrix.com/trac/wiki/Plan/Python3

see the reviewer check list

> it's also not clear it's possible for Twisted to try to make any other 
> choice (at some point Twisted has to interoperate with the path-related 
> APIs in Python itself - `sys.path`, for example).

Am Montag, 8. September 2014, 02:14:10 schrieb exarkun at twistedmatrix.com:
> If paths are being represented using unicode somewhere and you want to 
> use them with FilePath then you have to encode them (or you have to add 
> unicode path support to FilePath and let FilePath encode them).

I always thought module names must be ascii-only but now found PEP3131

So we should do the same for twisted.python.modules as in those other places
grepped below.
And add that assert isinstance(path, bytes) for PY3 in FilePath.

And maybe this should go into the above check list? I have no edit rights
in the Wiki.

BUT – I will stop trying to port python/modules.py, the usage of the 
same strings for both module names and file paths is too much interwoven,
I do not want to touch that.

My feeling is that file names should all be unicode, converting them only
where needed. But then I am not an expert about this.

Next problem - PEP3131. See separate mail.

grep -r __file__  | grep encode
web/test/test_webclient.py:serverPEM = FilePath(test.__file__.encode("utf-8")).sibling(b'server.pem')
test/ssl_helpers.py:certPath = nativeString(FilePath(__file__.encode("utf-8")
test/test_setup.py:if not FilePath(twisted.__file__.encode('utf-8')).sibling(b'topfiles').child(b'setup.py').exists():
python/test/test_deprecate.py:        self.assertEqual(FilePath(module.__file__.encode("utf-8")),
internet/test/test_gireactor.py:        path = FilePath(__file__.encode("utf-8")).sibling(


-- 
Wolfgang




More information about the Twisted-Python mailing list