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


Python os.py方法代码示例

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


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

示例1: default_mapper

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def default_mapper(entry, name):
    '''
    Stringify an entry that doesn't have an explicit mapping.

    Args:
        entry:  entry
        name: field name

    Returns: str

    '''
    try:
        val = eval("entry." + name)
    except:
        val = None
    if sys.version_info.major >= 3 and isinstance(val, bytes):
        # This is a dirty hack for py 2/3 compatibility. csig is a bytes object
        # in Python3 while Python2 bytes are str. Hence, we decode the csig to a
        # Python3 string
        val = val.decode()
    return str(val) 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:23,代码来源:sconsign.py

示例2: RegisterShellInfo

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def RegisterShellInfo(searchPaths):
    """Registers key parts of the Python installation with the Windows Shell.

       Assumes a valid, minimal Python installation exists
       (ie, SetupCore() has been previously successfully run)
    """
    import regutil, win32con
    suffix = IsDebug()
    # Set up a pointer to the .exe's
    exePath = FindRegisterPythonExe("Python%s.exe" % suffix, searchPaths)
    regutil.SetRegistryDefaultValue(".py", "Python.File", win32con.HKEY_CLASSES_ROOT)
    regutil.RegisterShellCommand("Open", QuotedFileName(exePath)+" \"%1\" %*", "&Run")
    regutil.SetRegistryDefaultValue("Python.File\\DefaultIcon", "%s,0" % exePath, win32con.HKEY_CLASSES_ROOT)

    FindRegisterHelpFile("Python.hlp", searchPaths, "Main Python Documentation")
    FindRegisterHelpFile("ActivePython.chm", searchPaths, "Main Python Documentation")

    # We consider the win32 core, as it contains all the win32 api type
    # stuff we need.
#       FindRegisterApp("win32", ["win32con.pyc", "win32api%s.pyd" % suffix], searchPaths) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:regsetup.py

示例3: get_site_packages

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def get_site_packages():
    """
    This is a hack to work around site.getsitepackages() not working in
    virtualenv. See https://github.com/pypa/virtualenv/issues/355
    """
    # Another hack...
    # Relies on the fact that os.py is in the dir above site_packages
    os_location = os.path.dirname(os.__file__)
    site_packages = []
    # Consider Debain/Ubuntu custom
    for site in ["site-packages", "dist-packages"]:
        site_path = os.path.join(os_location, site)
        if os.path.isdir(site_path):
            site_packages.append(site_path)
    try:
        site_packages += _site.getsitepackages()
    except AttributeError, ex:
        print("WARNING: Error trying to call site.getsitepackages(). Exception: %r" % ex)
        print("         Do you have sufficient permissions?") 
        print("         Otherwise this could probably be virtualenv issue#355") 
开发者ID:tintinweb,项目名称:scapy-ssl_tls,代码行数:22,代码来源:setup.py

示例4: _post_install

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def _post_install(dir_):
    """ Patches scapy config.py to add autoloading of the ssl_tls layer
    Takes a backup in the form of a config.py.bak file
    """

    def patch_ll(ll_match):
        match_start = ll_match.start()
        prefix = ll_match.start(1) - match_start
        suffix = ll_match.end(1) - match_start
        orig_code = ll_match.group(0)
        return orig_code[:prefix] + ', "ssl_tls",' + orig_code[suffix:]
    ll_regex = re.compile(r"load_layers = \[[^\]]*(,)[^,\]]*\]", re.DOTALL)

    scapy_locations = get_scapy_locations(get_site_packages())
    for scapy_location in scapy_locations:
        scapy_config = os.path.join(scapy_location, "config.py")
        if os.path.isfile(scapy_config):
            shutil.copy(scapy_config, scapy_config + ".bak")
            with open(scapy_config, "r+") as f:
                config_source = f.read()
                f.truncate(0)
                f.seek(0)
                f.write(ll_regex.sub(patch_ll, config_source)) 
开发者ID:tintinweb,项目名称:scapy-ssl_tls,代码行数:25,代码来源:setup.py

