Validate if policy is type str

    :param policy: S3 style Bucket policy.
    :return: True if policy parameter is of a valid type, 'string'.
    Raise :exc:`TypeError` otherwise.
553838
def is_valid_policy_type(policy):
    
    if _is_py3:
        string_type = str,
    elif _is_py2:
        string_type = basestring

    if not isinstance(policy, string_type):
        raise TypeError('policy can only be of type str')

    is_non_empty_string(policy)

    return True
30443
def check_type(self, value):
    

    if self.null and value is None:
      return
    if self.type is not None and not isinstance(value, self.type):
      msg = '{0!r} expected type {1}'
      raise TypeError(msg.format(self.full_name, self.type.__name__))
1122256
def _validate_params_types(self, method, params):
        
        if isinstance(params, list):
            if not isinstance(self.method_data[method]['types'], list):
                raise InvalidParamsError(
                    'expected keyword params, not positional')

            for param, type, posnum in zip(params,
                                           self.method_data[method]['types'],
                                           range(1, len(params)+1)):
                if not (isinstance(param, type) or param is None):
                    raise InvalidParamsError(
                        'positional arg #{} is the wrong type'.format(posnum))

        elif isinstance(params, dict):
            if not isinstance(self.method_data[method]['types'], dict):
                raise InvalidParamsError(
                    'expected positional params, not keyword')

            if 'required' in self.method_data[method]:
                for key in self.method_data[method]['required']:
                    if key not in params:
                        raise InvalidParamsError('missing key: %s' % key)

            for key in params.keys():
                if key not in self.method_data[method]['types'] or \
                    not (isinstance(params[key],
                                    self.method_data[method]['types'][key])
                         or params[key] is None):
                    raise InvalidParamsError(
                        'arg "{}" is the wrong type'.format(key))
354823
def type(self, type):
        
        if type is None:
            raise ValueError("Invalid value for `type`, must not be `None`")
        if type is not None and len(type) > 50:
            raise ValueError("Invalid value for `type`, length must be less than or equal to `50`")
        if type is not None and not re.search('[\\x21-\\x7E \\t]*', type):
            raise ValueError("Invalid value for `type`, must be a follow pattern or equal to `/[\\x21-\\x7E \\t]*/`")

        self._type = type
530517
def get_none_policy_text(none_policy,   # type: int
                         verbose=False  # type: bool
                         ):
    
    if none_policy is NonePolicy.SKIP:
        return "accept None without performing validation" if verbose else 'SKIP'
    elif none_policy is NonePolicy.FAIL:
        return "fail on None without performing validation" if verbose else 'FAIL'
    elif none_policy is NonePolicy.VALIDATE:
        return "validate None as any other values" if verbose else 'VALIDATE'
    elif none_policy is NoneArgPolicy.SKIP_IF_NONABLE_ELSE_FAIL:
        return "accept None without validation if the argument is optional, otherwise fail on None" if verbose \
            else 'SKIP_IF_NONABLE_ELSE_FAIL'
    elif none_policy is NoneArgPolicy.SKIP_IF_NONABLE_ELSE_VALIDATE:
        return "accept None without validation if the argument is optional, otherwise validate None as any other " \
               "values" if verbose else 'SKIP_IF_NONABLE_ELSE_VALIDATE'
    else:
        raise ValueError('Invalid none_policy ' + str(none_policy))
818105
private void validateAllPolicies(Collection<PolicyInfo> all) 
    throws IOException, NumberFormatException {
    for (PolicyInfo pinfo: all) {
      Path srcPath = pinfo.getSrcPath();
      if (srcPath == null) {
        throw new IOException("Unable to find srcPath in policy.");
      }
      if (pinfo.getProperty("replication") == null) {
        throw new IOException("Unable to find replication in policy." +  
                              srcPath);
      }
      int repl = Integer.parseInt(pinfo.getProperty("replication"));
      if (pinfo.getProperty("modTimePeriod") == null) {
        throw new IOException("Unable to find modTimePeriod in policy." + 
                              srcPath);
      }
      long value = Long.parseLong(pinfo.getProperty("modTimePeriod"));
      List<PathInfo> dpaths = pinfo.getDestPaths();
      if (dpaths == null || dpaths.size() == 0) {
        throw new IOException("Unable to find dest in policy." +  srcPath);
      }
      for (PathInfo pp: dpaths) {
        if (pp.getPath() == null)  {
          throw new IOException("Unable to find valid destPath in policy " +
                                srcPath);
        }
        if (pp.getProperty("replication") == null) {
          throw new IOException("Unable to find dest replication in policy." +  
                                srcPath);
        }
        repl = Integer.parseInt(pp.getProperty("replication"));
      }
    }
  }
