Python源码示例:ntpath.sep()

示例1
def test_windows_colon(self):
        import SimpleHTTPServer
        with test_support.swap_attr(SimpleHTTPServer.os, 'path', ntpath):
            path = self.handler.translate_path('c:c:c:foo/filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated)

            path = self.handler.translate_path('\\c:../filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated)

            path = self.handler.translate_path('c:\\c:..\\foo/filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated)

            path = self.handler.translate_path('c:c:foo\\c:c:bar/filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated) 
示例2
def test_windows_colon(self):
        with support.swap_attr(server.os, 'path', ntpath):
            path = self.handler.translate_path('c:c:c:foo/filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated)

            path = self.handler.translate_path('\\c:../filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated)

            path = self.handler.translate_path('c:\\c:..\\foo/filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated)

            path = self.handler.translate_path('c:c:foo\\c:c:bar/filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated) 
示例3
def test_windows_colon(self):
        with support.swap_attr(server.os, 'path', ntpath):
            path = self.handler.translate_path('c:c:c:foo/filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated)

            path = self.handler.translate_path('\\c:../filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated)

            path = self.handler.translate_path('c:\\c:..\\foo/filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated)

            path = self.handler.translate_path('c:c:foo\\c:c:bar/filename')
            path = path.replace(ntpath.sep, os.sep)
            self.assertEqual(path, self.translated) 
示例4
def to_os_native_path(path):
    """
    Normalize a path to use the native OS path separator.
    """
    path = path.replace(posixpath.sep, os.path.sep)
    path = path.replace(ntpath.sep, os.path.sep)
    path = path.rstrip(os.path.sep)
    return path 
示例5
def test_nt_helpers(self):
        # Trivial validation that the helpers do not break, and support both
        # unicode and bytes (UTF-8) paths

        drive, path = ntpath.splitdrive(sys.executable)
        drive = drive.rstrip(ntpath.sep) + ntpath.sep
        self.assertEqual(drive, nt._getvolumepathname(sys.executable))
        self.assertEqual(drive.encode(),
                         nt._getvolumepathname(sys.executable.encode()))

        cap, free = nt._getdiskusage(sys.exec_prefix)
        self.assertGreater(cap, 0)
        self.assertGreater(free, 0)
        b_cap, b_free = nt._getdiskusage(sys.exec_prefix.encode())
        # Free space may change, so only test the capacity is equal
        self.assertEqual(b_cap, cap)
        self.assertGreater(b_free, 0)

        for path in [sys.prefix, sys.executable]:
            final_path = nt._getfinalpathname(path)
            self.assertIsInstance(final_path, str)
            self.assertGreater(len(final_path), 0)

            b_final_path = nt._getfinalpathname(path.encode())
            self.assertIsInstance(b_final_path, bytes)
            self.assertGreater(len(b_final_path), 0) 
示例6
def visitFuncDo(self, ctx):
        func = self.visit(ctx.specialExpr(0))
        namespace = self.visit(ctx.specialExpr(1)) if ctx.IN() else ''
        args = self.visit(ctx.args(0)) or []
        kwargs = {}

        if ctx.FORM():
            if ctx.NAME():
                kwargs['name'] = str(self.visit(ctx.nameId))
                if ctx.LINKED():
                    kwargs['linked'] = True
            if args:
                kwargs['args'] = args
            if ctx.NOSHOW():
                kwargs['noshow'] = True
            form_call = make_func_code('vfpfunc.do_form', func, **kwargs)
            if ctx.TO():
                return add_args_to_code('{} = {}', (self.visit(ctx.toId), form_call))
            else:
                return form_call

        if os.path.splitext(namespace)[0] == self.filename:
            namespace = ''

        if not namespace:
            if func in self.function_list:
                return make_func_code(func, *args)

            if os.path.splitext(func)[1] in ('.prg', '.mpr', '.spr'):
                namespace = os.path.splitext(func)[0]
                if os.path.splitext(func)[1] in ('.mpr', '.spr'):
                    namespace += os.path.splitext(func)[1].replace('.', '_')
                func = 'MAIN'
            else:
                func = self.scopeId(func, 'func')
                return make_func_code(func, *args)

        if namespace.endswith('.prg'):
            namespace = namespace[:-4]

        if string_type(namespace) and valid_identifier(namespace):
            namespace = ntpath.normpath(ntpath.splitext(namespace)[0]).replace(ntpath.sep, '.')
            if namespace != 'vfpfunc':
                self.imports.append('import ' + namespace)
            mod = CodeStr(namespace)
        else:
            if string_type(namespace):
                namespace = CodeStr(repr(namespace))
            mod = make_func_code('vfpfunc.module', namespace)
        if string_type(func):
            func = CodeStr(func)
            func = add_args_to_code('{}.{}', (mod, func))
            if string_type(namespace):
                return make_func_code(func, *args)
        else:
            func = make_func_code('getattr', mod, func)

        return make_func_code(func, *args)