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

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

项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def stmt(self, nodelist):
        return self.com_stmt(nodelist[0])
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def suite(self, nodelist):
        # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
        if len(nodelist) == 1:
            return self.com_stmt(nodelist[0])

        stmts = []
        for node in nodelist:
            if node[0] == symbol.stmt:
                self.com_append_stmt(stmts, node)
        return Stmt(stmts)

    # --------------------------------------------------------------
    #
    # EXPRESSION NODES  (invoked by com_node())
    #
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def com_node(self, node):
        # Note: compile.c has handling in com_node for del_stmt, pass_stmt,
        #       break_stmt, stmt, small_stmt, flow_stmt, simple_stmt,
        #       and compound_stmt.
        #       We'll just dispatch them.
        return self._dispatch[node[0]](node[1:])
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def get_docstring(self, node, n=None):
        if n is None:
            n = node[0]
            node = node[1:]
        if n == symbol.suite:
            if len(node) == 1:
                return self.get_docstring(node[0])
            for sub in node:
                if sub[0] == symbol.stmt:
                    return self.get_docstring(sub)
            return None
        if n == symbol.file_input:
            for sub in node:
                if sub[0] == symbol.stmt:
                    return self.get_docstring(sub)
            return None
        if n == symbol.atom:
            if node[0][0] == token.STRING:
                s = ''
                for t in node:
                    s = s + eval(t[1])
                return s
            return None
        if n == symbol.stmt or n == symbol.simple_stmt \
           or n == symbol.small_stmt:
            return self.get_docstring(node[0])
        if n in _doc_nodes and len(node) == 1:
            return self.get_docstring(node[0])
        return None
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def stmt(self, nodelist):
        return self.com_stmt(nodelist[0])
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def suite(self, nodelist):
        # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
        if len(nodelist) == 1:
            return self.com_stmt(nodelist[0])

        stmts = []
        for node in nodelist:
            if node[0] == symbol.stmt:
                self.com_append_stmt(stmts, node)
        return Stmt(stmts)

    # --------------------------------------------------------------
    #
    # EXPRESSION NODES  (invoked by com_node())
    #
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def com_node(self, node):
        # Note: compile.c has handling in com_node for del_stmt, pass_stmt,
        #       break_stmt, stmt, small_stmt, flow_stmt, simple_stmt,
        #       and compound_stmt.
        #       We'll just dispatch them.
        return self._dispatch[node[0]](node[1:])
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def get_docstring(self, node, n=None):
        if n is None:
            n = node[0]
            node = node[1:]
        if n == symbol.suite:
            if len(node) == 1:
                return self.get_docstring(node[0])
            for sub in node:
                if sub[0] == symbol.stmt:
                    return self.get_docstring(sub)
            return None
        if n == symbol.file_input:
            for sub in node:
                if sub[0] == symbol.stmt:
                    return self.get_docstring(sub)
            return None
        if n == symbol.atom:
            if node[0][0] == token.STRING:
                s = ''
                for t in node:
                    s = s + eval(t[1])
                return s
            return None
        if n == symbol.stmt or n == symbol.simple_stmt \
           or n == symbol.small_stmt:
            return self.get_docstring(node[0])
        if n in _doc_nodes and len(node) == 1:
            return self.get_docstring(node[0])
        return None
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def stmt(self, nodelist):
        return self.com_stmt(nodelist[0])
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def suite(self, nodelist):
        # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
        if len(nodelist) == 1:
            return self.com_stmt(nodelist[0])

        stmts = []
        for node in nodelist:
            if node[0] == symbol.stmt:
                self.com_append_stmt(stmts, node)
        return Stmt(stmts)

    # --------------------------------------------------------------
    #
    # EXPRESSION NODES  (invoked by com_node())
    #
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def com_node(self, node):
        # Note: compile.c has handling in com_node for del_stmt, pass_stmt,
        #       break_stmt, stmt, small_stmt, flow_stmt, simple_stmt,
        #       and compound_stmt.
        #       We'll just dispatch them.
        return self._dispatch[node[0]](node[1:])
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def get_docstring(self, node, n=None):
        if n is None:
            n = node[0]
            node = node[1:]
        if n == symbol.suite:
            if len(node) == 1:
                return self.get_docstring(node[0])
            for sub in node:
                if sub[0] == symbol.stmt:
                    return self.get_docstring(sub)
            return None
        if n == symbol.file_input:
            for sub in node:
                if sub[0] == symbol.stmt:
                    return self.get_docstring(sub)
            return None
        if n == symbol.atom:
            if node[0][0] == token.STRING:
                s = ''
                for t in node:
                    s = s + eval(t[1])
                return s
            return None
        if n == symbol.stmt or n == symbol.simple_stmt \
           or n == symbol.small_stmt:
            return self.get_docstring(node[0])
        if n in _doc_nodes and len(node) == 1:
            return self.get_docstring(node[0])
        return None
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def stmt(self, nodelist):
        return self.com_stmt(nodelist[0])
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def suite(self, nodelist):
        # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
        if len(nodelist) == 1:
            return self.com_stmt(nodelist[0])

        stmts = []
        for node in nodelist:
            if node[0] == symbol.stmt:
                self.com_append_stmt(stmts, node)
        return Stmt(stmts)

    # --------------------------------------------------------------
    #
    # EXPRESSION NODES  (invoked by com_node())
    #
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def com_node(self, node):
        # Note: compile.c has handling in com_node for del_stmt, pass_stmt,
        #       break_stmt, stmt, small_stmt, flow_stmt, simple_stmt,
        #       and compound_stmt.
        #       We'll just dispatch them.
        return self._dispatch[node[0]](node[1:])
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def get_docstring(self, node, n=None):
        if n is None:
            n = node[0]
            node = node[1:]
        if n == symbol.suite:
            if len(node) == 1:
                return self.get_docstring(node[0])
            for sub in node:
                if sub[0] == symbol.stmt:
                    return self.get_docstring(sub)
            return None
        if n == symbol.file_input:
            for sub in node:
                if sub[0] == symbol.stmt:
                    return self.get_docstring(sub)
            return None
        if n == symbol.atom:
            if node[0][0] == token.STRING:
                s = ''
                for t in node:
                    s = s + eval(t[1])
                return s
            return None
        if n == symbol.stmt or n == symbol.simple_stmt \
           or n == symbol.small_stmt:
            return self.get_docstring(node[0])
        if n in _doc_nodes and len(node) == 1:
            return self.get_docstring(node[0])
        return None
