Return a function which validates that the value is a mapping of
    items. The function should return pairs of items that will be
    passed to the `dict` constructor.
329141
def build_map_type_validator(item_validator):
    
    def validate_mapping(value):
        return dict(item_validator(item) for item in validate_list(value))
    return validate_mapping
1345346
def validate_mapping(mapping):
    
    file_path = os.path.join(os.path.dirname(__file__),
                             'schemas', 'mapping.json')
    with open(file_path, 'r') as fh:
        validator = Draft4Validator(json.load(fh))
        validator.validate(mapping)
    return mapping
1337304
function __map(items, fn, includeNull) {
  // whether to return nulls in array of results; default = true;
  includeNull = includeNull == null ? true : includeNull;
  if (items == null) return items;
  var result;
  if (Array.isArray(items)) {
    result = [];
    items.forEach(function (v, ix) {
      var r = fn(v, ix);
      if (r != null || includeNull) {
        result[ix] = r;
      }
    });
  } else {
    result = fn(items);
  }
  return result;
}
139817
def valid_dict(d, keys=None):
    

    if keys is None:
        d_ = d
    else:
        d_ = itemfilter(lambda item: item[0] in keys, d)
        if len(d_) != len(keys):
            return False
    values = list(itervalues(d_))
    return False if None in values else True
1035535
def each_item(*validators):
    
    def validate(value):
        for item in value:
            for validator in validators:
                error = validator(item)
                if error:
                    return error
        return None
    return validate
381055
def validate_dict(in_dict, **kwargs):
    

    if not isinstance(in_dict, dict):
        raise ValueError('requires a dictionary')

    for key, value in kwargs.iteritems():

        if key == 'required':
            for required_key in value:
                if required_key not in in_dict:
                    return False

        elif key not in in_dict:
            continue

        elif value == bool:

            in_dict[key] = (True
                            if str(in_dict[key]).lower() == 'true'
                            else False)

        else:

            if (isinstance(in_dict[key], list) and
                len(in_dict[key]) == 1 and
                value != list):
                in_dict[key] = in_dict[key][0]

            try:
                if key in in_dict:
                    in_dict[key] = value(in_dict[key])
            except ValueError:
                return False

    return True
668802
def any(self, func):
        
        return any([func(k, v) for k, v in self.items()])
263837
def get_mapping(self, other):
        
        m = next(self._matcher(other).isomorphisms_iter(), None)
        if m:
            return {v: k for k, v in m.items()}
1141088
def itemtypes(cls, mapped_types, coll_type, visitor):
        
        rv = list(v for k, v in mapped_types)
        return rv[0] if len(rv) == 1 else rv
64960
def decode_map_element(self, item_type, value):
        """"""
        import urllib
        key = value
        if ":" in value:
            key, value = value.split(':',1)
            key = urllib.unquote(key)
        if Model in item_type.mro():
            value = item_type(id=value)
        else:
            value = self.decode(item_type, value)
        return (key, value)
1329667
def clean_dict(d, test=lambda v: v):
    
    return {k: v for k, v in d.items() if test(v)}
741533
def validate_keys(dict_, expected, funcname):
    
    expected = set(expected)
    received = set(dict_)

    missing = expected - received
    if missing:
        raise ValueError(
            "Missing keys in {}:\n"
            "Expected Keys: {}\n"
            "Received Keys: {}".format(
                funcname,
                sorted(expected),
                sorted(received),
            )
        )

    unexpected = received - expected
    if unexpected:
        raise ValueError(
            "Unexpected keys in {}:\n"
            "Expected Keys: {}\n"
            "Received Keys: {}".format(
                funcname,
                sorted(expected),
                sorted(received),
            )
        )
868932
def validate_dict(d):
    """"""
    try:
        return dict(d)
    except TypeError:
        d = validate_path_exists(d)
        try:
            with open(d) as f:
                return dict(yaml.load(f))
        except Exception:
            raise ValueError("Could not convert {} to dictionary!".format(d))
910745
def wrap(self, value):
        ''' 
        '''
        self.validate_wrap(value)
        ret = {}
        for k, v in value.items():
            ret[k] = self.value_type.wrap(v)
        return ret
999530
def itemize(data):
    
    if isinstance(data, dict):
        ret = {}
        for key in data:
            ret[key] = itemize(data[key])
        return ret
    elif isinstance(data, list):
        return {'item': [itemize(value) for value in data]}
    else:
        return data
731257
def dictionary_validator(key_type, value_type):
    """"""

    def _validate_dictionary(instance, attribute, value):
        # pylint: disable=unused-argument
        """Validate that a dictionary is structured as expected.

        :raises TypeError: if ``value`` is not a dictionary
        :raises TypeError: if ``value`` keys are not all of ``key_type`` type
        :raises TypeError: if ``value`` values are not all of ``value_type`` type
        """
        if not isinstance(value, dict):
            raise TypeError('"{}" must be a dictionary'.format(attribute.name))

        for key, data in value.items():
            if not isinstance(key, key_type):
                raise TypeError(
                    '"{name}" dictionary keys must be of type "{type}"'.format(name=attribute.name, type=key_type)
                )

            if not isinstance(data, value_type):
                raise TypeError(
                    '"{name}" dictionary values must be of type "{type}"'.format(name=attribute.name, type=value_type)
                )

    return _validate_dictionary
1332798
def clean_map(obj: Mapping[Any, Any]) -> Mapping[Any, Any]:
    
    return {k: v for k, v in obj.items() if v is not None}