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


Python request.pathname2url方法代码示例

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


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

示例1: get_swagger_spec

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def get_swagger_spec(settings):
    """Return a :class:`bravado_core.spec.Spec` constructed from
    the swagger specs in `pyramid_swagger.schema_directory`. If
    `pyramid_swagger.enable_swagger_spec_validation` is enabled the schema
    will be validated before returning it.

    :param settings: a pyramid registry settings with configuration for
        building a swagger schema
    :type settings: dict
    :rtype: :class:`bravado_core.spec.Spec`
    """
    schema_dir = settings.get('pyramid_swagger.schema_directory', 'api_docs/')
    schema_filename = settings.get('pyramid_swagger.schema_file',
                                   'swagger.json')
    schema_path = os.path.join(schema_dir, schema_filename)
    schema_url = urlparse.urljoin('file:', pathname2url(os.path.abspath(schema_path)))

    handlers = build_http_handlers(None)  # don't need http_client for file:
    file_handler = handlers['file']
    spec_dict = file_handler(schema_url)

    return Spec.from_dict(
        spec_dict,
        config=create_bravado_core_config(settings),
        origin_url=schema_url) 
开发者ID:striglia,项目名称:pyramid_swagger,代码行数:27,代码来源:ingest.py

示例2: validate_swagger_schema

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def validate_swagger_schema(schema_dir, resource_listing):
    """Validate the structure of Swagger schemas against the spec.

    **Valid only for Swagger v1.2 spec**

    Note: It is possible that resource_listing is not present in
    the schema_dir. The path is passed in the call so that ssv
    can fetch the api-declaration files from the path.

    :param resource_listing: Swagger Spec v1.2 resource listing
    :type resource_listing: dict
    :param schema_dir: A path to Swagger spec directory
    :type schema_dir: string
    :raises: :py:class:`swagger_spec_validator.SwaggerValidationError`
    """
    schema_filepath = os.path.join(schema_dir, API_DOCS_FILENAME)
    swagger_spec_validator.validator12.validate_spec(
        resource_listing,
        urlparse.urljoin('file:', pathname2url(os.path.abspath(schema_filepath))),
    ) 
开发者ID:striglia,项目名称:pyramid_swagger,代码行数:22,代码来源:spec.py

示例3: make_veto_table

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def make_veto_table(workflow, out_dir, vetodef_file=None, tags=None):
    """ Creates a node in the workflow for writing the veto_definer
    table. Returns a File instances for the output file.
    """
    if vetodef_file is None:
        if not workflow.cp.has_option_tags("workflow-segments",
                                           "segments-veto-definer-file", []):
            return None
        vetodef_file = workflow.cp.get_opt_tags("workflow-segments",
                                           "segments-veto-definer-file", [])
        file_url = urljoin('file:', pathname2url(vetodef_file))
        vdf_file = File(workflow.ifos, 'VETO_DEFINER',
                        workflow.analysis_time, file_url=file_url)
        vdf_file.PFN(file_url, site='local')
    else:
        vdf_file = vetodef_file

    if tags is None: tags = []
    makedir(out_dir)
    node = PlotExecutable(workflow.cp, 'page_vetotable', ifos=workflow.ifos,
                    out_dir=out_dir, tags=tags).create_node()
    node.add_input_opt('--veto-definer-file', vdf_file)
    node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file')
    workflow += node
    return node.output_files[0] 
开发者ID:gwastro,项目名称:pycbc,代码行数:27,代码来源:plotting.py

示例4: space_path2url

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def space_path2url(path):
    at_path = str(path)
    if " " not in at_path:
        return at_path
    return urljoin("file:", pathname2url(os.path.abspath(at_path))) 
开发者ID:tox-dev,项目名称:tox,代码行数:7,代码来源:test_provision.py

示例5: normalise_file_path_to_url

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
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)) 
开发者ID:nttcom,项目名称:eclcli,代码行数:7,代码来源:utils.py

示例6: path_to_file_uri

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def path_to_file_uri(path):
    """Convert local filesystem path to legal File URIs as described in:
    http://en.wikipedia.org/wiki/File_URI_scheme
    """
    x = pathname2url(os.path.abspath(path))
    if os.name == 'nt':
        x = x.replace('|', ':') # http://bugs.python.org/issue5861
    return 'file:///%s' % x.lstrip('/') 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:10,代码来源:url.py

示例7: fixture_uri

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def fixture_uri(path):
    base = os.path.join(fixtures_dir, path)
    base_uri = 'file://' + pathname2url(base)
    with open(base, 'r') as fh:
        return json.load(fh), base_uri 
开发者ID:pudo-attic,项目名称:jsonmapping,代码行数:7,代码来源:util.py

示例8: _build_swagger_20_schema_views

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def _build_swagger_20_schema_views(config):
    spec = config.registry.settings['pyramid_swagger.schema20']

    walker = NodeWalkerForRefFiles()
    all_files = walker.walk(spec)

    file_map = {}

    def view_for_swagger_schema(request):
        _, ext = os.path.splitext(request.path)
        ext = ext.lstrip('.')

        base_path = config.registry.settings\
            .get('pyramid_swagger.base_path_api_docs', '').rstrip('/')

        key_path = request.path_info[len(base_path):]

        actual_fname = file_map[key_path]

        with spec.resolver.resolving(actual_fname) as spec_dict:
            clean_response = strip_xscope(spec_dict)
            ref_walker = NodeWalkerForCleaningRefs()
            fixed_spec = ref_walker.walk(clean_response, ext)
            return fixed_spec

    for ref_fname in all_files:
        ref_fname_parts = os.path.splitext(pathname2url(ref_fname))
        for schema_format in ['yaml', 'json']:
            route_name = 'pyramid_swagger.swagger20.api_docs.{0}.{1}'\
                .format(ref_fname.replace('/', '.'), schema_format)
            path = '/{0}.{1}'.format(ref_fname_parts[0], schema_format)
            file_map[path] = ref_fname
            yield PyramidEndpoint(
                path=path,
                route_name=route_name,
                view=view_for_swagger_schema,
                renderer=schema_format,
            ) 
