当前位置: 首页>>代码示例>>Python>>正文


Python compat.func_code方法代码示例

本文整理汇总了Python中setuptools.compat.func_code方法的典型用法代码示例。如果您正苦于以下问题:Python compat.func_code方法的具体用法?Python compat.func_code怎么用?Python compat.func_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在setuptools.compat的用法示例。


在下文中一共展示了compat.func_code方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testExtractConst

# 需要导入模块: from setuptools import compat [as 别名]
# 或者: from setuptools.compat import func_code [as 别名]
def testExtractConst(self):
        if not hasattr(dep, 'extract_constant'):
            # skip on non-bytecode platforms
            return

        def f1():
            global x, y, z
            x = "test"
            y = z

        fc = func_code(f1)
        # unrecognized name
        self.assertEqual(dep.extract_constant(fc,'q', -1), None)

        # constant assigned
        self.assertEqual(dep.extract_constant(fc,'x', -1), "test")

        # expression assigned
        self.assertEqual(dep.extract_constant(fc,'y', -1), -1)

        # recognized name, not assigned
        self.assertEqual(dep.extract_constant(fc,'z', -1), None) 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:24,代码来源:__init__.py

示例2: testExtractConst

# 需要导入模块: from setuptools import compat [as 别名]
# 或者: from setuptools.compat import func_code [as 别名]
def testExtractConst(self):
        if not hasattr(dep, 'extract_constant'):
            # skip on non-bytecode platforms
            return

        def f1():
            global x, y, z
            x = "test"
            y = z

        fc = func_code(f1)

        # unrecognized name
        assert dep.extract_constant(fc,'q', -1) is None

        # constant assigned
        dep.extract_constant(fc,'x', -1) == "test"

        # expression assigned
        dep.extract_constant(fc,'y', -1) == -1

        # recognized name, not assigned
        dep.extract_constant(fc,'z', -1) is None 
开发者ID:ayush1997,项目名称:Sudoku-Solver,代码行数:25,代码来源:__init__.py

示例3: __patched_linecache_getlines

# 需要导入模块: from setuptools import compat [as 别名]
# 或者: from setuptools.compat import func_code [as 别名]
def __patched_linecache_getlines(self, filename, module_globals=None):
        m = self.__LINECACHE_FILENAME_RE.match(filename)
        if m and m.group('name') == self.test.name:
            example = self.test.examples[int(m.group('examplenum'))]
            return example.source.splitlines(True)
        elif func_code(self.save_linecache_getlines).co_argcount > 1:
            return self.save_linecache_getlines(filename, module_globals)
        else:
            return self.save_linecache_getlines(filename) 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:11,代码来源:doctest.py

示例4: _find_lineno

# 需要导入模块: from setuptools import compat [as 别名]
# 或者: from setuptools.compat import func_code [as 别名]
def _find_lineno(self, obj, source_lines):
        """
        Return a line number of the given object's docstring.  Note:
        this method assumes that the object has a docstring.
        """
        lineno = None

        # Find the line number for modules.
        if inspect.ismodule(obj):
            lineno = 0

        # Find the line number for classes.
        # Note: this could be fooled if a class is defined multiple
        # times in a single file.
        if inspect.isclass(obj):
            if source_lines is None:
                return None
            pat = re.compile(r'^\s*class\s*%s\b' %
                             getattr(obj, '__name__', '-'))
            for i, line in enumerate(source_lines):
                if pat.match(line):
                    lineno = i
                    break

        # Find the line number for functions & methods.
        if inspect.ismethod(obj): obj = im_func(obj)
        if inspect.isfunction(obj): obj = func_code(obj)
        if inspect.istraceback(obj): obj = obj.tb_frame
        if inspect.isframe(obj): obj = obj.f_code
        if inspect.iscode(obj):
            lineno = getattr(obj, 'co_firstlineno', None)-1

        # Find the line number where the docstring starts.  Assume
        # that it's the first line that begins with a quote mark.
        # Note: this could be fooled by a multiline function
        # signature, where a continuation line begins with a quote
        # mark.
        if lineno is not None:
            if source_lines is None:
                return lineno+1
            pat = re.compile('(^|.*:)\s*\w*("|\')')
            for lineno in range(lineno, len(source_lines)):
                if pat.match(source_lines[lineno]):
                    return lineno

        # We couldn't find the line number.
        return None

######################################################################
## 5. DocTest Runner
###################################################################### 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:53,代码来源:doctest.py


注:本文中的setuptools.compat.func_code方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。