def test_normalize_string(self): """test_normalize_string""" self.assertEqual(b"www.baidu.com", utils.normalize_string("www.baidu.com")) self.assertEqual(b"www.bai%5E%26%2A.com", utils.normalize_string("www.bai^&*.com")) self.assertEqual(b"www.baidu.com", utils.normalize_string("www.baidu.com", True))
def _get_canonical_headers(headers, headers_to_sign=None): headers = headers or {} if headers_to_sign is None or len(headers_to_sign) == 0: headers_to_sign = set( [b"host", b"content-md5", b"content-length", b"content-type"]) result = [] for k in headers: k_lower = k.strip().lower() value = utils.convert_to_standard_string(headers[k]).strip() if k_lower.startswith(http_headers.BCE_PREFIX) \ or k_lower in headers_to_sign: str_tmp = b"%s:%s" % (utils.normalize_string(k_lower), utils.normalize_string(value)) result.append(str_tmp) result.sort() return (b'\n').join(result)
def _get_canonical_headers(headers, headers_to_sign=None): headers = headers or {} if headers_to_sign is None or len(headers_to_sign) == 0: headers_to_sign = set(["host", "content-md5", "content-length", "content-type"]) result = [] for k in headers: k_lower = k.strip().lower() value = str(headers[k]).strip() if k_lower.startswith(http_headers.BCE_PREFIX) \ or k_lower in headers_to_sign: str_tmp = "%s:%s" % (utils.normalize_string(k_lower), utils.normalize_string(value)) result.append(str_tmp) result.sort() return '\n'.join(result)
def _get_canonical_headers(headers, headers_to_sign=None): headers = headers or {} if headers_to_sign is None or len(headers_to_sign) == 0: headers_to_sign = set( ["host", "content-md5", "content-length", "content-type"]) result = [] for k in headers: k_lower = k.strip().lower() value = '' if isinstance(headers[k], bytes): value = headers[k].decode(baidubce.DEFAULT_ENCODING).strip() else: value = str(headers[k]).strip() if k_lower.startswith(http_headers.BCE_PREFIX) \ or k_lower in headers_to_sign: str_tmp = "%s:%s" % (utils.normalize_string(k_lower), utils.normalize_string(value)) result.append(str_tmp) result.sort() return '\n'.join(result)
def copy_object(self, source_bucket_name, source_key, target_bucket_name, target_key, etag=None, content_type=None, user_metadata=None, storage_class=storage_class.STANDARD, config=None): """ Copy one object to another object :type source_bucket: string :param source_bucket: None :type source_key: string :param source_key: None :type target_bucket: string :param target_bucket: None :type target_key: string :param target_key: None :return: **HttpResponse Class** """ headers = self._prepare_object_headers(content_type=content_type, user_metadata=user_metadata, storage_class=storage_class) headers[http_headers.BCE_COPY_SOURCE] = utils.normalize_string( '/%s/%s' % (source_bucket_name, source_key), False) if etag is not None: headers[http_headers.BCE_COPY_SOURCE_IF_MATCH] = etag if user_metadata is not None: headers[http_headers.BCE_COPY_METADATA_DIRECTIVE] = 'replace' else: headers[http_headers.BCE_COPY_METADATA_DIRECTIVE] = 'copy' return self._send_request( http_methods.PUT, target_bucket_name, target_key, headers=headers, config=config, body_parser=bos_handler.parse_copy_object_response)
def copy_object(self, source_bucket_name, source_key, target_bucket_name, target_key, etag=None, content_type=None, user_metadata=None, config=None): """ Copy one object to another object :type source_bucket: string :param source_bucket: None :type source_key: string :param source_key: None :type target_bucket: string :param target_bucket: None :type target_key: string :param target_key: None :return: **HttpResponse Class** """ headers = self._prepare_object_headers( content_type=content_type, user_metadata=user_metadata) headers[http_headers.BCE_COPY_SOURCE] = utils.normalize_string( '/%s/%s' % (source_bucket_name, source_key), False) if etag is not None: headers[http_headers.BCE_COPY_SOURCE_IF_MATCH] = etag if user_metadata is not None: headers[http_headers.BCE_COPY_METADATA_DIRECTIVE] = 'replace' else: headers[http_headers.BCE_COPY_METADATA_DIRECTIVE] = 'copy' return self._send_request( http_methods.PUT, target_bucket_name, target_key, headers=headers, config=config)