def __eq__(self, other) : if ObjectHelper.isNone(other) : return self is None isEqual = True for value, name in ReflectionHelper.getAttributeDataList(other) : attributeIsEqual = ReflectionHelper.getAttributeOrMethod(self, name) == ReflectionHelper.getAttributeOrMethod(other, name) isEqual = isEqual == attributeIsEqual and True == attributeIsEqual return isEqual
def bindResource(apiInstance, resourceInstance): validateFlaskApi(apiInstance) validateResourceInstance(resourceInstance) setResource( ReflectionHelper.getAttributeOrMethod( apiInstance.resource, getResourceType(resourceInstance).lower()), resourceInstance)
def innerResourceInstanceMethod(*args, **kwargs): resourceInstanceName = methodClassName[:-len( FlaskManager.KW_SCHEDULER_RESOURCE)] resourceInstanceName = f'{resourceInstanceName[0].lower()}{resourceInstanceName[1:]}' args = FlaskManager.getArgumentInFrontOfArgs( args, ReflectionHelper.getAttributeOrMethod( apiInstance.resource.scheduler, resourceInstanceName)) resourceInstance = args[0] methodReturn = None try: FlaskManager.validateArgs(args, requestClass, innerResourceInstanceMethod) methodReturn = resourceInstanceMethod(*args, **kwargs) except Exception as exception: FlaskManager.raiseGlobalException(exception, resourceInstance, resourceInstanceMethod) log.log(innerResourceInstanceMethod, f'Not possible to run {shedulerId} properly', exception=exception) return methodReturn
def innerResourceInstanceMethod(*args, **kwargs): resourceInstanceName = methodClassName[:-len( FlaskManager.KW_SCHEDULER_RESOURCE)] resourceInstanceName = f'{resourceInstanceName[0].lower()}{resourceInstanceName[1:]}' args = FlaskManager.getArgumentInFrontOfArgs( args, ReflectionHelper.getAttributeOrMethod( apiInstance.resource.scheduler, resourceInstanceName)) resourceInstance = args[0] muteLogs = resourceInstance.muteLogs or resourceMethod.muteLogs if resourceInstance.enabled and not resourceInstance.disabled and not resourceMethod.disabled: if not muteLogs: log.debug( resourceMethod, f'{resourceMethod.shedulerId} scheduler started with args={methodArgs} and kwargs={methodKwargs}' ) methodReturn = None try: FlaskManager.validateArgs(args, requestClass, innerResourceInstanceMethod) methodReturn = resourceMethod(*args, **kwargs) except Exception as exception: if not muteLogs: log.warning( resourceMethod, f'Not possible to run {resourceMethod.shedulerId} properly', exception=exception, muteStackTrace=True) FlaskManager.raiseAndPersistGlobalException( exception, resourceInstance, resourceMethod) if not muteLogs: log.debug( resourceMethod, f'{resourceMethod.shedulerId} scheduler finished') return methodReturn if not muteLogs: log.warning( resourceMethod, f'{resourceMethod.shedulerId} scheduler didn{c.SINGLE_QUOTE}t started. {"Schedulers are disabled" if not resourceInstance.enabled else "This scheduler is disabled" if resourceInstance.disabled else "This scheduler method is disabled"}' )
def importResource(resourceName, resourceModuleName=None, muteLogs=False, reload=False, ignoreList=IGNORE_REOURCES, required=False): innerResourceName = getResourceName(resourceName) if innerResourceName not in ignoreList: resource = None importException = None if ObjectHelper.isNone(resourceModuleName): resourceModuleName = innerResourceName if (reload or resourceModuleName not in IMPORT_CASHE or required and ObjectHelper.isNone(IMPORT_CASHE.get(resourceModuleName))): IMPORT_CASHE[resourceModuleName] = importModule(resourceModuleName, muteLogs=muteLogs, reload=reload, required=required) if ObjectHelper.isNone(IMPORT_CASHE.get(resourceModuleName)): if required: raise Exception( f'Could not import module "{resourceModuleName}"') return nameList = [] try: accumulatedResourceModule = IMPORT_CASHE.get(resourceModuleName) for name in getInnerResourceNameList(resourceName, resourceModuleName): nameList.append(name) if reload: accumulatedResourceModule = ReflectionHelper.getAttributeOrMethod( accumulatedResourceModule, name) IMPORT_CASHE[getCompositeModuleName( resourceModuleName, nameList)] = accumulatedResourceModule elif getCompositeModuleName(resourceModuleName, nameList) in IMPORT_CASHE: accumulatedResourceModule = IMPORT_CASHE.get( getCompositeModuleName(resourceModuleName, nameList)) elif ReflectionHelper.hasAttributeOrMethod( accumulatedResourceModule, name): accumulatedResourceModule = ReflectionHelper.getAttributeOrMethod( accumulatedResourceModule, name) IMPORT_CASHE[getCompositeModuleName( resourceModuleName, nameList)] = accumulatedResourceModule except Exception as exception: importException = exception IMPORT_CASHE[getCompositeModuleName(resourceModuleName, nameList)] = None if not muteLogs: log.log( importResource, f'Not possible to import "{resourceName}" resource from "{resourceModuleName}" module', exception=exception) if required and ObjectHelper.isNone(accumulatedResourceModule): dotSpaceCause = f'{c.DOT_SPACE_CAUSE}{getExceptionTextWithoutDotAtTheEnd(importException)}' raise Exception( f'Error while importing {innerResourceName} resource from {resourceModuleName} module{dotSpaceCause}{c.BLANK if dotSpaceCause.endswith(DOT_SPACE_CHECK_LOG_LEVEL_LOGS_FOR_MORE_INFORMATION) else DOT_SPACE_CHECK_LOG_LEVEL_LOGS_FOR_MORE_INFORMATION}' ) return IMPORT_CASHE.get( getCompositeModuleName(resourceModuleName, nameList))
def __str__(self): return str( ReflectionHelper.getAttributeOrMethod(self, ENUM_VALUE_AS_STRING_KEY, muteLogs=True))
def __init__(self, *args, **kwargs): originalClassAttributeValueList = ReflectionHelper.getAttributeNameList( OuterEnum) if instanceLog: log.prettyPython(OuterEnum, 'originalClassAttributeValueList', originalClassAttributeValueList) OuterEnum.__init__(self, *args, **kwargs) self.__associateReturnsTo__ = associateReturnsTo attributeDataList = ReflectionHelper.getAttributeDataList(self) if instanceLog: log.prettyPython(OuterEnum, 'attributeDataList', attributeDataList) for attribute, enumValue in attributeDataList: if enumValue not in ENUM_STATIC_METHOD_NAME_LIST and enumValue not in originalClassAttributeValueList: __raiseBadImplementation__(enumValue, enum=self) nativeClassDataList = [] attributeAttributeDataList = ReflectionHelper.getAttributeDataList( attribute) if instanceLog: log.prettyPython(OuterEnum, 'attributeAttributeDataList', attributeAttributeDataList) # print(f'type({attribute}): {type(attribute)}') association = ReflectionHelper.getAttributeOrMethod( attribute, self.__associateReturnsTo__, muteLogs=True) if type(association) is type(None): # print('type(association) is type(None)') ReflectionHelper.setAttributeOrMethod( attribute, ENUM_VALUE_AS_STRING_KEY, ENUM_ITEM_CLASS_DICTIONARY.get( type(enumValue))(enumValue)) nativeClassDataList = ReflectionHelper.getAttributeDataList( type(enumValue)()) # print(f'type({enumValue}): {type(enumValue)}, type({type(enumValue)}()): {type(type(enumValue)())}') else: # print('not type(association) is type(None)') ReflectionHelper.setAttributeOrMethod( attribute, ENUM_VALUE_AS_STRING_KEY, ENUM_ITEM_CLASS_DICTIONARY.get( type(association))(association)) nativeClassDataList = ReflectionHelper.getAttributeDataList( type(association)()) # print(f'type({association}): {type(association)}, type({type(association)}()): {type(type(association)())}') # print() attribute.enumValue.enumName = enumValue ReflectionHelper.setAttributeOrMethod( attribute, ENUM_NAME_AS_STRING_KEY, enumValue) if isinstance(attribute, EnumItem): # print(attribute, attribute.enumName, attribute) updateEnumItem( attribute, attribute.enumName, attribute) ###- so that __eq__ does not crash if not c.TYPE_FUNCTION == ReflectionHelper.getClassName( attribute): attribute.enumValue.__enumItemMap__ = attribute.__enumItemMap__ attribute.enumValue.__enumItemEqMap__ = attribute.__enumItemEqMap__ for dataInstance, dataName in attributeAttributeDataList: nativeData = False for _, name in nativeClassDataList: if dataName == name: nativeData = True break if not nativeData: ReflectionHelper.setAttributeOrMethod( attribute.enumValue, dataName, dataInstance) ReflectionHelper.setAttributeOrMethod( attribute.enumValue, ENUM_VALUE_AS_STRING_KEY, ReflectionHelper.getAttributeOrMethod( attribute, self.__associateReturnsTo__, muteLogs=True)) ReflectionHelper.setAttributeOrMethod( attribute.enumValue, ENUM_NAME_AS_STRING_KEY, enumValue) ReflectionHelper.setAttributeOrMethod( attribute.enumValue, ENUM_AS_STRING_KEY, self) if ObjectHelper.isEmpty(OuterEnum.__enumEqList__): for attribute, value in attributeDataList: # print(f'type({value}): {type(value)}') # print(f'type({attribute}): {type(attribute)}') valueAsString = str(attribute.enumValue) if valueAsString not in ENUM_STATIC_METHOD_NAME_LIST: if valueAsString not in self.__enumMap__: self.__enumMap__[ valueAsString] = attribute.enumValue ###- ReflectionHelper.getAttributeOrMethod(attribute, valueAsString, muteLogs=True) ###- attribute else: __raiseBadImplementation__(valueAsString, enum=self) if value not in self.__enumMap__: self.__enumMap__[value] = attribute elif not self.__enumMap__[value] == attribute: __raiseBadImplementation__(valueAsString, enum=self) self.__enumEqList__.append( f'{value}({self.__associateReturnsTo__}:{valueAsString})' )