示例5: test_append_data

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def test_append_data(self):
        self.make_b_or_c_py()

        out = self.run_command("coverage run b_or_c.py b")
        self.assertEqual(out, 'done\n')
        self.assert_exists(".coverage")
        self.assertEqual(self.number_of_data_files(), 1)

        out = self.run_command("coverage run --append b_or_c.py c")
        self.assertEqual(out, 'done\n')
        self.assert_exists(".coverage")
        self.assertEqual(self.number_of_data_files(), 1)

        # Read the coverage file and see that b_or_c.py has all 7 lines
        # executed.
        data = coverage.CoverageData()
        data.read_file(".coverage")
        self.assertEqual(data.line_counts()['b_or_c.py'], 7) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:20,代码来源:test_process.py

示例6: test_append_data_with_different_file

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def test_append_data_with_different_file(self):
        self.make_b_or_c_py()

        self.make_file(".coveragerc", """\
            [run]
            data_file = .mycovdata
            """)

        out = self.run_command("coverage run b_or_c.py b")
        self.assertEqual(out, 'done\n')
        self.assert_doesnt_exist(".coverage")
        self.assert_exists(".mycovdata")

        out = self.run_command("coverage run --append b_or_c.py c")
        self.assertEqual(out, 'done\n')
        self.assert_doesnt_exist(".coverage")
        self.assert_exists(".mycovdata")

        # Read the coverage file and see that b_or_c.py has all 7 lines
        # executed.
        data = coverage.CoverageData()
        data.read_file(".mycovdata")
        self.assertEqual(data.line_counts()['b_or_c.py'], 7) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:25,代码来源:test_process.py

示例7: test_missing_source_file

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def test_missing_source_file(self):
        # Check what happens if the source is missing when reporting happens.
        self.make_file("fleeting.py", """\
            s = 'goodbye, cruel world!'
            """)

        self.run_command("coverage run fleeting.py")
        os.remove("fleeting.py")
        out = self.run_command("coverage html -d htmlcov")
        self.assertRegex(out, "No source for code: '.*fleeting.py'")
        self.assertNotIn("Traceback", out)

        # It happens that the code paths are different for *.py and other
        # files, so try again with no extension.
        self.make_file("fleeting", """\
            s = 'goodbye, cruel world!'
            """)

        self.run_command("coverage run fleeting")
        os.remove("fleeting")
        status, out = self.run_command_status("coverage html -d htmlcov")
        self.assertRegex(out, "No source for code: '.*fleeting'")
        self.assertNotIn("Traceback", out)
        self.assertEqual(status, 1) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:26,代码来源:test_process.py

示例8: test_code_throws

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def test_code_throws(self):
        self.make_file("throw.py", """\
            def f1():
                raise Exception("hey!")

            def f2():
                f1()

            f2()
            """)

        # The important thing is for "coverage run" and "python" to report the
        # same traceback.
        status, out = self.run_command_status("coverage run throw.py")
        out2 = self.run_command("python throw.py")
        if env.PYPY:
            # Pypy has an extra frame in the traceback for some reason
            out2 = re_lines(out2, "toplevel", match=False)
        self.assertMultiLineEqual(out, out2)

        # But also make sure that the output is what we expect.
        self.assertIn('File "throw.py", line 5, in f2', out)
        self.assertIn('raise Exception("hey!")', out)
        self.assertNotIn('coverage', out)
        self.assertEqual(status, 1) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:27,代码来源:test_process.py

示例9: test_code_exits

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def test_code_exits(self):
        self.make_file("exit.py", """\
            import sys
            def f1():
                print("about to exit..")
                sys.exit(17)

            def f2():
                f1()

            f2()
            """)

        # The important thing is for "coverage run" and "python" to have the
        # same output.  No traceback.
        status, out = self.run_command_status("coverage run exit.py")
        status2, out2 = self.run_command_status("python exit.py")
        self.assertMultiLineEqual(out, out2)
        self.assertMultiLineEqual(out, "about to exit..\n")
        self.assertEqual(status, status2)
        self.assertEqual(status, 17) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:23,代码来源:test_process.py

