这个python 装饰器代码是什么意思?
PHP中文网
PHP中文网 2017-04-17 17:53:45
0
1
356

在看openstack nova 的代码的时候,看到了这个问题,不知道这个函数代码是什么意思?这个是类作为一个函数的装饰器,是怎么装饰的?

class wsgify(object):

RequestClass = Request def __init__(self, func=None, RequestClass=None, args=(), kwargs=None, middleware_wraps=None): self.func = func if (RequestClass is not None and RequestClass is not self.RequestClass): self.RequestClass = RequestClass self.args = tuple(args) if kwargs is None: kwargs = {} self.kwargs = kwargs self.middleware_wraps = middleware_wraps **@webob.dec.wsgify(RequestClass=wsgi.Request) def __call__(self, req):** if os.path.normpath(req.path_info) == "/": resp = base.ec2_md_print(base.VERSIONS + ["latest"]) req.response.body = resp req.response.content_type = base.MIME_TYPE_TEXT_PLAIN return req.response

请问下这个装饰器是什么意思啊?

PHP中文网
PHP中文网

认证0级讲师

reply all (1)
大家讲道理

The official documentation is here http://docs.webob.org/en/stable/api/dec.html

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!