當前位置: 首頁>>代碼示例>>Python>>正文


Python path.normcase方法代碼示例

本文整理匯總了Python中os.path.normcase方法的典型用法代碼示例。如果您正苦於以下問題:Python path.normcase方法的具體用法?Python path.normcase怎麽用?Python path.normcase使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os.path的用法示例。


在下文中一共展示了path.normcase方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_set_env_path_with_node_path_success

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def test_set_env_path_with_node_path_success(self):
        tmpdir, bin_dir, mgr_bin = self.fake_mgr_bin()
        other_dir = mkdtemp(self)
        # default constructor
        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr', working_dir=other_dir)
        # the which_with_node_modules will not work immeidately in this
        # case
        self.assertIsNone(driver.which_with_node_modules())
        self.assertIsNone(driver.env_path)
        # using NODE_PATH set to a valid node_modules
        driver.node_path = join(tmpdir, 'node_modules')
        # this should work now.
        self.assertEqual(
            normcase(driver.which_with_node_modules()), normcase(mgr_bin))
        self.assertTrue(driver._set_env_path_with_node_modules())
        self.assertEqual(driver.env_path, bin_dir)
        # should still result in the same thing.
        self.assertTrue(driver._set_env_path_with_node_modules())
        self.assertEqual(driver.env_path, bin_dir) 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:22,代碼來源:test_cli.py

示例2: test_missing_distribution

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def test_missing_distribution(self):
        d_egg_root = join(mkdtemp(self), 'dummyns')
        make_dummy_dist(self, ((
            'namespace_packages.txt',
            'not_ns\n',
        ), (
            'entry_points.txt',
            '[dummyns]\n'
            'dummyns = dummyns:attr\n',
        ),), 'dummyns', '2.0', working_dir=d_egg_root)
        working_set = pkg_resources.WorkingSet([
            d_egg_root,
            self.ds_egg_root,
        ])
        dummyns_ep = next(working_set.iter_entry_points('dummyns'))
        with pretty_logging(stream=StringIO()) as fd:
            p = indexer.resource_filename_mod_entry_point(
                'dummyns', dummyns_ep)
        # not stubbed working_set, so this is derived using fallback
        # value from the sys.modules['dummyns'] location
        self.assertEqual(normcase(p), normcase(self.dummyns_path))
        self.assertIn("distribution 'dummyns 2.0' not found", fd.getvalue()) 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:24,代碼來源:test_indexer.py

示例3: is_subdir

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def is_subdir(path, directory):
    """
    Returns true if *path* in a subdirectory of *directory*.
    Both paths must be absolute.

    :arg path: An absolute path.
    :type path: string or bytes
    """
    from os.path import normpath, normcase, sep
    path = normpath(normcase(path))
    directory = normpath(normcase(directory))
    if len(path) > len(directory):
        sep = sep.encode('ascii') if isinstance(directory, bytes) else sep
        if path.startswith(directory.rstrip(sep) + sep):
            return True
    return False 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:path.py

示例4: should_debug_code

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def should_debug_code(code):
    if not code or not code.co_filename:
        return False

    filename = path.normcase(code.co_filename)
    if not DEBUG_STDLIB:
        for prefix in PREFIXES:
            if prefix != '' and filename.startswith(prefix):
                return False

    for dont_debug_file in DONT_DEBUG:
        if is_same_py_file(filename, dont_debug_file):
            return False

    if is_file_in_zip(filename):
        # file in inside an egg or zip, so we can't debug it
        return False

    return True 
開發者ID:ms-iot,項目名稱:iot-utilities,代碼行數:21,代碼來源:visualstudio_py_debugger.py

示例5: should_block_on_frame

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def should_block_on_frame(self, frame):
        if not should_debug_code(frame.f_code):
            return False
        # It is still possible that we're somewhere in standard library code, but that code was invoked by our
        # internal debugger machinery (e.g. socket.sendall or text encoding while tee'ing print output to VS).
        # We don't want to block on any of that, either, so walk the stack and see if we hit debugger frames
        # at some point below the non-debugger ones.
        while frame is not None:
            # There is usually going to be a debugger frame at the very bottom of the stack - the one that
            # invoked user code on this thread when starting debugging. If we reached that, then everything
            # above is user code, so we know that we do want to block here.
            if frame.f_code in DEBUG_ENTRYPOINTS:
                break
            # Otherwise, check if it's some other debugger code.
            filename = path.normcase(frame.f_code.co_filename)
            is_debugger_frame = False
            for debugger_file in DONT_DEBUG:
                if is_same_py_file(filename, debugger_file):
                    # If it is, then the frames above it on the stack that we have just walked through
                    # were for debugger internal purposes, and we do not want to block here.
                    return False
            frame = frame.f_back
        return True 
