2

我试图让 ladon 工作,但是,我似乎无法正确定义服务。

具体来说,即使有一个最小的测试用例,它也会抛出

Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\ladon\server\wsgi_application.py", line 332, in __call__
    self.import_services(self.service_list)
  File "C:\Python33\lib\site-packages\ladon\server\wsgi_application.py", line 288, in import_services
    __import__(service)
  File "D:\Workspaces\Python\SOAPManager.py", line 20, in <module>
    @ladonize(PORTABLE_STRING, PORTABLE_STRING, rtype=PORTABLE_STRING)
  File "C:\Python33\lib\site-packages\ladon\ladonizer\decorator.py", line 118, in decorator
    injector.__doc__ = ladon_method_info._doc
AttributeError: 'NoneType' object has no attribute '_doc'

我的 Run.py 包含:

from ladon.server.wsgi import LadonWSGIApplication
from os.path import abspath, dirname
from wsgiref.simple_server import make_server


application = LadonWSGIApplication(
    ['SOAPManager'],
    [dirname(abspath(__file__))],
    catalog_name='API',
    catalog_desc='API Description')

httpd = make_server('0.0.0.0', 8004, application)
print("Listening on port 8004...")

# Respond to requests until process is killed
httpd.serve_forever()

SOAPManager.py 中的最小测试用例:

from ladon.ladonizer import ladonize
from ladon.types.ladontype import LadonType
from ladon.compat import PORTABLE_STRING

@ladonize(PORTABLE_STRING, PORTABLE_STRING, rtype=PORTABLE_STRING)
def Authenticate(Username, Password):
    return "Test"

错误是从ladonize装饰器内部引发的。尝试建立服务定义时似乎正在发生这种情况。具体来说,在 ladon 中,返回而不是方法的decorator调用。我认为它没有通过行号检查。collection.add_service_methodNone

firstlineno = f.__code__.co_firstlineno
# get an ast-analyzed object of the source file
sinfo = self.source_info(src_fname)
...
for clsname,v in sinfo.items():
    if firstlineno>v[0] and firstlineno<=v[1]:

由于某种原因,检查失败,因此该方法默认为返回None

4

0 回答 0