def innerMethodWrapper(resourceInstanceMethod, *args, **kwargs): noException = None log.debug(ControllerMethod, f'''wrapping {resourceInstanceMethod.__name__}''') def innerResourceInstanceMethod(*args, **kwargs): resourceInstance = args[0] try: if roleRequired and (type(list()) == type(roleRequired) and not [] == roleRequired): completeResponse = securedMethod(args, kwargs, consumes, resourceInstance, resourceInstanceMethod, requestClass, roleRequired) else: completeResponse = notSecuredMethod( args, kwargs, consumes, resourceInstance, resourceInstanceMethod, requestClass) validateResponseClass(responseClass, completeResponse[0]) except Exception as exception: completeResponse = getCompleteResponseByException( exception, resourceInstance, resourceInstanceMethod) ###- request.method: GET ###- request.url: http://127.0.0.1:5000/alert/dingding/test?x=y ###- request.base_url: http://127.0.0.1:5000/alert/dingding/test ###- request.url_charset: utf-8 ###- request.url_root: http://127.0.0.1:5000/ ###- str(request.url_rule): /alert/dingding/test ###- request.host_url: http://127.0.0.1:5000/ ###- request.host: 127.0.0.1:5000 ###- request.script_root: ###- request.path: /alert/dingding/test ###- request.full_path: /alert/dingding/test?x=y ###- request.args: ImmutableMultiDict([('x', 'y')]) ###- request.args.get('x'): y controllerResponse = completeResponse[0] status = completeResponse[1] return jsonifyResponse(controllerResponse, produces, status) overrideSignatures(innerResourceInstanceMethod, resourceInstanceMethod) innerResourceInstanceMethod.url = controllerMethodUrl innerResourceInstanceMethod.requestClass = controllerMethodRequestClass innerResourceInstanceMethod.responseClass = controllerMethodResponseClass innerResourceInstanceMethod.roleRequired = controllerMethodRoleRequired innerResourceInstanceMethod.produces = controllerMethodProduces innerResourceInstanceMethod.consumes = controllerMethodConsumes return innerResourceInstanceMethod
def Wrapper(OuterClass, *args, **kwargs): apiInstance = getApi() noException = None log.debug(Converter, f'''wrapping {OuterClass.__name__}''') class InnerClass(OuterClass): def __init__(self, *args, **kwargs): log.debug( OuterClass, f'in {InnerClass.__name__}.__init__(*{args},**{kwargs})') OuterClass.__init__(self, *args, **kwargs) self.helper = apiInstance.resource.helper self.converter = apiInstance.resource.converter overrideSignatures(InnerClass, OuterClass) return InnerClass
def innerMethodWrapper(resourceInstanceMethod, *args, **kwargs): noException = None log.debug(ValidatorMethod, f'''wrapping {resourceInstanceMethod.__name__}''') def innerResourceInstanceMethod(*args, **kwargs): resourceInstance = args[0] try: validateArgs(args, requestClass, innerResourceInstanceMethod) methodReturn = resourceInstanceMethod(*args, **kwargs) except Exception as exception: raiseGlobalException(exception, resourceInstance, resourceInstanceMethod) return methodReturn overrideSignatures(innerResourceInstanceMethod, resourceInstanceMethod) return innerResourceInstanceMethod
def Wrapper(OuterClass, *args, **kwargs): apiInstance = getApi() noException = None log.debug(Repository, f'''wrapping {OuterClass.__name__}''') class InnerClass(OuterClass): model = repositoryModel def __init__(self, *args, **kwargs): log.debug( OuterClass, f'in {InnerClass.__name__}.__init__(*{args},**{kwargs})') OuterClass.__init__(self, *args, **kwargs) self.repository = apiInstance.repository self.globals = apiInstance.globals overrideSignatures(InnerClass, OuterClass) return InnerClass
def Wrapper(OuterClass, *args, **kwargs): apiInstance = getApi() log.debug(Controller, f'''wrapping {OuterClass.__name__}''') class InnerClass(OuterClass, flask_restful.Resource): url = controllerUrl tag = controllerTag description = controllerDescription def __init__(self, *args, **kwargs): log.debug( OuterClass, f'in {InnerClass.__name__}.__init__(*{args},**{kwargs})') OuterClass.__init__(self) flask_restful.Resource.__init__(self, *args, **kwargs) self.service = apiInstance.resource.service overrideSignatures(InnerClass, OuterClass) return InnerClass
def Wrapper(OuterClass, *args, **kwargs): apiInstance = getApi() noException = None log.debug(Service, f'''wrapping {OuterClass.__name__}''') class InnerClass(OuterClass): def __init__(self, *args, **kwargs): log.debug( OuterClass, f'in {InnerClass.__name__}.__init__(*{args},**{kwargs})') OuterClass.__init__(self, *args, **kwargs) self.globals = apiInstance.globals self.service = apiInstance.resource.service self.repository = apiInstance.resource.repository self.validator = apiInstance.resource.validator self.mapper = apiInstance.resource.mapper self.helper = apiInstance.resource.helper self.converter = apiInstance.resource.converter overrideSignatures(InnerClass, OuterClass) return InnerClass
def buildNewClassMethod(resourceInstance, newMethod): def myInnerMethod(*args, **kwargs): return newMethod(resourceInstance, *args, **kwargs) overrideSignatures(myInnerMethod, newMethod) return myInnerMethod