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


Python urllib.pathname2url方法代码示例

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


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

示例1: test_trivial

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def test_trivial(self):
        # A couple trivial tests

        self.assertRaises(ValueError, urllib2.urlopen, 'bogus url')

        # XXX Name hacking to get this to work on Windows.
        fname = os.path.abspath(urllib2.__file__).replace(os.sep, '/')

        # And more hacking to get it to work on MacOS. This assumes
        # urllib.pathname2url works, unfortunately...
        if os.name == 'riscos':
            import string
            fname = os.expand(fname)
            fname = fname.translate(string.maketrans("/.", "./"))

        if os.name == 'nt':
            file_url = "file:///%s" % fname
        else:
            file_url = "file://%s" % fname

        f = urllib2.urlopen(file_url)

        buf = f.read()
        f.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_urllib2.py

示例2: test_trivial

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def test_trivial(self):
        # A couple trivial tests

        self.assertRaises(ValueError, urllib2.urlopen, 'bogus url')

        # XXX Name hacking to get this to work on Windows.
        fname = os.path.abspath(urllib2.__file__).replace('\\', '/')

        # And more hacking to get it to work on MacOS. This assumes
        # urllib.pathname2url works, unfortunately...
        if os.name == 'riscos':
            import string
            fname = os.expand(fname)
            fname = fname.translate(string.maketrans("/.", "./"))

        if os.name == 'nt':
            file_url = "file:///%s" % fname
        else:
            file_url = "file://%s" % fname

        f = urllib2.urlopen(file_url)

        buf = f.read()
        f.close() 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:26,代码来源:test_urllib2.py

示例3: file_path_to_url

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def file_path_to_url(path):
    """
    converts an absolute native path to a FILE URL.

    Parameters
    ----------
    path : a path in native format

    Returns
    -------
    a valid FILE URL
    """
    return urljoin('file:', pathname2url(path))


# ZipFile is not a context manager for <= 2.6
# must be tuple index here since 2.6 doesn't use namedtuple for version_info 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:common.py

示例4: report_detailed_failure

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def report_detailed_failure(self, scene, reference_filepath, output_filepath, log_filepath, error_message, num_diff, max_diff, num_comps, diff_filepath):
        self.failures += 1

        command = self.__make_update_command(output_filepath, reference_filepath)
        self.all_commands.append(command)

        self.file.write(self.__render(self.detailed_failure_template,
                                      {'project-path': scene,
                                       'ref-image-url': urllib.pathname2url(reference_filepath),
                                       'diff-image-url': urllib.pathname2url(diff_filepath) if diff_filepath is not None else "",
                                       'output-image-url': urllib.pathname2url(output_filepath),
                                       'failure-reason': error_message,
                                       'log-file-url': urllib.pathname2url(log_filepath),
                                       'log-file-path': os.path.basename(log_filepath),
                                       'max-abs-diff': max_diff,
                                       'diff-comps-count': num_diff,
                                       'diff-comps-percents': "{0:.2f}".format(100.0 * num_diff / num_comps),
                                       'update-command': command}))
        self.file.flush() 
开发者ID:appleseedhq,项目名称:blenderseed,代码行数:21,代码来源:runtestsuite.py

示例5: build_resources

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def build_resources(self):
        resources = []
        if not self.root_dir:
            return resources
        for root, dirs, files in os.walk(self.root_dir, followlinks=True):
            for file_name in files:
                path = os.path.join(root, file_name)
                if os.path.getsize(path) > MAX_FILESIZE_BYTES:
                    continue
                with open(path, 'rb') as f:
                    content = f.read()

                    path_for_url = pathname2url(path.replace(self.root_dir, '', 1))
                    if self.base_url[-1] == '/' and path_for_url[0] == '/':
                        path_for_url = path_for_url.replace('/', '' , 1)


                    resource_url = "{0}{1}".format(self.base_url, path_for_url)
                    resource = percy.Resource(
                        resource_url=resource_url,
                        sha=utils.sha256hash(content),
                        local_path=os.path.abspath(path),
                    )
                    resources.append(resource)
        return resources 
开发者ID:percy,项目名称:python-percy-client,代码行数:27,代码来源:resource_loader.py

示例6: _get_resource_location

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def _get_resource_location(resource_name,
                           resources_base_path,
                           current_resource_context=None):
    url_parts = resource_name.split(':')
    if url_parts[0] in ['http', 'https', 'file', 'ftp', 'plugin']:
        return resource_name

    if os.path.exists(resource_name):
        return 'file:{0}'.format(
            urllib.pathname2url(os.path.abspath(resource_name)))

    if current_resource_context:
        candidate_url = current_resource_context[
            :current_resource_context.rfind('/') + 1] + resource_name
        if utils.url_exists(candidate_url):
            return candidate_url

    if resources_base_path:
        full_path = os.path.join(resources_base_path, resource_name)
        return 'file:{0}'.format(
            urllib.pathname2url(os.path.abspath(full_path)))

    return None 
开发者ID:cloudify-cosmo,项目名称:cloudify-dsl-parser,代码行数:25,代码来源:imports.py

