Exemplo n.º 1
0
 def getCanonicalQueryString(self, args_path):
     canonMap = {}
     for key, value in args_path.items():
         canonMap[key] = value
     cannoList = sorted(canonMap.items(), key=lambda d: d[0])
     queryStr = ''
     i = 0
     for val in cannoList:
         if i != 0:
             queryStr += '&'
         queryStr += '%s=%s'%(common_util.encode_item(val[0], ' ,:?&%'), common_util.encode_item(val[1], ' ,:?&%')) #v4签名value必须转移'/'
         i = 1
     return queryStr
Exemplo n.º 2
0
    def __make_canonicalstring(self,
                               method,
                               bucket_name,
                               key,
                               path_args,
                               headers,
                               expires=None):

        str_list = []
        str_list.append(method + '\n')

        interesting_headers = {}
        content_list = ['content-type', 'content-md5', 'date']
        if isinstance(headers, dict):
            for hash_key in headers.keys():
                lk = hash_key.lower()

                if lk in content_list or lk.startswith(
                        common_util.AMAZON_HEADER_PREFIX):
                    s = headers.get(hash_key)
                    interesting_headers[lk] = ''.join(s)

        keylist = interesting_headers.keys()

        if common_util.ALTERNATIVE_DATE_HEADER in keylist:
            interesting_headers.setdefault('date', '')

        if expires:
            interesting_headers['date'] = expires

        if 'content-type' not in keylist:
            interesting_headers['content-type'] = ''

        if 'content-md5' not in keylist:
            interesting_headers['content-md5'] = ''

        keylist = sorted(interesting_headers.keys())

        for k in keylist:
            header_key = str(k)
            if header_key.startswith(common_util.AMAZON_HEADER_PREFIX):
                str_list.append(header_key + ':' +
                                interesting_headers[header_key])
            else:
                str_list.append(interesting_headers[header_key])
            str_list.append('\n')

        URI = ''
        if bucket_name is not None and bucket_name != '':
            URI += '/'
            URI += bucket_name
            if not self.path_style:
                URI += '/'

        if key is not None:
            if not URI.endswith('/'):
                URI += '/'
            URI += common_util.encode_object_key(key)

        if URI:
            str_list.append(URI)
        else:
            str_list.append('/')

        if path_args:
            e1 = '?'
            e2 = '&'
            canonMap = {}
            for _key, value in path_args.items():
                canonMap[_key] = value
            cannoList = sorted(canonMap.items(), key=lambda d: d[0])
            for val in cannoList:
                path_key, path_value = val[0], val[1]
                flag = True
                if path_key.lower(
                ) not in common_util.ALLOWED_RESOURCE_PARAMTER_NAMES:
                    flag = False
                if flag:
                    path_key = common_util.encode_item(
                        common_util.toString(path_key), ' ,:?&%')
                    if path_value is None:
                        e1 += path_key + '&'
                        continue
                    e2 += path_key + '=' + common_util.toString(
                        path_value) + '&'
            e = (e1 + e2).replace('&&', '&').replace('?&', '?')[:-1]
            str_list.append(e)
        return ''.join(str_list)