コード例 #1
0
ファイル: test_posixpath.py プロジェクト: Logotrop/trida
        def test_realpath_resolve_before_normalizing(self):
            # Bug #990669: Symbolic links should be resolved before we
            # normalize the path. E.g.: if we have directories 'a', 'k' and 'y'
            # in the following hierarchy:
            # a/k/y
            #
            # and a symbolic link 'link-y' pointing to 'y' in directory 'a',
            # then realpath("link-y/..") should return 'k', not 'a'.
            try:
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/k")
                os.mkdir(ABSTFN + "/k/y")
                os.symlink(ABSTFN + "/k/y", ABSTFN + "/link-y")

                # Absolute path.
                self.assertEqual(realpath(ABSTFN + "/link-y/.."), ABSTFN + "/k")
                # Relative path.
                with support.change_cwd(dirname(ABSTFN)):
                    self.assertEqual(realpath(basename(ABSTFN) + "/link-y/.."),
                                     ABSTFN + "/k")
            finally:
                test_support.unlink(ABSTFN + "/link-y")
                safe_rmdir(ABSTFN + "/k/y")
                safe_rmdir(ABSTFN + "/k")
                safe_rmdir(ABSTFN)
コード例 #2
0
 def __init__(self, src, dst, path = None):
     if path is not None:
         src = posixpath.join(path, src)
         dst = posixpath.join(path, dst)
     self.__src = posixpath.realpath(src)
     self.__dst = posixpath.realpath(dst)
     os.rename(src, dst)
コード例 #3
0
ファイル: test_posixpath.py プロジェクト: hk520570/kbengine-1
 def test_realpath_basic(self):
     # Basic operation.
     try:
         os.symlink(ABSTFN + "1", ABSTFN)
         self.assertEqual(realpath(ABSTFN), ABSTFN + "1")
     finally:
         support.unlink(ABSTFN)
コード例 #4
0
        def test_realpath_resolve_first(self):
            # Bug #1213894: The first component of the path, if not absolute,
            # must be resolved too.

            try:
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/k")
                os.symlink(ABSTFN, ABSTFN + "link")
                with support.change_cwd(dirname(ABSTFN)):
                    base = basename(ABSTFN)
                    self.assertEqual(realpath(base + "link"), ABSTFN)
                    self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
            finally:
                test_support.unlink(ABSTFN + "link")
                safe_rmdir(ABSTFN + "/k")
                safe_rmdir(ABSTFN)
コード例 #5
0
        def test_realpath_deep_recursion(self):
            depth = 10
            try:
                os.mkdir(ABSTFN)
                for i in range(depth):
                    os.symlink('/'.join(['%d' % i] * 10), ABSTFN + '/%d' % (i + 1))
                os.symlink('.', ABSTFN + '/0')
                self.assertEqual(realpath(ABSTFN + '/%d' % depth), ABSTFN)

                # Test using relative path as well.
                with support.change_cwd(ABSTFN):
                    self.assertEqual(realpath('%d' % depth), ABSTFN)
            finally:
                for i in range(depth + 1):
                    test_support.unlink(ABSTFN + '/%d' % i)
                safe_rmdir(ABSTFN)
コード例 #6
0
ファイル: test_posixpath.py プロジェクト: Logotrop/trida
        def test_realpath_resolve_first(self):
            # Bug #1213894: The first component of the path, if not absolute,
            # must be resolved too.

            try:
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/k")
                os.symlink(ABSTFN, ABSTFN + "link")
                with support.change_cwd(dirname(ABSTFN)):
                    base = basename(ABSTFN)
                    self.assertEqual(realpath(base + "link"), ABSTFN)
                    self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
            finally:
                test_support.unlink(ABSTFN + "link")
                safe_rmdir(ABSTFN + "/k")
                safe_rmdir(ABSTFN)
コード例 #7
0
ファイル: test_posixpath.py プロジェクト: Logotrop/trida
 def test_realpath_basic(self):
     # Basic operation.
     try:
         os.symlink(ABSTFN+"1", ABSTFN)
         self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
     finally:
         test_support.unlink(ABSTFN)
コード例 #8
0
ファイル: test_posixpath.py プロジェクト: Alex-CS/sonify
 def test_realpath_basic(self):
     # Basic operation.
     try:
         os.symlink(ABSTFN+"1", ABSTFN)
         self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
     finally:
         self.safe_remove(ABSTFN)
コード例 #9
0
ファイル: test_posixpath.py プロジェクト: Logotrop/trida
        def test_realpath_deep_recursion(self):
            depth = 10
            try:
                os.mkdir(ABSTFN)
                for i in range(depth):
                    os.symlink('/'.join(['%d' % i] * 10), ABSTFN + '/%d' % (i + 1))
                os.symlink('.', ABSTFN + '/0')
                self.assertEqual(realpath(ABSTFN + '/%d' % depth), ABSTFN)

                # Test using relative path as well.
                with support.change_cwd(ABSTFN):
                    self.assertEqual(realpath('%d' % depth), ABSTFN)
            finally:
                for i in range(depth + 1):
                    test_support.unlink(ABSTFN + '/%d' % i)
                safe_rmdir(ABSTFN)
コード例 #10
0
ファイル: smart.py プロジェクト: btubbs/spa
 def make_path_absolute(self, path):
     """
     Given a relative url found inside the CSS file we're currently serving,
     return an absolute form of that URL.
     """
     env = self.request.environ
     pinfo = posixpath.dirname(env['PATH_INFO'])
     return posixpath.realpath(env['SCRIPT_NAME'] + pinfo + '/' + path)
コード例 #11
0
ファイル: test_posixpath.py プロジェクト: pierreorz/web_ctp
    def test_realpath_deep_recursion(self):
        depth = 10
        old_path = abspath(".")
        try:
            os.mkdir(ABSTFN)
            for i in range(depth):
                os.symlink("/".join(["%d" % i] * 10), ABSTFN + "/%d" % (i + 1))
            os.symlink(".", ABSTFN + "/0")
            self.assertEqual(realpath(ABSTFN + "/%d" % depth), ABSTFN)

            # Test using relative path as well.
            os.chdir(ABSTFN)
            self.assertEqual(realpath("%d" % depth), ABSTFN)
        finally:
            os.chdir(old_path)
            for i in range(depth + 1):
                support.unlink(ABSTFN + "/%d" % i)
            safe_rmdir(ABSTFN)