450189
def is_valid_type(self, filepath):
        
        if self.in_repo(filepath):
            return False

        validators = self._validators
        if len(validators) == 0:
            validators = [self.default_validator]

        if any([hasattr(v, 'runnable') for v in self._validators]):
            # case where we select the runnable function by the validator
            for validator in validators:
                if validator(filepath):
                    if hasattr(validator, 'runnable'):
                        self._scent.set_runner(validator.runnable)
                        return True
            return False

        for validator in validators:
            if not validator(filepath):
                return False
        return True
623060
def has_arrlist(type_str):
    
    try:
        abi_type = grammar.parse(type_str)
    except exceptions.ParseError:
        return False

    return abi_type.arrlist is not None
142343
def check_tile_bounds_policy(self):
        
        if self.tile_bounds_policy not in self.valid_tile_bounds_policies:
            raise ValueError(
                "Got self.tile_bounds_policy=%s, which is not in %s."
                %
                (self.tile_bounds_policy, self.valid_tile_bounds_policies)
            )
1212948
public boolean hasPolicy(String sec, String ptype, List<String> rule) {
        for (List<String> r : model.get(sec).get(ptype).policy) {
            if (Util.arrayEquals(rule, r)) {
                return true;
            }
        }

        return false;
    }
1207345
function isValidType(value, authorizedTypes) {
  var valueToString = Object.prototype.toString.call(value);

  for (var i = 0; i < authorizedTypes.length; i++)
    if (valueToString === '[object ' + authorizedTypes[i] + ']') return true;

  return false;
}
352980
def validate_key(self, key):
        
        if not key:
            name = self.__class__.__name__
            msg = "%s response missing %s" % (name, self.key_name)
            raise ValidationException(msg, self)
        elif not isinstance(key, str):
            msg = "Response contains invalid %s type" % self.key_name
            raise ValidationException(msg, type(key))
1276494
def is_string_type(type_):
    

    string_types = _get_types(Types.STRING)
    if is_typing_type(type_):
        return type_ in string_types or is_regex_type(type_)
    return type_ in string_types
558562
def validate(self):
        
        if not self.principals:
            raise InvalidApplicationPolicyError(error_message='principals not provided')

        if not self.actions:
            raise InvalidApplicationPolicyError(error_message='actions not provided')

        if any(not self._PRINCIPAL_PATTERN.match(p) for p in self.principals):
            raise InvalidApplicationPolicyError(
                error_message='principal should be 12-digit AWS account ID or "*"')

        unsupported_actions = sorted(set(self.actions) - set(self.SUPPORTED_ACTIONS))
        if unsupported_actions:
            raise InvalidApplicationPolicyError(
                error_message='{} not supported'.format(', '.join(unsupported_actions)))

        return True
1317755
def conditionally_attach_managed_policies(role_name, sr_entry):
  
  service_type = sr_entry['type']
  if not (service_type in SERVICE_TYPE_ROLE and "aws_managed_policies" in sr_entry):
    print_if_verbose("not eligible for policies; service_type: {} is not valid for policies "
                     "or no 'aws_managed_policies' key in service registry for this role".format(service_type))
    return

  for policy_name in sr_entry['aws_managed_policies']:
    print_if_verbose("loading policy: {} for role: {}".format(policy_name, role_name))

    if CONTEXT.commit:
      try:
        CLIENTS["iam"].attach_role_policy(RoleName=role_name, PolicyArn='arn:aws:iam::aws:policy/' + policy_name)
      except:
        fail("Exception putting policy: {} onto role: {}".format(policy_name, role_name), sys.exc_info())
893331
public boolean addPolicy(String sec, String ptype, List<String> rule) {
        if (!hasPolicy(sec, ptype, rule)) {
            model.get(sec).get(ptype).policy.add(rule);
            return true;
        }
        return false;
    }
783305
def set_policy(self, policy, headers=None):
        
        response = self.connection.make_request('PUT', self.name,
                                                data=policy,
                                                query_args='policy',
                                                headers=headers)
        body = response.read()
        if response.status >= 200 and response.status <= 204:
            return True
        else:
            raise self.connection.provider.storage_response_error(
                response.status, response.reason, body)