開發者ID:ms-iot,項目名稱:iot-utilities,代碼行數:25,代碼來源:visualstudio_py_debugger.py

示例6: print_exception

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def print_exception(exc_type, exc_value, exc_tb):
    # remove debugger frames from the top and bottom of the traceback
    tb = traceback.extract_tb(exc_tb)
    for i in [0, -1]:
        while tb:
            frame_file = path.normcase(tb[i][0])
            if not any(is_same_py_file(frame_file, f) for f in DONT_DEBUG):
                break
            del tb[i]

    # print the traceback
    if tb:
        print('Traceback (most recent call last):')
        for out in traceback.format_list(tb):
            sys.stderr.write(out)
    
    # print the exception
    for out in traceback.format_exception_only(exc_type, exc_value):
        sys.stdout.write(out) 
開發者ID:ms-iot,項目名稱:iot-utilities,代碼行數:21,代碼來源:visualstudio_py_debugger.py

示例7: breakpoint_path_match

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def breakpoint_path_match(vs_path, local_path):
    vs_path_norm = path.normcase(vs_path)
    local_path_norm = path.normcase(local_path)
    if local_path_to_vs_path.get(local_path_norm) == vs_path_norm:
        return True
    
    # Walk the local filesystem from local_path up, matching agains win_path component by component,
    # and stop when we no longer see an __init__.py. This should give a reasonably close approximation
    # of matching the package name.
    while True:
        local_path, local_name = path.split(local_path)
        vs_path, vs_name = ntpath.split(vs_path)
        # Match the last component in the path. If one or both components are unavailable, then
        # we have reached the root on the corresponding path without successfully matching.
        if not local_name or not vs_name or path.normcase(local_name) != path.normcase(vs_name):
            return False
        # If we have an __init__.py, this module was inside the package, and we still need to match
        # thatpackage, so walk up one level and keep matching. Otherwise, we've walked as far as we
        # needed to, and matched all names on our way, so this is a match.
        if not path.exists(path.join(local_path, '__init__.py')):
            break
    
    local_path_to_vs_path[local_path_norm] = vs_path_norm
    return True 
開發者ID:ms-iot,項目名稱:iot-utilities,代碼行數:26,代碼來源:visualstudio_py_debugger.py

示例8: safe_join

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def safe_join(base, *paths):
    """
    Joins one or more path components to the base path component intelligently.
    Returns a normalized, absolute version of the final path.

    The final path must be located inside of the base path component (otherwise
    a ValueError is raised).
    """
    base = force_text(base)
    paths = [force_text(p) for p in paths]
    final_path = abspathu(join(base, *paths))
    base_path = abspathu(base)
    # Ensure final_path starts with base_path (using normcase to ensure we
    # don't false-negative on case insensitive operating systems like Windows),
    # further, one of the following conditions must be true:
    #  a) The next character is the path separator (to prevent conditions like
    #     safe_join("/dir", "/../d"))
    #  b) The final path must be the same as the base path.
    #  c) The base path must be the most root path (meaning either "/" or "C:\\")
    if (not normcase(final_path).startswith(normcase(base_path + sep)) and
        normcase(final_path) != normcase(base_path) and
        dirname(normcase(base_path)) != normcase(base_path)):
        raise ValueError('The joined path (%s) is located outside of the base '
                         'path component (%s)' % (final_path, base_path))
    return final_path 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:27,代碼來源:_os.py

示例9: safe_join

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def safe_join(base, *paths):
    """
    Joins one or more path components to the base path component intelligently.
    Returns a normalized, absolute version of the final path.

    The final path must be located inside of the base path component (otherwise
    a ValueError is raised).
    """
    # We need to use normcase to ensure we don't false-negative on case
    # insensitive operating systems (like Windows).
    base = force_unicode(base)
    paths = [force_unicode(p) for p in paths]
    final_path = normcase(abspathu(join(base, *paths)))
    base_path = normcase(abspathu(base))
    base_path_len = len(base_path)
    # Ensure final_path starts with base_path and that the next character after
    # the final path is os.sep (or nothing, in which case final_path must be
    # equal to base_path).
    if not final_path.startswith(base_path) or final_path[base_path_len:base_path_len+1] not in ('', sep):
        raise ValueError('the joined path is located outside of the base path'
                         ' component')
    return final_path 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:24,代碼來源:_os.py

示例10: assertPathsEqual

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def assertPathsEqual(self, first, second):
        def norm(items):
            return [normcase(i) for i in items]
        self.assertEqual(norm(first), norm(second)) 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:6,代碼來源:test_artifact.py