示例10: test_warnings_during_reporting

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def test_warnings_during_reporting(self):
        # While fixing issue #224, the warnings were being printed far too
        # often.  Make sure they're not any more.
        self.make_file("hello.py", """\
            import sys, os, the_other
            print("Hello")
            """)
        self.make_file("the_other.py", """\
            print("What?")
            """)
        self.make_file(".coveragerc", """\
            [run]
            source =
                .
                xyzzy
            """)

        self.run_command("coverage run hello.py")
        out = self.run_command("coverage html")
        self.assertEqual(out.count("Module xyzzy was never imported."), 0) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:22,代码来源:test_process.py

示例11: test_warnings_trace_function_changed_with_threads

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def test_warnings_trace_function_changed_with_threads(self):
        # https://bitbucket.org/ned/coveragepy/issue/164
        self.make_file("bug164.py", """\
            import threading
            import time

            class MyThread (threading.Thread):
                def run(self):
                    print("Hello")

            thr = MyThread()
            thr.start()
            thr.join()
            """)
        out = self.run_command("coverage run --timid bug164.py")

        self.assertIn("Hello\n", out)
        self.assertNotIn("warning", out) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:20,代码来源:test_process.py

示例12: test_warn_preimported

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def test_warn_preimported(self):
        self.make_file("hello.py", """\
            import goodbye
            import coverage
            cov = coverage.Coverage(include=["good*"], check_preimported=True)
            cov.start()
            print(goodbye.f())
            cov.stop()
            """)
        self.make_file("goodbye.py", """\
            def f():
                return "Goodbye!"
            """)
        goodbye_path = os.path.abspath("goodbye.py")

        out = self.run_command("python hello.py")
        self.assertIn("Goodbye!", out)

        msg = (
            "Coverage.py warning: "
            "Already imported a file that will be measured: {0} "
            "(already-imported)").format(goodbye_path)
        self.assertIn(msg, out) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:25,代码来源:test_process.py

示例13: test_lang_c

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def test_lang_c(self):
        if env.JYTHON:
            # Jython as of 2.7.1rc3 won't compile a filename that isn't utf8.
            self.skipTest("Jython can't handle this test")
        # LANG=C forces getfilesystemencoding on Linux to 'ascii', which causes
        # failures with non-ascii file names. We don't want to make a real file
        # with strange characters, though, because that gets the test runners
        # tangled up.  This will isolate the concerns to the coverage.py code.
        # https://bitbucket.org/ned/coveragepy/issues/533/exception-on-unencodable-file-name
        self.make_file("weird_file.py", r"""
            globs = {}
            code = "a = 1\nb = 2\n"
            exec(compile(code, "wut\xe9\xea\xeb\xec\x01\x02.py", 'exec'), globs)
            print(globs['a'])
            print(globs['b'])
            """)
        self.set_environ("LANG", "C")
        out = self.run_command("coverage run weird_file.py")
        self.assertEqual(out, "1\n2\n") 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:21,代码来源:test_process.py

示例14: test_deprecation_warnings

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def test_deprecation_warnings(self):
        # Test that coverage doesn't trigger deprecation warnings.
        # https://bitbucket.org/ned/coveragepy/issue/305/pendingdeprecationwarning-the-imp-module
        self.make_file("allok.py", """\
            import warnings
            warnings.simplefilter('default')
            import coverage
            print("No warnings!")
            """)

        # Some of our testing infrastructure can issue warnings.
        # Turn it all off for the sub-process.
        self.del_environ("COVERAGE_TESTING")

        out = self.run_command("python allok.py")
        self.assertEqual(out, "No warnings!\n") 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:18,代码来源:test_process.py

示例15: assert_tryexecfile_output

# 需要导入模块: import os [as 别名]
# 或者: from os import py [as 别名]
def assert_tryexecfile_output(self, out1, out2):
        """Assert that the output we got is a successful run of try_execfile.py.

        `out1` and `out2` must be the same, modulo a few slight known platform
        differences.

        """
        # First, is this even credible try_execfile.py output?
        self.assertIn('"DATA": "xyzzy"', out1)

        if env.JYTHON:                  # pragma: only jython
            # Argv0 is different for Jython, remove that from the comparison.
            out1 = re_lines(out1, r'\s+"argv0":', match=False)
            out2 = re_lines(out2, r'\s+"argv0":', match=False)

        self.assertMultiLineEqual(out1, out2) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:18,代码来源:test_process.py


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