Python six.moves.urllib_parse.parse_qs() Examples
The following are 12
code examples of six.moves.urllib_parse.parse_qs().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
six.moves.urllib_parse
, or try the search function
.
Example #1
Source File: vk.py From script.module.urlresolver with GNU General Public License v2.0 | 6 votes |
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')
Example #2
Source File: vk.py From script.module.resolveurl with GNU General Public License v2.0 | 6 votes |
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')
Example #3
Source File: http.py From flex with MIT License | 5 votes |
def query_data(self): return urlparse.parse_qs(self.query)
Example #4
Source File: kodi.py From script.module.urlresolver with GNU General Public License v2.0 | 5 votes |
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
Example #5
Source File: parse_url.py From gdown with MIT License | 5 votes |
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
Example #6
Source File: test_upload.py From google-resumable-media-python with Apache License 2.0 | 5 votes |
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
Example #7
Source File: kodi.py From script.module.resolveurl with GNU General Public License v2.0 | 5 votes |
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
Example #8
Source File: base_api_test.py From apitools with Apache License 2.0 | 5 votes |
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)
Example #9
Source File: tar.py From treadmill with Apache License 2.0 | 5 votes |
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)
Example #10
Source File: test_file.py From jarvis with GNU General Public License v2.0 | 5 votes |
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)
Example #11
Source File: server.py From git-stacktrace with Apache License 2.0 | 5 votes |
def from_qs(query_string): return Args(parse_qs(query_string.lstrip('?')))
Example #12
Source File: Public.py From NSC_BUILDER with MIT License | 4 votes |
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