# Path: hurray/server/util.py
# PY3 = sys.version_info >= (3,)
#     def cast(typ, x):
# def import_object(name):
# def raise_exc_info(exc_info):
# def exec_in(code, glob, loc=None):
# def errno_from_exception(e):
#     def __new__(cls, *args, **kwargs):
#     def configurable_base(cls):
#     def configurable_default(cls):
#     def initialize(self):
#     def configure(cls, impl, **kwargs):
#     def configured_class(cls):
#     def _save_configuration(cls):
#     def _restore_configuration(cls, saved):
#     def __init__(self, func, name):
#     def _getargnames(self, func):
#     def get_old_value(self, args, kwargs, default=None):
#     def replace(self, new_value, args, kwargs):
# def timedelta_to_seconds(td):
# class Configurable(object):
# class ArgReplacer(object):


from hurray.server.util import PY3, unicode_type

Also includes a few other miscellaneous string manipulation functions that
have crept in over time.
"""

from __future__ import absolute_import, division, print_function, with_statement


if PY3:
    unichr = chr

_UTF8_TYPES = (bytes, type(None))


def utf8(value):
    # type: (typing.Union[bytes,unicode_type,None])->typing.Union[bytes,None]
    """Converts a string argument to a byte string.

    If the argument is already a byte string or None, it is returned unchanged.
    Otherwise it must be a unicode string and is encoded as utf8.
    """
    if isinstance(value, _UTF8_TYPES):
        return value
    if not isinstance(value, unicode_type):
        raise TypeError(
            "Expected bytes, unicode, or None; got %r" % type(value)
        )
    return value.encode("utf-8")



# Path: hurray/server/util.py
# PY3 = sys.version_info >= (3,)
#     def cast(typ, x):
# def import_object(name):
# def raise_exc_info(exc_info):
# def exec_in(code, glob, loc=None):
# def errno_from_exception(e):
#     def __new__(cls, *args, **kwargs):
#     def configurable_base(cls):
#     def configurable_default(cls):
#     def initialize(self):
#     def configure(cls, impl, **kwargs):
#     def configured_class(cls):
#     def _save_configuration(cls):
#     def _restore_configuration(cls, saved):
#     def __init__(self, func, name):
#     def _getargnames(self, func):
#     def get_old_value(self, args, kwargs, default=None):
#     def replace(self, new_value, args, kwargs):
# def timedelta_to_seconds(td):
# class Configurable(object):
# class ArgReplacer(object):


# Path: hurray/server/escape.py
from hurray.server.util import PY3, unicode_type


Also includes a few other miscellaneous string manipulation functions that
have crept in over time.
"""

from __future__ import absolute_import, division, print_function, with_statement


if PY3:
    unichr = chr

_UTF8_TYPES = (bytes, type(None))


def utf8(value):
    # type: (typing.Union[bytes,unicode_type,None])->typing.Union[bytes,None]
    """Converts a string argument to a byte string.

    If the argument is already a byte string or None, it is returned unchanged.
    Otherwise it must be a unicode string and is encoded as utf8.
    """
    if isinstance(value, _UTF8_TYPES):
        return value
    if not isinstance(value, unicode_type):
        raise TypeError(
            "Expected bytes, unicode, or None; got %r" % type(value)
        )
    return value.encode("utf-8")



_TO_UNICODE_TYPES = (unicode_type, type(None))