def decodeCriteria(self, typeCriteria, getterCriteria): ''' Exploit that provides the decoder for the criteria. @param typeCriteria: TypeCriteria The criteria type to decode. @param getterCriteria: callable(object) -> object The getter used to get the criteria from the target object. @return: callable(**data) -> boolean The exploit that provides the criteria decoding. ''' assert isinstance( typeCriteria, TypeCriteria), 'Invalid criteria type %s' % typeCriteria assert callable(getterCriteria), 'Invalid getter %s' % getterCriteria criteria = typeCriteria.container assert isinstance(criteria, Criteria) if issubclass(typeCriteria.clazz, AsOrdered): exclude = ('ascending', 'priority') else: exclude = () children = {} for prop, typeProp in criteria.properties.items(): if prop in exclude: continue if isinstance(typeProp, Iter): assert isinstance(typeProp, Iter) setter = setterWithGetter(obtainOnObj(prop, list), list.append) propDecode = self.decodePrimitiveList(setter, typeProp.itemType) else: propDecode = self.decodePrimitive(setterOnObj(prop), typeProp) children[prop] = propDecode exploitPath = self.decodePath(children) def exploit(path, target, **data): assert isinstance(path, deque), 'Invalid path %s' % path if path: return exploitPath(path=path, target=getterCriteria(target), **data) if not criteria.main: return False data.update(path=path, target=getterCriteria(target)) for prop in criteria.main: if not children[prop](**data): return False return True return exploit
def decodeCriteria(self, typeCriteria, getterCriteria): """ Exploit that provides the decoder for the criteria. @param typeCriteria: TypeCriteria The criteria type to decode. @param getterCriteria: callable(object) -> object The getter used to get the criteria from the target object. @return: callable(**data) -> boolean The exploit that provides the criteria decoding. """ assert isinstance(typeCriteria, TypeCriteria), "Invalid criteria type %s" % typeCriteria assert callable(getterCriteria), "Invalid getter %s" % getterCriteria criteria = typeCriteria.container assert isinstance(criteria, Criteria) if issubclass(typeCriteria.clazz, AsOrdered): exclude = ("ascending", "priority") else: exclude = () children = {} for prop, typeProp in criteria.properties.items(): if prop in exclude: continue if isinstance(typeProp, Iter): assert isinstance(typeProp, Iter) setter = setterWithGetter(obtainOnObj(prop, list), list.append) propDecode = self.decodePrimitiveList(setter, typeProp.itemType) else: propDecode = self.decodePrimitive(setterOnObj(prop), typeProp) children[prop] = propDecode exploitPath = self.decodePath(children) def exploit(path, target, **data): assert isinstance(path, deque), "Invalid path %s" % path if path: return exploitPath(path=path, target=getterCriteria(target), **data) if not criteria.main: return False data.update(path=path, target=getterCriteria(target)) for prop in criteria.main: if not children[prop](**data): return False return True return exploit
def decoderId(self, propertyName, typeValue): ''' Create a decode exploit for a property id decode and add it to this model decode. @param propertyName: string The property name to use for the id value. @param typeValue: Type The type of the property to decode. @return: callable(**data) The exploit that provides the id decoding. ''' assert isinstance(propertyName, str), 'Invalid property name %s' % propertyName return DecodeId(setterOnObj(propertyName), typeValue)
def decoderPrimitive(self, propertyName, typeValue): ''' Create a decode exploit for a primitive property also decodes primitive value list. @param propertyName: string The property name to use for the primitive. @param typeValue: Type The type of the property value to decode. @return: callable(**data) The exploit that provides the primitive decoding. ''' assert isinstance(propertyName, str), 'Invalid property name %s' % propertyName assert isinstance(typeValue, Type), 'Invalid property value type %s' % typeValue if isinstance(typeValue, List): assert isinstance(typeValue, List) return DecodePrimitiveList(typeValue.itemType, obtainOnObj(propertyName, list)) return DecodePrimitive(setterOnObj(propertyName), typeValue)