示例#1
0
def ParsePythonEnum(string: str,
                    enumType: typing.Type[enum_lib.Enum]) -> typing.Any:
    if not isinstance(string, str):
        raise Exceptions.IncorrectTypeException(string, "string", (str, ))

    if not isinstance(enumType, type):
        raise Exceptions.IncorrectTypeException(enumType, "enumType", (type, ))

    if not issubclass(enumType, enum_lib.Enum):
        raise Exceptions.DoesNotInheritException("enumType", (enum_lib.Enum, ))

    if "." in string:
        stringSplit = string.split(".")  # type: typing.List[str]

        if len(stringSplit) == 2:
            if stringSplit[0] == enumType.__name__:
                string = stringSplit[1]
            else:
                raise ValueError("Cannot parse '" + string + "' to '" +
                                 Types.GetFullName(enumType) + "'.")
        else:
            raise ValueError("Cannot parse '" + string + "' to '" +
                             Types.GetFullName(enumType) + "'.")

    try:
        return enumType[string]
    except KeyError:
        pass

    raise ValueError("'" + string + "' is not an attribute of '" +
                     Types.GetFullName(enumType) + "'.")
示例#2
0
def RegisterHandlerType(
        identifier: str,
        handlerType: typing.Type[HandlerBase.HandlerBase]) -> None:
    """
	Register a reproductive handler type. Registration is required to allow for the handler to be loaded. If a handler type with this identifier is already
	registered it will be replaced.
	:param identifier: The identifier of the handler type.
	:type identifier: str
	:param handlerType: The handler type's class.
	:type handlerType: typing.Type[HandlerBase.BaseHandler]
	"""

    if not isinstance(identifier, str):
        raise Exceptions.IncorrectTypeException(identifier, "identifier",
                                                (str, ))

    if not isinstance(handlerType, type):
        raise Exceptions.IncorrectTypeException(handlerType, "handlerType",
                                                (type, ))

    if not issubclass(handlerType, HandlerBase.HandlerBase):
        raise Exceptions.DoesNotInheritException("handlerType",
                                                 (HandlerBase.HandlerBase, ))

    _handlerTypes[identifier] = handlerType
def RegisterTrackerType(
        identifier: str,
        trackerType: typing.Type[ReproductionShared.TrackerBase]) -> None:
    """
	Register a reproductive cycle type. Registration is required to allow for the tracker to be loaded. If a tracker type with this identifier is already
	registered it will be replaced.
	:param identifier: The identifier of the tracker type.
	:type identifier: str
	:param trackerType: The tracker type's class.
	:type trackerType: typing.Type[ReproductionShared.TrackerBase]
	"""

    if not isinstance(identifier, str):
        raise Exceptions.IncorrectTypeException(identifier, "identifier",
                                                (str, ))

    if not isinstance(trackerType, type):
        raise Exceptions.IncorrectTypeException(trackerType, "trackerType",
                                                (type, ))

    if not issubclass(trackerType, ReproductionShared.TrackerBase):
        raise Exceptions.DoesNotInheritException(
            "trackerType", (ReproductionShared.TrackerBase, ))

    _trackerTypes[identifier] = trackerType
示例#4
0
def RegisterEffectType(
        identifier: str,
        effectType: typing.Type[EffectsBase.EffectBase]) -> None:
    """
	Register a reproductive effect type. Registration is required to allow for the effect to be loaded. If a effect type with this identifier is already
	registered it will be replaced.
	:param identifier: The identifier of the effect type.
	:type identifier: str
	:param effectType: The effect type's class.
	:type effectType: typing.Type[EffectsBase.BaseEffect]
	"""

    if not isinstance(identifier, str):
        raise Exceptions.IncorrectTypeException(identifier, "identifier",
                                                (str, ))

    if not isinstance(effectType, type):
        raise Exceptions.IncorrectTypeException(effectType, "effectType",
                                                (type, ))

    if not issubclass(effectType, EffectsBase.EffectBase):
        raise Exceptions.DoesNotInheritException("effectType",
                                                 (EffectsBase.EffectBase, ))

    _effectTypes[identifier] = effectType
示例#5
0
def RegisterLanguageHandler(
        languageHandler: typing.Type[LanguageHandlerBase]) -> None:
    if not isinstance(languageHandler, type):
        raise Exceptions.IncorrectTypeException(languageHandler,
                                                "languageHandler", (type, ))

    if isinstance(languageHandler, LanguageHandlerBase):
        raise Exceptions.DoesNotInheritException("languageHandler",
                                                 (LanguageHandlerBase, ))

    _registeredLanguageHandlers.append(languageHandler)
示例#6
0
def SetupAnnouncer(announcer: typing.Type[Announcer]) -> None:
    if not isinstance(announcer, type):
        raise Exceptions.IncorrectTypeException(announcer, "announcer",
                                                (type, ))

    if not issubclass(announcer, Announcer):
        raise Exceptions.DoesNotInheritException("announcer", (Announcer, ))

    if announcer in _announcers:
        return

    _Register(announcer)

    _SortAnnouncer()
示例#7
0
    def __init__(self, setting: typing.Type[AbstractSettings.SettingAbstract]):
        """
		A wrapper for the standard settings system used by NeonOcean
		"""

        if not isinstance(setting, type):
            raise Exceptions.IncorrectTypeException(setting, "setting",
                                                    (type, ))

        if not issubclass(setting, AbstractSettings.SettingAbstract):
            raise Exceptions.DoesNotInheritException(
                "setting", (AbstractSettings.SettingAbstract, ))

        super().__init__(setting)
示例#8
0
    def __init__(
            self,
            setting: typing.Type[AbstractSettings.SettingBranchedAbstract],
            branch: str):
        """
		A wrapper for the branch settings system used by NeonOcean
		"""

        if not isinstance(setting, type):
            raise Exceptions.IncorrectTypeException(setting, "setting",
                                                    (type, ))

        if not issubclass(setting, AbstractSettings.SettingBranchedAbstract):
            raise Exceptions.DoesNotInheritException(
                "setting", (AbstractSettings.SettingBranchedAbstract, ))

        if not isinstance(branch, str):
            raise Exceptions.IncorrectTypeException(branch, "branch", (str, ))

        self._branch = branch  # type: str

        super().__init__(setting)
示例#9
0
def RegisterCycleType(identifier: str,
                      cycleType: typing.Type[CycleBase.CycleBase]) -> None:
    """
	Register a reproductive cycle type. Registration is required to allow for the cycle to be loaded. If a cycle type with this identifier is already
	registered it will be replaced.
	:param identifier: The identifier of the cycle type.
	:type identifier: str
	:param cycleType: The cycle type's class.
	:type cycleType: typing.Type[CyclesBase.CycleBase]
	"""

    if not isinstance(identifier, str):
        raise Exceptions.IncorrectTypeException(identifier, "identifier",
                                                (str, ))

    if not isinstance(cycleType, type):
        raise Exceptions.IncorrectTypeException(cycleType, "cycleType",
                                                (type, ))

    if not issubclass(cycleType, CycleBase.CycleBase):
        raise Exceptions.DoesNotInheritException("cycleType",
                                                 (CycleBase.CycleBase, ))

    _cycleTypes[identifier] = cycleType