[Python-checkins] python/dist/src/Lib decimal.py,1.20,1.21
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Sun Aug 8 06:03:27 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13331
Modified Files:
decimal.py
Log Message:
* Context.copy() now makes a deepcopy.
* Facilitate reloads of local thread.
Index: decimal.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/decimal.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** decimal.py 6 Aug 2004 23:42:16 -0000 1.20
--- decimal.py 8 Aug 2004 04:03:24 -0000 1.21
***************
*** 393,397 ****
"""Set this thread's context to context."""
if context in (DefaultContext, BasicContext, ExtendedContext):
! context = copy.deepcopy(context)
context.clear_flags()
threading.currentThread().__decimal_context__ = context
--- 393,397 ----
"""Set this thread's context to context."""
if context in (DefaultContext, BasicContext, ExtendedContext):
! context = context.copy()
context.clear_flags()
threading.currentThread().__decimal_context__ = context
***************
*** 414,417 ****
--- 414,419 ----
local = threading.local()
+ if hasattr(local, '__decimal_context__'):
+ del local.__decimal_context__
def getcontext(_local=local):
***************
*** 432,436 ****
"""Set this thread's context to context."""
if context in (DefaultContext, BasicContext, ExtendedContext):
! context = copy.deepcopy(context)
context.clear_flags()
_local.__decimal_context__ = context
--- 434,438 ----
"""Set this thread's context to context."""
if context in (DefaultContext, BasicContext, ExtendedContext):
! context = context.copy()
context.clear_flags()
_local.__decimal_context__ = context
***************
*** 643,647 ****
return -((-1)**self._sign)
! context = context.copy()
rounding = context._set_rounding(ROUND_UP) #round away from 0
--- 645,649 ----
return -((-1)**self._sign)
! context = context._shallow_copy()
rounding = context._set_rounding(ROUND_UP) #round away from 0
***************
*** 862,866 ****
if not round:
! context = context.copy()
context._set_rounding_decision(NEVER_ROUND)
--- 864,868 ----
if not round:
! context = context._shallow_copy()
context._set_rounding_decision(NEVER_ROUND)
***************
*** 1359,1363 ****
# If DivisionImpossible causes an error, do not leave Rounded/Inexact
# ignored in the calling function.
! context = context.copy()
flags = context._ignore_flags(Rounded, Inexact)
#keep DivisionImpossible flags
--- 1361,1365 ----
# If DivisionImpossible causes an error, do not leave Rounded/Inexact
# ignored in the calling function.
! context = context._shallow_copy()
flags = context._ignore_flags(Rounded, Inexact)
#keep DivisionImpossible flags
***************
*** 1368,1372 ****
return r
! context = context.copy()
rounding = context._set_rounding_decision(NEVER_ROUND)
--- 1370,1374 ----
return r
! context = context._shallow_copy()
rounding = context._set_rounding_decision(NEVER_ROUND)
***************
*** 1601,1605 ****
if prec != context.prec:
! context = context.copy()
context.prec = prec
ans = this_function(prec, expdiff, context)
--- 1603,1607 ----
if prec != context.prec:
! context = context._shallow_copy()
context.prec = prec
ans = this_function(prec, expdiff, context)
***************
*** 1739,1743 ****
mul = Decimal(self)
val = Decimal(1)
! context = context.copy()
context.prec = firstprec + elength + 1
rounding = context.rounding
--- 1741,1745 ----
mul = Decimal(self)
val = Decimal(1)
! context = context._shallow_copy()
context.prec = firstprec + elength + 1
rounding = context.rounding
***************
*** 1939,1943 ****
tmp._exp = 0
! context = context.copy()
flags = context._ignore_all_flags()
firstprec = context.prec
--- 1941,1945 ----
tmp._exp = 0
! context = context._shallow_copy()
flags = context._ignore_all_flags()
firstprec = context.prec
***************
*** 2167,2176 ****
self.flags[flag] = 0
! def copy(self):
! """Returns a copy from self."""
nc = Context(self.prec, self.rounding, self.traps, self.flags,
self._rounding_decision, self.Emin, self.Emax,
self.capitals, self._clamp, self._ignored_flags)
return nc
__copy__ = copy
--- 2169,2185 ----
self.flags[flag] = 0
! def _shallow_copy(self):
! """Returns a shallow copy from self."""
nc = Context(self.prec, self.rounding, self.traps, self.flags,
self._rounding_decision, self.Emin, self.Emax,
self.capitals, self._clamp, self._ignored_flags)
return nc
+
+ def copy(self):
+ """Returns a deep copy from self."""
+ nc = Context(self.prec, self.rounding, self.traps.copy(), self.flags.copy(),
+ self._rounding_decision, self.Emin, self.Emax,
+ self.capitals, self._clamp, self._ignored_flags)
+ return nc
__copy__ = copy
***************
*** 2234,2238 ****
rounding decision. Often used like:
! context = context.copy()
# That so you don't change the calling context
# if an error occurs in the middle (say DivisionImpossible is raised).
--- 2243,2247 ----
rounding decision. Often used like:
! context = context._shallow_copy()
# That so you don't change the calling context
# if an error occurs in the middle (say DivisionImpossible is raised).
More information about the Python-checkins
mailing list