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


Python request.pathname2url方法代码示例

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


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

示例1: file_path_to_url

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request 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

示例2: build_resources

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request 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

示例3: relpathA2B

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import pathname2url [as 别名]
def relpathA2B(self,A,B):
        """Return a relative pathname to get from file A to B"""
        retval = ''
        A = os.path.abspath(A)
        B = os.path.abspath(B)
        cp = os.path.split(os.path.commonprefix([A,B]))[0]
        if cp == '':
            #raise NameError('Unable to construct a relative path from ' + \
            #    A + ' to ' + B)
            # As Heinz indicates this can happen on M$ with driveletters, so
            # return absolute path to B, hopefully that works.
            return 'file:' + pathname2url(B)
        a = os.path.dirname(A)
        while a != cp:
            retval += "../"
            a = os.path.dirname(a)
        rv = os.path.basename(B)
        b = os.path.dirname(B)
        while b != cp:
            rv = os.path.basename(b) + '/' + rv
            b = os.path.dirname(b)
        return retval + rv 
开发者ID:gramps-project,项目名称:addons-source,代码行数:24,代码来源:DenominoViso.py

示例4: get_contents_if_file

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

示例5: test_update_with_file_uri

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import pathname2url [as 别名]
def test_update_with_file_uri(self):
        self.requests_mock.put(self.TEST_URL + URL_TEMPLATE_SCOPE,
                               json={'workflows': [WORKFLOW]})

        # The contents of wf_v2.yaml must be identical to WF_DEF
        path = pkg.resource_filename(
            'mistralclient',
            'tests/unit/resources/wf_v2.yaml'
        )
        path = os.path.abspath(path)

        # Convert the file path to file URI
        uri = parse.urljoin('file:', request.pathname2url(path))

        wfs = self.workflows.update(uri)

        self.assertIsNotNone(wfs)
        self.assertEqual(WF_DEF, wfs[0].definition)

        last_request = self.requests_mock.last_request

        self.assertEqual(WF_DEF, last_request.text)
        self.assertEqual('text/plain', last_request.headers['content-type']) 
开发者ID:openstack,项目名称:python-mistralclient,代码行数:25,代码来源:test_workflows.py

示例6: test_create_with_file_uri

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import pathname2url [as 别名]
def test_create_with_file_uri(self):
        self.requests_mock.post(self.TEST_URL + URL_TEMPLATE,
                                json=WORKBOOK,
                                status_code=201)

        # The contents of wb_v2.yaml must be identical to WB_DEF
        path = pkg.resource_filename(
            'mistralclient',
            'tests/unit/resources/wb_v2.yaml'
        )
        path = os.path.abspath(path)

        # Convert the file path to file URI
        uri = parse.urljoin('file:', request.pathname2url(path))

        wb = self.workbooks.create(uri)

        self.assertIsNotNone(wb)
        self.assertEqual(WB_DEF, wb.definition)

        last_request = self.requests_mock.last_request

        self.assertEqual(WB_DEF, last_request.text)
        self.assertEqual('text/plain', last_request.headers['content-type']) 
开发者ID:openstack,项目名称:python-mistralclient,代码行数:26,代码来源:test_workbooks.py

示例7: test_update_with_file_uri

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import pathname2url [as 别名]
def test_update_with_file_uri(self):
        self.requests_mock.put(self.TEST_URL + URL_TEMPLATE,
                               json={'actions': [ACTION]})

        # The contents of action_v2.yaml must be identical to ACTION_DEF
        path = pkg.resource_filename(
            'mistralclient',
            'tests/unit/resources/action_v2.yaml'
        )
        path = os.path.abspath(path)

        # Convert the file path to file URI
        uri = parse.urljoin('file:', request.pathname2url(path))

        actions = self.actions.update(uri)

        self.assertIsNotNone(actions)
        self.assertEqual(ACTION_DEF, actions[0].definition)

        last_request = self.requests_mock.last_request
        self.assertEqual('scope=private', last_request.query)
        self.assertEqual('text/plain', last_request.headers['content-type'])
        self.assertEqual(ACTION_DEF, last_request.text) 
开发者ID:openstack,项目名称:python-mistralclient,代码行数:25,代码来源:test_actions.py

示例8: setUp

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import pathname2url [as 别名]
def setUp(self):
        self.vectors_cache_dir = '.cache'
        if os.path.exists(self.vectors_cache_dir):
            shutil.rmtree(self.vectors_cache_dir)

        self.data_cache_path = os.path.join(test_dir_path, 'test_datasets',
            'train_cache.pth')
        if os.path.exists(self.data_cache_path):
            os.remove(self.data_cache_path)

        vec_dir = os.path.abspath(os.path.join(test_dir_path, 'test_datasets'))
        filename = 'fasttext_sample.vec.zip'
        url_base = urljoin('file:', pathname2url(vec_dir)) + os.path.sep
        ft = FastText(filename, url_base=url_base, cache=self.vectors_cache_dir)

        self.train, self.valid, self.test = process(
            path=os.path.join(test_dir_path, 'test_datasets'),
            cache='train_cache.pth',
            train='test_train.csv',
            validation='test_valid.csv',
            test='test_test.csv',
            embeddings=ft,
            embeddings_cache_path='',
            ignore_columns=('left_id', 'right_id')) 