コード例 #12
0
 def test_realpath_repeated_indirect_symlinks(self):
     try:
         os.mkdir(ABSTFN)
         os.symlink('../' + basename(ABSTFN), ABSTFN + '/self')
         os.symlink('self/self/self', ABSTFN + '/link')
         self.assertEqual(realpath(ABSTFN + '/link'), ABSTFN)
     finally:
         support.unlink(ABSTFN + '/self')
         support.unlink(ABSTFN + '/link')
         safe_rmdir(ABSTFN)
コード例 #13
0
ファイル: P2pSupplicant.py プロジェクト: zenghui0-0/tempfile
    def __init__(self, name, model, eqt_params, bench_params):
        """
        Constructor
        """
        IP2pSupplicant.__init__(self)
        EquipmentBase.__init__(self, name, model, eqt_params)
        computer = str(bench_params.get_param_value("Computer"))
        # NOTE: import here to avoid circular dependency on
        # EquipmentManager if imported at top level
        from acs_test_scripts.Equipment.EquipmentManager import EquipmentManager
        self._em = EquipmentManager()
        self._computer = self._em.get_computer(computer)
        self._p2psupplicant_ongoing = False

        # Get binary and cofiguration file path
        self._wpa_supplicant_bin = posixpath.realpath(
            eqt_params[model]["Binary"])
        self._wpa_p2p_conf = posixpath.realpath(
            eqt_params[model]["Configuration"])
コード例 #14
0
ファイル: test_posixpath.py プロジェクト: prodigeni/mypy
    def test_realpath_resolve_first(self) -> None:
        # Bug #1213894: The first component of the path, if not absolute,
        # must be resolved too.

        try:
            old_path = abspath('.')
            os.mkdir(ABSTFN)
            os.mkdir(ABSTFN + "/k")
            os.symlink(ABSTFN, ABSTFN + "link")
            os.chdir(dirname(ABSTFN))

            base = basename(ABSTFN)
            self.assertEqual(realpath(base + "link"), ABSTFN)
            self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
        finally:
            os.chdir(old_path)
            support.unlink(ABSTFN + "link")
            safe_rmdir(ABSTFN + "/k")
            safe_rmdir(ABSTFN)
コード例 #15
0
ファイル: test_posixpath.py プロジェクト: kivipe/mypy
    def test_realpath_resolve_first(self) -> None:
        # Bug #1213894: The first component of the path, if not absolute,
        # must be resolved too.

        try:
            old_path = abspath('.')
            os.mkdir(ABSTFN)
            os.mkdir(ABSTFN + "/k")
            os.symlink(ABSTFN, ABSTFN + "link")
            os.chdir(dirname(ABSTFN))

            base = basename(ABSTFN)
            self.assertEqual(realpath(base + "link"), ABSTFN)
            self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
        finally:
            os.chdir(old_path)
            support.unlink(ABSTFN + "link")
            safe_rmdir(ABSTFN + "/k")
            safe_rmdir(ABSTFN)
コード例 #16
0
ファイル: test_posixpath.py プロジェクト: Logotrop/trida
 def test_realpath_repeated_indirect_symlinks(self):
     # Issue #6975.
     try:
         os.mkdir(ABSTFN)
         os.symlink('../' + basename(ABSTFN), ABSTFN + '/self')
         os.symlink('self/self/self', ABSTFN + '/link')
         self.assertEqual(realpath(ABSTFN + '/link'), ABSTFN)
     finally:
         test_support.unlink(ABSTFN + '/self')
         test_support.unlink(ABSTFN + '/link')
         safe_rmdir(ABSTFN)
コード例 #17
0
 def test_realpath_resolve_parents(self):
     try:
         os.mkdir(ABSTFN)
         os.mkdir(ABSTFN + '/y')
         os.symlink(ABSTFN + '/y', ABSTFN + '/k')
         with support.change_cwd(ABSTFN + '/k'):
             self.assertEqual(realpath('a'), ABSTFN + '/y/a')
     finally:
         support.unlink(ABSTFN + '/k')
         safe_rmdir(ABSTFN + '/y')
         safe_rmdir(ABSTFN)
コード例 #18
0
ファイル: test_posixpath.py プロジェクト: pierreorz/web_ctp
 def test_realpath_repeated_indirect_symlinks(self):
     # Issue #6975.
     try:
         os.mkdir(ABSTFN)
         os.symlink("../" + basename(ABSTFN), ABSTFN + "/self")
         os.symlink("self/self/self", ABSTFN + "/link")
         self.assertEqual(realpath(ABSTFN + "/link"), ABSTFN)
     finally:
         support.unlink(ABSTFN + "/self")
         support.unlink(ABSTFN + "/link")
         safe_rmdir(ABSTFN)
コード例 #19
0
        def test_realpath_symlink_loops(self):
            # Bug #930024, return the path unchanged if we get into an infinite
            # symlink loop.
            try:
                old_path = abspath('.')
                os.symlink(ABSTFN, ABSTFN)
                self.assertEqual(realpath(ABSTFN), ABSTFN)

                os.symlink(ABSTFN+"1", ABSTFN+"2")
                os.symlink(ABSTFN+"2", ABSTFN+"1")
                self.assertEqual(realpath(ABSTFN+"1"), ABSTFN+"1")
                self.assertEqual(realpath(ABSTFN+"2"), ABSTFN+"2")

                # Test using relative path as well.
                os.chdir(dirname(ABSTFN))
                self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
            finally:
                os.chdir(old_path)
                test_support.unlink(ABSTFN)
                test_support.unlink(ABSTFN+"1")
                test_support.unlink(ABSTFN+"2")
コード例 #20
0
        def test_realpath_symlink_loops(self):
            # Bug #930024, return the path unchanged if we get into an infinite
            # symlink loop.
            try:
                old_path = abspath('.')
                os.symlink(ABSTFN, ABSTFN)
                self.assertEqual(realpath(ABSTFN), ABSTFN)

                os.symlink(ABSTFN+"1", ABSTFN+"2")
                os.symlink(ABSTFN+"2", ABSTFN+"1")
                self.assertEqual(realpath(ABSTFN+"1"), ABSTFN+"1")
                self.assertEqual(realpath(ABSTFN+"2"), ABSTFN+"2")

                # Test using relative path as well.
                os.chdir(dirname(ABSTFN))
                self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
            finally:
                os.chdir(old_path)
                test_support.unlink(ABSTFN)
                test_support.unlink(ABSTFN+"1")
                test_support.unlink(ABSTFN+"2")
