Computes region of a given bucket name. If set, this.region is considered. Otherwise,
resort to the server location API.
198726
private String getRegion(String bucketName) throws InvalidBucketNameException, NoSuchAlgorithmException,
          InsufficientDataException, IOException, InvalidKeyException, NoResponseException, XmlPullParserException,
          ErrorResponseException, InternalException {
    String region;
    if (this.region == null || "".equals(this.region)) {
      updateRegionCache(bucketName);
      region = BucketRegionCache.INSTANCE.region(bucketName);
    } else {
      region = this.region;
    }
    return region;
  }
319315
def get_s3_region_from_endpoint(endpoint):
    

    # Extract region by regex search.
    m = _EXTRACT_REGION_REGEX.search(endpoint)
    if m:
        # Regex matches, we have found a region.
        region = m.group(1)
        if region == 'external-1':
            # Handle special scenario for us-east-1 URL.
            return 'us-east-1'
        if region.startswith('dualstack'):
            # Handle special scenario for dualstack URL.
            return region.split('.')[1]
        return region

    # No regex matches return None.
    return None
265650
public RegionInfo queryRegionInfo(String accessKey, String bucket) throws QiniuException {
        RegionIndex index = new RegionIndex(accessKey, bucket);
        RegionInfo info = regions.get(index);
        if (info == null) {
            UCRet ret = getRegionJson(index);
            try {
                info = RegionInfo.buildFromUcRet(ret);
            } catch (Exception e) {
                e.printStackTrace();
            }

            if (info != null) {
                regions.put(index, info);
            }
        }
        return info;
    }
692984
def get_by_name(account_name, bucket, region='us-west-2', json_path='accounts.json', alias=None):
    """"""
    for account in get_all_accounts(bucket, region, json_path)['accounts']:
        if 'aws' in account['type']:
            if account['name'] == account_name:
                return account
            elif alias:
                for a in account['alias']:
                    if a == account_name:
                        return account
825127
def GetRegion(region_name):
  
  regions = boto_ec2.regions()
  region = None
  valid_region_names = []
  for r in regions:
    valid_region_names.append(r.name)
    if r.name == region_name:
        region = r
        break
  if not region:
    logging.info( 'invalid region name: %s ' % (region_name))
    logging.info( 'Try one of these:\n %s' % ('\n'.join(valid_region_names)))
    assert(False)
  return  region
831845
def _validate_region(self):
        """"""
        if not self.region:
            raise GCECloudException(
                'Zone is required for GCE cloud framework: '
                'Example: us-west1-a'
            )

        try:
            zone = self.compute_driver.ex_get_zone(self.region)
        except Exception:
            zone = None

        if not zone:
            raise GCECloudException(
                '{region} is not a valid GCE zone. '
                'Example: us-west1-a'.format(
                    region=self.region
                )
            )
267199
function correctBucketRegionFromCache(req) {
    var bucket = req.params.Bucket || null;
    if (bucket) {
      var service = req.service;
      var requestRegion = req.httpRequest.region;
      var cachedRegion = service.bucketRegionCache[bucket];
      if (cachedRegion && cachedRegion !== requestRegion) {
        service.updateReqBucketRegion(req, cachedRegion);
      }
    }
  }
397858
def regions(self):
        """"""
        url = "%s/regions" % self.root
        params = {"f": "json"}
        return self._get(url=url,
                            param_dict=params,
                            proxy_url=self._proxy_url,
                            proxy_port=self._proxy_port)
326616
def parse_buckets(self, bucket, params):
        
        bucket['name'] = bucket.pop('Name')
        api_client = params['api_clients'][get_s3_list_region(list(params['api_clients'].keys())[0])]

        bucket['CreationDate'] = str(bucket['CreationDate'])
        bucket['region'] = get_s3_bucket_location(api_client, bucket['name'])
        # h4ck :: fix issue #59, location constraint can be EU or eu-west-1 for Ireland...
        if bucket['region'] == 'EU':
            bucket['region'] = 'eu-west-1'
        # h4ck :: S3 is global but region-aware...
        if bucket['region'] not in params['api_clients']:
            printInfo('Skipping bucket %s (region %s outside of scope)' % (bucket['name'], bucket['region']))
            self.buckets_count -= 1
            return

        api_client = params['api_clients'][bucket['region']]
        get_s3_bucket_logging(api_client, bucket['name'], bucket)
        get_s3_bucket_versioning(api_client, bucket['name'], bucket)
        get_s3_bucket_webhosting(api_client, bucket['name'], bucket)
        get_s3_bucket_default_encryption(api_client, bucket['name'], bucket)
        bucket['grantees'] = get_s3_acls(api_client, bucket['name'], bucket)
        get_s3_bucket_policy(api_client, bucket['name'], bucket)
        get_s3_bucket_secure_transport(api_client, bucket['name'], bucket)
        # If requested, get key properties
        #if params['check_encryption'] or params['check_acls']:
        #    get_s3_bucket_keys(api_client, bucket['name'], bucket, params['check_encryption'],
        #                       params['check_acls'])
        bucket['id'] = self.get_non_aws_id(bucket['name'])
        self.buckets[bucket['id']] = bucket