项目:gdata-python3    作者:dvska    | 项目源码 | 文件源码
def analyze_morf(self, morf):
        if morf in self.analysis_cache:
            return self.analysis_cache[morf]
        filename = self.morf_filename(morf)
        ext = os.path.splitext(filename)[1]
        if ext == '.pyc':
            if not os.path.exists(filename[0:-1]):
                raise self.error("No source for compiled code '%s'."
                                 % filename)
            filename = filename[0:-1]
        elif ext != '.py':
            raise self.error("File '%s' not Python source." % filename)
        source = open(filename, 'r')
        import parser
        tree = parser.suite(source.read()).totuple(1)
        source.close()
        statements = {}
        self.find_statements(tree, statements)
        lines = list(statements.keys())
        lines.sort()
        result = filename, lines
        self.analysis_cache[morf] = result
        return result

    # find_statements(tree, dict).  Find each statement in the parse
    # tree and record the line on which the statement starts in the
    # dictionary (by assigning it to 1).
    #
    # It works by walking the whole tree depth-first.  Every time it
    # comes across a statement (symbol.stmt -- this includes compound
    # statements like 'if' and 'while') it calls find_statement, which
    # descends the tree below the statement to find the first terminal
    # token in that statement and record the lines on which that token
    # was found.
    #
    # This algorithm may find some lines several times (because of the
    # grammar production statement -> compound statement -> statement),
    # but that doesn't matter because we record lines as the keys of the
    # dictionary.
    #
    # See also [GDR 2001-12-04b, 3.2].
项目:gdata-python3    作者:dvska    | 项目源码 | 文件源码
def find_statements(self, tree, dict):
        import symbol, token
        if token.ISNONTERMINAL(tree[0]):
            for t in tree[1:]:
                self.find_statements(t, dict)
            if tree[0] == symbol.stmt:
                self.find_statement(tree[1], dict)
        elif (tree[0] == token.NAME
              and tree[1] in ['elif', 'except', 'finally']):
            dict[tree[2]] = 1
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def stmt(self, nodelist):
        return self.com_stmt(nodelist[0])
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def suite(self, nodelist):
        # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
        if len(nodelist) == 1:
            return self.com_stmt(nodelist[0])

        stmts = []
        for node in nodelist:
            if node[0] == symbol.stmt:
                self.com_append_stmt(stmts, node)
        return Stmt(stmts)

    # --------------------------------------------------------------
    #
    # EXPRESSION NODES  (invoked by com_node())
    #
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def com_node(self, node):
        # Note: compile.c has handling in com_node for del_stmt, pass_stmt,
        #       break_stmt, stmt, small_stmt, flow_stmt, simple_stmt,
        #       and compound_stmt.
        #       We'll just dispatch them.
        return self._dispatch[node[0]](node[1:])
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def get_docstring(self, node, n=None):
        if n is None:
            n = node[0]
            node = node[1:]
        if n == symbol.suite:
            if len(node) == 1:
                return self.get_docstring(node[0])
            for sub in node:
                if sub[0] == symbol.stmt:
                    return self.get_docstring(sub)
            return None
        if n == symbol.file_input:
            for sub in node:
                if sub[0] == symbol.stmt:
                    return self.get_docstring(sub)
            return None
        if n == symbol.atom:
            if node[0][0] == token.STRING:
                s = ''
                for t in node:
                    s = s + eval(t[1])
                return s
            return None
        if n == symbol.stmt or n == symbol.simple_stmt \
           or n == symbol.small_stmt:
            return self.get_docstring(node[0])
        if n in _doc_nodes and len(node) == 1:
            return self.get_docstring(node[0])
        return None