コード例 #21
0
 def test_realpath_curdir(self):
     self.assertEqual(realpath('.'), os.getcwd())
     self.assertEqual(realpath('./.'), os.getcwd())
     self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd())
     self.assertEqual(realpath(b'.'), os.getcwdb())
     self.assertEqual(realpath(b'./.'), os.getcwdb())
     self.assertEqual(realpath(b'/'.join([b'.'] * 100)), os.getcwdb())
コード例 #22
0
 def test_realpath_pardir(self):
     self.assertEqual(realpath('..'), dirname(os.getcwd()))
     self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd())))
     self.assertEqual(realpath('/'.join(['..'] * 100)), '/')
     self.assertEqual(realpath(b'..'), dirname(os.getcwdb()))
     self.assertEqual(realpath(b'../..'), dirname(dirname(os.getcwdb())))
     self.assertEqual(realpath(b'/'.join([b'..'] * 100)), b'/')
コード例 #23
0
    def test_realpath_pardir(self):
        self.assertEqual(realpath('..'), dirname(os.getcwd()))
        self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd())))
        self.assertEqual(realpath('/'.join(['..'] * 100)), '/')

        self.assertEqual(realpath(b'..'), dirname(os.getcwdb()))
        self.assertEqual(realpath(b'../..'), dirname(dirname(os.getcwdb())))
        self.assertEqual(realpath(b'/'.join([b'..'] * 100)), b'/')
コード例 #24
0
ファイル: test_posixpath.py プロジェクト: pierreorz/web_ctp
    def test_realpath_pardir(self):
        self.assertEqual(realpath(".."), dirname(os.getcwd()))
        self.assertEqual(realpath("../.."), dirname(dirname(os.getcwd())))
        self.assertEqual(realpath("/".join([".."] * 100)), "/")

        self.assertEqual(realpath(b".."), dirname(os.getcwdb()))
        self.assertEqual(realpath(b"../.."), dirname(dirname(os.getcwdb())))
        self.assertEqual(realpath(b"/".join([b".."] * 100)), b"/")
コード例 #25
0
    def test_realpath_curdir(self):
        self.assertEqual(realpath('.'), os.getcwd())
        self.assertEqual(realpath('./.'), os.getcwd())
        self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd())

        self.assertEqual(realpath(b'.'), os.getcwdb())
        self.assertEqual(realpath(b'./.'), os.getcwdb())
        self.assertEqual(realpath(b'/'.join([b'.'] * 100)), os.getcwdb())
コード例 #26
0
ファイル: test_posixpath.py プロジェクト: pierreorz/web_ctp
    def test_realpath_curdir(self):
        self.assertEqual(realpath("."), os.getcwd())
        self.assertEqual(realpath("./."), os.getcwd())
        self.assertEqual(realpath("/".join(["."] * 100)), os.getcwd())

        self.assertEqual(realpath(b"."), os.getcwdb())
        self.assertEqual(realpath(b"./."), os.getcwdb())
        self.assertEqual(realpath(b"/".join([b"."] * 100)), os.getcwdb())
コード例 #27
0
ファイル: stack.py プロジェクト: 5l1v3r1/TransIP-STACK-API
    def cd(self, path: str = "/") -> StackDirectory:
        """
        Change the current STACK working directory
        :param path: Path to change to, default is the root directory ('/')
        :return: StackDirectory
        """
        if path.startswith("/"):
            path = path
        else:
            path = realpath(join(self.__cwd, path))

        directory = self.directory(path)
        self.__cwd = path
        return directory
コード例 #28
0
    def render_powershell(self) -> str:
        template = TEMPLATES["powershell"]

        script_path = posixpath.realpath(sys.argv[0])
        script_name = self.prog[0]
        aliases = self.prog

        function = self._generate_function_name(script_name, script_path)

        commands = []
        global_options = set()
        commands_options = {}
        for option, _ in self.getter.get_options():
            global_options.add(option)

        for name, command in self.getter.get_commands().items():
            command_options = []
            commands.append(name)

            for option, _ in command.get_options():
                command_options.append(option)

            commands_options[name] = command_options

        opts = ", ".join(f'"{option}"' for option in sorted(global_options))
        coms = ", ".join(f'"{cmd}"' for cmd in sorted(commands))
        command_list = []
        for name, options in commands_options.items():
            cmd_opts = ", ".join(f'"{option}"' for option in sorted(options))
            command_list.append(
                f'                "{name}" {{ $opts = @({cmd_opts}) }}')

        return template.safe_substitute({
            "script_name":
            script_name,
            "function":
            function,
            "aliases":
            ", ".join(f'"{name}"' for name in aliases),
            "opts":
            opts,
            "coms":
            coms,
            "command_list":
            "\n".join(command_list),
            "version":
            __version__,
        })
コード例 #29
0
    def test_realpath_resolve_parents(self):
        # We also need to resolve any symlinks in the parents of a relative
        # path passed to realpath. E.g.: current working directory is
        # /usr/doc with 'doc' being a symlink to /usr/share/doc. We call
        # realpath("a"). This should return /usr/share/doc/a/.
        try:
            os.mkdir(ABSTFN)
            os.mkdir(ABSTFN + "/y")
            os.symlink(ABSTFN + "/y", ABSTFN + "/k")

            with support.change_cwd(ABSTFN + "/k"):
                self.assertEqual(realpath("a"), ABSTFN + "/y/a")
        finally:
            support.unlink(ABSTFN + "/k")
            safe_rmdir(ABSTFN + "/y")
            safe_rmdir(ABSTFN)
コード例 #30
0
ファイル: test_posixpath.py プロジェクト: Logotrop/trida
        def test_realpath_resolve_parents(self):
            # We also need to resolve any symlinks in the parents of a relative
            # path passed to realpath. E.g.: current working directory is
            # /usr/doc with 'doc' being a symlink to /usr/share/doc. We call
            # realpath("a"). This should return /usr/share/doc/a/.
            try:
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/y")
                os.symlink(ABSTFN + "/y", ABSTFN + "/k")

                with support.change_cwd(ABSTFN + "/k"):
                    self.assertEqual(realpath("a"), ABSTFN + "/y/a")
            finally:
                test_support.unlink(ABSTFN + "/k")
                safe_rmdir(ABSTFN + "/y")
                safe_rmdir(ABSTFN)
