summaryrefslogtreecommitdiffstats
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-08-02 10:16:33 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-08-02 10:16:33 (GMT)
commit8d238293cd76e019f8b37dcbd62d22b7852c4774 (patch)
tree89a1a15e5e6e13a81301e805719f7dece31867e0 /Lib/decimal.py
parente634d873155580cac61bbc809a3fdc54c106501e (diff)
downloadcpython-8d238293cd76e019f8b37dcbd62d22b7852c4774.zip
cpython-8d238293cd76e019f8b37dcbd62d22b7852c4774.tar.gz
cpython-8d238293cd76e019f8b37dcbd62d22b7852c4774.tar.bz2
Merged revisions 74279 via svnmerge from
svn+ssh://pythondev@www.python.org/python/branches/py3k ........ r74279 | mark.dickinson | 2009-08-02 11:14:23 +0100 (Sun, 02 Aug 2009) | 1 line Issue #6595: Allow Decimal constructor to accept non-European decimal digits, as recommended by the specification. ........
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py27
1 files changed, 10 insertions, 17 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index aac90d7..042dd8b 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -554,20 +554,16 @@ class Decimal(object):
intpart = m.group('int')
if intpart is not None:
# finite number
- fracpart = m.group('frac')
+ fracpart = m.group('frac') or ''
exp = int(m.group('exp') or '0')
- if fracpart is not None:
- self._int = (intpart+fracpart).lstrip('0') or '0'
- self._exp = exp - len(fracpart)
- else:
- self._int = intpart.lstrip('0') or '0'
- self._exp = exp
+ self._int = str(int(intpart+fracpart))
+ self._exp = exp - len(fracpart)
self._is_special = False
else:
diag = m.group('diag')
if diag is not None:
# NaN
- self._int = diag.lstrip('0')
+ self._int = str(int(diag or '0')).lstrip('0')
if m.group('signal'):
self._exp = 'N'
else:
@@ -5482,26 +5478,23 @@ ExtendedContext = Context(
# 2. For finite numbers (not infinities and NaNs) the body of the
# number between the optional sign and the optional exponent must have
# at least one decimal digit, possibly after the decimal point. The
-# lookahead expression '(?=[0-9]|\.[0-9])' checks this.
-#
-# As the flag UNICODE is not enabled here, we're explicitly avoiding any
-# other meaning for \d than the numbers [0-9].
+# lookahead expression '(?=\d|\.\d)' checks this.
import re
_parser = re.compile(r""" # A numeric string consists of:
# \s*
(?P<sign>[-+])? # an optional sign, followed by either...
(
- (?=[0-9]|\.[0-9]) # ...a number (with at least one digit)
- (?P<int>[0-9]*) # having a (possibly empty) integer part
- (\.(?P<frac>[0-9]*))? # followed by an optional fractional part
- (E(?P<exp>[-+]?[0-9]+))? # followed by an optional exponent, or...
+ (?=\d|\.\d) # ...a number (with at least one digit)
+ (?P<int>\d*) # having a (possibly empty) integer part
+ (\.(?P<frac>\d*))? # followed by an optional fractional part
+ (E(?P<exp>[-+]?\d+))? # followed by an optional exponent, or...
|
Inf(inity)? # ...an infinity, or...
|
(?P<signal>s)? # ...an (optionally signaling)
NaN # NaN
- (?P<diag>[0-9]*) # with (possibly empty) diagnostic info.
+ (?P<diag>\d*) # with (possibly empty) diagnostic info.
)
# \s*
\Z