當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。