开发者ID:anhaidgroup,项目名称:deepmatcher,代码行数:26,代码来源:test_integration.py

示例9: test_extend_vocab_1

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import pathname2url [as 别名]
def test_extend_vocab_1(self):
        vectors_cache_dir = '.cache'
        if os.path.exists(vectors_cache_dir):
            shutil.rmtree(vectors_cache_dir)

        mf = MatchingField()
        lf = MatchingField(id=True, sequential=False)
        fields = [('id', lf), ('left_a', mf), ('right_a', mf), ('label', lf)]
        col_naming = {'id': 'id', 'label': 'label', 'left': 'left_', 'right': 'right_'}

        pathdir = os.path.abspath(os.path.join(test_dir_path, 'test_datasets'))
        filename = 'fasttext_sample.vec'
        file = os.path.join(pathdir, filename)
        url_base = urljoin('file:', pathname2url(file))
        vecs = Vectors(name=filename, cache=vectors_cache_dir, url=url_base)

        data_path = os.path.join(test_dir_path, 'test_datasets', 'sample_table_small.csv')
        md = MatchingDataset(fields, col_naming, path=data_path)

        mf.build_vocab()
        mf.vocab.vectors = torch.Tensor(len(mf.vocab.itos), 300)
        mf.extend_vocab(md, vectors=vecs)
        self.assertEqual(len(mf.vocab.itos), 6)
        self.assertEqual(mf.vocab.vectors.size(), torch.Size([6, 300])) 
开发者ID:anhaidgroup,项目名称:deepmatcher,代码行数:26,代码来源:test_field.py

示例10: test_extend_vectors_1

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import pathname2url [as 别名]
def test_extend_vectors_1(self):
        vectors_cache_dir = '.cache'
        if os.path.exists(vectors_cache_dir):
            shutil.rmtree(vectors_cache_dir)

        pathdir = os.path.abspath(os.path.join(test_dir_path, 'test_datasets'))
        filename = 'fasttext_sample.vec'
        file = os.path.join(pathdir, filename)
        url_base = urljoin('file:', pathname2url(file))
        vecs = Vectors(name=filename, cache=vectors_cache_dir, url=url_base)
        self.assertIsInstance(vecs, Vectors)

        vec_data = MatchingField._get_vector_data(vecs, vectors_cache_dir)
        v = MatchingVocab(Counter())
        v.vectors = torch.Tensor(1, vec_data[0].dim)
        v.unk_init = torch.Tensor.zero_
        tokens = {'hello', 'world'}
        v.extend_vectors(tokens, vec_data)
        self.assertEqual(len(v.itos), 4)
        self.assertEqual(v.vectors.size(), torch.Size([4, 300]))
        self.assertEqual(list(v.vectors[2][0:10]), [0.0] * 10)
        self.assertEqual(list(v.vectors[3][0:10]), [0.0] * 10)

        if os.path.exists(vectors_cache_dir):
            shutil.rmtree(vectors_cache_dir) 
开发者ID:anhaidgroup,项目名称:deepmatcher,代码行数:27,代码来源:test_field.py

示例11: get_pbm_wsdl_location

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import pathname2url [as 别名]
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("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 
开发者ID:openstack,项目名称:oslo.vmware,代码行数:23,代码来源:pbm.py

示例12: test_get_pbm_wsdl_location

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

示例13: encrypt

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import pathname2url [as 别名]
def encrypt(self, command):
        from Crypto.Util import Padding
        if not self._encryption_ready:
            return command
        if self._salt != "" and self.new_salt_needed():
            prev_salt = self._salt
            self._salt = self.genarate_salt()
            s = "nextSalt/{}/{}/{}\0".format(prev_salt, self._salt, command)
        else:
            if self._salt == "":
                self._salt = self.genarate_salt()
            s = "salt/{}/{}\0".format(self._salt, command)
        s = Padding.pad(bytes(s, "utf-8"), 16)
        aes_cipher = self.get_new_aes_chiper()
        encrypted = aes_cipher.encrypt(s)
        encoded = b64encode(encrypted)
        encoded_url = req.pathname2url(encoded.decode("utf-8"))
        return CMD_ENCRYPT_CMD + encoded_url 
开发者ID:JoDehli,项目名称:PyLoxone,代码行数:20,代码来源:__init__.py

示例14: file_path_to_url

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request 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)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:common.py

示例15: path2url

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


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