Example #1
0
 def _canonical_query_string_params(self, params):
     l = []
     for param in params:
         value = str(params[param])
         l.append('%s=%s' %
                  (quote(param, safe='-_.~'), quote(value, safe='-_.~')))
     l = sorted(l)
     cqs = '&'.join(l)
     return cqs
 def _canonical_query_string_params(self, params):
     l = []
     for param in params:
         value = str(params[param])
         l.append('%s=%s' % (quote(param, safe='-_.~'),
                             quote(value, safe='-_.~')))
     l = sorted(l)
     cqs = '&'.join(l)
     return cqs
Example #3
0
 def _canonical_query_string_url(self, parts):
     buf = ''
     if parts.query:
         qsa = parts.query.split('&')
         qsa = [a.split('=', 1) for a in qsa]
         quoted_qsa = []
         for q in qsa:
             if len(q) == 2:
                 quoted_qsa.append('%s=%s' % (quote(
                     q[0], safe='-_.~'), quote(unquote(q[1]), safe='-_.~')))
             elif len(q) == 1:
                 quoted_qsa.append('%s=' % quote(q[0], safe='-_.~'))
         if len(quoted_qsa) > 0:
             quoted_qsa.sort()
             buf += '&'.join(quoted_qsa)
     return buf
 def _canonical_query_string_url(self, parts):
     buf = ''
     if parts.query:
         qsa = parts.query.split('&')
         qsa = [a.split('=', 1) for a in qsa]
         quoted_qsa = []
         for q in qsa:
             if len(q) == 2:
                 quoted_qsa.append(
                     '%s=%s' % (quote(q[0], safe='-_.~'),
                                quote(unquote(q[1]), safe='-_.~')))
             elif len(q) == 1:
                 quoted_qsa.append('%s=' % quote(q[0], safe='-_.~'))
         if len(quoted_qsa) > 0:
             quoted_qsa.sort()
             buf += '&'.join(quoted_qsa)
     return buf
def percent_encode(input_str, safe=SAFE_CHARS):
    """Urlencodes a string.

    Whereas percent_encode_sequence handles taking a dict/sequence and
    producing a percent encoded string, this function deals only with
    taking a string (not a dict/sequence) and percent encoding it.

    """
    if not isinstance(input_str, string_types):
        input_str = text_type(input_str)
    return quote(text_type(input_str).encode('utf-8'), safe=safe)
Example #6
0
def percent_encode(input_str, safe=SAFE_CHARS):
    """Urlencodes a string.

    Whereas percent_encode_sequence handles taking a dict/sequence and
    producing a percent encoded string, this function deals only with
    taking a string (not a dict/sequence) and percent encoding it.

    """
    if not isinstance(input_str, string_types):
        input_str = text_type(input_str)
    return quote(text_type(input_str).encode('utf-8'), safe=safe)
Example #7
0
 def calc_signature(self, request, params):
     logger.debug("Calculating signature using v2 auth.")
     split = urlsplit(request.url)
     path = split.path
     if len(path) == 0:
         path = '/'
     string_to_sign = '%s\n%s\n%s\n' % (request.method, split.netloc, path)
     lhmac = hmac.new(self.credentials.secret_key.encode('utf-8'),
                      digestmod=sha256)
     pairs = []
     for key in sorted(params):
         value = six.text_type(params[key])
         pairs.append(
             quote(key.encode('utf-8'), safe='') + '=' +
             quote(value.encode('utf-8'), safe='-_~'))
     qs = '&'.join(pairs)
     string_to_sign += qs
     logger.debug('String to sign: %s', string_to_sign)
     lhmac.update(string_to_sign.encode('utf-8'))
     b64 = base64.b64encode(lhmac.digest()).strip().decode('utf-8')
     return (qs, b64)
 def calc_signature(self, request, params):
     logger.debug("Calculating signature using v2 auth.")
     split = urlsplit(request.url)
     path = split.path
     if len(path) == 0:
         path = '/'
     string_to_sign = '%s\n%s\n%s\n' % (request.method,
                                        split.netloc,
                                        path)
     lhmac = hmac.new(self.credentials.secret_key.encode('utf-8'),
                      digestmod=sha256)
     pairs = []
     for key in sorted(params):
         value = six.text_type(params[key])
         pairs.append(quote(key.encode('utf-8'), safe='') + '=' +
                      quote(value.encode('utf-8'), safe='-_~'))
     qs = '&'.join(pairs)
     string_to_sign += qs
     logger.debug('String to sign: %s', string_to_sign)
     lhmac.update(string_to_sign.encode('utf-8'))
     b64 = base64.b64encode(lhmac.digest()).strip().decode('utf-8')
     return (qs, b64)
 def _normalize_url_path(self, path):
     normalized_path = quote(normalize_url_path(path), safe='/~')
     return normalized_path
Example #10
0
def quote_source_header(params, **kwargs):
    if params['headers'] and 'x-amz-copy-source' in params['headers']:
        value = params['headers']['x-amz-copy-source']
        params['headers']['x-amz-copy-source'] = quote(value.encode('utf-8'),
                                                       '/~')
def quote_source_header(params, **kwargs):
    if params['headers'] and 'x-amz-copy-source' in params['headers']:
        value = params['headers']['x-amz-copy-source']
        params['headers']['x-amz-copy-source'] = quote(
            value.encode('utf-8'), '/~')
Example #12
0
 def _normalize_url_path(self, path):
     normalized_path = quote(normalize_url_path(path), safe='/~')
     return normalized_path