mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
pep8 and small perf improvement for human_readable()
This commit is contained in:
parent
6579327a6d
commit
54a9a7c98e
@ -310,9 +310,9 @@ def get_parsed_proxy(typ='http', debug=True):
|
||||
proxy = proxies.get(typ, None)
|
||||
if proxy:
|
||||
pattern = re.compile((
|
||||
'(?:ptype://)?' \
|
||||
'(?:(?P<user>\w+):(?P<pass>.*)@)?' \
|
||||
'(?P<host>[\w\-\.]+)' \
|
||||
'(?:ptype://)?'
|
||||
'(?:(?P<user>\w+):(?P<pass>.*)@)?'
|
||||
'(?P<host>[\w\-\.]+)'
|
||||
'(?::(?P<port>\d+))?').replace('ptype', typ)
|
||||
)
|
||||
|
||||
@ -535,7 +535,7 @@ def entity_to_unicode(match, exceptions=[], encoding='cp1252',
|
||||
ent = match.group(1)
|
||||
if ent in exceptions:
|
||||
return '&'+ent+';'
|
||||
if ent in {'apos', 'squot'}: # squot is generated by some broken CMS software
|
||||
if ent in {'apos', 'squot'}: # squot is generated by some broken CMS software
|
||||
return check("'")
|
||||
if ent == 'hellips':
|
||||
ent = 'hellip'
|
||||
@ -565,7 +565,7 @@ def entity_to_unicode(match, exceptions=[], encoding='cp1252',
|
||||
return '&'+ent+';'
|
||||
|
||||
_ent_pat = re.compile(r'&(\S+?);')
|
||||
xml_entity_to_unicode = partial(entity_to_unicode, result_exceptions = {
|
||||
xml_entity_to_unicode = partial(entity_to_unicode, result_exceptions={
|
||||
'"' : '"',
|
||||
"'" : ''',
|
||||
'<' : '<',
|
||||
@ -670,8 +670,8 @@ def human_readable(size, sep=' '):
|
||||
""" Convert a size in bytes into a human readable form """
|
||||
divisor, suffix = 1, "B"
|
||||
for i, candidate in enumerate(('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB')):
|
||||
if size < 1024**(i+1):
|
||||
divisor, suffix = 1024**(i), candidate
|
||||
if size < (1 << ((i + 1) * 10)):
|
||||
divisor, suffix = (1 << (i * 10)), candidate
|
||||
break
|
||||
size = str(float(size)/divisor)
|
||||
if size.find(".") > -1:
|
||||
|
Loading…
x
Reference in New Issue
Block a user