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


Python urllib_parse.parse_qs方法代码示例

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


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

示例1: get_media_url

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import parse_qs [as 别名]
def get_media_url(self, host, media_id):
        headers = {'User-Agent': common.EDGE_USER_AGENT,
                   'Referer': 'https://vk.com/',
                   'Origin': 'https://vk.com'}

        query = urllib_parse.parse_qs(media_id)

        try:
            oid, video_id = query['oid'][0], query['id'][0]
        except:
            oid, video_id = re.findall('(.*)_(.*)', media_id)[0]

        sources = self.__get_sources(oid, video_id)
        if sources:
            sources.sort(key=lambda x: int(x[0]), reverse=True)
            source = helpers.pick_source(sources)
            if source:
                return source + helpers.append_headers(headers)

        raise ResolverError('No video found') 
开发者ID:tvaddonsco,项目名称:script.module.urlresolver,代码行数:22,代码来源:vk.py

示例2: query_data

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import parse_qs [as 别名]
def query_data(self):
        return urlparse.parse_qs(self.query) 
开发者ID:pipermerriam,项目名称:flex,代码行数:4,代码来源:http.py

示例3: parse_query

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import parse_qs [as 别名]
def parse_query(query):
    q = {'mode': 'main'}
    if query.startswith('?'):
        query = query[1:]
    queries = urllib_parse.parse_qs(query)
    for key in queries:
        if len(queries[key]) == 1:
            q[key] = queries[key][0]
        else:
            q[key] = queries[key]
    return q 
开发者ID:tvaddonsco,项目名称:script.module.urlresolver,代码行数:13,代码来源:kodi.py

示例4: parse_url

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import parse_qs [as 别名]
def parse_url(url, warning=True):
    """Parse URLs especially for Google Drive links.

    file_id: ID of file on Google Drive.
    is_download_link: Flag if it is download link of Google Drive.
    """
    parsed = urllib_parse.urlparse(url)
    query = urllib_parse.parse_qs(parsed.query)
    is_gdrive = parsed.hostname == "drive.google.com"
    is_download_link = parsed.path.endswith("/uc")

    file_id = None
    if is_gdrive and "id" in query:
        file_ids = query["id"]
        if len(file_ids) == 1:
            file_id = file_ids[0]
    match = re.match(r"^/file/d/(.*?)/view$", parsed.path)
    if match:
        file_id = match.groups()[0]

    if is_gdrive and not is_download_link:
        warnings.warn(
            "You specified Google Drive Link but it is not the correct link "
            "to download the file. Maybe you should try: {url}".format(
                url="https://drive.google.com/uc?id={}".format(file_id)
            )
        )

    return file_id, is_download_link 
开发者ID:wkentaro,项目名称:gdown,代码行数:31,代码来源:parse_url.py

示例5: get_upload_id

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import parse_qs [as 别名]
def get_upload_id(upload_url):
    parse_result = urllib_parse.urlparse(upload_url)
    parsed_query = urllib_parse.parse_qs(parse_result.query)
    # NOTE: We are unpacking here, so asserting exactly one match.
    (upload_id,) = parsed_query[u"upload_id"]
    return upload_id 
开发者ID:googleapis,项目名称:google-resumable-media-python,代码行数:8,代码来源:test_upload.py

示例6: testQueryRemapping

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import parse_qs [as 别名]
def testQueryRemapping(self):
        method_config = base_api.ApiMethodInfo(
            request_type_name='MessageWithRemappings',
            query_params=['remapped_field', 'enum_field'])
        request = MessageWithRemappings(
            str_field='foo', enum_field=MessageWithRemappings.AnEnum.value_one)
        http_request = FakeService().PrepareHttpRequest(method_config, request)
        result_params = urllib_parse.parse_qs(
            urllib_parse.urlparse(http_request.url).query)
        expected_params = {'enum_field': 'ONE%2FTWO', 'remapped_field': 'foo'}
        self.assertTrue(expected_params, result_params) 
开发者ID:google,项目名称:apitools,代码行数:13,代码来源:base_api_test.py