コード例 #31
0
 def __init__(self, cli: Any, prog: Optional[List[str]] = None) -> None:
     for getter in GETTERS:
         try:
             self.getter = getter(cli)
             break
         except NotSupportedError:
             pass
     else:
         raise NotSupportedError(
             f"CLI object type {type(cli)} is not supported yet. "
             "It must be one of (`argparse.ArgumentParser`, `click.Command`).\n"
             "It may be also because requirements are not met to detect a specified "
             "framework. Please make sure you install pycomplete in the same "
             "environment as the target CLI app.")
     if prog is None:
         prog = [os.path.basename(posixpath.realpath(sys.argv[0]))]
     self.prog = prog
コード例 #32
0
def _make_temp_dir(needs_sudo=False):
    if needs_sudo and psutil.MACOS:
        # macOS has user-specific TMPDIRs, which don't work well
        # with tests that require changing users. So this gets a
        # global multi-user TMPDIR by using sudo.
        base_temp_dir = subprocess.check_output([
            'sudo', sys.executable, '-c',
            'import tempfile as t; print(t.gettempdir())',
        ]).decode('utf-8').strip()
    else:
        base_temp_dir = tempfile.gettempdir()

    temp_dir = posixpath.realpath(
        tempfile.mkdtemp(prefix='daemonocle_pytest_', dir=base_temp_dir))
    # This chmod is necessary for the setuid/setgid tests
    os.chmod(temp_dir, 0o711)

    return temp_dir
コード例 #33
0
    def __init__(self, name, model, eqt_params, bench_params):
        """
        Constructor
        """
        IP2pClient.__init__(self)
        EquipmentBase.__init__(self, name, model, eqt_params)
        computer = str(bench_params.get_param_value("Computer"))
        # NOTE: import here to avoid circular dependency on
        # EquipmentManager if imported at top level
        from acs_test_scripts.Equipment.EquipmentManager import EquipmentManager
        self._em = EquipmentManager()
        self._computer = self._em.get_computer(computer)
        self._lan_interface = ""
        self._p2pclient_ongoing = False

        # Get binary file path
        self._wpa_cli_bin = posixpath.realpath(eqt_params[model]["Binary"])

        self._logger = self.get_logger()
コード例 #34
0
ファイル: test_helpers.py プロジェクト: jnrbsn/daemonocle
def test_exec_worker_detached(pyscript):
    script = pyscript("""
        from daemonocle import Daemon
        from daemonocle.helpers import ExecWorker

        Daemon(
            name='goodnight_world',
            worker=ExecWorker(b'sleep', b'10'),
            pid_file='goodnight_world.pid',
        ).cli()
    """)

    result = script.run('--help')
    assert result.returncode == 0
    assert b'Run "sleep" as a daemon.' in result.stdout
    assert result.stderr == b''

    pid_file = posixpath.realpath(
        posixpath.join(script.dirname, 'goodnight_world.pid'))

    result = script.run('start')
    assert result.returncode == 0
    assert result.stdout == b'Starting goodnight_world ... OK\n'
    assert result.stderr == b''

    with open(pid_file, 'rb') as f:
        pid = int(f.read())

    result = script.run('status', '--json')
    assert result.returncode == 0
    status = json.loads(result.stdout.decode('ascii').rstrip('\n'))
    assert status['name'] == 'goodnight_world'
    assert status['pid'] == pid
    assert status['status'] in {'running', 'sleeping'}
    assert isinstance(status['uptime'], float)
    assert isinstance(status['cpu_percent'], float)
    assert isinstance(status['memory_percent'], float)

    result = script.run('stop')
    assert result.returncode == 0
    assert result.stdout == b'Stopping goodnight_world ... OK\n'
    assert result.stderr == b''
コード例 #35
0
def test_unresponsive_stop(pyscript):
    script = pyscript("""
        import signal
        import sys
        import time
        from daemonocle import Daemon

        def worker():
            def handle_sigterm(*args, **kwargs):
                time.sleep(10)

            signal.signal(signal.SIGTERM, handle_sigterm)
            time.sleep(10)

        daemon = Daemon(worker=worker, name='foo', pid_file='foo.pid',
                        stop_timeout=1)
        daemon.do_action(sys.argv[1])
    """)
    pid_file = posixpath.realpath(posixpath.join(script.dirname, 'foo.pid'))

    script.run('start')

    with open(pid_file, 'rb') as f:
        pid = int(f.read())

    result = script.run('stop')
    assert result.returncode == 1
    assert result.stdout == b'Stopping foo ... FAILED\n'
    assert result.stderr == ('ERROR: Timed out while waiting for process '
                             '(PID {pid}) to terminate\n').format(
                                 pid=pid).encode('utf-8')

    assert psutil.pid_exists(pid)

    os.kill(pid, signal.SIGQUIT)

    try:
        proc = psutil.Process(pid)
    except psutil.NoSuchProcess:
        pass
    else:
        proc.wait(timeout=1)
コード例 #36
0
ファイル: test_lightgbm.py プロジェクト: yangtaokm/fairing
def test_entrypoint_content_no_weight_file():
    with patch('fairing.cloud.storage.GCSStorage.exists', new=lambda bucket,path: not path.endswith(".weight")):
        output_map = lightgbm.generate_context_files(
            EXAMPLE_CONFIG, EXMAPLE_CONFIG_FILE_NAME, 1)
    entrypoint_file_in_docker = posixpath.join(constants.DEFAULT_DEST_PREFIX, 'entrypoint.sh')
    entrypoint_file = None
    for k, v in output_map.items():
        if v == entrypoint_file_in_docker:
            entrypoint_file = k
    actual = open(entrypoint_file, "r").read()
    expected = """#!/bin/sh
set -e
gsutil cp -r gs://lightgbm-test/regression.train {0}/regression.train
gsutil cp -r gs://lightgbm-test/regression.test {0}/regression.test
echo 'All files are copied!'
lightgbm config={0}/config.conf
gsutil cp -r {0}/model.txt gs://lightgbm-test/model.txt
""".format(posixpath.realpath(constants.DEFAULT_DEST_PREFIX))
    print(actual)
    assert expected == actual
