parameters: (self, bucket, response)
return_statement: return region
docstring: There are multiple potential sources for the new region to redirect to,
          but they aren't all universally available for use. This will try to
          find region from response elements, but will fall back to calling
          HEAD on the bucket if all else fails.
  
          :param bucket: The bucket to find the region for. This is necessary if
              the region is not available in the error response.
          :param response: A response representing a service request that failed
              due to incorrect region configuration.
docstring_summary: There are multiple potential sources for the new region to redirect to,
          but they aren't all universally available for use. This will try to
          find region from response elements, but will fall back to calling
          HEAD on the bucket if all else fails.
docstring_tokens: There are multiple potential sources for the new region to redirect to but they aren t all universally available for use . This will try to find region from response elements but will fall back to calling HEAD on the bucket if all else fails .
function: def get_bucket_region(self, bucket, response):
          """
          There are multiple potential sources for the new region to redirect to,
          but they aren't all universally available for use. This will try to
          find region from response elements, but will fall back to calling
          HEAD on the bucket if all else fails.
  
          :param bucket: The bucket to find the region for. This is necessary if
              the region is not available in the error response.
          :param response: A response representing a service request that failed
              due to incorrect region configuration.
          """
          # First try to source the region from the headers.
          service_response = response[1]
          response_headers = service_response['ResponseMetadata']['HTTPHeaders']
          if 'x-amz-bucket-region' in response_headers:
              return response_headers['x-amz-bucket-region']
  
          # Next, check the error body
          region = service_response.get('Error', {}).get('Region', None)
          if region is not None:
              return region
  
          # Finally, HEAD the bucket. No other choice sadly.
          try:
              response = self._client.head_bucket(Bucket=bucket)
              headers = response['ResponseMetadata']['HTTPHeaders']
          except ClientError as e:
              headers = e.response['ResponseMetadata']['HTTPHeaders']
  
          region = headers.get('x-amz-bucket-region', None)
          return region
function_tokens: def get_bucket_region ( self , bucket , response ) : # First try to source the region from the headers. service_response = response [ 1 ] response_headers = service_response [ 'ResponseMetadata' ] [ 'HTTPHeaders' ] if 'x-amz-bucket-region' in response_headers : return response_headers [ 'x-amz-bucket-region' ] # Next, check the error body region = service_response . get ( 'Error' , { } ) . get ( 'Region' , None ) if region is not None : return region # Finally, HEAD the bucket. No other choice sadly. try : response = self . _client . head_bucket ( Bucket = bucket ) headers = response [ 'ResponseMetadata' ] [ 'HTTPHeaders' ] except ClientError as e : headers = e . response [ 'ResponseMetadata' ] [ 'HTTPHeaders' ] region = headers . get ( 'x-amz-bucket-region' , None ) return region