mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: Port use of maketrans
This commit is contained in:
parent
569c576293
commit
40491089f1
@ -15,19 +15,19 @@ import operator
|
|||||||
import string
|
import string
|
||||||
|
|
||||||
from css_selectors.errors import SelectorSyntaxError, ExpressionError
|
from css_selectors.errors import SelectorSyntaxError, ExpressionError
|
||||||
from polyglot.builtins import unicode_type, codepoint_to_chr
|
from polyglot.builtins import unicode_type, codepoint_to_chr, range
|
||||||
|
|
||||||
|
|
||||||
tab = string.maketrans(string.ascii_uppercase, string.ascii_lowercase)
|
|
||||||
utab = {c:c+32 for c in range(ord('A'), ord('Z')+1)}
|
utab = {c:c+32 for c in range(ord('A'), ord('Z')+1)}
|
||||||
|
|
||||||
|
if sys.version_info.major < 3:
|
||||||
|
tab = string.maketrans(string.ascii_uppercase, string.ascii_lowercase)
|
||||||
|
|
||||||
def ascii_lower(string):
|
def ascii_lower(string):
|
||||||
"""Lower-case, but only in the ASCII range."""
|
"""Lower-case, but only in the ASCII range."""
|
||||||
return string.translate(utab if isinstance(string, unicode_type) else tab)
|
return string.translate(utab if isinstance(string, unicode_type) else tab)
|
||||||
|
|
||||||
|
def urepr(x):
|
||||||
def urepr(x):
|
|
||||||
if isinstance(x, list):
|
if isinstance(x, list):
|
||||||
return '[%s]' % ', '.join((map(urepr, x)))
|
return '[%s]' % ', '.join((map(urepr, x)))
|
||||||
ans = repr(x)
|
ans = repr(x)
|
||||||
@ -36,6 +36,14 @@ def urepr(x):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
def ascii_lower(x):
|
||||||
|
return x.translate(utab)
|
||||||
|
|
||||||
|
urepr = repr
|
||||||
|
|
||||||
|
|
||||||
# Parsed objects
|
# Parsed objects
|
||||||
|
|
||||||
class Selector(object):
|
class Selector(object):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user