コード例 #37
0
ファイル: test_lightgbm.py プロジェクト: tnachen/fairing
def test_entrypoint_content():
    output_map = lightgbm.generate_context_files(EXAMPLE_CONFIG,
                                                 EXMAPLE_CONFIG_FILE_NAME)
    entrypoint_file_in_docker = posixpath.join(constants.DEFAULT_DEST_PREFIX,
                                               'entrypoint.sh')
    entrypoint_file = None
    for k, v in output_map.items():
        if v == entrypoint_file_in_docker:
            entrypoint_file = k
    actual = open(entrypoint_file, "r").read()
    expected = """#!/bin/sh
set -e
gsutil cp gs://lightgbm-test/regression.train {0}/regression.train
gsutil cp gs://lightgbm-test/regression.test {0}/regression.test
echo 'All files are copied!'
lightgbm config={0}/config.conf
gsutil cp {0}/model.txt gs://lightgbm-test/model.txt
""".format(posixpath.realpath(constants.DEFAULT_DEST_PREFIX))
    print(actual)
    assert actual == expected
コード例 #38
0
ファイル: test_lightgbm.py プロジェクト: tnachen/fairing
def test_final_config():
    output_map = lightgbm.generate_context_files(EXAMPLE_CONFIG,
                                                 EXMAPLE_CONFIG_FILE_NAME)
    config_file_in_docker = posixpath.join(constants.DEFAULT_DEST_PREFIX,
                                           'config.conf')
    config_file_local = None
    for k, v in output_map.items():
        if v == config_file_in_docker:
            config_file_local = k
    actual = open(config_file_local, "r").read()
    expected = """task=train
boosting_type=gbdt
objective=regression
n_estimators=10
is_training_metric=true
valid_data={0}/regression.test
train_data={0}/regression.train
verbose=1
model_output={0}/model.txt
""".format(posixpath.realpath(constants.DEFAULT_DEST_PREFIX))
    print(actual)
    assert actual == expected
コード例 #39
0
ファイル: test_basics.py プロジェクト: jnrbsn/daemonocle
def test_stdout_and_stderr_file(pyscript):
    script = pyscript("""
        import sys
        import time
        from daemonocle import Daemon

        def worker():
            sys.stdout.write('1ohhyMgprGBsSgPF7R388fs1VYtF3UyxCzp\\n')
            sys.stdout.flush()
            sys.stderr.write('1PMQcUFXReMo8V4jRK8sRkixpGm6TVb1KJJ\\n')
            sys.stderr.flush()
            time.sleep(10)

        daemon = Daemon(worker=worker, name='foo', pid_file='foo.pid',
                        stdout_file='stdout.log', stderr_file='stderr.log')
        daemon.do_action(sys.argv[1])
    """)
    pid_file = posixpath.realpath(posixpath.join(script.dirname, 'foo.pid'))

    result = script.run('start')
    try:
        assert result.returncode == 0
        assert result.stdout == b'Starting foo ... OK\n'
        assert result.stderr == b''

        with open(pid_file, 'rb') as f:
            proc = psutil.Process(int(f.read()))

        assert proc.status() in {psutil.STATUS_RUNNING, psutil.STATUS_SLEEPING}

        with open(posixpath.join(script.dirname, 'stdout.log'), 'rb') as f:
            assert f.read() == b'1ohhyMgprGBsSgPF7R388fs1VYtF3UyxCzp\n'
        with open(posixpath.join(script.dirname, 'stderr.log'), 'rb') as f:
            assert f.read() == b'1PMQcUFXReMo8V4jRK8sRkixpGm6TVb1KJJ\n'
    finally:
        result = script.run('stop')
        assert result.returncode == 0
        assert result.stdout == b'Stopping foo ... OK\n'
        assert result.stderr == b''
コード例 #40
0
ファイル: test_basics.py プロジェクト: jnrbsn/daemonocle
def test_stdout_and_stderr_file_same_path(pyscript):
    script = pyscript("""
        import sys
        import time
        from daemonocle import Daemon

        def worker():
            sys.stdout.write('1XPRq1KToN6Wz1y1PeR2dj8BNrnjiPTPaup\\n')
            sys.stdout.flush()
            sys.stderr.write('29qM7pLGqgwwhGAVrWxnce14AsQicSWHnwE\\n')
            sys.stderr.flush()
            time.sleep(10)

        daemon = Daemon(worker=worker, name='foo', pid_file='foo.pid',
                        stdout_file='output.log', stderr_file='output.log')
        daemon.do_action(sys.argv[1])
    """)
    pid_file = posixpath.realpath(posixpath.join(script.dirname, 'foo.pid'))

    result = script.run('start')
    try:
        assert result.returncode == 0
        assert result.stdout == b'Starting foo ... OK\n'
        assert result.stderr == b''

        with open(pid_file, 'rb') as f:
            proc = psutil.Process(int(f.read()))

        assert proc.status() in {psutil.STATUS_RUNNING, psutil.STATUS_SLEEPING}

        with open(posixpath.join(script.dirname, 'output.log'), 'rb') as f:
            assert f.read() == (
                b'1XPRq1KToN6Wz1y1PeR2dj8BNrnjiPTPaup\n'
                b'29qM7pLGqgwwhGAVrWxnce14AsQicSWHnwE\n')
    finally:
        result = script.run('stop')
        assert result.returncode == 0
        assert result.stdout == b'Stopping foo ... OK\n'
        assert result.stderr == b''
コード例 #41
0
def _hadoop_prefix_from_bin(hadoop_bin):
    """Given a path to the hadoop binary, return the path of the implied
    hadoop home, or None if we don't know.

    Don't return the parent directory of directories in the default
    path (not ``/``, ``/usr``, or ``/usr/local``).
    """
    # resolve unqualified binary name (relative paths are okay)
    if '/' not in hadoop_bin:
        hadoop_bin = which(hadoop_bin)
        if not hadoop_bin:
            return None

    # use parent of hadoop_bin's directory
    hadoop_home = posixpath.abspath(
        posixpath.join(posixpath.realpath(posixpath.dirname(hadoop_bin)),
                       '..'))

    if hadoop_home in _BAD_HADOOP_HOMES:
        return None

    return hadoop_home
