Gre*_*reg 5 python google-app-engine google-cloud-endpoints
我有一组使用Google Cloud Endpoints开发的API.API方法看起来像这样:
@endpoints.method(message_types.VoidMessage, SystemAboutResponse, name="about", http_method="GET")
def about(self, request):
"""
Returns some simple information about the APIs.
Example:
...
"""
return SystemAboutResponse(version=API_VERSION)
Run Code Online (Sandbox Code Playgroud)
我想使用pydoc为包含此方法的模块生成文档.但是,当我这样做时,由于使用了endpoints.method装饰器,因此不保留docstring.
我已经看到了其他问题的答案,这些问题展示了在编写自己的装饰器时如何使用functools.wraps(例如Python装饰器处理文档字符串),以便它们保留装饰方法的文档字符串.有没有办法通过Google Cloud Endpoints装饰器执行此操作,因为我无法控制这些装饰器的代码?
我最终对端点库的副本进行了本地修改。变化在 api_config.py 中,特别是装饰器apiserving_method_decorator的函数method。我将@wraps装饰添加到invoke_remote其中包含的函数中apiserving_method_decorator:
def method(request_message=message_types.VoidMessage,
response_message=message_types.VoidMessage,
name=None,
path=None,
http_method='POST',
cache_control=None,
scopes=None,
audiences=None,
allowed_client_ids=None,
auth_level=None):
# ...
def apiserving_method_decorator(api_method):
# ...
@wraps(api_method)
def invoke_remote(service_instance, request):
# ...
Run Code Online (Sandbox Code Playgroud)
然后,当我运行 pydoc 时,我确保端点库的本地修改副本位于我的文件中PYTHONPATH。
| 归档时间: |
|
| 查看次数: |
376 次 |
| 最近记录: |