示例7: validate_json

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def validate_json(json_data, schema_file):
    with open(schema_file) as f:
        schema = json.load(f)

    schema_dir = os.path.dirname(schema_file)
    schema_path = 'file://{0}/'.format(pathname2url(schema_dir))

    resolver = RefResolver(schema_path, schema)

    try:
        Draft4Validator.check_schema(schema)
        validate(json_data, schema, resolver=resolver)
    except SchemaError as e:
        raise Exception("Failed to check JSON schema in {}: {}".format(schema_file, e.message))
    except ValidationError as e:
        raise Exception("Unable to validate data against json schema in {}: {}, {}, {}, {}, {}".format(schema_file, e.message, e.context, e.path, e.schema_path, e.cause)) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:18,代码来源:validation_util.py

示例8: test_trivial

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def test_trivial(self):
        # A couple trivial tests

        self.assertRaises(ValueError, urllib2.urlopen, 'bogus url')

        # XXX Name hacking to get this to work on Windows.
        fname = os.path.abspath(urllib2.__file__).replace('\\', '/')
        if fname[1:2] == ":":
            fname = fname[2:]
        # And more hacking to get it to work on MacOS. This assumes
        # urllib.pathname2url works, unfortunately...
        if os.name == 'mac':
            fname = '/' + fname.replace(':', '/')
        elif os.name == 'riscos':
            import string
            fname = os.expand(fname)
            fname = fname.translate(string.maketrans("/.", "./"))

        file_url = "file://%s" % fname
        f = urllib2.urlopen(file_url)

        buf = f.read()
        f.close() 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:25,代码来源:test_urllib2.py

示例9: contents_url_from_path

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def contents_url_from_path(path):
    """
    Get github API url for contents of file from full path

    :param path: Path to file (<owner>/<repo>/<dir>/.../<filename>)
    :returns: URL suitable for a content call with github API
    """

    owner, repo, file_path = split_full_file_path(path)

    # Cannot pass unicode data to pathname2url or it can raise KeyError. Must
    # only pass URL-safe bytes. So, something like u'\u2026' will raise a
    # KeyError but if we encode it to bytes, '%E2%80%A6', things work
    # correctly.
    # http://stackoverflow.com/questions/15115588/urllib-quote-throws-keyerror
    owner = owner.encode('utf-8')
    repo = repo.encode('utf-8')
    file_path = file_path.encode('utf-8')

    return urllib.pathname2url('repos/%s/%s/contents/%s' % (owner, repo,
                                                            file_path)) 
开发者ID:pluralsight,项目名称:guides-cms,代码行数:23,代码来源:remote.py

示例10: path2url

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def path2url(path):
    return urljoin(
        'file:', pathname2url(os.path.abspath(path))) 
开发者ID:acsone,项目名称:git-aggregator,代码行数:5,代码来源:test_repo.py

示例11: constructLocalFileUrl

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def constructLocalFileUrl(self, filePath):
        return "file://%s" % urllib.pathname2url(os.path.abspath(filePath)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_urllib.py

示例12: test_basic

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def test_basic(self):
        # Make sure simple tests pass
        expected_path = os.path.join("parts", "of", "a", "path")
        expected_url = "parts/of/a/path"
        result = urllib.pathname2url(expected_path)
        self.assertEqual(expected_url, result,
                         "pathname2url() failed; %s != %s" %
                         (result, expected_url))
        result = urllib.url2pathname(expected_url)
        self.assertEqual(expected_path, result,
                         "url2pathame() failed; %s != %s" %
                         (result, expected_path)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_urllib.py

示例13: test_quoting

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def test_quoting(self):
        # Test automatic quoting and unquoting works for pathnam2url() and
        # url2pathname() respectively
        given = os.path.join("needs", "quot=ing", "here")
        expect = "needs/%s/here" % urllib.quote("quot=ing")
        result = urllib.pathname2url(given)
        self.assertEqual(expect, result,
                         "pathname2url() failed; %s != %s" %
                         (expect, result))
        expect = given
        result = urllib.url2pathname(result)
        self.assertEqual(expect, result,
                         "url2pathname() failed; %s != %s" %
                         (expect, result))
        given = os.path.join("make sure", "using_quote")
        expect = "%s/using_quote" % urllib.quote("make sure")
        result = urllib.pathname2url(given)
        self.assertEqual(expect, result,
                         "pathname2url() failed; %s != %s" %
                         (expect, result))
        given = "make+sure/using_unquote"
        expect = os.path.join("make+sure", "using_unquote")
        result = urllib.url2pathname(given)
        self.assertEqual(expect, result,
                         "url2pathname() failed; %s != %s" %
                         (expect, result)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,代码来源:test_urllib.py

示例14: sanepathname2url

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def sanepathname2url(path):
    import urllib
    urlpath = urllib.pathname2url(path)
    if os.name == "nt" and urlpath.startswith("///"):
        urlpath = urlpath[2:]
    # XXX don't ask me about the mac...
    return urlpath 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_urllib2.py

示例15: set_location

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import pathname2url [as 别名]
def set_location(_option, _opt_str, value, parser):
    """Sets the location variable in the parser to the filename in question"""
    if not os.path.exists(os.path.abspath(value)):
        debug.error("The requested file doesn't exist")
    if parser.values.location == None:
        slashes = "//"
        # Windows pathname2url decides to convert C:\blah to ///C:/blah
        # So to keep the URLs correct, we only add file: rather than file://
        if sys.platform.startswith('win'):
            slashes = ""
        parser.values.location = "file:" + slashes + urllib.pathname2url(os.path.abspath(value)) 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:13,代码来源:fileparam.py


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