# Path: src/evesrp/util/decimal.py
# class PrettyDecimal(Decimal):
#     """:py:class:`~.Decimal` subclass that can pretty-print itself."""
# 
#     def currency(self):
#         """Format the Decimal as a currency number.
# 
#         An older implementation of this also handled formatting with thousands
#         separators. This is not longer supported.
#         """
#         sign, digits, exp = self.quantize(Decimal('0.01')).as_tuple()
#         digits = list(map(unicode, digits))
#         result = []
#         for i in range(2):
#             result.append(digits.pop() if digits else u'0')
#         result.append(u'.')
#         if not digits:
#             result.append(u'0')
#         while digits:
#             result.append(digits.pop())
#         result.append(u'-' if sign else u'')
#         return u''.join(reversed(result))


from flask import request
from flask.json import JSONEncoder
from decimal import Decimal
from .util import PrettyDecimal
import six
            return list(o)
        return super(IterableEncoder, self).default(o)


class PrivateJsonEncoder(JSONEncoder):
    def default(self, o):
        if hasattr(o, '_json'):
            try:
                extended = request.json_extended
            except AttributeError:
                extended = request.args.get('extended', False)
            # request.json_extended can be a dict to set extended mode for only
            # certain types of objects
            if isinstance(extended, dict):
                scope_class = object
                scope_extended = False
                for cls, ext in six.iteritems(extended):
                    if isinstance(o, cls) and issubclass(type(o), scope_class):
                        scope_extended = ext
                        scope_class = cls
                extended = scope_extended
            return o._json(extended)
        return super(PrivateJsonEncoder, self).default(o)


class DecimalEncoder(JSONEncoder):
    def default(self, o):
        if isinstance(o, PrettyDecimal):
            return o.currency()
        elif isinstance(o, Decimal):

# Path: src/evesrp/util/decimal.py
# class PrettyDecimal(Decimal):
#     """:py:class:`~.Decimal` subclass that can pretty-print itself."""
# 
#     def currency(self):
#         """Format the Decimal as a currency number.
# 
#         An older implementation of this also handled formatting with thousands
#         separators. This is not longer supported.
#         """
#         sign, digits, exp = self.quantize(Decimal('0.01')).as_tuple()
#         digits = list(map(unicode, digits))
#         result = []
#         for i in range(2):
#             result.append(digits.pop() if digits else u'0')
#         result.append(u'.')
#         if not digits:
#             result.append(u'0')
#         while digits:
#             result.append(digits.pop())
#         result.append(u'-' if sign else u'')
#         return u''.join(reversed(result))


# Path: src/evesrp/json.py
from flask import request
from flask.json import JSONEncoder
from decimal import Decimal
from .util import PrettyDecimal
import six

            return list(o)
        return super(IterableEncoder, self).default(o)


class PrivateJsonEncoder(JSONEncoder):
    def default(self, o):
        if hasattr(o, '_json'):
            try:
                extended = request.json_extended
            except AttributeError:
                extended = request.args.get('extended', False)
            # request.json_extended can be a dict to set extended mode for only
            # certain types of objects
            if isinstance(extended, dict):
                scope_class = object
                scope_extended = False
                for cls, ext in six.iteritems(extended):
                    if isinstance(o, cls) and issubclass(type(o), scope_class):
                        scope_extended = ext
                        scope_class = cls
                extended = scope_extended
            return o._json(extended)
        return super(PrivateJsonEncoder, self).default(o)


class DecimalEncoder(JSONEncoder):
    def default(self, o):
        if isinstance(o, PrettyDecimal):
            return o.currency()
        elif isinstance(o, Decimal):

            return unicode(o)