MCPcopy Create free account
hub / github.com/s3tools/s3cmd / update_region_inner_request

Method update_region_inner_request

S3/S3.py:1664–1691  ·  view source on GitHub ↗

Get and update region for the request if needed. Signature v4 needs the region of the bucket or the request will fail with the indication of the correct region. We are trying to avoid this failure by pre-emptively getting the correct region to use, if not provided by

(self, request)

Source from the content-addressed store, hash-verified

1662 raise S3Error(response)
1663
1664 def update_region_inner_request(self, request):
1665 """Get and update region for the request if needed.
1666
1667 Signature v4 needs the region of the bucket or the request will fail
1668 with the indication of the correct region.
1669 We are trying to avoid this failure by pre-emptively getting the
1670 correct region to use, if not provided by the user.
1671 """
1672 if request.resource.get('bucket') and not request.use_signature_v2() \
1673 and S3Request.region_map.get(
1674 request.resource['bucket'], Config().bucket_location
1675 ) == "US":
1676 debug("===== SEND Inner request to determine the bucket region "
1677 "=====")
1678 try:
1679 s3_uri = S3Uri(u's3://' + request.resource['bucket'])
1680 # "force_us_default" should prevent infinite recursivity because
1681 # it will set the region_map dict.
1682 region = self.get_bucket_location(s3_uri, force_us_default=True)
1683 if region is not None:
1684 S3Request.region_map[request.resource['bucket']] = region
1685 debug("===== SUCCESS Inner request to determine the bucket "
1686 "region (%r) =====", region)
1687 except Exception as exc:
1688 # Ignore errors, it is just an optimisation, so nothing critical
1689 debug("getlocation inner request failure reason: %s", exc)
1690 debug("===== FAILED Inner request to determine the bucket "
1691 "region =====")
1692
1693 def send_request(self, request, retries=None):
1694 if retries is None:

Callers 3

send_requestMethod · 0.95
send_fileMethod · 0.95
recv_fileMethod · 0.95

Calls 5

get_bucket_locationMethod · 0.95
ConfigClass · 0.90
S3UriClass · 0.90
use_signature_v2Method · 0.80
getMethod · 0.45

Tested by

no test coverage detected