Python symbol 模块,decorators() 实例源码

我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用symbol.decorators()

项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def decorators(self, nodelist):
        # decorators: decorator ([NEWLINE] decorator)* NEWLINE
        items = []
        for dec_nodelist in nodelist:
            assert dec_nodelist[0] == symbol.decorator
            items.append(self.decorator(dec_nodelist[1:]))
        return Decorators(items)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def decorated(self, nodelist):
        assert nodelist[0][0] == symbol.decorators
        if nodelist[1][0] == symbol.funcdef:
            n = [nodelist[0]] + list(nodelist[1][1:])
            return self.funcdef(n)
        elif nodelist[1][0] == symbol.classdef:
            decorators = self.decorators(nodelist[0][1:])
            cls = self.classdef(nodelist[1][1:])
            cls.decorators = decorators
            return cls
        raise WalkerError()
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def funcdef(self, nodelist):
        #                    -6   -5    -4         -3  -2    -1
        # funcdef: [decorators] 'def' NAME parameters ':' suite
        # parameters: '(' [varargslist] ')'

        if len(nodelist) == 6:
            assert nodelist[0][0] == symbol.decorators
            decorators = self.decorators(nodelist[0][1:])
        else:
            assert len(nodelist) == 5
            decorators = None

        lineno = nodelist[-4][2]
        name = nodelist[-4][1]
        args = nodelist[-3][2]

        if args[0] == symbol.varargslist:
            names, defaults, flags = self.com_arglist(args[1:])
        else:
            names = defaults = ()
            flags = 0
        doc = self.get_docstring(nodelist[-1])

        # code for function
        code = self.com_node(nodelist[-1])

        if doc is not None:
            assert isinstance(code, Stmt)
            assert isinstance(code.nodes[0], Discard)
            del code.nodes[0]
        return Function(decorators, name, names, defaults, flags, doc, code,
                     lineno=lineno)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def decorators(self, nodelist):
        # decorators: decorator ([NEWLINE] decorator)* NEWLINE
        items = []
        for dec_nodelist in nodelist:
            assert dec_nodelist[0] == symbol.decorator
            items.append(self.decorator(dec_nodelist[1:]))
        return Decorators(items)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def decorated(self, nodelist):
        assert nodelist[0][0] == symbol.decorators
        if nodelist[1][0] == symbol.funcdef:
            n = [nodelist[0]] + list(nodelist[1][1:])
            return self.funcdef(n)
        elif nodelist[1][0] == symbol.classdef:
            decorators = self.decorators(nodelist[0][1:])
            cls = self.classdef(nodelist[1][1:])
            cls.decorators = decorators
            return cls
        raise WalkerError()
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def funcdef(self, nodelist):
        #                    -6   -5    -4         -3  -2    -1
        # funcdef: [decorators] 'def' NAME parameters ':' suite
        # parameters: '(' [varargslist] ')'

        if len(nodelist) == 6:
            assert nodelist[0][0] == symbol.decorators
            decorators = self.decorators(nodelist[0][1:])
        else:
            assert len(nodelist) == 5
            decorators = None

        lineno = nodelist[-4][2]
        name = nodelist[-4][1]
        args = nodelist[-3][2]

        if args[0] == symbol.varargslist:
            names, defaults, flags = self.com_arglist(args[1:])
        else:
            names = defaults = ()
            flags = 0
        doc = self.get_docstring(nodelist[-1])

        # code for function
        code = self.com_node(nodelist[-1])

        if doc is not None:
            assert isinstance(code, Stmt)
            assert isinstance(code.nodes[0], Discard)
            del code.nodes[0]
        return Function(decorators, name, names, defaults, flags, doc, code,
                     lineno=lineno)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def decorators(self, nodelist):
        # decorators: decorator ([NEWLINE] decorator)* NEWLINE
        items = []
        for dec_nodelist in nodelist:
            assert dec_nodelist[0] == symbol.decorator
            items.append(self.decorator(dec_nodelist[1:]))
        return Decorators(items)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def decorated(self, nodelist):
        assert nodelist[0][0] == symbol.decorators
        if nodelist[1][0] == symbol.funcdef:
            n = [nodelist[0]] + list(nodelist[1][1:])
            return self.funcdef(n)
        elif nodelist[1][0] == symbol.classdef:
            decorators = self.decorators(nodelist[0][1:])
            cls = self.classdef(nodelist[1][1:])
            cls.decorators = decorators
            return cls
        raise WalkerError()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def funcdef(self, nodelist):
        #                    -6   -5    -4         -3  -2    -1
        # funcdef: [decorators] 'def' NAME parameters ':' suite
        # parameters: '(' [varargslist] ')'

        if len(nodelist) == 6:
            assert nodelist[0][0] == symbol.decorators
            decorators = self.decorators(nodelist[0][1:])
        else:
            assert len(nodelist) == 5
            decorators = None

        lineno = nodelist[-4][2]
        name = nodelist[-4][1]
        args = nodelist[-3][2]

        if args[0] == symbol.varargslist:
            names, defaults, flags = self.com_arglist(args[1:])
        else:
            names = defaults = ()
            flags = 0
        doc = self.get_docstring(nodelist[-1])

        # code for function
        code = self.com_node(nodelist[-1])

        if doc is not None:
            assert isinstance(code, Stmt)
            assert isinstance(code.nodes[0], Discard)
            del code.nodes[0]
        return Function(decorators, name, names, defaults, flags, doc, code,
                     lineno=lineno)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def decorators(self, nodelist):
        # decorators: decorator ([NEWLINE] decorator)* NEWLINE
        items = []
        for dec_nodelist in nodelist:
            assert dec_nodelist[0] == symbol.decorator
            items.append(self.decorator(dec_nodelist[1:]))
        return Decorators(items)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def decorated(self, nodelist):
        assert nodelist[0][0] == symbol.decorators
        if nodelist[1][0] == symbol.funcdef:
            n = [nodelist[0]] + list(nodelist[1][1:])
            return self.funcdef(n)
        elif nodelist[1][0] == symbol.classdef:
            decorators = self.decorators(nodelist[0][1:])
            cls = self.classdef(nodelist[1][1:])
            cls.decorators = decorators
            return cls
        raise WalkerError()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def funcdef(self, nodelist):
        #                    -6   -5    -4         -3  -2    -1
        # funcdef: [decorators] 'def' NAME parameters ':' suite
        # parameters: '(' [varargslist] ')'

        if len(nodelist) == 6:
            assert nodelist[0][0] == symbol.decorators
            decorators = self.decorators(nodelist[0][1:])
        else:
            assert len(nodelist) == 5
            decorators = None

        lineno = nodelist[-4][2]
        name = nodelist[-4][1]
        args = nodelist[-3][2]

        if args[0] == symbol.varargslist:
            names, defaults, flags = self.com_arglist(args[1:])
        else:
            names = defaults = ()
            flags = 0
        doc = self.get_docstring(nodelist[-1])

        # code for function
        code = self.com_node(nodelist[-1])

        if doc is not None:
            assert isinstance(code, Stmt)
            assert isinstance(code.nodes[0], Discard)
            del code.nodes[0]
        return Function(decorators, name, names, defaults, flags, doc, code,
                     lineno=lineno)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def decorators(self, nodelist):
        # decorators: decorator ([NEWLINE] decorator)* NEWLINE
        items = []
        for dec_nodelist in nodelist:
            assert dec_nodelist[0] == symbol.decorator
            items.append(self.decorator(dec_nodelist[1:]))
        return Decorators(items)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def decorated(self, nodelist):
        assert nodelist[0][0] == symbol.decorators
        if nodelist[1][0] == symbol.funcdef:
            n = [nodelist[0]] + list(nodelist[1][1:])
            return self.funcdef(n)
        elif nodelist[1][0] == symbol.classdef:
            decorators = self.decorators(nodelist[0][1:])
            cls = self.classdef(nodelist[1][1:])
            cls.decorators = decorators
            return cls
        raise WalkerError()
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def funcdef(self, nodelist):
        #                    -6   -5    -4         -3  -2    -1
        # funcdef: [decorators] 'def' NAME parameters ':' suite
        # parameters: '(' [varargslist] ')'

        if len(nodelist) == 6:
            assert nodelist[0][0] == symbol.decorators
            decorators = self.decorators(nodelist[0][1:])
        else:
            assert len(nodelist) == 5
            decorators = None

        lineno = nodelist[-4][2]
        name = nodelist[-4][1]
        args = nodelist[-3][2]

        if args[0] == symbol.varargslist:
            names, defaults, flags = self.com_arglist(args[1:])
        else:
            names = defaults = ()
            flags = 0
        doc = self.get_docstring(nodelist[-1])

        # code for function
        code = self.com_node(nodelist[-1])

        if doc is not None:
            assert isinstance(code, Stmt)
            assert isinstance(code.nodes[0], Discard)
            del code.nodes[0]
        return Function(decorators, name, names, defaults, flags, doc, code,
                     lineno=lineno)