# Path: lib/util/str.py
# def bytes_to_str(data):
#     '''
#     Converts `data` to `str`.
# 
#     If data is a `bytes`, it is decoded into `str`.
#     If data is `str`, it is returned as-is.
#     '''
#     assert isinstance(data, (str, bytes)), \
#         'data must be str or bytes: %r' % (data)
#     if isinstance(data, str):
#         # already str, yay
#         return data
#     return data.decode()
# 
# def str_to_bytes(data):
#     '''
#     Converts `data` to `bytes`.
# 
#     If data is a `str`, it is encoded into `bytes`.
#     If data is `bytes`, it is returned as-is.
#     '''
#     assert isinstance(data, (str, bytes)), \
#         'data must be str or bytes: %r' % (data)
#     if isinstance(data, bytes):
#         # already bytes, yay
#         return data
#     return data.encode()


import base64
import json
import logging
from ..util.str import (
    bytes_to_str,
    str_to_bytes,
)
def base64_encode(data):
    '''
    Encodes the given `data` in base-64. The result will either be a `str`,
    or `bytes`, depending on the input type (same as input type).
    '''
    assert isinstance(data, (str, bytes)), \
        'data must be str or bytes: %r' % (data)

    is_str = isinstance(data, str)
    if is_str:
        data = str_to_bytes(data)

    encoded = base64.b64encode(data)

    if is_str:
        encoded = bytes_to_str(encoded)

    return encoded


def base64_decode(data):
    '''
    Decodes the given `data` from base-64. The result will either be a `str`,
    or `bytes`, depending on the input type (same as input type).
    '''
    assert isinstance(data, (str, bytes)), \
        'data must be str or bytes: %r' % (data)

    is_str = isinstance(data, str)
    if is_str:

# Path: lib/util/str.py
# def bytes_to_str(data):
#     '''
#     Converts `data` to `str`.
# 
#     If data is a `bytes`, it is decoded into `str`.
#     If data is `str`, it is returned as-is.
#     '''
#     assert isinstance(data, (str, bytes)), \
#         'data must be str or bytes: %r' % (data)
#     if isinstance(data, str):
#         # already str, yay
#         return data
#     return data.decode()
# 
# def str_to_bytes(data):
#     '''
#     Converts `data` to `bytes`.
# 
#     If data is a `str`, it is encoded into `bytes`.
#     If data is `bytes`, it is returned as-is.
#     '''
#     assert isinstance(data, (str, bytes)), \
#         'data must be str or bytes: %r' % (data)
#     if isinstance(data, bytes):
#         # already bytes, yay
#         return data
#     return data.encode()


# Path: lib/util/format.py
import base64
import json
import logging
from ..util.str import (
    bytes_to_str,
    str_to_bytes,
)

def base64_encode(data):
    '''
    Encodes the given `data` in base-64. The result will either be a `str`,
    or `bytes`, depending on the input type (same as input type).
    '''
    assert isinstance(data, (str, bytes)), \
        'data must be str or bytes: %r' % (data)

    is_str = isinstance(data, str)
    if is_str:
        data = str_to_bytes(data)

    encoded = base64.b64encode(data)

    if is_str:
        encoded = bytes_to_str(encoded)

    return encoded


def base64_decode(data):
    '''
    Decodes the given `data` from base-64. The result will either be a `str`,
    or `bytes`, depending on the input type (same as input type).
    '''
    assert isinstance(data, (str, bytes)), \
        'data must be str or bytes: %r' % (data)

    is_str = isinstance(data, str)
    if is_str:

        data = str_to_bytes(data)