示例7: get

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import parse_qs [as 别名]
def get(self, url):
        images_dir = os.path.join(self.tm_env.images_dir, TAR_DIR)
        fs.mkdir_safe(images_dir)

        image = urllib_parse.urlparse(url)
        sha256 = urllib_parse.parse_qs(image.query).get('sha256', None)

        with tempfile.NamedTemporaryFile(dir=images_dir, delete=False,
                                         prefix='.tmp') as temp:
            if image.scheme == 'http':
                _download(url, temp)
            else:
                _copy(image.path, temp)

        if not tarfile.is_tarfile(temp.name):
            _LOGGER.error('File %r is not a tar file.', url)
            raise Exception('File {0} is not a tar file.'.format(url))

        new_sha256 = _sha256sum(temp.name)

        if sha256 is not None and sha256[0] != new_sha256:
            _LOGGER.error('Hash does not match %r - %r', sha256[0], new_sha256)
            raise Exception(
                'Hash of {0} does not match {1}.'.format(new_sha256, url))

        # TODO: rename tar file to sha256 to allow for caching.
        return TarImage(self.tm_env, temp.name) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:29,代码来源:tar.py

示例8: test_token_refresh_store_expired

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import parse_qs [as 别名]
def test_token_refresh_store_expired(self):
        expiration = (datetime.datetime.utcnow() -
                      datetime.timedelta(minutes=15))
        credentials = self._create_test_credentials(expiration=expiration)

        storage = file_module.Storage(FILENAME)
        storage.put(credentials)
        credentials = storage.get()
        new_cred = copy.copy(credentials)
        new_cred.access_token = 'bar'
        storage.put(new_cred)

        access_token = '1/3w'
        token_response = {'access_token': access_token, 'expires_in': 3600}
        response_content = json.dumps(token_response).encode('utf-8')
        http = http_mock.HttpMock(data=response_content)

        credentials._refresh(http)
        self.assertEquals(credentials.access_token, access_token)

        # Verify mocks.
        self.assertEqual(http.requests, 1)
        self.assertEqual(http.uri, credentials.token_uri)
        self.assertEqual(http.method, 'POST')
        expected_body = {
            'grant_type': ['refresh_token'],
            'client_id': [credentials.client_id],
            'client_secret': [credentials.client_secret],
            'refresh_token': [credentials.refresh_token],
        }
        self.assertEqual(urllib_parse.parse_qs(http.body), expected_body)
        expected_headers = {
            'content-type': 'application/x-www-form-urlencoded',
            'user-agent': credentials.user_agent,
        }
        self.assertEqual(http.headers, expected_headers) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:38,代码来源:test_file.py

示例9: from_qs

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import parse_qs [as 别名]
def from_qs(query_string):
        return Args(parse_qs(query_string.lstrip('?'))) 
开发者ID:pinterest,项目名称:git-stacktrace,代码行数:4,代码来源:server.py

示例10: parse_url

# 需要导入模块: from six.moves import urllib_parse [as 别名]
# 或者: from six.moves.urllib_parse import parse_qs [as 别名]
def parse_url(url, warning=True):
	"""Parse URLs especially for Google Drive links.
	file_id: ID of file on Google Drive.  
	is_download_link: Flag if it is download link of Google Drive.
	"""
	# test=url.split('drive')
	# print(test)
	# if len(test)>1:
		# url='https://drive.{}'.format(test[1])
	# print(url)	
	parsed = urllib_parse.urlparse(url)
	query = urllib_parse.parse_qs(parsed.query)
	is_gdrive = parsed.hostname == 'drive.google.com'
	is_download_link = parsed.path.endswith('/uc')
	if is_download_link == False:
		is_download_link = parsed.path.endswith('/view')
	if is_download_link == False:
		is_download_link = parsed.path.endswith('/edit')
	if is_download_link == False:
		is_download_link = parsed.path.endswith('/view?usp=drivesdk')
		
	file_id = None
	if is_gdrive and 'id' in query:
		file_ids = query['id']
		if len(file_ids) == 1:
			file_id = file_ids[0]
	match = re.match(r'^/file/d/(.*?)/view$', parsed.path)
	if not match:
		match = re.match(r'^/file/d/(.*?)/edit$', parsed.path)	
	if match:
		file_id = match.groups()[0]
		
	if is_gdrive and not is_download_link:
		if url.startswith('https://drive.google.com/open?id='):
			url=url.replace('https://drive.google.com/open?id=','')	
		if '/' in url:
			url=url.split('/')
			file_id=url[0]
		else:
			file_id=url
		is_download_link=True
	
	if is_gdrive and not is_download_link:
		warnings.warn(
			'You specified Google Drive Link but it is not the correct link '
			"to download the file. Maybe you should try: {url}".format(url='https://drive.google.com/uc?id={}'.format(file_id))
		)
	return file_id, is_download_link 
开发者ID:julesontheroad,项目名称:NSC_BUILDER,代码行数:50,代码来源:Public.py


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