コード例 #42
0
ファイル: hadoop.py プロジェクト: okomestudio/mrjob
def _hadoop_prefix_from_bin(hadoop_bin):
    """Given a path to the hadoop binary, return the path of the implied
    hadoop home, or None if we don't know.

    Don't return the parent directory of directories in the default
    path (not ``/``, ``/usr``, or ``/usr/local``).
    """
    # resolve unqualified binary name (relative paths are okay)
    if '/' not in hadoop_bin:
        hadoop_bin = which(hadoop_bin)
        if not hadoop_bin:
            return None

    # use parent of hadoop_bin's directory
    hadoop_home = posixpath.abspath(
        posixpath.join(posixpath.realpath(posixpath.dirname(hadoop_bin)), '..')
    )

    if hadoop_home in _BAD_HADOOP_HOMES:
        return None

    return hadoop_home
コード例 #43
0
        def test_realpath_resolve_parents(self):
            # We also need to resolve any symlinks in the parents of a relative
            # path passed to realpath. E.g.: current working directory is
            # /usr/doc with 'doc' being a symlink to /usr/share/doc. We call
            # realpath("a"). This should return /usr/share/doc/a/.
            if sys.platform == "qnx6":
                # On a qnx4fs, resolution of directory doesn't work
                # as this test expects.
                return
            try:
                old_path = abspath('.')
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/y")
                os.symlink(ABSTFN + "/y", ABSTFN + "/k")

                os.chdir(ABSTFN + "/k")
                self.assertEqual(realpath("a"), ABSTFN + "/y/a")
            finally:
                os.chdir(old_path)
                self.safe_remove(ABSTFN + "/k")
                self.safe_rmdir(ABSTFN + "/y")
                self.safe_rmdir(ABSTFN)
コード例 #44
0
ファイル: smart.py プロジェクト: btubbs/spa
    def convert_css_url(self, css_url):
        split_url = urlsplit(css_url)
        url_path = split_url.path
        if not url_path.startswith('/'):
            abs_url_path = self.make_path_absolute(url_path)
        else:
            abs_url_path = posixpath.realpath(url_path)

        prefix = self.get_url_prefix()

        # now make the path as it would be passed in to this handler when
        # requested from the web.  From there we can use existing methods on the
        # class to resolve to a real file.
        _, _, content_filepath = abs_url_path.partition(prefix)
        content_filepath = clean_path(content_filepath)

        content_file_hash = self.hash_cache.get_path_hash(content_filepath)
        if content_file_hash is None:
            content_file = self.get_file(content_filepath)
            if content_file is None:
                return 'NOT FOUND: "%s"' % url_path
            try:
                content_file_hash = get_hash(content_file.handle)
            finally:
                content_file.handle.close()
        parts = list(split_url)
        parts[2] = add_hash_to_filepath(url_path, content_file_hash)

        url = urlunsplit(parts)

        # Special casing for a @font-face hack, like url(myfont.eot?#iefix")
        # http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax
        if '?#' in css_url:
            parts = list(urlsplit(url))
            if not parts[3]:
                parts[2] += '?'
            url = urlunsplit(parts)
        return url
コード例 #45
0
ファイル: test_lightgbm.py プロジェクト: ycheng/fairing
def test_entrypoint_content_dist_data_parallel():
    config = EXAMPLE_CONFIG.copy()
    config["tree_learner"] = "data"
    config["train_data"] = ",".join([
        "gs://lightgbm-test/regression.train1",
        "gs://lightgbm-test/regression.train2"
    ])
    with patch('fairing.cloud.storage.GCSStorage.exists'):
        output_map = lightgbm.generate_context_files(config,
                                                     EXMAPLE_CONFIG_FILE_NAME,
                                                     2)
    entrypoint_file_in_docker = posixpath.join(constants.DEFAULT_DEST_PREFIX,
                                               'entrypoint.sh')
    entrypoint_file = None
    for k, v in output_map.items():
        if v == entrypoint_file_in_docker:
            entrypoint_file = k
    actual = open(entrypoint_file, "r").read()
    expected = """#!/bin/sh
set -e
RANK=`python lightgbm_dist_training_init.py config.conf mlist.txt`
case $RANK in
	0)
		gsutil cp -r gs://lightgbm-test/regression.train1 /app/train_data
		gsutil cp -r gs://lightgbm-test/regression.train1.weight /app/train_data.weight
		;;
	1)
		gsutil cp -r gs://lightgbm-test/regression.train2 /app/train_data
		gsutil cp -r gs://lightgbm-test/regression.train2.weight /app/train_data.weight
		;;
esac
gsutil cp -r gs://lightgbm-test/regression.test {0}/regression.test
echo 'All files are copied!'
lightgbm config={0}/config.conf
gsutil cp -r {0}/model.txt gs://lightgbm-test/model.txt
""".format(posixpath.realpath(constants.DEFAULT_DEST_PREFIX))
    print(actual)
    assert expected == actual
コード例 #46
0
 def __init__(self, path):
     self.__path = posixpath.realpath(path)
     (self.__od, self.__of) = self.scan()
コード例 #47
0
 def testAbsolutifies(self):
   self.assertPlatformSpecificLogdirParsing(
       posixpath, 'lol/cat', {posixpath.realpath('lol/cat'): None})
   self.assertPlatformSpecificLogdirParsing(
       ntpath, 'lol\\cat', {ntpath.realpath('lol\\cat'): None})
