fix ox.text in python 3
This commit is contained in:
parent
d4d09b56b6
commit
a9002374b1
1 changed files with 5 additions and 3 deletions
|
@ -322,7 +322,7 @@ def find_string(string, string0='', string1 = ''):
|
||||||
def parse_useragent(useragent):
|
def parse_useragent(useragent):
|
||||||
data = {}
|
data = {}
|
||||||
for key in UA_REGEXPS:
|
for key in UA_REGEXPS:
|
||||||
for alias, regexp in UA_ALIASES[key].iteritems():
|
for alias, regexp in UA_ALIASES[key].items():
|
||||||
alias = alias if key == 'browser' else alias + ' \\1'
|
alias = alias if key == 'browser' else alias + ' \\1'
|
||||||
useragent = re.sub(regexp, alias, useragent)
|
useragent = re.sub(regexp, alias, useragent)
|
||||||
for regexp in UA_REGEXPS[key]:
|
for regexp in UA_REGEXPS[key]:
|
||||||
|
@ -390,7 +390,7 @@ def wrap_string(string, length=80, separator='\n', balance=False):
|
||||||
# can be achieved with a shorter line length
|
# can be achieved with a shorter line length
|
||||||
lines = wrap_string(string, length, separator, False).split(separator)
|
lines = wrap_string(string, length, separator, False).split(separator)
|
||||||
if len(lines) > 1:
|
if len(lines) > 1:
|
||||||
while length > max(map(lambda x : len(x), words)):
|
while length > max([len(x) for x in words]):
|
||||||
length -= 1
|
length -= 1
|
||||||
if len(wrap_string(string, length, separator, False).split(separator)) > len(lines):
|
if len(wrap_string(string, length, separator, False).split(separator)) > len(lines):
|
||||||
length += 1
|
length += 1
|
||||||
|
@ -588,4 +588,6 @@ def sort_string(string):
|
||||||
return unicodedata.normalize('NFKD', string)
|
return unicodedata.normalize('NFKD', string)
|
||||||
|
|
||||||
def sorted_strings(strings, key=None):
|
def sorted_strings(strings, key=None):
|
||||||
return sorted(strings, cmp=lambda a, b: cmp(sort_string(a), sort_string(b)), key=key)
|
if not key:
|
||||||
|
key = lambda k: sort_string(k)
|
||||||
|
return sorted(strings, key=key)
|
||||||
|
|
Loading…
Reference in a new issue