开发者ID:striglia,项目名称:pyramid_swagger,代码行数:40,代码来源:api.py

示例9: test_data_utils

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def test_data_utils(in_tmpdir):
    """Tests get_file from a url, plus extraction and validation.
    """
    dirname = 'data_utils'

    with open('test.txt', 'w') as text_file:
        text_file.write('Float like a butterfly, sting like a bee.')

    with tarfile.open('test.tar.gz', 'w:gz') as tar_file:
        tar_file.add('test.txt')

    with zipfile.ZipFile('test.zip', 'w') as zip_file:
        zip_file.write('test.txt')

    origin = urljoin('file://', pathname2url(os.path.abspath('test.tar.gz')))

    path = get_file(dirname, origin, untar=True)
    filepath = path + '.tar.gz'
    hashval_sha256 = _hash_file(filepath)
    hashval_md5 = _hash_file(filepath, algorithm='md5')
    path = get_file(dirname, origin, md5_hash=hashval_md5, untar=True)
    path = get_file(filepath, origin, file_hash=hashval_sha256, extract=True)
    assert os.path.exists(filepath)
    assert validate_file(filepath, hashval_sha256)
    assert validate_file(filepath, hashval_md5)
    os.remove(filepath)
    os.remove('test.tar.gz')

    origin = urljoin('file://', pathname2url(os.path.abspath('test.zip')))

    hashval_sha256 = _hash_file('test.zip')
    hashval_md5 = _hash_file('test.zip', algorithm='md5')
    path = get_file(dirname, origin, md5_hash=hashval_md5, extract=True)
    path = get_file(dirname, origin, file_hash=hashval_sha256, extract=True)
    assert os.path.exists(path)
    assert validate_file(path, hashval_sha256)
    assert validate_file(path, hashval_md5)

    os.remove(path)
    os.remove('test.txt')
    os.remove('test.zip') 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:43,代码来源:data_utils_test.py

示例10: relative_path_to_artifact_path

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def relative_path_to_artifact_path(path):
    if os.path == posixpath:
        return path
    if os.path.abspath(path) == path:
        raise Exception("This method only works with relative paths.")
    return unquote(pathname2url(path)) 
开发者ID:mlflow,项目名称:mlflow,代码行数:8,代码来源:file_utils.py

示例11: path_to_local_file_uri

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def path_to_local_file_uri(path):
    """
    Convert local filesystem path to local file uri.
    """
    path = pathname2url(path)
    if path == posixpath.abspath(path):
        return "file://{path}".format(path=path)
    else:
        return "file:{path}".format(path=path) 
开发者ID:mlflow,项目名称:mlflow,代码行数:11,代码来源:file_utils.py

示例12: path_to_local_sqlite_uri

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def path_to_local_sqlite_uri(path):
    """
    Convert local filesystem path to sqlite uri.
    """
    path = posixpath.abspath(pathname2url(os.path.abspath(path)))
    prefix = "sqlite://" if sys.platform == "win32" else "sqlite:///"
    return prefix + path 
开发者ID:mlflow,项目名称:mlflow,代码行数:9,代码来源:file_utils.py

示例13: normalize_url

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
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 
开发者ID:eliangcs,项目名称:http-prompt,代码行数:8,代码来源:cli.py

示例14: get_openapi_schema

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def get_openapi_schema(version):
    path = 'resources/schemas/v{0}/schema.json'.format(version)
    path_resource = resource_filename('openapi_spec_validator', path)
    path_full = os.path.join(os.path.dirname(__file__), path_resource)
    schema = read_yaml_file(path_full)
    schema_url = parse.urljoin('file:', request.pathname2url(path_full))
    return schema, schema_url 
开发者ID:p1c2u,项目名称:openapi-spec-validator,代码行数:9,代码来源:schemas.py

示例15: get_ipn_sky_files

# 需要导入模块: from six.moves.urllib import request [as 别名]
# 或者: from six.moves.urllib.request import pathname2url [as 别名]
def get_ipn_sky_files(workflow, file_url, tags=None):
    '''
    Retreive the sky point files for searching over the IPN error box and
    populating it with injections.

    Parameters
    ----------
    workflow: pycbc.workflow.core.Workflow
        An instanced class that manages the constructed workflow.
    file_url : string
        The URL of the IPN sky points file.
    tags : list of strings
        If given these tags are used to uniquely name and identify output files
        that would be produced in multiple calls to this function.

    Returns
    --------
    sky_points_file : pycbc.workflow.core.File
        File object representing the IPN sky points file.
    '''
    tags = tags or []
    ipn_sky_points = resolve_url(file_url)
    sky_points_url = urljoin("file:", pathname2url(ipn_sky_points))
    sky_points_file = File(workflow.ifos, "IPN_SKY_POINTS",
            workflow.analysis_time, file_url=sky_points_url, tags=tags)
    sky_points_file.PFN(sky_points_url, site="local")

    return sky_points_file 
开发者ID:gwastro,项目名称:pycbc,代码行数:30,代码来源:grb_utils.py


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