zopefoundation / zope.publisher

Map requests from HTTP/WebDAV clients, web browsers, XML-RPC and FTP clients onto Python objects
Other
3 stars 13 forks source link

Refactoring: use u"" literals instead of _u("...") #43

Closed mgedmin closed 5 years ago

mgedmin commented 5 years ago

The _u() compat function was necessary to support Python 3.0 and 3.1 which did not allow u-literals. Today it only makes the code harder to read and understand.

mgedmin commented 5 years ago

It is still used in several places to do conversions of some kind, e.g.

text = _u(text, charset)
filename = _u(aFieldStorage.filename, 'UTF-8')
title = tname = _u(t)

and (my favourite):

        rk = _u(k if type(k) == bytes
                else k.encode('latin1'), ENCODING)
        rv = _u(v.value if type(v.value) == bytes
                else v.value.encode('latin1'), ENCODING)

I will replace these in a separate PR, when my mind works a bit better.

mgedmin commented 5 years ago

Continued in https://github.com/zopefoundation/zope.publisher/pull/45