コード例 #48
0
    def test_realpath_symlink_loops(self):
        # Bug #930024, return the path unchanged if we get into an infinite
        # symlink loop.
        try:
            os.symlink(ABSTFN, ABSTFN)
            self.assertEqual(realpath(ABSTFN), ABSTFN)

            os.symlink(ABSTFN + "1", ABSTFN + "2")
            os.symlink(ABSTFN + "2", ABSTFN + "1")
            self.assertEqual(realpath(ABSTFN + "1"), ABSTFN + "1")
            self.assertEqual(realpath(ABSTFN + "2"), ABSTFN + "2")

            self.assertEqual(realpath(ABSTFN + "1/x"), ABSTFN + "1/x")
            self.assertEqual(realpath(ABSTFN + "1/.."), dirname(ABSTFN))
            self.assertEqual(realpath(ABSTFN + "1/../x"),
                             dirname(ABSTFN) + "/x")
            os.symlink(ABSTFN + "x", ABSTFN + "y")
            self.assertEqual(
                realpath(ABSTFN + "1/../" + basename(ABSTFN) + "y"),
                ABSTFN + "y")
            self.assertEqual(
                realpath(ABSTFN + "1/../" + basename(ABSTFN) + "1"),
                ABSTFN + "1")

            os.symlink(basename(ABSTFN) + "a/b", ABSTFN + "a")
            self.assertEqual(realpath(ABSTFN + "a"), ABSTFN + "a/b")

            os.symlink(
                "../" + basename(dirname(ABSTFN)) + "/" + basename(ABSTFN) +
                "c", ABSTFN + "c")
            self.assertEqual(realpath(ABSTFN + "c"), ABSTFN + "c")

            # Test using relative path as well.
            with support.change_cwd(dirname(ABSTFN)):
                self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
        finally:
            support.unlink(ABSTFN)
            support.unlink(ABSTFN + "1")
            support.unlink(ABSTFN + "2")
            support.unlink(ABSTFN + "y")
            support.unlink(ABSTFN + "c")
            support.unlink(ABSTFN + "a")
コード例 #49
0
 def test_realpath_relative(self):
     try:
         os.symlink(posixpath.relpath(ABSTFN + "1"), ABSTFN)
         self.assertEqual(realpath(ABSTFN), ABSTFN + "1")
     finally:
         support.unlink(ABSTFN)
コード例 #50
0
ファイル: completions_command.py プロジェクト: sdispater/cleo
    def render_zsh(self):
        template = TEMPLATES["zsh"]

        script_path = posixpath.realpath(self._args.script_name)
        script_name = os.path.basename(script_path)
        aliases = [script_path]
        aliases += self.option("alias")

        function = self._generate_function_name(script_name, script_path)

        global_options = set()
        commands_descriptions = []
        options_descriptions = {}
        commands_options_descriptions = {}
        commands_options = {}
        for option in self.application.config.options.values():
            options_descriptions["--" + option.long_name] = self.io.remove_format(
                option.description
            )
            global_options.add("--" + option.long_name)

        for command in self.application.commands:
            command_config = command.config
            if not command_config.is_enabled() or command_config.is_hidden():
                continue

            command_options = []
            commands_options_descriptions[command_config.name] = {}
            command_description = self._io.remove_format(command_config.description)
            commands_descriptions.append(
                self._zsh_describe(command_config.name, command_description)
            )

            options = command_config.options
            for name in sorted(options.keys()):
                option = options[name]
                name = "--" + option.long_name
                description = self.io.remove_format(option.description)
                command_options.append(name)
                options_descriptions[name] = description
                commands_options_descriptions[command_config.name][name] = description

            commands_options[command_config.name] = command_options

        compdefs = "\n".join(
            ["compdef {} {}".format(function, alias) for alias in aliases]
        )

        commands = sorted(list(commands_options.keys()))
        command_list = []
        for i, command in enumerate(commands):
            options = set(commands_options[command]).difference(global_options)
            options = sorted(options)
            options = [
                self._zsh_describe(opt, commands_options_descriptions[command][opt])
                for opt in options
            ]

            desc = [
                "            ({})".format(command),
                "            opts+=({})".format(" ".join(options)),
                "            ;;",
            ]

            if i < len(commands) - 1:
                desc.append("")

            command_list.append("\n".join(desc))

        opts = []
        for opt in global_options:
            opts.append(self._zsh_describe(opt, options_descriptions[opt]))

        output = template % {
            "script_name": script_name,
            "function": function,
            "opts": " ".join(sorted(opts)),
            "coms": " ".join(sorted(commands_descriptions)),
            "command_list": "\n".join(command_list),
            "compdefs": compdefs,
        }

        return output
コード例 #51
0
ファイル: completions_command.py プロジェクト: sdispater/cleo
    def render_fish(self):
        template = TEMPLATES["fish"]

        script_path = posixpath.realpath(self._args.script_name)
        script_name = os.path.basename(script_path)
        aliases = [script_name]
        aliases += self.option("alias")

        function = self._generate_function_name(script_name, script_path)

        global_options = set()
        commands_descriptions = {}
        options_descriptions = {}
        commands_options_descriptions = {}
        commands_options = {}
        for option in self.application.config.options.values():
            options_descriptions["--" + option.long_name] = self.io.remove_format(
                option.description
            )
            global_options.add("--" + option.long_name)

        for command in self.application.commands:
            command_config = command.config
            if not command_config.is_enabled() or command_config.is_hidden():
                continue

            command_options = []
            commands_options_descriptions[command_config.name] = {}
            commands_descriptions[command_config.name] = self._io.remove_format(
                command_config.description
            )

            options = command_config.options
            for name in sorted(options.keys()):
                option = options[name]
                name = "--" + option.long_name
                description = self._io.remove_format(option.description)
                command_options.append(name)
                options_descriptions[name] = description
                commands_options_descriptions[command_config.name][name] = description

            commands_options[command_config.name] = command_options

        opts = []
        for opt in sorted(global_options):
            opts.append(
                "complete -c {} -n '__fish{}_no_subcommand' "
                "-l {} -d '{}'".format(
                    script_name,
                    function,
                    opt[2:],
                    options_descriptions[opt].replace("'", "\\'"),
                )
            )

        cmds_names = sorted(list(commands_options.keys()))

        cmds = []
        cmds_opts = []
        for i, cmd in enumerate(cmds_names):
            cmds.append(
                "complete -c {} -f -n '__fish{}_no_subcommand' "
                "-a {} -d '{}'".format(
                    script_name,
                    function,
                    cmd,
                    commands_descriptions[cmd].replace("'", "\\'"),
                )
            )

            cmds_opts += ["# {}".format(cmd)]
            options = set(commands_options[cmd]).difference(global_options)
            options = sorted(options)

            for opt in options:
                cmds_opts.append(
                    "complete -c {} -A -n '__fish_seen_subcommand_from {}' "
                    "-l {} -d '{}'".format(
                        script_name,
                        cmd,
                        opt[2:],
                        commands_options_descriptions[cmd][opt].replace("'", "\\'"),
                    )
                )

            if i < len(cmds_names) - 1:
                cmds_opts.append("")

        output = template % {
            "script_name": script_name,
            "function": function,
            "cmds_names": " ".join(cmds_names),
            "opts": "\n".join(opts),
            "cmds": "\n".join(cmds),
            "cmds_opts": "\n".join(cmds_opts),
        }

        return output
