import webbrowser
from python_helper import Constant as c
from python_helper import log, StringHelper
from flask import Response, request
import flask_restful
from python_framework.api.src.annotation.MethodWrapper import Function, overrideSignatures
from python_framework.api.src.helper import Serializer
from python_framework.api.src.service import GlobalException
from python_framework.api.src.domain import HttpStatus
from python_framework.api.src.service import Security
from python_framework.api.src.service.openapi import OpenApiManager
KW_URL = 'url'
KW_DEFAULT_URL = 'defaultUrl'
KW_MODEL = 'model'
KW_API = 'api'
KW_METHOD = 'method'
KW_RESOURCE = 'resource'
KW_CONTROLLER_RESOURCE = 'Controller'
KW_SERVICE_RESOURCE = 'Service'
KW_REPOSITORY_RESOURCE = 'Repository'
KW_VALIDATOR_RESOURCE = 'Validator'
KW_MAPPER_RESOURCE = 'Mapper'
KW_HELPER_RESOURCE = 'Helper'
KW_CONVERTER_RESOURCE = 'Converter'
KW_RESOURCE_LIST = [
KW_CONTROLLER_RESOURCE,
KW_SERVICE_RESOURCE,
KW_REPOSITORY_RESOURCE,
KW_VALIDATOR_RESOURCE,
KW_MAPPER_RESOURCE,
KW_HELPER_RESOURCE,
KW_CONVERTER_RESOURCE
]
LOCALHOST_URL = 'http://127.0.0.1:5000'
DOT_SPACE_CAUSE = f'''{c.DOT_SPACE}{c.LOG_CAUSE}'''
def printMyStuff(stuff):
print()
print(f' type(stuff).__name__ = {type(stuff).__name__}')
print(f' type(stuff).__class__.__name__ = {type(stuff).__class__.__name__}')
print(f' stuff.__class__.__name__ = {stuff.__class__.__name__}')
print(f' stuff.__class__.__module__ = {stuff.__class__.__module__}')
print(f' stuff.__class__.__qualname__ = {stuff.__class__.__qualname__}')
def printClass(Class) :
print(f'{2 * c.TAB}Class.__name__ = {Class.__name__}')
print(f'{2 * c.TAB}Class.__module__ = {Class.__module__}')
print(f'{2 * c.TAB}Class.__qualname__ = {Class.__qualname__}')
@Function
def jsonifyResponse(object, contentType, status) :
return Response(Serializer.jsonifyIt(object), mimetype = contentType, status = status)
@Function
def getClassName(instance) :
return instance.__class__.__name__
@Function
def getModuleName(instance) :
return instance.__class__.__module__
@Function
def getQualitativeName(instance) :
return instance.__class__.__qualname__
def appendArgs(args, argument, isControllerMethod=False) :
if isControllerMethod and Serializer.isList(argument) :
return args + argument
args.append(argument)
return args
@Function
def getArgsWithSerializerReturnAppended(argument, args, isControllerMethod=False) :
args = [arg for arg in args]
args = appendArgs(args, argument, isControllerMethod=isControllerMethod)
return tuple(arg for arg in args)
@Function
def getArgsWithResponseClassInstanceAppended(args, responseClass) :
if responseClass :
resourceInstance = args[0]
objectRequest = args[1]
serializerReturn = Serializer.convertFromObjectToObject(objectRequest, responseClass)
args = getArgsWithSerializerReturnAppended(serializerReturn, args)
return args
@Function
def getResourceFinalName(resourceInstance, resourceName=None) :
if not resourceName :
resourceName = resourceInstance.__class__.__name__
for kwAsset in KW_RESOURCE_LIST :
if kwAsset in resourceName :
resourceName = resourceName.replace(kwAsset, c.NOTHING)
return f'{resourceName[0].lower()}{resourceName[1:]}'
@Function
def getResourceType(resourceInstance, resourceName = None) :
if not resourceName :
resourceName = resourceInstance.__class__.__name__
for kwAsset in KW_RESOURCE_LIST :
if kwAsset in resourceName :
return kwAsset
@Function
def getAttributePointerList(object) :
return [
getattr(object, objectAttributeName)
for objectAttributeName in dir(object)
if (not objectAttributeName.startswith('__') and not objectAttributeName.startswith('_'))
]
@Function
def setMethod(resourceInstance, newMethod, methodName = None) :
def buildNewClassMethod(resourceInstance, newMethod) :
def myInnerMethod(*args, **kwargs) :
return newMethod(resourceInstance,*args, **kwargs)
overrideSignatures(myInnerMethod, newMethod)
return myInnerMethod
if not type(newMethod).__name__ == KW_METHOD :
newMethod = buildNewClassMethod(resourceInstance, newMethod)
if not methodName :
methodName = newMethod.__name__
setattr(resourceInstance, methodName, newMethod)
return resourceInstance
@Function
def getGlobals() :
try :
from app import globals
except Exception as exception :
raise Exception('Failed to get "globals" instance from app.py')
return globals
@Function
def getApi() :
try:
api = getGlobals().api
except Exception as exception :
raise Exception(f'Failed to return api from "globals" instance. Cause: {str(exception)}')
return api
@Function
def getNullableApi() :
try :
api = getApi()
except :
api = None
return api
@Function
def raiseBadResponseImplementetion(cause):
raise Exception(f'Bad response implementation. {cause}')
@Function
def validateFlaskApi(instance) :
apiClassName = flask_restful.Api.__name__
moduleName = flask_restful.__name__
if not apiClassName == getClassName(instance) and apiClassName == getQualitativeName(instance) and moduleName == getModuleName(instance) :
raise Exception(f'Globals can only be added to a "flask_restful.Api" instance. Not to {apiInstance}')
@Function
def validateResponseClass(responseClass, controllerResponse) :
log.debug(validateResponseClass, controllerResponse)
if responseClass :
if not controllerResponse and not isinstance(controllerResponse, list):
raiseBadResponseImplementetion(f'Response not present')
if isinstance(responseClass, list) :
if 0 == len(responseClass) :
raiseBadResponseImplementetion(f'"responseClass" was not defined')
elif len(responseClass) == 1 :
if not isinstance(responseClass[0], list) :
if not isinstance(controllerResponse, responseClass[0]) :
raiseBadResponseImplementetion(f'Response class does not match expected class. Expected "{responseClass[0].__name__}", response "{controllerResponse.__class__.__name__}"')
elif not isinstance(responseClass[0][0], list) :
if not isinstance(controllerResponse, list) :
raiseBadResponseImplementetion(f'Response is not a list. Expected "{responseClass[0].__class__.__name__}", but found "{controllerResponse.__class__.__name__}"')
elif isinstance(controllerResponse, list) and len(controllerResponse) > 0 and not isinstance(controllerResponse[0], responseClass[0][0]):
# print(f'responseClass = {responseClass}')
# print(f'responseClass[0] = {responseClass[0]}')
# print(f'responseClass[0][0] = {responseClass[0][0]}')
raiseBadResponseImplementetion(f'Response element class does not match expected element class. Expected "{responseClass[0][0].__name__}", response "{controllerResponse[0].__class__.__name__}"')
else :
if not isinstance(controllerResponse, responseClass) :
raiseBadResponseImplementetion(f'Response class does not match expected class. Expected "{responseClass.__name__}", response "{controllerResponse.__class__.__name__}"')
@Function
def setResource(apiInstance, resourceInstance, resourceName=None) :
resourceName = getResourceFinalName(resourceInstance, resourceName=resourceName)
setattr(apiInstance,resourceName,resourceInstance)
@Function
def bindResourc
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共19个文件
py:17个
cfg:1个
pkg-info:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
资源分类:Python库 所属语言:Python 资源全名:python_framework-0.0.1-33.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 19 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/277f6345dca0446498fbbc03843436aa_qq_38161040.jpg!1)
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)