當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。