code: def parse(cls, key):
          
  
          try:
              if isinstance(key, int):
                  return key
              elif re.match('[<]KEY_.*[>]', key):
                  # Curses control character
                  return getattr(curses, key[1:-1])
              elif re.match('[<].*[>]', key):
                  # Ascii control character
                  return getattr(curses.ascii, key[1:-1])
              elif key.startswith('0x'):
                  # Ascii hex code
                  return int(key, 16)
              elif len(key) == 2:
                  # Double presses
                  return tuple(cls.parse(k) for k in key)
              else:
                  # Ascii character
                  code = ord(key)
                  if 0 <= code <= 255:
                      return code
                  # Python 3.3 has a curses.get_wch() function that we can use
                  # for unicode keys, but Python 2.7 is limited to ascii.
                  raise exceptions.ConfigError('Invalid configuration! `%s` is '
                                               'not in the ascii range' % key)
  
          except (AttributeError, ValueError, TypeError):
              raise exceptions.ConfigError('Invalid configuration! "%s" is not a '
                                           'valid key' % key)
docs: Parse a key represented by a string and return its character code.