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'%(util.encode_item(val[0], '/'), util.encode_item(val[1], '')) i = 1 return queryStr
def __make_canonical_string(self, method, bucket_name, key, path_args, headers, expires=None): interesting_headers = self.__make_canonicalstring_interesting_headers( headers, expires) key_list = sorted(interesting_headers.keys()) str_list = self.__make_canonicalstring_str_list( key_list, method, interesting_headers) URI = '' _bucket_name = self.server if self.is_cname else bucket_name if _bucket_name: URI += '/' URI += _bucket_name if not self.path_style or self.is_cname: URI += '/' if key: if not URI.endswith('/'): URI += '/' URI += util.encode_object_key(key) if URI: str_list.append(URI) else: str_list.append('/') if path_args: e = '?' cannoList = sorted(path_args.items(), key=lambda d: d[0]) for path_key, path_value in cannoList: if path_key.lower( ) in const.ALLOWED_RESOURCE_PARAMTER_NAMES or path_key.lower( ).startswith(self.ha._get_header_prefix()): path_key = util.encode_item(path_key, '/') if path_value is None: e += path_key + '&' continue e += path_key + '=' + util.to_string(path_value) + '&' e = e[:-1] str_list.append(e) return ''.join(str_list)
def __make_canonicalstring(self, method, bucket_name, key, path_args, headers, expires=None): str_list = [] str_list.append(method + '\n') interesting_headers = {} if isinstance(headers, dict): for hash_key in headers.keys(): lk = hash_key.lower() if lk in const.CONTENT_LIST or lk.startswith( self.ha._get_header_prefix()): s = headers.get(hash_key) interesting_headers[lk] = ''.join(s) keylist = interesting_headers.keys() if self.ha.date_header() in keylist: interesting_headers[const.DATE_HEADER.lower()] = '' if expires: interesting_headers[const.DATE_HEADER.lower()] = expires if const.CONTENT_TYPE_HEADER.lower() not in keylist: interesting_headers[const.CONTENT_TYPE_HEADER.lower()] = '' if const.CONTENT_MD5_HEADER.lower() not in keylist: interesting_headers[const.CONTENT_MD5_HEADER.lower()] = '' keylist = sorted(interesting_headers.keys()) for k in keylist: header_key = util.to_string(k) val = '' if interesting_headers[ header_key] is None else interesting_headers[header_key] if header_key.startswith(self.ha._get_meta_header_prefix()): str_list.append(header_key + ':' + util.to_string(val).strip()) elif header_key.startswith(self.ha._get_header_prefix()): str_list.append(header_key + ':' + val) else: str_list.append(val) str_list.append('\n') URI = '' _bucket_name = self.server if self.is_cname else bucket_name if _bucket_name: URI += '/' URI += _bucket_name if not self.path_style or self.is_cname: URI += '/' if key: if not URI.endswith('/'): URI += '/' URI += util.encode_object_key(key) if URI: str_list.append(URI) else: str_list.append('/') if path_args: e1 = '?' e2 = '&' cannoList = sorted(path_args.items(), key=lambda d: d[0]) for path_key, path_value in cannoList: if path_key.lower( ) in const.ALLOWED_RESOURCE_PARAMTER_NAMES or path_key.lower( ).startswith(self.ha._get_header_prefix()): path_key = util.encode_item(path_key, '/') if path_value is None: e1 += path_key + '&' continue e2 += path_key + '=' + util.to_string(path_value) + '&' e = (e1 + e2).replace('&&', '&').replace('?&', '?')[:-1] str_list.append(e) return ''.join(str_list)