def __format__(self, specifier, context=None):
        """Format a Decimal instance according to the given specifier.

        The specifier should be a standard format specifier, with the
        form described in PEP 3101.  Formatting types 'e', 'E', 'f',
        'F', 'g', 'G', and '%' are supported.  If the formatting type
        is omitted it defaults to 'g' or 'G', depending on the value
        of context.capitals.

        At this time the 'n' format specifier type (which is supposed
        to use the current locale) is not supported.
        """

        # Note: PEP 3101 says that if the type is not present then
        # there should be at least one digit after the decimal point.
        # We take the liberty of ignoring this requirement for
        # Decimal---it's presumably there to make sure that
        # format(float, '') behaves similarly to str(float).
        if context is None:
            context = getcontext()

        spec = _parse_format_specifier(specifier)

        # special values don't care about the type or precision...
        if self._is_special:
            return _format_align(str(self), spec)

        # a type of None defaults to 'g' or 'G', depending on context
        # if type is '%', adjust exponent of self accordingly
        if spec['type'] is None:
            spec['type'] = ['g', 'G'][context.capitals]
        elif spec['type'] == '%':
            self = _dec_from_triple(self._sign, self._int, self._exp+2)

        # round if necessary, taking rounding mode from the context
        rounding = context.rounding
        precision = spec['precision']
        if precision is not None:
            if spec['type'] in 'eE':
                self = self._round(precision+1, rounding)
            elif spec['type'] in 'gG':
                if len(self._int) > precision:
                    self = self._round(precision, rounding)
            elif spec['type'] in 'fF%':
                self = self._rescale(-precision, rounding)
        # special case: zeros with a positive exponent can't be
        # represented in fixed point; rescale them to 0e0.
        elif not self and self._exp > 0 and spec['type'] in 'fF%':
            self = self._rescale(0, rounding)

        # figure out placement of the decimal point
        leftdigits = self._exp + len(self._int)
        if spec['type'] in 'fF%':
            dotplace = leftdigits
        elif spec['type'] in 'eE':
            if not self and precision is not None:
                dotplace = precision - 1
            else:
                dotplace = 1
        elif spec['type'] in 'gG':
            if self._exp <= 0 and leftdigits > -6:
                dotplace = leftdigits
            else:
                dotplace = 1

        # figure out main part of numeric string...
        if dotplace <= 0:
            num = '0.' + '0'*(-dotplace) + self._int
        elif dotplace >= len(self._int):
            # make sure we're not padding a '0' with extra zeros on the right
            assert dotplace==len(self._int) or self._int != '0'
            num = self._int + '0'*(dotplace-len(self._int))
        else:
            num = self._int[:dotplace] + '.' + self._int[dotplace:]

        # ...then the trailing exponent, or trailing '%'
        if leftdigits != dotplace or spec['type'] in 'eE':
            echar = {'E': 'E', 'e': 'e', 'G': 'E', 'g': 'e'}[spec['type']]
            num = num + "{0}{1:+}".format(echar, leftdigits-dotplace)
        elif spec['type'] == '%':
            num = num + '%'

        # add sign
        if self._sign == 1:
            num = '-' + num
        return _format_align(num, spec)
dataset/ETHPy150Open deanhiller/databus/webapp/play1.3.x/python/Lib/decimal.py/Decimal.__format__/swapped operands of `-`