Python six.moves.urllib.request 模块,pathname2url() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用six.moves.urllib.request.pathname2url()

项目:mos-horizon    作者:Mirantis    | 项目源码 | 文件源码
def find_asset(theme, asset):

    theme_path = ''
    for name, label, path in hz_themes.get_themes():
        if theme == name:
            theme_path = path

    theme_path = os.path.join(settings.ROOT_PATH, theme_path)

    # If there is a 'static' subdir of the theme, then use
    # that as the theme's asset root path
    static_path = os.path.join(theme_path, 'static')
    if os.path.exists(static_path):
        theme_path = static_path

    # The full path to the asset requested
    asset_path = os.path.join(theme_path, asset)
    if os.path.exists(asset_path):
        return_path = os.path.join(hz_themes.get_theme_dir(), theme, asset)
    else:
        return_path = os.path.join('dashboard', asset)

    return staticfiles_storage.url(pathname2url(return_path))
项目:python-kingbirdclient    作者:openstack    | 项目源码 | 文件源码
def get_contents_if_file(contents_or_file_name):
    """Get the contents of a file.

    If the value passed in is a file name or file URI, return the
    contents. If not, or there is an error reading the file contents,
    return the value passed in as the contents.

    For example, a workflow definition will be returned if either the
    workflow definition file name, or file URI are passed in, or the
    actual workflow definition itself is passed in.
    """
    try:
        if parse.urlparse(contents_or_file_name).scheme:
            definition_url = contents_or_file_name
        else:
            path = os.path.abspath(contents_or_file_name)
            definition_url = parse.urljoin(
                'file:',
                request.pathname2url(path)
            )
        return request.urlopen(definition_url).read().decode('utf8')
    except Exception:
        return contents_or_file_name
项目:deb-oslo.vmware    作者:openstack    | 项目源码 | 文件源码
def test_get_pbm_wsdl_location(self):
        wsdl = pbm.get_pbm_wsdl_location(None)
        self.assertIsNone(wsdl)

        def expected_wsdl(version):
            driver_abs_dir = os.path.abspath(os.path.dirname(pbm.__file__))
            path = os.path.join(driver_abs_dir, 'wsdl', version,
                                'pbmService.wsdl')
            return urlparse.urljoin('file:', urllib.pathname2url(path))

        with mock.patch('os.path.exists') as path_exists:
            path_exists.return_value = True
            wsdl = pbm.get_pbm_wsdl_location('5')
            self.assertEqual(expected_wsdl('5'), wsdl)
            wsdl = pbm.get_pbm_wsdl_location('5.5')
            self.assertEqual(expected_wsdl('5.5'), wsdl)
            wsdl = pbm.get_pbm_wsdl_location('5.5.1')
            self.assertEqual(expected_wsdl('5.5'), wsdl)
            path_exists.return_value = False
            wsdl = pbm.get_pbm_wsdl_location('5.5')
            self.assertIsNone(wsdl)
项目:deb-oslo.vmware    作者:openstack    | 项目源码 | 文件源码
def get_pbm_wsdl_location(vc_version):
    """Return PBM WSDL file location corresponding to VC version.

    :param vc_version: a dot-separated version string. For example, "1.2".
    :return: the pbm wsdl file location.
    """
    if not vc_version:
        return
    ver = vc_version.split('.')
    major_minor = ver[0]
    if len(ver) >= 2:
        major_minor = '%s.%s' % (major_minor, ver[1])
    curr_dir = os.path.abspath(os.path.dirname(__file__))
    pbm_service_wsdl = os.path.join(curr_dir, 'wsdl', major_minor,
                                    'pbmService.wsdl')
    if not os.path.exists(pbm_service_wsdl):
        LOG.warning(_LW("PBM WSDL file %s not found."), pbm_service_wsdl)
        return
    pbm_wsdl = urlparse.urljoin('file:', urllib.pathname2url(pbm_service_wsdl))
    LOG.debug("Using PBM WSDL location: %s.", pbm_wsdl)
    return pbm_wsdl
项目:http-prompt    作者:eliangcs    | 项目源码 | 文件源码
def normalize_url(ctx, param, value):
    if value:
        if not re.search(r'^\w+://', value):
            value = 'file:' + pathname2url(os.path.abspath(value))
        return value
    return None
项目:python-zunclient    作者:openstack    | 项目源码 | 文件源码
def normalise_file_path_to_url(path):
    if parse.urlparse(path).scheme:
        return path
    path = os.path.abspath(path)
    return parse.urljoin('file:', request.pathname2url(path))
项目:eclcli    作者:nttcom    | 项目源码 | 文件源码
def normalise_file_path_to_url(path):
    if parse.urlparse(path).scheme:
        return path
    path = os.path.abspath(path)
    return parse.urljoin('file:', request.pathname2url(path))
项目:solaris-ips    作者:oracle    | 项目源码 | 文件源码
def get_repo_url(self):
                return urlunparse(("file", "", pathname2url(
                    self.__dir), "", "", ""))