def METHOD_NAME(self, key):
    """
    Encodes a dict key. Currently only supports encoding tuples and strings as keys
    """
    if not (isinstance(key, tuple) or isinstance(key, str) or isinstance(key, str)):
        raise Exception('PyJSON can only encode dicts with str, unicode or tuple keys')
    if hasattr(key, '_asdict'):  # detect namedtuple
        nt_name = type(key).__name__
        nt_fields = key._asdict().keys()
        nt_vals = key._asdict().values()
        if PyJSONEncoder.NAMEDTUPLE_FIELD_STR in [nt_name] + list(nt_fields) + list(nt_vals):
            raise Exception(
                '%s is reserved for pyjson encoder but found in namedtuple. Can\'t encode this dict'
                % PyJSONEncoder.NAMEDTUPLE_FIELD_STR
            )
        if PyJSONEncoder.NAMEDTUPLE_VAL_STR in [nt_name] + list(nt_fields) + list(nt_vals):
            raise Exception(
                '%s is reserved for pyjson encoder but found in namedtuple. Can\'t encode this dict'
                % PyJSONEncoder.NAMEDTUPLE_VAL_STR
            )
        if PyJSONEncoder.NAMEDTUPLE_SEP_STR in [nt_name] + list(nt_fields) + list(nt_vals):
            raise Exception(
                '%s is reserved for pyjson encoder but found in namedtuple. Can\'t encode this dict'
                % PyJSONEncoder.NAMEDTUPLE_SEP_STR
            )
        key = '%s%s%s%s%s%s' % (
            PyJSONEncoder.NAMEDTUPLE_KEY_STR,
            nt_name,
            PyJSONEncoder.NAMEDTUPLE_SEP_STR,
            PyJSONEncoder.NAMEDTUPLE_FIELD_STR.join(nt_fields),
            PyJSONEncoder.NAMEDTUPLE_SEP_STR,
            PyJSONEncoder.NAMEDTUPLE_VAL_STR.join(nt_vals),
        )
    if isinstance(key, tuple):
        if not all(isinstance(tuple_el, str) for tuple_el in key):
            raise Exception(
                'Tuple elements need to be all strings (or unicode) for PyJSON to work'
            )
        if any(PyJSONEncoder.TUPLE_KEY_STR in tuple_el for tuple_el in key):
            raise Exception(
                '%s is reserved for pyjson encoder but found in keys. Can\'t encode this dict'
                % PyJSONEncoder.TUPLE_KEY_STR
            )
        if any(PyJSONEncoder.TUPLE_ELEM_STR in tuple_el for tuple_el in key):
            raise Exception(
                '%s is reserved for pyjson encoder but found in keys. Can\'t encode this dict'
                % PyJSONEncoder.TUPLE_ELEM_STR
            )
        key = '%s%s' % (PyJSONEncoder.TUPLE_KEY_STR, PyJSONEncoder.TUPLE_ELEM_STR.join(key))
    return key