Example #1
0
 def func(json):
     included = json.get('included') if include else None
     data = json.get('data')
     result = [cls._resource_class(entry, registry)
               (entry, session, include=include, included=included)
               for entry in data]
     return result if filter is None else list(_filter(filter, result))
Example #2
0
 def _process(json):
     included = json.get('included')
     mk_one = dest_class._mk_one(session,
                                 resource_classes=resource_classes)
     result = [mk_one({'data': entry}) for entry in included]
     return result if filter is None else list(
         _filter(filter, result))
Example #3
0
def resource_filter(cls, client, value,
                    lookup_filter=None,
                    resources=None,
                    include=None):
    if resources is None:
        resources = cls.all(client, include=include)
    lookup_filter = lookup_filter or filter_attribute('id')
    resource_filter = lookup_filter(value)
    return list(_filter(resource_filter, resources))
Example #4
0
 def func(json):
     included = json.get('included') if include else None
     data = json.get('data')
     result = [
         cls._resource_class(entry, registry)(entry,
                                              session,
                                              include=include,
                                              included=included)
         for entry in data
     ]
     return result if filter is None else list(_filter(filter, result))
Example #5
0
def resource_filter(cls,
                    client,
                    value,
                    lookup_filter=None,
                    resources=None,
                    include=None):
    if resources is None:
        resources = cls.all(client, include=include)
    lookup_filter = lookup_filter or filter_attribute('id')
    resource_filter = lookup_filter(value)
    return list(_filter(resource_filter, resources))
Example #6
0
 def _fetch_relationship_included(self, filter=None):
     session = self._session
     include = self._include
     if include is None or dest_class not in include:
         # You requested an included relationship that was
         # not originally included
         error = "{} was not included".format(dest_class.__name__)
         raise AttributeError(error)
     included = self._included.get(dest_resource_type)
     mk_one = dest_class._mk_one(session,
                                 resource_classes=resource_classes)
     result = [mk_one({'data': entry}) for entry in included]
     return result if filter is None else list(_filter(filter, result))
Example #7
0
 def members(obj, predicate=None, filter=None):
     """
     Return all member objects in *obj* that match *predicate* and
     are not filtered by *filter*. This is a wrapper for Python's
     `inspect.getmembers()` with the addition of the filter function.
     """
     return sorted(
         _filter(
             filter,
             [x for _, x in getmembers(obj, predicate)]
         ),
         key=sourceline_sort
     )
Example #8
0
 def _fetch_relationship_included(self, filter=None):
     session = self._session
     include = self._include
     if include is None or dest_class not in include:
         # You requested an included relationship that was
         # not originally included
         error = "{} was not included".format(dest_class.__name__)
         raise AttributeError(error)
     included = self._included.get(dest_resource_type)
     mk_one = dest_class._mk_one(session,
                                 resource_classes=resource_classes)
     result = [mk_one({'data': entry}) for entry in included]
     return result if filter is None else list(_filter(filter, result))
Example #9
0
            def _filter_included(resource_type):
                # Get the relationship list and store the ids
                related = relationships.get(resource_type, {})
                related = related.get('data', None) or []
                if isinstance(related, dict):
                    # to one relationship
                    related = frozenset([related.get('id')])
                else:
                    related = frozenset([r.get('id') for r in related])

                def _resource_filter(resource):
                    return resource.get('id') in related
                # Filter all included objects for the resources
                return list(_filter(_resource_filter, self._included))
Example #10
0
def parse_function(string, typedefs=None):
    """Parse a function declaration into its name, its return type and its
    arguments."""
    try:
        res, args = _parameter_re.fullmatch(string).groups()
    except AttributeError:
        raise ValueError("Function '{}' not understood.".format(string))
    args = list(_filter(None, _re.split(r"\s*,\s*", args)))
    args = [i for i in args if not _re.fullmatch(r"\s*void\s*", i)]
    a, b, name = parse_parameter(res, typedefs=typedefs)
    res = _choose_ctype(a, b, name)
    args = [
        _choose_ctype(*parse_parameter(i, typedefs=typedefs)) for i in args
    ]
    return name, res, args
Example #11
0
            def _filter_included(resource_type):
                # Get the relationship list and store the ids
                related = relationships.get(resource_type, {})
                related = related.get('data', None) or []
                if isinstance(related, dict):
                    # to one relationship
                    related = frozenset([related.get('id')])
                else:
                    related = frozenset([r.get('id') for r in related])

                def _resource_filter(resource):
                    return resource.get('id') in related

                # Filter all included objects for the resources
                return list(_filter(_resource_filter, self._included))
Example #12
0
 def filter(f, seq):
     return list(_filter(f, seq))
Example #13
0
 def _process(json):
     included = json.get('included')
     mk_one = dest_class._mk_one(session,
                                 resource_classes=resource_classes)
     result = [mk_one({'data': entry}) for entry in included]
     return result if filter is None else list(_filter(filter, result))