コード例 #52
0
    pass

def have_dpkg():
    try:
        BPY.buildarch()
        return True
    except Exception:
        return False

def tar_ignore_supported():
    output = subprocess.Popen(['dpkg-source', '--version'], stdout=subprocess.PIPE).communicate()[0]
    m = re.search('version\s+(\d+(?:\.\d+)+)', output)
    v = re.split('\.', m.group(1))
    return int(v[0]) > 1 or (int(v[0]) == 1 and int(v[1]) > 14)

LIB_a = posixpath.realpath('cmake/a')
LIB_b = posixpath.realpath('cmake/b')

BPY_std = """import mirbuild
mirbuild.CMakeProject('test').run()
"""

BPY_dep = """import mirbuild
project = mirbuild.CMakeProject('test')
project.depends('foo', 'oh-my')
project.define('HAVE_LIB_A')
project.define('HAVE_LIB_B')
project.run()
"""

BPY_ver = """import mirbuild
コード例 #53
0
ファイル: generateBoard.py プロジェクト: DISTORTEC/distortos
	if not arguments.distortosPath:
		arguments.distortosPath = os.path.relpath(sys.argv[0] + '/../..')

	yaml = ruamel.yaml.YAML()
	yaml.register_class(Reference)

	dictionary = yaml.load(arguments.inputFile)
	dictionary = resolveExtensions(dictionary, arguments.distortosPath)
	labels = getLabels(dictionary)
	resolveReferences(dictionary, labels)
	addPaths(dictionary)

	# in case of "raw" board - generated directly from chip YAML file - use chip name as board
	board = dictionary.get('board', dictionary['chip'])['compatible'][0]

	relativeDistortosPath = posixpath.relpath(posixpath.realpath(arguments.distortosPath),
			posixpath.realpath(arguments.outputPath))
	relativeOutputPath = posixpath.relpath(posixpath.realpath(arguments.outputPath),
			posixpath.realpath(arguments.distortosPath))

	jinjaEnvironment = jinja2.Environment(trim_blocks = True, lstrip_blocks = True, keep_trailing_newline = True,
			loader = jinja2.FileSystemLoader(['.', arguments.distortosPath]))
	jinjaEnvironment.add_extension(RaiseExtension)
	jinjaEnvironment.filters['sanitize'] = common.sanitize
	jinjaEnvironment.globals['board'] = board
	jinjaEnvironment.globals['distortosPath'] = relativeDistortosPath
	jinjaEnvironment.globals['enumerate'] = enumerate
	jinjaEnvironment.globals['len'] = len
	jinjaEnvironment.globals['outputPath'] = relativeOutputPath
	jinjaEnvironment.globals['sanitizedBoard'] = common.sanitize(board)
	jinjaEnvironment.tests['fullMatch'] = isFullMatch
コード例 #54
0
ファイル: test_posixpath.py プロジェクト: Logotrop/trida
        def test_realpath_symlink_loops(self):
            # Bug #930024, return the path unchanged if we get into an infinite
            # symlink loop.
            try:
                os.symlink(ABSTFN, ABSTFN)
                self.assertEqual(realpath(ABSTFN), ABSTFN)

                os.symlink(ABSTFN+"1", ABSTFN+"2")
                os.symlink(ABSTFN+"2", ABSTFN+"1")
                self.assertEqual(realpath(ABSTFN+"1"), ABSTFN+"1")
                self.assertEqual(realpath(ABSTFN+"2"), ABSTFN+"2")

                self.assertEqual(realpath(ABSTFN+"1/x"), ABSTFN+"1/x")
                self.assertEqual(realpath(ABSTFN+"1/.."), dirname(ABSTFN))
                self.assertEqual(realpath(ABSTFN+"1/../x"), dirname(ABSTFN) + "/x")
                os.symlink(ABSTFN+"x", ABSTFN+"y")
                self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "y"),
                                ABSTFN + "y")
                self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "1"),
                                ABSTFN + "1")

                os.symlink(basename(ABSTFN) + "a/b", ABSTFN+"a")
                self.assertEqual(realpath(ABSTFN+"a"), ABSTFN+"a/b")

                os.symlink("../" + basename(dirname(ABSTFN)) + "/" +
                        basename(ABSTFN) + "c", ABSTFN+"c")
                self.assertEqual(realpath(ABSTFN+"c"), ABSTFN+"c")

                # Test using relative path as well.
                with support.change_cwd(dirname(ABSTFN)):
                    self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
            finally:
                test_support.unlink(ABSTFN)
                test_support.unlink(ABSTFN+"1")
                test_support.unlink(ABSTFN+"2")
                test_support.unlink(ABSTFN+"y")
                test_support.unlink(ABSTFN+"c")
                test_support.unlink(ABSTFN+"a")
コード例 #55
0
 def testAbsolutifies(self):
   self.assertPlatformSpecificLogdirParsing(
       posixpath, 'lol/cat', {posixpath.realpath('lol/cat'): None})
   self.assertPlatformSpecificLogdirParsing(
       ntpath, 'lol\\cat', {ntpath.realpath('lol\\cat'): None})
コード例 #56
0
 def test_realpath_relative(self):
     try:
         os.symlink(posixpath.relpath(ABSTFN+"1"), ABSTFN)
         self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
     finally:
         support.unlink(ABSTFN)
コード例 #57
0
ファイル: server_backends.py プロジェクト: JosephCottam/bokeh
def safe_url_join(base_path, paths):
    proposed_path = posixpath.realpath(posixpath.join(base_path, *paths))
    if not proposed_path.startswith(base_path):
        raise IOError('security error')
    return proposed_path
コード例 #58
0
 def __init__(self, path):
     self.__path = posixpath.realpath(path)
     (self.__od, self.__of) = self.scan()
コード例 #59
0
 def test_realpath(self):
     self.assert_("foo" in realpath("foo"))
     self.assertRaises(TypeError, posixpath.realpath)