* Update the test suite to reflect that ConversionSyntax was no longer

public.
* Removed the non-signal conditions from __all__.
* Removed the XXX comment which was resolved.
* Use ^ instead of operator.xor
* Remove the threading lock which is no longer necessary.
This commit is contained in:
Raymond Hettinger 2004-07-09 10:52:54 +00:00
parent 5aa478badf
commit d87ac8f24d
2 changed files with 6 additions and 18 deletions

View File

@ -114,10 +114,8 @@ __all__ = [
'DefaultContext', 'BasicContext', 'ExtendedContext',
# Exceptions
'DecimalException', 'Clamped', 'InvalidOperation', 'ConversionSyntax',
'DivisionByZero', 'DivisionImpossible', 'DivisionUndefined',
'Inexact', 'InvalidContext', 'Rounded', 'Subnormal', 'Overflow',
'Underflow',
'DecimalException', 'Clamped', 'InvalidOperation', 'DivisionByZero',
'Inexact', 'Rounded', 'Subnormal', 'Overflow', 'Underflow',
# Constants for use in setting up contexts
'ROUND_DOWN', 'ROUND_HALF_UP', 'ROUND_HALF_EVEN', 'ROUND_CEILING',
@ -211,12 +209,6 @@ class InvalidOperation(DecimalException):
return Decimal( (args[1]._sign, args[1]._int, 'n') )
return NaN
# XXX Is there a logic error in subclassing InvalidOperation?
# Setting the InvalidOperation trap to zero does not preclude ConversionSyntax.
# Also, incrementing Conversion syntax flag will not increment InvalidOperation.
# Both of these issues interfere with cross-language portability because
# code following the spec would not know about the Python subclasses.
class ConversionSyntax(InvalidOperation):
"""Trying to convert badly formed string.
@ -1032,7 +1024,7 @@ class Decimal(object):
if ans:
return ans
resultsign = operator.xor(self._sign, other._sign)
resultsign = self._sign ^ other._sign
if self._isinfinity():
if not other:
return context._raise_error(InvalidOperation, '(+-)INF * 0')
@ -1126,7 +1118,7 @@ class Decimal(object):
else:
return ans
sign = operator.xor(self._sign, other._sign)
sign = self._sign ^ other._sign
if not self and not other:
if divmod:
return context._raise_error(DivisionUndefined, '0 / 0', 1)
@ -2117,8 +2109,6 @@ class Context(object):
_clamp - If 1, change exponents if too high (Default 0)
"""
DefaultLock = threading.Lock()
def __init__(self, prec=None, rounding=None,
trap_enablers=None, flags=None,
_rounding_decision=None,
@ -2127,13 +2117,11 @@ class Context(object):
_ignored_flags=[]):
if flags is None:
flags = dict.fromkeys(Signals, 0)
self.DefaultLock.acquire()
for name, val in locals().items():
if val is None:
setattr(self, name, copy.copy(getattr(DefaultContext, name)))
else:
setattr(self, name, val)
self.DefaultLock.release()
del self.self
def __repr__(self):

View File

@ -134,7 +134,7 @@ class DecimalTest(unittest.TestCase):
#print line
try:
t = self.eval_line(line)
except ConversionSyntax:
except InvalidOperation:
print 'Error in test cases:'
print line
continue
@ -189,7 +189,7 @@ class DecimalTest(unittest.TestCase):
ans = L[0]
exceptions = L[1:]
except (TypeError, AttributeError, IndexError):
raise ConversionSyntax
raise InvalidOperation
def FixQuotes(val):
val = val.replace("''", 'SingleQuote').replace('""', 'DoubleQuote')
val = val.replace("'", '').replace('"', '')