def METHOD_NAME(self, key):
    result = None
    if key in self.replacement_mods:
        result = self.replacement_mods[key]
    elif key in self.replacement_keys:
        result = self.replacement_keys[key]
        if result >= 277:
            result -= 277
    elif len(key) == 1:
        result = ord(key.upper()) 
    if result is None:
        raise KeyboardHandlerError("Could not translate key %r into a valid keycode." % key)
    return result