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