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