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


Python path.replace方法代碼示例

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


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

示例1: run_command

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def run_command(quteproc, server, tmpdir, command):
    """Run a qutebrowser command.

    The suffix "with count ..." can be used to pass a count to the command.
    """
    if 'with count' in command:
        command, count = command.split(' with count ')
        count = int(count)
    else:
        count = None

    invalid_tag = ' (invalid command)'
    if command.endswith(invalid_tag):
        command = command[:-len(invalid_tag)]
        invalid = True
    else:
        invalid = False

    command = command.replace('(port)', str(server.port))
    command = command.replace('(testdata)', testutils.abs_datapath())
    command = command.replace('(tmpdir)', str(tmpdir))
    command = command.replace('(dirsep)', os.sep)
    command = command.replace('(echo-exe)', _get_echo_exe_path())

    quteproc.send_cmd(command, count=count, invalid=invalid) 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:27,代碼來源:conftest.py

示例2: path_to_url

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def path_to_url(self, path, *, port=None, https=False):
        """Get a URL based on a filename for the localhost webserver.

        URLs like about:... and qute:... are handled specially and returned
        verbatim.
        """
        special_schemes = ['about:', 'qute:', 'chrome:', 'view-source:',
                           'data:', 'http:', 'https:']
        server = self.request.getfixturevalue('server')
        server_port = server.port if port is None else port

        if any(path.startswith(scheme) for scheme in special_schemes):
            path = path.replace('(port)', str(server_port))
            return path
        else:
            return '{}://localhost:{}/{}'.format(
                'https' if https else 'http',
                server_port,
                path if path != '/' else '') 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:21,代碼來源:quteprocess.py

示例3: test_resource_url

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def test_resource_url():
    """Test resource_url() which can be used from templates."""
    data = jinja.render('test2.html')
    print(data)
    url = QUrl(data)
    assert url.isValid()
    assert url.scheme() == 'file'

    path = url.path()

    if utils.is_windows:
        path = path.lstrip('/')
        path = path.replace('/', os.sep)

    with open(path, 'r', encoding='utf-8') as f:
        assert f.read().splitlines()[0] == "Hello World!" 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:18,代碼來源:test_jinja.py

示例4: test_glob_matching

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def test_glob_matching(
		monkeypatch,
		pattern: ty.Union[ty.AnyStr, filescanner.re_pattern_t, ty.List[ty.Union[ty.AnyStr, filescanner.re_pattern_t]]],
		path: ty.AnyStr,
		is_dir: bool,
		descend: bool,
		report: bool,
		kwargs: ty.Dict[str, bool]
):
	# Hopefully useless sanity check
	assert os.path.sep == "/" or os.path.altsep == "/"
	
	slash = "/"         if isinstance(path, str) else b"/"  # type: ty.AnyStr
	sep   = os.path.sep if isinstance(path, str) else os.fsencode(os.path.sep)  # type: ty.AnyStr
	
	path = path.replace(slash, sep)
	
	matcher = filescanner.matcher_from_spec(pattern, **kwargs)
	assert matcher.should_descend(path)               is descend
	assert matcher.should_report(path, is_dir=is_dir) is report 
開發者ID:ipfs-shipyard,項目名稱:py-ipfs-http-client,代碼行數:22,代碼來源:test_filescanner.py

示例5: _process_execute_error

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def _process_execute_error(self, msg):
        """ Reimplemented for IPython-style traceback formatting.
        """
        content = msg['content']
        traceback = '\n'.join(content['traceback']) + '\n'
        if False:
            # FIXME: For now, tracebacks come as plain text, so we can't use
            # the html renderer yet.  Once we refactor ultratb to produce
            # properly styled tracebacks, this branch should be the default
            traceback = traceback.replace(' ', ' ')
            traceback = traceback.replace('\n', '<br/>')

            ename = content['ename']
            ename_styled = '<span class="error">%s</span>' % ename
            traceback = traceback.replace(ename, ename_styled)

            self._append_html(traceback)
        else:
            # This is the fallback for now, using plain text with ansi escapes
            self._append_plain_text(traceback) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:22,代碼來源:ipython_widget.py

示例6: get_intel_registry_value

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def get_intel_registry_value(valuename, version=None, abi=None):
    """
    Return a value from the Intel compiler registry tree. (Windows only)
    """
    # Open the key:
    if is_win64:
        K = 'Software\\Wow6432Node\\Intel\\Compilers\\C++\\' + version + '\\'+abi.upper()
    else:
        K = 'Software\\Intel\\Compilers\\C++\\' + version + '\\'+abi.upper()
    try:
        k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE, K)
    except SCons.Util.RegError:
        raise MissingRegistryError("%s was not found in the registry, for Intel compiler version %s, abi='%s'"%(K, version,abi))

    # Get the value:
    try:
        v = SCons.Util.RegQueryValueEx(k, valuename)[0]
        return v  # or v.encode('iso-8859-1', 'replace') to remove unicode?
    except SCons.Util.RegError:
        raise MissingRegistryError("%s\\%s was not found in the registry."%(K, valuename)) 
