diff options
| author | Seth M Morton <seth.m.morton@gmail.com> | 2015-11-01 14:26:53 -0800 |
|---|---|---|
| committer | Seth M Morton <seth.m.morton@gmail.com> | 2015-11-01 14:26:53 -0800 |
| commit | 992d3224af09fe9eaf0fb2c2446a1b7210eddc1a (patch) | |
| tree | 1f3b6615c5121a72be567d6cab500c9c9e2e1582 | |
| parent | 8b1bcf6162a1839148b1ac1832c93adc0a05d727 (diff) | |
| download | natsort-992d3224af09fe9eaf0fb2c2446a1b7210eddc1a.tar.gz | |
Made fake_fastnumbers behave similarly to fastnumbers.
The slow splitters also updated to behave more like fastnumbers.
| -rw-r--r-- | natsort/compat/fake_fastnumbers.py | 11 | ||||
| -rw-r--r-- | test_natsort/slow_splitters.py | 3 |
2 files changed, 8 insertions, 6 deletions
diff --git a/natsort/compat/fake_fastnumbers.py b/natsort/compat/fake_fastnumbers.py index 6fd954a..115b028 100644 --- a/natsort/compat/fake_fastnumbers.py +++ b/natsort/compat/fake_fastnumbers.py @@ -15,11 +15,12 @@ from __future__ import ( import sys import re import unicodedata -float_re = re.compile(r'[-+]?(\d*\.?\d+(?:[eE][-+]?\d+)?|inf(?:inity)?|nan)$') +s = r'\s*[-+]?(\d*\.?\d+(?:[eE][-+]?\d+)?|inf(?:inity)?|nan)\s*$' +float_re = re.compile(s) if sys.version[0] == '2': - int_re = re.compile(r'[-+]?\d+[lL]?$') + int_re = re.compile(r'\s*[-+]?\d+[lL]?\s*$') else: - int_re = re.compile(r'[-+]?\d+$') + int_re = re.compile(r'\s*[-+]?\d+\s*$') long = int unicode = str @@ -29,7 +30,7 @@ def fast_float(x, regex_matcher=float_re.match, uni=unicodedata.numeric): if type(x) in (int, long, float): return float(x) elif regex_matcher(x): - return float(x) + return float(x.strip()) elif type(x) == unicode and len(x) == 1 and uni(x, None) is not None: return uni(x) else: @@ -43,7 +44,7 @@ def fast_int(x, regex_matcher=int_re.match, uni=unicodedata.digit): if type(x) in (int, long, float): return int(x) elif regex_matcher(x): - return int(x.rstrip('Ll')) + return int(x.strip().rstrip('Ll')) elif type(x) == unicode and len(x) == 1 and uni(x, None) is not None: return uni(x) else: diff --git a/test_natsort/slow_splitters.py b/test_natsort/slow_splitters.py index 61e8025..8fec3de 100644 --- a/test_natsort/slow_splitters.py +++ b/test_natsort/slow_splitters.py @@ -136,7 +136,8 @@ def float_splitter(x, signed, exp, safe, sep): # Fix a float that looks like a string. fstrings = ('inf', 'infinity', '-inf', '-infinity', '+inf', '+infinity', 'nan') - full_list = [float(y) if type(y) != float and y.lower() in fstrings else y + full_list = [float(y.strip()) + if type(y) != float and y.lower().strip() in fstrings else y for y in full_list] if safe: full_list = sep_inserter(full_list, (float,), sep) |