1106372
def discover_region(self, move_x, move_y):
        """"""
        field_list = deque([(move_y, move_x)])

        while len(field_list) != 0:
            field = field_list.popleft()

            (tl_idx, br_idx, region_sum) = self.get_region(field[1], field[0])
            if region_sum == 0:
                self.info_map[field[0], field[1]] = region_sum
                # get surrounding to queue
                region_mat = self.info_map[tl_idx[0]:br_idx[0]+1,
                                           tl_idx[1]:br_idx[1]+1]
                x_list, y_list = np.nonzero(region_mat == 11)

                for x_idx, y_idx in zip(x_list, y_list):
                    field_temp = (x_idx+max(field[0]-1, 0),
                                  y_idx+max(field[1]-1, 0))
                    if field_temp not in field_list:
                        field_list.append(field_temp)
            elif region_sum > 0:
                self.info_map[field[0], field[1]] = region_sum
661218
public OvhRegion project_serviceName_region_POST(String serviceName, String region) throws IOException {
		String qPath = "/cloud/project/{serviceName}/region";
		StringBuilder sb = path(qPath, serviceName);
		HashMap<String, Object>o = new HashMap<String, Object>();
		addBody(o, "region", region);
		String resp = exec(qPath, "POST", sb.toString(), o);
		return convertTo(resp, OvhRegion.class);
	}
1032933
function reqRegionForNetworkingError(resp, done) {
    if (!AWS.util.isBrowser()) {
      return done();
    }
    var error = resp.error;
    var request = resp.request;
    var bucket = request.params.Bucket;
    if (!error || error.code !== 'NetworkingError' || !bucket ||
        request.httpRequest.region === 'us-east-1') {
      return done();
    }
    var service = request.service;
    var bucketRegionCache = service.bucketRegionCache;
    var cachedRegion = bucketRegionCache[bucket] || null;

    if (cachedRegion && cachedRegion !== request.httpRequest.region) {
      service.updateReqBucketRegion(request, cachedRegion);
      done();
    } else if (!service.dnsCompatibleBucketName(bucket)) {
      service.updateReqBucketRegion(request, 'us-east-1');
      if (bucketRegionCache[bucket] !== 'us-east-1') {
        bucketRegionCache[bucket] = 'us-east-1';
      }
      done();
    } else if (request.httpRequest.virtualHostedBucket) {
      var getRegionReq = service.listObjects({Bucket: bucket, MaxKeys: 0});
      service.updateReqBucketRegion(getRegionReq, 'us-east-1');
      getRegionReq._requestRegionForBucket = bucket;

      getRegionReq.send(function() {
        var region = service.bucketRegionCache[bucket] || null;
        if (region && region !== request.httpRequest.region) {
          service.updateReqBucketRegion(request, region);
        }
        done();
      });
    } else {
      // DNS-compatible path-style
      // (s3ForcePathStyle or bucket name with dot over https)
      // Cannot obtain region information for this case
      done();
    }
   }
991955
URI resolveServiceEndpoint(String bucketName) {

        if (getSignerRegion() != null || isSignerOverridden()) return endpoint;

        final String regionStr = fetchRegionFromCache(bucketName);
        final com.amazonaws.regions.Region region = RegionUtils.getRegion(regionStr);

        if (region == null) {
            log.warn("Region information for "
                    + regionStr
                    + " is not available. Please upgrade to latest version of AWS Java SDK");
        }

        return region != null
                ? RuntimeHttpUtils.toUri(region.getServiceEndpoint(S3_SERVICE_NAME), clientConfiguration)
                : endpoint;
    }
367313
def region(self):
        

        region_item = [subtag for subtag in self.subtags if subtag.type == 'region']

        return region_item[0] if len(region_item) > 0 else None
858062
def url(self, name):
        
        name = urllib.quote_plus(self._clean_name(name), safe='/')

        if self.bucket_cname:
            return "http://%s/%s" % (self.bucket_cname, name)
        elif self.host:
            return "http://%s/%s/%s" % (self.host, self.bucket_name, name)
        # No host ? Then it's the default region
        return "http://s3.amazonaws.com/%s/%s" % (self.bucket_name, name)
1316490
def regions(self):
        
        json = self.request('/regions', method='GET')
        status = json.get('status')
        if status == 'OK':
            regions_json = json.get('regions', [])
            regions = [Region.from_json(region) for region in regions_json]
            return regions
        else:
            message = json.get('message')
            raise DOPException('[%s]: %s' % (status, message))
1301854
def do_region(self, x, y, w, h):
        """"""
        if (x is not None):
            raise IIIFError(code=501, parameter="region",
                            text="Null manipulator supports only region=/full/.")