開發者ID:coin3d,項目名稱:pivy,代碼行數:22,代碼來源:intelc.py

示例7: glob_matches_path

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def glob_matches_path(path, pattern, sep=os.sep, altsep=os.altsep):
    if altsep:
        pattern = pattern.replace(altsep, sep)
        path = path.replace(altsep, sep)

    drive = ''
    if len(path) > 1 and path[1] == ':':
        drive, path = path[0], path[2:]

    if drive and len(pattern) > 1:
        if pattern[1] == ':':
            if drive.lower() != pattern[0].lower():
                return False
            pattern = pattern[2:]

    patterns = pattern.split(sep)
    paths = path.split(sep)
    if paths:
        if paths[0] == '':
            paths = paths[1:]
    if patterns:
        if patterns[0] == '':
            patterns = patterns[1:]

    return _check_matches(patterns, paths) 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:27,代碼來源:pydevd_filtering.py

示例8: map

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def map(self, path):
        """Map `path` through the aliases.

        `path` is checked against all of the patterns.  The first pattern to
        match is used to replace the root of the path with the result root.
        Only one pattern is ever used.  If no patterns match, `path` is
        returned unchanged.

        The separator style in the result is made to match that of the result
        in the alias.

        Returns the mapped path.  If a mapping has happened, this is a
        canonical path.  If no mapping has happened, it is the original value
        of `path` unchanged.

        """
        for regex, result in self.aliases:
            m = regex.match(path)
            if m:
                new = path.replace(m.group(0), result)
                new = new.replace(sep(path), sep(result))
                new = canonical_filename(new)
                return new
        return path 
開發者ID:nedbat,項目名稱:coveragepy-bbmirror,代碼行數:26,代碼來源:files.py

示例9: makeExtension

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def makeExtension(extName):
    global libs
    extPath = extName.replace(".", os.path.sep)+".pyx"

    ## For Mojave Users
    if platform.system() == "Darwin":
        if "10.14" in platform.mac_ver()[0]:
            return Extension(
            extName,
            [extPath],include_dirs=[np.get_include()],language='c++',libraries=libs,
            extra_compile_args=["-stdlib=libc++"]
            )
    
    return Extension(
        extName,
        [extPath],include_dirs=[np.get_include()],language='c++',libraries=libs,
        #extra_compile_args = ["-O0", "-fopenmp"],extra_link_args=['-fopenmp']

        )

# get the list of extensions 
開發者ID:Jacobe2169,項目名稱:GMatch4py,代碼行數:23,代碼來源:setup.py

示例10: set_setting_given

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def set_setting_given(quteproc, server, opt, value):
    """Set a qutebrowser setting.

    This is available as "Given:" step so it can be used as "Background:".
    """
    if value == '<empty>':
        value = ''
    value = value.replace('(port)', str(server.port))
    quteproc.set_setting(opt, value) 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:11,代碼來源:conftest.py

示例11: set_setting

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def set_setting(quteproc, server, opt, value):
    """Set a qutebrowser setting."""
    if value == '<empty>':
        value = ''
    value = value.replace('(port)', str(server.port))
    quteproc.set_setting(opt, value) 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:8,代碼來源:conftest.py

示例12: expect_message

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def expect_message(quteproc, server, category, message):
    """Expect the given message in the qutebrowser log."""
    category_to_loglevel = {
        'message': logging.INFO,
        'error': logging.ERROR,
        'warning': logging.WARNING,
    }
    message = message.replace('(port)', str(server.port))
    quteproc.mark_expected(category='message',
                           loglevel=category_to_loglevel[category],
                           message=message) 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:13,代碼來源:conftest.py

示例13: should_be_logged

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def should_be_logged(quteproc, server, is_regex, pattern, loglevel):
    """Expect the given pattern on regex in the log."""
    if is_regex:
        pattern = re.compile(pattern)
    else:
        pattern = pattern.replace('(port)', str(server.port))

    args = {
        'message': pattern,
    }
    if loglevel:
        args['loglevel'] = getattr(logging, loglevel.upper())

    line = quteproc.wait_for(**args)
    line.expected = True 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:17,代碼來源:conftest.py

示例14: clipboard_contains

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def clipboard_contains(quteproc, server, what, content):
    expected = content.replace('(port)', str(server.port))
    expected = expected.replace('\\n', '\n')
    expected = expected.replace('(linesep)', os.linesep)
    quteproc.wait_for(message='Setting fake {}: {}'.format(
        what, json.dumps(expected))) 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:8,代碼來源:conftest.py

示例15: clipboard_contains_multiline

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import replace [as 別名]
def clipboard_contains_multiline(quteproc, server, content):
    expected = textwrap.dedent(content).replace('(port)', str(server.port))
    quteproc.wait_for(message='Setting fake clipboard: {}'.format(
        json.dumps(expected))) 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:6,代碼來源:conftest.py


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