Replace sequential split/join calls on strings with a single replace call.
Thanks Andrew Gaul.
This commit is contained in:
parent
708b4dacf4
commit
aaeffaf01e
@ -159,18 +159,16 @@ def str(val):
|
|||||||
"""Convert float to integer, taking the locale into account."""
|
"""Convert float to integer, taking the locale into account."""
|
||||||
return format("%.12g",val)
|
return format("%.12g",val)
|
||||||
|
|
||||||
def atof(str,func=float):
|
def atof(string,func=float):
|
||||||
"Parses a string as a float according to the locale settings."
|
"Parses a string as a float according to the locale settings."
|
||||||
#First, get rid of the grouping
|
#First, get rid of the grouping
|
||||||
ts = localeconv()['thousands_sep']
|
ts = localeconv()['thousands_sep']
|
||||||
if ts:
|
if ts:
|
||||||
s=str.split(ts)
|
str = str.replace(ts, '')
|
||||||
str="".join(s)
|
|
||||||
#next, replace the decimal point with a dot
|
#next, replace the decimal point with a dot
|
||||||
dd = localeconv()['decimal_point']
|
dd = localeconv()['decimal_point']
|
||||||
if dd:
|
if dd:
|
||||||
s=str.split(dd)
|
str = str.replace(dd, '.')
|
||||||
str='.'.join(s)
|
|
||||||
#finally, parse the string
|
#finally, parse the string
|
||||||
return func(str)
|
return func(str)
|
||||||
|
|
||||||
|
@ -169,9 +169,7 @@ class URLopener:
|
|||||||
proxy = None
|
proxy = None
|
||||||
name = 'open_' + urltype
|
name = 'open_' + urltype
|
||||||
self.type = urltype
|
self.type = urltype
|
||||||
if '-' in name:
|
name = name.replace('-', '_')
|
||||||
# replace - with _
|
|
||||||
name = '_'.join(name.split('-'))
|
|
||||||
if not hasattr(self, name):
|
if not hasattr(self, name):
|
||||||
if proxy:
|
if proxy:
|
||||||
return self.open_unknown_proxy(proxy, fullurl, data)
|
return self.open_unknown_proxy(proxy, fullurl, data)
|
||||||
@ -1045,9 +1043,7 @@ def unquote(s):
|
|||||||
|
|
||||||
def unquote_plus(s):
|
def unquote_plus(s):
|
||||||
"""unquote('%7e/abc+def') -> '~/abc def'"""
|
"""unquote('%7e/abc+def') -> '~/abc def'"""
|
||||||
if '+' in s:
|
s = s.replace('+', ' ')
|
||||||
# replace '+' with ' '
|
|
||||||
s = ' '.join(s.split('+'))
|
|
||||||
return unquote(s)
|
return unquote(s)
|
||||||
|
|
||||||
always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user