示例11: test_normcase_registration

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def test_normcase_registration(self):
        # create an empty working set for a clean-slate test.
        cwd = utils.mkdtemp(self)
        mock_ws = WorkingSet([])
        dist_ = Distribution(cwd, project_name='pkg', version='1.0')
        dist_.egg_info = cwd  # just lazy
        registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
        # case sensitive test; have to patch the normcase at artifact
        # module with the nt version
        from ntpath import normcase as nt_normcase
        utils.stub_item_attr_value(self, artifact, 'normcase', nt_normcase)
        # using named case for case sensitivity test.
        c1 = EntryPoint.parse('case.js = dummy_builder:builder1')
        c1.dist = dist_
        c2 = EntryPoint.parse('Case.js = dummy_builder:builder2')
        c2.dist = dist_
        # use the error one
        ct = join(cwd, 'calmjs_artifacts', 'Case.js')
        with pretty_logging(stream=mocks.StringIO()) as stream:
            registry.register_entry_point(c1)
            registry.register_entry_point(c2)

        log = stream.getvalue()
        self.assertIn(
            "entry point 'Case.js = dummy_builder:builder2' from package "
            "'pkg 1.0' resolves to the path '%s' which was already "
            "registered to entry point 'case.js = dummy_builder:builder1'; "
            "conflicting entry point registration will be ignored." % ct,
            log
        )
        self.assertIn(
            "the file mapping error is caused by this platform's case-"
            "insensitive filename", log
        ) 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:36,代碼來源:test_artifact.py

示例12: test_get_exec_binary_with_binary

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def test_get_exec_binary_with_binary(self):
        tmpdir = mkdtemp(self)
        prog = create_fake_bin(tmpdir, 'prog')
        self.assertEqual(normcase(prog), normcase(base._get_exec_binary(
            'prog', {'env': {'PATH': tmpdir}}))) 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:7,代碼來源:test_base.py

示例13: test_which_is_set

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def test_which_is_set(self):
        stub_os_environ(self)
        tmpdir = mkdtemp(self)
        mgr_bin = self.create_fake_mgr_bin(tmpdir)
        driver = cli.PackageManagerDriver(pkg_manager_bin='mgr')
        driver.env_path = tmpdir
        self.assertEqual(normcase(driver.which()), normcase(mgr_bin))

        driver.env_path = None
        self.assertIsNone(driver.which()) 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:12,代碼來源:test_cli.py

示例14: test_set_env_path_with_node_modules_success

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def test_set_env_path_with_node_modules_success(self):
        tmpdir, bin_dir, mgr_bin = self.fake_mgr_bin()
        # constructor with an explicit working directory.
        driver = cli.PackageManagerDriver(
            pkg_manager_bin='mgr', working_dir=tmpdir)
        self.assertIsNone(driver.env_path)
        # the which_with_node_modules should work immediately
        self.assertEqual(
            normcase(driver.which_with_node_modules()), normcase(mgr_bin))
        self.assertTrue(driver._set_env_path_with_node_modules())
        self.assertEqual(driver.env_path, bin_dir)
        # should still result in the same thing.
        self.assertTrue(driver._set_env_path_with_node_modules())
        self.assertEqual(driver.env_path, bin_dir) 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:16,代碼來源:test_cli.py

示例15: test_standard

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import normcase [as 別名]
def test_standard(self):
        d_egg_root = join(mkdtemp(self), 'dummyns')

        make_dummy_dist(self, ((
            'namespace_packages.txt',
            'dummyns\n',
        ), (
            'entry_points.txt',
            '[dummyns]\n'
            'dummyns = dummyns:attr\n',
        ),), 'dummyns', '1.0', working_dir=d_egg_root)
        working_set = pkg_resources.WorkingSet([
            d_egg_root,
            self.ds_egg_root,
        ])
        # ensure the working_set is providing the distributions being
        # mocked here so that resource_filename will resolve correctly
        stub_item_attr_value(self, pkg_resources, 'working_set', working_set)

        moddir = join(d_egg_root, 'dummyns')
        os.makedirs(moddir)

        # make this also a proper thing
        with open(join(moddir, '__init__.py'), 'w') as fd:
            fd.write('')

        dummyns_ep = next(working_set.iter_entry_points('dummyns'))
        p = indexer.resource_filename_mod_entry_point('dummyns', dummyns_ep)

        # finally, this should work.
        self.assertEqual(normcase(p), normcase(moddir)) 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:33,代碼來源:test_indexer.py


注:本文中的os.path.normcase方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。