# Path: ejtp/util/hasher.py
# @StringDecorator()
# @StringDecorator(args=False, ret=True, strict=True)
# def strict(obj=None):
#     ''' Convert an object into a strict JSON string '''
#     if isinstance(obj, bool) or obj==None or isinstance(obj, int):
#         return json.dumps(obj)
#     if isinstance(obj, String):
#         return json.dumps(obj.export())
#     if isinstance(obj, RawData):
#         obj = tuple(obj)
#     if isinstance(obj, list) or isinstance(obj, tuple):
#         return "[%s]" % ",".join([strict(x).export() for x in obj])
#     if isinstance(obj, dict):
#         strdict = {}
#         for key in obj:
#             strdict[key] = obj[key]
#         keys = sorted(strdict.keys())
#         return "{%s}" % ",".join([strict(key).export()+":"+strict(strdict[key]).export() for key in keys])


from json import loads
from persei import String, StringDecorator
from ejtp.util.hasher import strict


@StringDecorator()
def str_address(address):
    '''
        Converts address to string, only if it isn't already
        >>> str_address([0,9])
        '[0,9]'
        >>> str_address("[0,9]")
        '[0,9]'
    '''
    if isinstance(address, String):
        return address
    else:
        return strict(address)

@StringDecorator()
def py_address(address):
    '''
        Converts address to non-string, only if it isn't already
        >>> py_address([0,9])
        [0, 9]
        >>> py_address("[0,9]")
        [0, 9]
    '''
    if isinstance(address, String):
        return loads(address.export())
    elif isinstance(address, list):
        return address
    elif isinstance(address, tuple):

# Path: ejtp/util/hasher.py
# @StringDecorator()
# @StringDecorator(args=False, ret=True, strict=True)
# def strict(obj=None):
#     ''' Convert an object into a strict JSON string '''
#     if isinstance(obj, bool) or obj==None or isinstance(obj, int):
#         return json.dumps(obj)
#     if isinstance(obj, String):
#         return json.dumps(obj.export())
#     if isinstance(obj, RawData):
#         obj = tuple(obj)
#     if isinstance(obj, list) or isinstance(obj, tuple):
#         return "[%s]" % ",".join([strict(x).export() for x in obj])
#     if isinstance(obj, dict):
#         strdict = {}
#         for key in obj:
#             strdict[key] = obj[key]
#         keys = sorted(strdict.keys())
#         return "{%s}" % ",".join([strict(key).export()+":"+strict(strdict[key]).export() for key in keys])


# Path: ejtp/address.py
from json import loads
from persei import String, StringDecorator
from ejtp.util.hasher import strict



@StringDecorator()
def str_address(address):
    '''
        Converts address to string, only if it isn't already
        >>> str_address([0,9])
        '[0,9]'
        >>> str_address("[0,9]")
        '[0,9]'
    '''
    if isinstance(address, String):
        return address
    else:
        return strict(address)

@StringDecorator()
def py_address(address):
    '''
        Converts address to non-string, only if it isn't already
        >>> py_address([0,9])
        [0, 9]
        >>> py_address("[0,9]")
        [0, 9]
    '''
    if isinstance(address, String):
        return loads(address.export())
    elif isinstance(address, list):
        return address
    elif isinstance(address, tuple):

        return loads(strict(address).export())