def test_default(self): target = S3ResultTarget(test_config.get_tmp_path('result.job')) target.aws_access_key_id = 'AWS_ACCESS_KEY_ID' target.aws_secret_access_key = 'AWS_SECRET_ACCESS_KEY' target.bucket = 'test-bucket' target.path = 'test-prefix/test.tsv' url = urlparse(target.get_result_url()) params = parse_qs(url.query) eq_(url.scheme, 's3') eq_(url.path, '/{0}/{1}'.format(target.bucket, target.path)) eq_(url_unquote(url.username), target.aws_access_key_id) eq_(url_unquote(url.password), target.aws_secret_access_key) eq_(params.get('format'), ['tsv'])
def test_default(self): target = TableauOnlineResultTarget(test_config.get_tmp_path('result.job')) target.username = '******' target.password = '******' target.datasource = 'test-datasource' url = urlparse(target.get_result_url()) params = parse_qs(url.query) eq_(url.scheme, 'tableau') eq_(url.hostname, 'online.tableausoftware.com') eq_(url.path, '/' + target.datasource) eq_(url_unquote(url.username), target.username) eq_(url_unquote(url.password), target.password) eq_(params['server_version'], ['online']) eq_(params['mode'], ['replace'])
def test_default(self): target = TableauOnlineResultTarget( test_config.get_tmp_path('result.job')) target.username = '******' target.password = '******' target.datasource = 'test-datasource' url = urlparse(target.get_result_url()) params = parse_qs(url.query) eq_(url.scheme, 'tableau') eq_(url.hostname, 'online.tableausoftware.com') eq_(url.path, '/' + target.datasource) eq_(url_unquote(url.username), target.username) eq_(url_unquote(url.password), target.password) eq_(params['server_version'], ['online']) eq_(params['mode'], ['replace'])
def test_default(self): target = TestTableauServerResultTarget(test_config.get_tmp_path('result.job')) target.datasource = 'test-datasource' url = urlparse(target.get_result_url()) params = parse_qs(url.query) eq_(url.scheme, 'tableau') eq_(url.hostname, 'tableau.example.com') eq_(url.path, '/' + target.datasource) eq_(url_unquote(url.username), TestTableauServerResultTarget.username) eq_(url_unquote(url.password), TestTableauServerResultTarget.password) eq_(params.get('ssl'), ['true']) eq_(params.get('ssl_verify'), ['true']) eq_(params.get('server_version'), None) eq_(params.get('site'), None) eq_(params.get('project'), None) eq_(params.get('mode'), ['replace'])
def access_key(self): """ The access key id used to sign the request. If the access key is not in the same credential scope as this request, an AttributeError exception is raised. """ credential = self.query_parameters.get(_x_amz_credential) if credential is not None: credential = url_unquote(credential[0]) else: credential = self.authorization_header_parameters.get(_credential) if credential is None: raise AttributeError( "Credential was not passed in the request") try: key, scope = credential.split("/", 1) except ValueError: raise AttributeError("Invalid request credential: %r" % credential) if scope != self.credential_scope: raise AttributeError("Incorrect credential scope: %r (wanted %r)" % (scope, self.credential_scope)) return key
def signed_headers(self): """ An ordered dictionary containing the signed header names and values. """ # See if the signed headers are listed in the query string signed_headers = self.query_parameters.get(_x_amz_signedheaders) if signed_headers is not None: signed_headers = url_unquote(signed_headers[0]) else: # Get this from the authentication header signed_headers = self.authorization_header_parameters[ _signedheaders] # Header names are separated by semicolons. parts = signed_headers.split(";") # Make sure the signed headers list is canonicalized. For security # reasons, we consider it an error if it isn't. canonicalized = sorted([sh.lower() for sh in parts]) if parts != canonicalized: raise AttributeError("SignedHeaders is not canonicalized: %r" % (signed_headers, )) # Allow iteration in-order. return OrderedDict([(header, self.headers[header]) for header in signed_headers.split(";")])
def signed_headers(self): """ An ordered dictionary containing the signed header names and values. """ # See if the signed headers are listed in the query string signed_headers = self.query_parameters.get(_x_amz_signedheaders) if signed_headers is not None: signed_headers = url_unquote(signed_headers[0]) else: # Get this from the authentication header signed_headers = self.authorization_header_parameters[ _signedheaders] # Header names are separated by semicolons. parts = signed_headers.split(";") # Make sure the signed headers list is canonicalized. For security # reasons, we consider it an error if it isn't. canonicalized = sorted([sh.lower() for sh in parts]) if parts != canonicalized: raise AttributeError("SignedHeaders is not canonicalized: %r" % (signed_headers,)) # Allow iteration in-order. return OrderedDict([(header, self.headers[header]) for header in signed_headers.split(";")])
def access_key(self): """ The access key id used to sign the request. If the access key is not in the same credential scope as this request, an AttributeError exception is raised. """ credential = self.query_parameters.get(_x_amz_credential) if credential is not None: credential = url_unquote(credential[0]) else: credential = self.authorization_header_parameters.get(_credential) if credential is None: raise AttributeError("Credential was not passed in the request") try: key, scope = credential.split("/", 1) except ValueError: raise AttributeError("Invalid request credential: %r" % credential) if scope != self.credential_scope: raise AttributeError("Incorrect credential scope: %r (wanted %r)" % (scope, self.credential_scope)) return key
def test_default(self): target = TestTableauServerResultTarget( test_config.get_tmp_path('result.job')) target.datasource = 'test-datasource' url = urlparse(target.get_result_url()) params = parse_qs(url.query) eq_(url.scheme, 'tableau') eq_(url.hostname, 'tableau.example.com') eq_(url.path, '/' + target.datasource) eq_(url_unquote(url.username), TestTableauServerResultTarget.username) eq_(url_unquote(url.password), TestTableauServerResultTarget.password) eq_(params.get('ssl'), ['true']) eq_(params.get('ssl_verify'), ['true']) eq_(params.get('server_version'), None) eq_(params.get('site'), None) eq_(params.get('project'), None) eq_(params.get('mode'), ['replace'])
def unquote(text): """Replace all percent-encoded entities in text.""" while '%' in text: newtext = url_unquote(text) if newtext == text: break text = newtext return text
def parse_name(value, safechar=True): path = fixurl(decode(value), unquote=False) url_p = urlparse(path.rstrip('/')) name = (url_p.path.split('/')[-1] or url_p.query.split('=', 1)[::-1][0].split('&', 1)[0] or url_p.netloc.split('.', 1)[0]) name = url_unquote(name) return safename(name) if safechar else name
def fixurl(url, unquote=None): old = url url = url_unquote(url) if unquote is None: unquote = url is old url = decode(url) try: url = smart_text(url, encoding='unicode-escape') except UnicodeDecodeError: pass url = html_unescape(url) url = re.sub(r'(?<!:)/{2,}', '/', url).strip().lstrip('.') if not unquote: url = url_quote(url) return url
def _get_parsed_url(url): # type: (S) -> Url """This is a stand-in function for `urllib3.util.parse_url` The orignal function doesn't handle special characters very well, this simply splits out the authentication section, creates the parsed url, then puts the authentication section back in, bypassing validation. :return: The new, parsed URL object :rtype: :class:`~urllib3.util.url.Url` """ try: parsed = urllib3_parse(url) except ValueError: scheme, _, url = url.partition("://") auth, _, url = url.rpartition("@") url = "{scheme}://{url}".format(scheme=scheme, url=url) parsed = urllib3_parse(url)._replace(auth=auth) if parsed.auth: return parsed._replace(auth=url_unquote(parsed.auth)) return parsed
def get_username(self, unquote=False): # type: (bool) -> str username = self.username if self.username else "" if username and unquote and self._username_is_quoted: username = url_unquote(username) return username
def get_password(self, unquote=False, include_token=True): # type: (bool, bool) -> str password = self.password if self.password else "" if password and unquote and self._password_is_quoted: password = url_unquote(password) return password