bce-python-sdk 0.9.64__py3-none-any.whl → 0.9.67__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
baidubce/__init__.py CHANGED
@@ -18,7 +18,7 @@ from builtins import bytes
18
18
  from . import protocol
19
19
 
20
20
 
21
- SDK_VERSION = b'0.9.64'
21
+ SDK_VERSION = b'0.9.67'
22
22
  DEFAULT_SERVICE_DOMAIN = b'bcebos.com'
23
23
  URL_PREFIX = b'/v1'
24
24
  DEFAULT_ENCODING = 'UTF-8'
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # Copyright 2014 Baidu, Inc.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
@@ -204,7 +204,7 @@ def send_request(
204
204
 
205
205
  conn = _get_connection(protocol, host, port, config.connection_timeout_in_mills,
206
206
  config.proxy_host, config.proxy_port)
207
- _logger.debug('request args:method=%s, uri=%s, headers=%s,patams=%s, body=%s',
207
+ _logger.debug('request args: method=%s, uri=%s, headers=%s, patams=%s, body=%s',
208
208
  http_method, uri, headers, params, body)
209
209
 
210
210
  http_response = _send_http_request(
@@ -56,6 +56,14 @@ BCE_ACL = b"x-bce-acl"
56
56
 
57
57
  BCE_CONTENT_SHA256 = b"x-bce-content-sha256"
58
58
 
59
+ BCE_CONTENT_CRC32 = b"x-bce-content-crc32"
60
+
61
+ BCE_CONTENT_CRC32C = b"x-bce-content-crc32c"
62
+
63
+ BCE_CONTENT_CRC32C_FLAG = b"x-bce-content-crc32c-flag"
64
+
65
+ BCE_CONTENT_CRC64ECMA = b"x-bce-content-crc64ecma"
66
+
59
67
  BCE_COPY_METADATA_DIRECTIVE = b"x-bce-metadata-directive"
60
68
 
61
69
  BCE_COPY_SOURCE = b"x-bce-copy-source"
@@ -48,6 +48,7 @@ from baidubce.services.bos import bos_handler
48
48
  from baidubce.services.bos import storage_class
49
49
  from baidubce.utils import required
50
50
  from baidubce import compat
51
+ import baidubce.protocol as Protocol
51
52
 
52
53
  _logger = logging.getLogger(__name__)
53
54
 
@@ -706,6 +707,8 @@ class BosClient(BceBaseClient):
706
707
  :return:
707
708
  **URL string**
708
709
  """
710
+ key = compat.convert_to_string(key)
711
+ key = (key or "").strip('/')
709
712
  key = compat.convert_to_bytes(key)
710
713
  if len(key) == 0 or key == b'v1':
711
714
  raise ValueError('generate url the key param error!')
@@ -716,7 +719,16 @@ class BosClient(BceBaseClient):
716
719
 
717
720
  # specified protocol in endpoint > protocal > default protocol in config
718
721
  if protocol is not None:
719
- config.protocol = protocol
722
+ if isinstance(protocol, str):
723
+ p = protocol.lower()
724
+ if p == 'http':
725
+ config.protocol = Protocol.HTTP
726
+ elif p == 'https':
727
+ config.protocol = Protocol.HTTPS
728
+ else:
729
+ raise ValueError('Invalid protocol: %s' % protocol)
730
+ else:
731
+ config.protocol = protocol
720
732
  endpoint_protocol, endpoint_host, endpoint_port = \
721
733
  utils.parse_host_port(config.endpoint, config.protocol)
722
734
 
@@ -1011,10 +1023,14 @@ class BosClient(BceBaseClient):
1011
1023
  headers = {}
1012
1024
  if days is not None:
1013
1025
  headers[http_headers.BOS_RESTORE_DAYS] = days
1014
- if compat.convert_to_string(tier) not in ("Standard", "Expedited", "LowCost"):
1015
- raise ValueError('invalid tier:{} for restore_object.The valid value is \"Standard\" or \"Expedited\" or '\
1016
- '\"LowCost\"'.format(tier) )
1017
- headers[http_headers.BOS_RESTORE_TIER] = compat.convert_to_bytes(tier)
1026
+ if tier is not None:
1027
+ tier_str = tier if isinstance(tier, str) else tier.decode('utf-8') if isinstance(tier, bytes) else str(tier)
1028
+ if tier_str not in ("Standard", "Expedited", "LowCost"):
1029
+ raise ValueError('invalid tier:{} for restore_object.The valid value is "Standard" or \
1030
+ "Expedited" or "LowCost"'.format(tier) )
1031
+ headers[http_headers.BOS_RESTORE_TIER] = compat.convert_to_bytes(tier)
1032
+ else:
1033
+ raise BceClientError("tier can not be None for restore_object.")
1018
1034
  return self._send_request(
1019
1035
  http_methods.POST,
1020
1036
  bucket_name,
@@ -1146,15 +1162,18 @@ class BosClient(BceBaseClient):
1146
1162
  @required(bucket_name=(bytes, str),
1147
1163
  key=(bytes, str),
1148
1164
  data=object,
1149
- content_length=compat.integer_types,
1150
- content_md5=(bytes, str))
1165
+ content_length=compat.integer_types)
1151
1166
  def append_object(self, bucket_name, key, data,
1152
- content_md5,
1153
1167
  content_length,
1168
+ content_md5=None,
1154
1169
  offset=None,
1155
1170
  content_type=None,
1156
1171
  user_metadata=None,
1157
1172
  content_sha256=None,
1173
+ content_crc32=None,
1174
+ content_crc32c=None,
1175
+ content_crc32c_flag=None,
1176
+ content_crc64ecma=None,
1158
1177
  storage_class=None,
1159
1178
  user_headers=None,
1160
1179
  progress_callback=None,
@@ -1176,12 +1195,44 @@ class BosClient(BceBaseClient):
1176
1195
  **HTTP Response**
1177
1196
  """
1178
1197
  key = compat.convert_to_bytes(key)
1179
- content_md5 = compat.convert_to_bytes(content_md5)
1198
+ if content_md5 is None and content_sha256 is None and content_crc32 is None and \
1199
+ content_crc32c is None and content_crc64ecma is None:
1200
+ max_retries = 3
1201
+ for retry_count in range(max_retries):
1202
+ try:
1203
+ content_crc32 = utils.get_crc32_from_fp(data, length=content_length,
1204
+ buf_size=self._get_config_parameter(config, 'recv_buf_size'))
1205
+ break
1206
+ except Exception as e:
1207
+ if retry_count < max_retries - 1:
1208
+ _logger.warning("CRC32 calculation failed, retrying (attempt %d/%d): %s",
1209
+ retry_count + 1, max_retries, str(e))
1210
+ continue
1211
+ else:
1212
+ _logger.error("CRC32 calculation failed after %d attempts: %s", max_retries, str(e))
1213
+ content_crc32 = None
1214
+ if content_md5:
1215
+ content_md5 = compat.convert_to_bytes(content_md5)
1216
+ if content_sha256:
1217
+ content_sha256 = compat.convert_to_bytes(content_sha256)
1218
+ if content_crc32:
1219
+ content_crc32 = compat.convert_to_bytes(content_crc32)
1220
+ if content_crc32c:
1221
+ content_crc32c = compat.convert_to_bytes(content_crc32c)
1222
+ if content_crc32c_flag is not None:
1223
+ content_crc32c_flag = compat.convert_to_bytes(content_crc32c_flag)
1224
+ if content_crc64ecma:
1225
+ content_crc64ecma = compat.convert_to_bytes(content_crc64ecma)
1226
+
1180
1227
  headers = self._prepare_object_headers(
1181
1228
  content_length=content_length,
1182
1229
  content_md5=content_md5,
1183
1230
  content_type=content_type,
1184
1231
  content_sha256=content_sha256,
1232
+ content_crc32=content_crc32,
1233
+ content_crc32c=content_crc32c,
1234
+ content_crc32c_flag=content_crc32c_flag,
1235
+ content_crc64ecma=content_crc64ecma,
1185
1236
  user_metadata=user_metadata,
1186
1237
  storage_class=storage_class,
1187
1238
  user_headers=user_headers,
@@ -1195,7 +1246,7 @@ class BosClient(BceBaseClient):
1195
1246
  params = {b'append': b''}
1196
1247
  if offset is not None:
1197
1248
  params[b'offset'] = offset
1198
-
1249
+
1199
1250
  if progress_callback:
1200
1251
  data = utils.make_progress_adapter(data, progress_callback)
1201
1252
 
@@ -1217,6 +1268,10 @@ class BosClient(BceBaseClient):
1217
1268
  content_type=None,
1218
1269
  user_metadata=None,
1219
1270
  content_sha256=None,
1271
+ content_crc32=None,
1272
+ content_crc32c=None,
1273
+ content_crc32c_flag=None,
1274
+ content_crc64ecma=None,
1220
1275
  storage_class=None,
1221
1276
  user_headers=None,
1222
1277
  progress_callback=None,
@@ -1233,8 +1288,8 @@ class BosClient(BceBaseClient):
1233
1288
  fp = None
1234
1289
  try:
1235
1290
  fp = io.BytesIO(data)
1236
- if content_md5 is None:
1237
- content_md5 = utils.get_md5_from_fp(
1291
+ if content_crc32 is None:
1292
+ content_crc32 = utils.get_crc32_from_fp(
1238
1293
  fp, buf_size=self._get_config_parameter(config, 'recv_buf_size'))
1239
1294
 
1240
1295
  return self.append_object(bucket_name=bucket_name,
@@ -1246,6 +1301,10 @@ class BosClient(BceBaseClient):
1246
1301
  content_type=content_type,
1247
1302
  user_metadata=user_metadata,
1248
1303
  content_sha256=content_sha256,
1304
+ content_crc32=content_crc32,
1305
+ content_crc32c=content_crc32c,
1306
+ content_crc32c_flag=content_crc32c_flag,
1307
+ content_crc64ecma=content_crc64ecma,
1249
1308
  storage_class=storage_class,
1250
1309
  user_headers=user_headers,
1251
1310
  progress_callback=progress_callback,
@@ -1258,13 +1317,16 @@ class BosClient(BceBaseClient):
1258
1317
  @required(bucket_name=(bytes, str),
1259
1318
  key=(bytes, str),
1260
1319
  data=object,
1261
- content_length=compat.integer_types,
1262
- content_md5=(bytes, str))
1320
+ content_length=compat.integer_types)
1263
1321
  def put_object(self, bucket_name, key, data,
1264
1322
  content_length,
1265
- content_md5,
1323
+ content_md5=None,
1266
1324
  content_type=None,
1267
1325
  content_sha256=None,
1326
+ content_crc32=None,
1327
+ content_crc32c=None,
1328
+ content_crc32c_flag=None,
1329
+ content_crc64ecma=None,
1268
1330
  user_metadata=None,
1269
1331
  storage_class=None,
1270
1332
  user_headers=None,
@@ -1295,29 +1357,62 @@ class BosClient(BceBaseClient):
1295
1357
  **HTTP Response**
1296
1358
  """
1297
1359
  key = compat.convert_to_bytes(key)
1298
- content_md5 = compat.convert_to_bytes(content_md5)
1360
+ if content_md5 is None and content_sha256 is None and content_crc32 is None and \
1361
+ content_crc32c is None and content_crc64ecma is None:
1362
+ max_retries = 3
1363
+ for retry_count in range(max_retries):
1364
+ try:
1365
+ content_crc32 = utils.get_crc32_from_fp(data, length=content_length,
1366
+ buf_size=self._get_config_parameter(config, 'recv_buf_size'))
1367
+ break
1368
+ except Exception as e:
1369
+ if retry_count < max_retries - 1:
1370
+ _logger.warning("CRC32 calculation failed, retrying (attempt %d/%d): %s",
1371
+ retry_count + 1, max_retries, str(e))
1372
+ continue
1373
+ else:
1374
+ _logger.error("CRC32 calculation failed after %d attempts: %s", max_retries, str(e))
1375
+ content_crc32 = None
1376
+ if content_md5:
1377
+ content_md5 = compat.convert_to_bytes(content_md5)
1378
+ if content_sha256:
1379
+ content_sha256 = compat.convert_to_bytes(content_sha256)
1380
+ if content_crc32:
1381
+ content_crc32 = compat.convert_to_bytes(content_crc32)
1382
+ if content_crc32c:
1383
+ content_crc32c = compat.convert_to_bytes(content_crc32c)
1384
+ if content_crc32c_flag:
1385
+ content_crc32c_flag = compat.convert_to_bytes(content_crc32c_flag)
1386
+ if content_crc64ecma:
1387
+ content_crc64ecma = compat.convert_to_bytes(content_crc64ecma)
1388
+
1299
1389
  headers = self._prepare_object_headers(
1300
1390
  content_length=content_length,
1301
1391
  content_md5=content_md5,
1302
1392
  content_type=content_type,
1303
1393
  content_sha256=content_sha256,
1394
+ content_crc32=content_crc32,
1395
+ content_crc32c=content_crc32c,
1396
+ content_crc32c_flag=content_crc32c_flag,
1397
+ content_crc64ecma=content_crc64ecma,
1304
1398
  user_metadata=user_metadata,
1305
1399
  storage_class=storage_class,
1306
1400
  user_headers=user_headers,
1401
+ encryption=encryption,
1402
+ customer_key=customer_key,
1403
+ customer_key_md5=customer_key_md5,
1307
1404
  traffic_limit=traffic_limit,
1308
1405
  object_tagging=object_tagging,)
1309
1406
 
1310
1407
  if cond_read_write is not None:
1311
1408
  headers = self._get_cond_read_write_headers(http_methods.PUT, headers, cond_read_write)
1312
1409
 
1313
- buf_size = self._get_config_parameter(config, 'recv_buf_size')
1314
-
1315
1410
  if content_length > bos.MAX_PUT_OBJECT_LENGTH:
1316
1411
  raise ValueError('Object length should be less than %d. '
1317
1412
  'Use multi-part upload instead.' % bos.MAX_PUT_OBJECT_LENGTH)
1318
-
1413
+
1319
1414
  if progress_callback:
1320
- data = utils.make_progress_adapter(data, progress_callback)
1415
+ data = utils.make_progress_adapter(data, progress_callback)
1321
1416
 
1322
1417
  return self._send_request(
1323
1418
  http_methods.PUT,
@@ -1332,6 +1427,10 @@ class BosClient(BceBaseClient):
1332
1427
  content_md5=None,
1333
1428
  content_type=None,
1334
1429
  content_sha256=None,
1430
+ content_crc32=None,
1431
+ content_crc32c=None,
1432
+ content_crc32c_flag=None,
1433
+ content_crc64ecma=None,
1335
1434
  user_metadata=None,
1336
1435
  storage_class=None,
1337
1436
  user_headers=None,
@@ -1367,14 +1466,18 @@ class BosClient(BceBaseClient):
1367
1466
  fp = None
1368
1467
  try:
1369
1468
  fp = io.BytesIO(data)
1370
- if content_md5 is None:
1371
- content_md5 = utils.get_md5_from_fp(
1469
+ if content_crc32 is None:
1470
+ content_crc32 = utils.get_crc32_from_fp(
1372
1471
  fp, buf_size=self._get_config_parameter(config, 'recv_buf_size'))
1373
1472
  return self.put_object(bucket, key, fp,
1374
1473
  content_length=len(data),
1375
1474
  content_md5=content_md5,
1376
1475
  content_type=content_type,
1377
1476
  content_sha256=content_sha256,
1477
+ content_crc32=content_crc32,
1478
+ content_crc32c=content_crc32c,
1479
+ content_crc32c_flag=content_crc32c_flag,
1480
+ content_crc64ecma=content_crc64ecma,
1378
1481
  user_metadata=user_metadata,
1379
1482
  storage_class=storage_class,
1380
1483
  user_headers=user_headers,
@@ -1396,6 +1499,10 @@ class BosClient(BceBaseClient):
1396
1499
  content_md5=None,
1397
1500
  content_type=None,
1398
1501
  content_sha256=None,
1502
+ content_crc32=None,
1503
+ content_crc32c=None,
1504
+ content_crc32c_flag=None,
1505
+ content_crc64ecma=None,
1399
1506
  user_metadata=None,
1400
1507
  storage_class=None,
1401
1508
  user_headers=None,
@@ -1433,9 +1540,9 @@ class BosClient(BceBaseClient):
1433
1540
  fp.seek(0, os.SEEK_END)
1434
1541
  content_length = fp.tell()
1435
1542
  fp.seek(0)
1436
- if content_md5 is None:
1543
+ if content_crc32 is None:
1437
1544
  recv_buf_size = self._get_config_parameter(config, 'recv_buf_size')
1438
- content_md5 = utils.get_md5_from_fp(fp, length=content_length,
1545
+ content_crc32 = utils.get_crc32_from_fp(fp, length=content_length,
1439
1546
  buf_size=recv_buf_size)
1440
1547
  if content_type is None:
1441
1548
  content_type = utils.guess_content_type_by_file_name(file_name)
@@ -1444,6 +1551,10 @@ class BosClient(BceBaseClient):
1444
1551
  content_md5=content_md5,
1445
1552
  content_type=content_type,
1446
1553
  content_sha256=content_sha256,
1554
+ content_crc32=content_crc32,
1555
+ content_crc32c=content_crc32c,
1556
+ content_crc32c_flag=content_crc32c_flag,
1557
+ content_crc64ecma=content_crc64ecma,
1447
1558
  user_metadata=user_metadata,
1448
1559
  storage_class=storage_class,
1449
1560
  user_headers=user_headers,
@@ -1676,9 +1787,9 @@ class BosClient(BceBaseClient):
1676
1787
  part_number=int,
1677
1788
  part_size=compat.integer_types,
1678
1789
  part_fp=object)
1679
- def upload_part(self, bucket_name, key, upload_id,
1680
- part_number, part_size, part_fp, part_md5=None,
1681
- progress_callback=None, traffic_limit=None, config=None):
1790
+ def upload_part(self, bucket_name, key, upload_id, part_number, part_size, part_fp, part_md5=None,
1791
+ part_crc32=None, part_sha256=None, part_crc32c=None, part_crc32c_flag=None,
1792
+ part_crc64ecma=None, progress_callback=None, traffic_limit=None, config=None):
1682
1793
  """
1683
1794
  Upload a part.
1684
1795
 
@@ -1717,11 +1828,46 @@ class BosClient(BceBaseClient):
1717
1828
  if part_size > bos.MAX_PUT_OBJECT_LENGTH:
1718
1829
  raise ValueError('Single part length should be less than %d. '
1719
1830
  % bos.MAX_PUT_OBJECT_LENGTH)
1720
-
1721
- headers = {http_headers.CONTENT_LENGTH: part_size,
1722
- http_headers.CONTENT_TYPE: http_content_types.OCTET_STREAM}
1723
- if part_md5 is not None:
1724
- headers[http_headers.CONTENT_MD5] = part_md5
1831
+
1832
+ if part_md5 is None and part_crc32 is None and part_sha256 is None and \
1833
+ part_crc32c is None and part_crc64ecma is None:
1834
+ max_retries = 3
1835
+ for retry_count in range(max_retries):
1836
+ try:
1837
+ part_crc32 = utils.get_crc32_from_fp(part_fp, length=part_size,
1838
+ buf_size=self._get_config_parameter(config, 'recv_buf_size'))
1839
+ break
1840
+ except Exception as e:
1841
+ if retry_count < max_retries - 1:
1842
+ _logger.warning("CRC32 calculation failed, retrying (attempt %d/%d): %s",
1843
+ retry_count + 1, max_retries, str(e))
1844
+ continue
1845
+ else:
1846
+ _logger.error("CRC32 calculation failed after %d attempts: %s", max_retries, str(e))
1847
+ part_crc32 = None
1848
+ if part_md5:
1849
+ part_md5 = compat.convert_to_bytes(part_md5)
1850
+ if part_sha256:
1851
+ part_sha256 = compat.convert_to_bytes(part_sha256)
1852
+ if part_crc32:
1853
+ part_crc32 = compat.convert_to_bytes(part_crc32)
1854
+ if part_crc32c:
1855
+ part_crc32c = compat.convert_to_bytes(part_crc32c)
1856
+ if part_crc32c_flag:
1857
+ part_crc32c_flag = compat.convert_to_bytes(part_crc32c_flag)
1858
+ if part_crc64ecma:
1859
+ part_crc64ecma = compat.convert_to_bytes(part_crc64ecma)
1860
+
1861
+ headers = self._prepare_object_headers(
1862
+ content_length=part_size,
1863
+ content_md5=part_md5,
1864
+ content_sha256=part_sha256,
1865
+ content_crc32=part_crc32,
1866
+ content_crc32c=part_crc32c,
1867
+ content_crc32c_flag=part_crc32c_flag,
1868
+ content_crc64ecma=part_crc64ecma,
1869
+ traffic_limit=traffic_limit,
1870
+ )
1725
1871
 
1726
1872
  if progress_callback:
1727
1873
  part_fp = utils.make_progress_adapter(part_fp, progress_callback, part_size)
@@ -1806,6 +1952,8 @@ class BosClient(BceBaseClient):
1806
1952
  offset=compat.integer_types)
1807
1953
  def upload_part_from_file(self, bucket_name, key, upload_id,
1808
1954
  part_number, part_size, file_name, offset, part_md5=None,
1955
+ part_crc32=None, part_sha256=None, part_crc32c=None,
1956
+ part_crc32c_flag=None, part_crc64ecma=None,
1809
1957
  progress_callback=None, traffic_limit=None, config=None):
1810
1958
  """
1811
1959
 
@@ -1825,8 +1973,11 @@ class BosClient(BceBaseClient):
1825
1973
  try:
1826
1974
  f.seek(offset)
1827
1975
  return self.upload_part(bucket_name, key, upload_id, part_number, part_size, f,
1828
- part_md5=part_md5, progress_callback=progress_callback,
1829
- traffic_limit=traffic_limit, config=config)
1976
+ part_md5=part_md5, part_crc32=part_crc32,
1977
+ part_sha256=part_sha256, part_crc32c=part_crc32c,
1978
+ part_crc32c_flag=part_crc32c_flag, part_crc64ecma=part_crc64ecma,
1979
+ progress_callback=progress_callback, traffic_limit=traffic_limit,
1980
+ config=config)
1830
1981
  finally:
1831
1982
  f.close()
1832
1983
 
@@ -1838,6 +1989,10 @@ class BosClient(BceBaseClient):
1838
1989
  upload_id, part_list,
1839
1990
  user_headers=None,
1840
1991
  user_metadata=None,
1992
+ content_crc32=None,
1993
+ content_crc32c=None,
1994
+ content_crc32c_flag=None,
1995
+ content_crc64ecma=None,
1841
1996
  cond_read_write=None,
1842
1997
  config=None):
1843
1998
  """
@@ -1862,7 +2017,11 @@ class BosClient(BceBaseClient):
1862
2017
  headers = self._prepare_object_headers(
1863
2018
  content_type=http_content_types.JSON,
1864
2019
  user_metadata=user_metadata,
1865
- user_headers=user_headers)
2020
+ user_headers=user_headers,
2021
+ content_crc32=content_crc32,
2022
+ content_crc32c=content_crc32c,
2023
+ content_crc32c_flag=content_crc32c_flag,
2024
+ content_crc64ecma=content_crc64ecma)
1866
2025
 
1867
2026
  if cond_read_write is not None:
1868
2027
  headers = self._get_cond_read_write_headers(http_methods.POST, headers, cond_read_write)
@@ -2019,14 +2178,16 @@ class BosClient(BceBaseClient):
2019
2178
 
2020
2179
  def _upload_task(self, bucket_name, object_key, upload_id,
2021
2180
  part_number, part_size, file_name, offset, part_list, uploadTaskHandle,
2181
+ part_crc32=None, part_crc32c=None, part_crc32c_flag=None, part_crc64ecma=None,
2022
2182
  progress_callback=None, traffic_limit=None):
2023
2183
  if uploadTaskHandle.is_cancel():
2024
2184
  _logger.debug("upload task canceled with partNumber={}!".format(part_number))
2025
2185
  return
2026
2186
  try:
2027
2187
  response = self.upload_part_from_file(bucket_name, object_key, upload_id,
2028
- part_number, part_size, file_name, offset, progress_callback=progress_callback
2029
- , traffic_limit=traffic_limit)
2188
+ part_number, part_size, file_name, offset, part_crc32=part_crc32,
2189
+ part_crc32c=part_crc32c, part_crc32c_flag=part_crc32c_flag, part_crc64ecma=part_crc64ecma,
2190
+ progress_callback=progress_callback, traffic_limit=traffic_limit)
2030
2191
  part_list.append({
2031
2192
  "partNumber": part_number,
2032
2193
  "eTag": response.metadata.etag
@@ -2035,15 +2196,18 @@ class BosClient(BceBaseClient):
2035
2196
  except Exception as e:
2036
2197
  _logger.debug("upload task failed with partNumber={}!".format(part_number))
2037
2198
  raise e
2038
- #_logger.debug(e)
2039
2199
 
2040
2200
  @required(bucket_name=(bytes, str), key=(bytes, str), file_name=(bytes, str))
2041
- def put_super_obejct_from_file(self, bucket_name, key, file_name, chunk_size=5,
2201
+ def put_super_object_from_file(self, bucket_name, key, file_name, chunk_size=5,
2042
2202
  thread_num=None,
2043
2203
  uploadTaskHandle=None,
2044
2204
  content_type=None,
2045
2205
  storage_class=None,
2046
2206
  user_headers=None,
2207
+ content_crc32=None,
2208
+ content_crc32c=None,
2209
+ content_crc32c_flag=None,
2210
+ content_crc64ecma=None,
2047
2211
  progress_callback=None,
2048
2212
  traffic_limit=None,
2049
2213
  cond_read_write=None,
@@ -2079,30 +2243,50 @@ class BosClient(BceBaseClient):
2079
2243
  offset = 0
2080
2244
  part_number = 1
2081
2245
  part_list = []
2246
+ part_crc_list = []
2247
+
2248
+ with open(file_name, 'rb') as fp:
2249
+ while left_size > 0:
2250
+ current_part_size = part_size
2251
+ if left_size < part_size:
2252
+ current_part_size = left_size
2253
+ part_crc = utils.get_crc32_from_fp(fp, offset, current_part_size)
2254
+ part_crc_list.append((part_crc, current_part_size))
2255
+
2256
+ temp_task = executor.submit(self._upload_task, bucket_name, key, upload_id, part_number,
2257
+ current_part_size, file_name, offset, part_list, uploadTaskHandle,
2258
+ part_crc, None, None, None, progress_callback, traffic_limit)
2259
+ all_tasks.append(temp_task)
2260
+ left_size -= current_part_size
2261
+ offset += current_part_size
2262
+ part_number += 1
2082
2263
 
2083
- while left_size > 0:
2084
- if left_size < part_size:
2085
- part_size = left_size
2086
- temp_task= executor.submit(self._upload_task, bucket_name, key, upload_id, part_number, part_size,
2087
- file_name, offset, part_list, uploadTaskHandle, progress_callback, traffic_limit)
2088
- all_tasks.append(temp_task)
2089
- left_size -= part_size
2090
- offset += part_size
2091
- part_number += 1
2092
2264
  # wait all upload task to exit
2093
2265
  wait(all_tasks, return_when=ALL_COMPLETED)
2094
2266
  if uploadTaskHandle.is_cancel():
2095
2267
  _logger.debug("putting super object is canceled!")
2096
- self.abort_multipart_upload(bucket_name, key, upload_id = upload_id)
2268
+ self.abort_multipart_upload(bucket_name, key, upload_id=upload_id)
2097
2269
  return False
2098
2270
  elif len(part_list) != total_part:
2099
2271
  _logger.debug("putting super object failed!")
2100
- self.abort_multipart_upload(bucket_name, key, upload_id = upload_id)
2272
+ self.abort_multipart_upload(bucket_name, key, upload_id=upload_id)
2101
2273
  return False
2102
2274
  # sort
2103
2275
  part_list.sort(key=lambda x: x["partNumber"])
2104
2276
  # complete_multipart_upload
2105
- self.complete_multipart_upload(bucket_name, key, upload_id, part_list, cond_read_write)
2277
+ # Combine CRC32 values correctly: start with the first part's CRC,
2278
+ # then combine with each subsequent part
2279
+ if part_crc_list:
2280
+ final_crc32 = part_crc_list[0][0]
2281
+ for i in range(1, len(part_crc_list)):
2282
+ crc, length = part_crc_list[i]
2283
+ final_crc32 = utils.crc32_combine(final_crc32, crc, length)
2284
+ final_crc32 &= 0xffffffff
2285
+ if content_crc32 is None:
2286
+ content_crc32 = final_crc32
2287
+ self.complete_multipart_upload(bucket_name, key, upload_id, part_list, content_crc32=content_crc32,
2288
+ content_crc32c=content_crc32c, content_crc32c_flag=content_crc32c_flag,
2289
+ content_crc64ecma=content_crc64ecma, cond_read_write=cond_read_write)
2106
2290
  return True
2107
2291
 
2108
2292
  @required(bucket_name=(bytes, str), key=(bytes, str), acl=(list, dict))
@@ -2593,6 +2777,7 @@ class BosClient(BceBaseClient):
2593
2777
  bucket_name=bucket_name,
2594
2778
  body=json.dumps({'status': status}, default=BosClient._dump_acl_object),
2595
2779
  params={b'versioning': b''},
2780
+ headers={http_headers.CONTENT_TYPE: http_content_types.JSON},
2596
2781
  config=config,)
2597
2782
 
2598
2783
  def get_bucket_versioning(self, bucket_name, config=None):
@@ -2852,6 +3037,10 @@ class BosClient(BceBaseClient):
2852
3037
  content_md5=None,
2853
3038
  content_type=None,
2854
3039
  content_sha256=None,
3040
+ content_crc32=None,
3041
+ content_crc32c=None,
3042
+ content_crc32c_flag=None,
3043
+ content_crc64ecma=None,
2855
3044
  etag=None,
2856
3045
  user_metadata=None,
2857
3046
  storage_class=None,
@@ -2877,7 +3066,15 @@ class BosClient(BceBaseClient):
2877
3066
  headers[http_headers.CONTENT_TYPE] = http_content_types.OCTET_STREAM
2878
3067
 
2879
3068
  if content_sha256 is not None:
2880
- headers[http_headers.BCE_CONTENT_SHA256] = content_sha256
3069
+ headers[http_headers.BCE_CONTENT_SHA256] = utils.convert_to_standard_string(content_sha256)
3070
+ if content_crc32 is not None:
3071
+ headers[http_headers.BCE_CONTENT_CRC32] = utils.convert_to_standard_string(content_crc32)
3072
+ if content_crc32c is not None:
3073
+ headers[http_headers.BCE_CONTENT_CRC32C] = utils.convert_to_standard_string(content_crc32c)
3074
+ if content_crc32c_flag is not None:
3075
+ headers[http_headers.BCE_CONTENT_CRC32C_FLAG] = utils.convert_to_standard_string(content_crc32c_flag)
3076
+ if content_crc64ecma is not None:
3077
+ headers[http_headers.BCE_CONTENT_CRC64ECMA] = utils.convert_to_standard_string(content_crc64ecma)
2881
3078
 
2882
3079
  if etag is not None:
2883
3080
  headers[http_headers.ETAG] = b'"%s"' % utils.convert_to_standard_string(etag)
@@ -3096,8 +3293,7 @@ class BosClient(BceBaseClient):
3096
3293
  def _send_request(
3097
3294
  self, http_method, bucket_name=None, key=None,
3098
3295
  body=None, headers=None, params=None,
3099
- config=None,
3100
- body_parser=None):
3296
+ config=None, body_parser=None):
3101
3297
  config = self._merge_config(config, bucket_name)
3102
3298
 
3103
3299
  path = BosClient._get_path(config, bucket_name, key)
File without changes