Contains the context for a Decimal instance. Contains: prec - precision (for use in rounding, division, square roots..) rounding - rounding type (how you round) traps - If traps[exception] = 1, then the exception is raised when it is caused. Otherwise, a value i
| 3848 | setcontext(self.saved_context) |
| 3849 | |
| 3850 | class Context(object): |
| 3851 | """Contains the context for a Decimal instance. |
| 3852 | |
| 3853 | Contains: |
| 3854 | prec - precision (for use in rounding, division, square roots..) |
| 3855 | rounding - rounding type (how you round) |
| 3856 | traps - If traps[exception] = 1, then the exception is |
| 3857 | raised when it is caused. Otherwise, a value is |
| 3858 | substituted in. |
| 3859 | flags - When an exception is caused, flags[exception] is set. |
| 3860 | (Whether or not the trap_enabler is set) |
| 3861 | Should be reset by user of Decimal instance. |
| 3862 | Emin - Minimum exponent |
| 3863 | Emax - Maximum exponent |
| 3864 | capitals - If 1, 1*10^1 is printed as 1E+1. |
| 3865 | If 0, printed as 1e1 |
| 3866 | clamp - If 1, change exponents if too high (Default 0) |
| 3867 | """ |
| 3868 | |
| 3869 | def __init__(self, prec=None, rounding=None, Emin=None, Emax=None, |
| 3870 | capitals=None, clamp=None, flags=None, traps=None, |
| 3871 | _ignored_flags=None): |
| 3872 | # Set defaults; for everything except flags and _ignored_flags, |
| 3873 | # inherit from DefaultContext. |
| 3874 | try: |
| 3875 | dc = DefaultContext |
| 3876 | except NameError: |
| 3877 | pass |
| 3878 | |
| 3879 | self.prec = prec if prec is not None else dc.prec |
| 3880 | self.rounding = rounding if rounding is not None else dc.rounding |
| 3881 | self.Emin = Emin if Emin is not None else dc.Emin |
| 3882 | self.Emax = Emax if Emax is not None else dc.Emax |
| 3883 | self.capitals = capitals if capitals is not None else dc.capitals |
| 3884 | self.clamp = clamp if clamp is not None else dc.clamp |
| 3885 | |
| 3886 | if _ignored_flags is None: |
| 3887 | self._ignored_flags = [] |
| 3888 | else: |
| 3889 | self._ignored_flags = _ignored_flags |
| 3890 | |
| 3891 | if traps is None: |
| 3892 | self.traps = dc.traps.copy() |
| 3893 | elif not isinstance(traps, dict): |
| 3894 | self.traps = dict((s, int(s in traps)) for s in _signals + traps) |
| 3895 | else: |
| 3896 | self.traps = traps |
| 3897 | |
| 3898 | if flags is None: |
| 3899 | self.flags = dict.fromkeys(_signals, 0) |
| 3900 | elif not isinstance(flags, dict): |
| 3901 | self.flags = dict((s, int(s in flags)) for s in _signals + flags) |
| 3902 | else: |
| 3903 | self.flags = flags |
| 3904 | |
| 3905 | def _set_integer_check(self, name, value, vmin, vmax): |
| 3906 | if not isinstance(value, int): |
| 3907 | raise TypeError("%s must be an integer" % name) |
no outgoing calls
no test coverage detected
searching dependent graphs…