def process(self, chain, processing, create:DefineEncoder, **keyargs): ''' @see: HandlerBranching.process Create the collection encoder. ''' assert isinstance(create, DefineEncoder), 'Invalid create %s' % create if create.encoder is not None: return # There is already an encoder, nothing to do. if not isinstance(create.objType, Iter): return # The type is not for a collection, nothing to do, just move along assert isinstance(create.objType, Iter) itemType = create.objType.itemType if DefineEncoder.name in create and create.name: name = create.name else: if not isinstance(itemType, (TypeModel, TypeProperty)): log.error('Cannot get the collection name for item %s', itemType) raise Abort(create) if isinstance(itemType, TypeProperty): assert isinstance(itemType, TypeProperty) model = itemType.parent else: model = itemType assert isinstance(model, TypeModel), 'Invalid model %s' % model name = self.nameMarkedList % model.name encoder = createEncoder(processing, itemType, **keyargs) if encoder is None: log.error('Cannot encode collection item %s', itemType) raise Abort(create) create.encoder = EncoderCollection(name, encoder, encoderSpecifiers(create))
def process(self, chain, decoding: Decoding, parameter: Parameter, invoker: Invoker, **keyargs): ''' @see: HandlerProcessor.process Indexed the parameter decodings. ''' assert isinstance(decoding, Decoding), 'Invalid decoding %s' % decoding assert isinstance(parameter, Parameter), 'Invalid parameter %s' % parameter assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker if not decoding.doDecode: return name = self.separator.join(parameter.path) if invoker.decodingsParameter is None: invoker.decodingsParameter = {} if name in invoker.decodingsParameter: log.error( 'Cannot use because there is the parameters for \'%s\' and \'%s\' have the same path \'%s\'', findFirst(decoding, Decoding.parent, Decoding.input) or name, findFirst(invoker.decodingsParameter[name], Decoding.parent, Decoding.input) or name, name) raise Abort(decoding) invoker.decodingsParameter[name] = decoding
def process(self, chain, register: Register, **keyargs): ''' @see: HandlerProcessor.process Process the solved inputs. ''' assert isinstance(register, Register), 'Invalid register %s' % register if not register.invokers: return # No invokers to process. reported, aborted = set(), [] for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker if not invoker.inputs: continue if invoker.solved is None: solved = frozenset() else: solved = invoker.solved unsolved, keep = [], True for inp in invoker.inputs: assert isinstance(inp, Input), 'Invalid input %s' % inp if inp not in solved: unsolved.append('\'%s\'' % inp.name) if not inp.hasDefault: keep = False if not keep: if invoker.location not in reported: log.error( 'Cannot use because of unsolved inputs %s, at:%s', ', '.join(unsolved), invoker.location) reported.add(invoker.location) aborted.append(invoker) if aborted: raise Abort(*aborted)
def process(self, chain, register: Register, **keyargs): ''' @see: HandlerProcessor.process Populate the content flag if required. ''' assert isinstance(register, Register), 'Invalid register %s' % register if not register.invokers: return # No invokers to process. aborted = [] for invoker in register.invokers: assert isinstance(invoker, InvokerAssembler), 'Invalid invoker %s' % invoker if not invoker.inputs: continue inpContent, toMany = None, False for inp in invoker.inputs: assert isinstance(inp, Input), 'Invalid input %s' % inp if inp.type == self.contentType: if inpContent is not None: toMany = True inpContent = inp if toMany: log.error( 'Cannot use because there are to many \'%s\' inputs, only a maximum of one is allowed, at:%s', typeFor(Content), invoker.location) aborted.append(invoker) elif inpContent: if invoker.solved is None: invoker.solved = set() invoker.solved.add(inpContent) invoker.inputContent = inpContent if aborted: raise Abort(*aborted)
def process(self, chain, register:Register, **keyargs): ''' @see: HandlerProcessor.process Provides the conflict resolving. ''' assert isinstance(register, Register), 'Invalid register %s' % register if Register.hintsCall in register: if register.hintsCall is None: register.hintsCall = {} register.hintsCall[self.hintName] = self.hintDescription if not register.nodes: return reported, aborted = set(), [] for node in register.nodes: assert isinstance(node, Node), 'Invalid node %s' % node if not node.conflicts: continue assert isinstance(node.conflicts, dict), 'Invalid conflicts %s' % node.conflicts for invokers in node.conflicts.values(): assert isinstance(invokers, list), 'Invalid invokers %s' % invokers byService, solving = {}, [] for invoker in invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker if not invoker.service or not invoker.call: continue if invoker.service in byService: continue replaces = invoker.call.hints.get(self.hintName) if not replaces: continue if not isinstance(replaces, tuple): replaces = (replaces,) byService[invoker.service] = invoker solving.append((invoker, replaces)) if byService: locations = [] for invoker, replaces in solving: locations.append(invoker.location) for clazz in replaces: service = typeFor(clazz) if not isinstance(service, TypeService): log.error('Cannot use invoker because the replace hints are invalid, at:%s, ' 'it should be:\n%s', invoker.location, self.hintDescription) aborted.append(invoker) break assert isinstance(service, TypeService), 'Invalid service class %s' % clazz byService.pop(service, None) if not byService: if reported.isdisjoint(locations): log.error('Cannot use invokers because the replace hints are circular among them, at:%s', ''.join(locations)) reported.update(locations) aborted.extend(invokers) else: solved = set(byService) for invoker, replaces in solving: if invoker not in solved: aborted.append(invoker) if aborted: raise Abort(*aborted)
def process(self, chain, processing, decoding:Decoding, **keyargs): ''' @see: HandlerBranching.process Populate the dictionary decoder. ''' assert isinstance(processing, Processing), 'Invalid processing %s' % processing assert isinstance(decoding, Decoding), 'Invalid decoding %s' % decoding if decoding.doDecode: return if not isinstance(decoding.type, Dict): return # The type is not a list, just move along. assert isinstance(decoding.type, Dict) idecoding = decoding.__class__() assert isinstance(idecoding, Decoding), 'Invalid decoding %s' % idecoding idecoding.parent = decoding idecoding.isMandatory = True idecoding.doSet = self.createSetItem(decoding.doGet, decoding.doSet) arg = processing.execute(decoding=idecoding, **keyargs) assert isinstance(arg.decoding, Decoding), 'Invalid decoding %s' % arg.decoding if arg.decoding.doDecode: decoding.doDecode = self.createDecode(arg.decoding, decoding) else: log.error('Cannot decode dictionary item %s', decoding.type) raise Abort(decoding)
def process(self, chain, processing, create:Create, invoker:Invoker, **keyargs): ''' HandlerBranching.process Process the content decoding. ''' assert isinstance(processing, Processing), 'Invalid processing %s' % processing assert isinstance(create, Create), 'Invalid create %s' % create assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker if not create.decodings: return keyargs.update(create=create, invoker=invoker) for decoding in create.decodings: assert isinstance(decoding, Decoding), 'Invalid decoding %s' % decoding if decoding.doDecode: continue arg = processing.execute(decoding=decoding, **keyargs) assert isinstance(arg.decoding, Decoding), 'Invalid decoding %s' % arg.decoding if not arg.decoding.doDecode: continue if invoker.decodingContent: log.error('Cannot use because there are more then one content inputs %s, %s', findFirst(invoker.decodingContent, Decoding.parent, Decoding.input), findFirst(decoding, Decoding.parent, Decoding.input)) raise Abort(invoker.decodingContent, decoding) invoker.decodingContent = arg.decoding
def process(self, chain, processing, invoker: Invoker, create: DefineEncoder, **keyargs): ''' @see: HandlerBranching.process Create the model property encoder. ''' assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker assert isinstance(create, DefineEncoder), 'Invalid create %s' % create if create.encoder is not None: return # There is already an encoder, nothing to do. prop = create.objType if not isinstance(prop, TypeProperty): return # The type is not for a property, nothing to do, just move along assert isinstance(prop, TypeProperty) if not isinstance(prop.parent, TypeModel): return # The type is not for a model, nothing to do, just move along assert isinstance(prop.parent, TypeModel) if not invoker.hideProperties: encoder = createEncoderNamed(processing, prop.name, prop, **keyargs) if encoder is None: log.error('Cannot encode %s', prop) raise Abort(create) else: encoder = None create.encoder = EncoderModelProperty( encoderName(create, prop.parent.name), encoder, encoderSpecifiers(create))
def process(self, chain, register: RegisterNodes, **keyargs): ''' @see: HandlerProcessor.process Provides the shdow conflict resolving. ''' assert isinstance(register, RegisterNodes), 'Invalid register %s' % register if not register.nodes: return aborted = [] for node in register.nodes: assert isinstance(node, NodeConflict), 'Invalid node %s' % node if not node.conflicts: continue assert isinstance(node.conflicts, dict), 'Invalid conflicts %s' % node.conflicts for invokers in node.conflicts.values(): assert isinstance(invokers, list), 'Invalid invokers %s' % invokers k = 0 while k < len(invokers) and len(invokers) > 1: invoker = invokers[k] k += 1 assert isinstance( invoker, InvokerShadow), 'Invalid invoker %s' % invoker if invoker.shadowing: aborted.append(invoker) k -= 1 del invokers[k] if aborted: raise Abort(*aborted)
def process(self, chain, processingKey, processingValue, decoding:DecodingItem, **keyargs): ''' @see: HandlerBranching.process Populate the dictionary decoder. ''' assert isinstance(processingKey, Processing), 'Invalid processing %s' % processingKey assert isinstance(processingValue, Processing), 'Invalid processing %s' % processingValue assert isinstance(decoding, DecodingItem), 'Invalid decoding %s' % decoding if decoding.doDecode: return if not decoding.parent: return assert isinstance(decoding.parent, DecodingItem), 'Invalid decoding %s' % decoding.parent if not isinstance(decoding.parent.type, Dict): return # The type is not a list, just move along. assert isinstance(decoding.parent.type, Dict) kdecoding, vdecoding = decoding.__class__(), decoding.__class__() assert isinstance(kdecoding, DecodingItem), 'Invalid decoding %s' % kdecoding assert isinstance(vdecoding, DecodingItem), 'Invalid decoding %s' % vdecoding kdecoding.parent = decoding kdecoding.isMandatory = True kdecoding.type = decoding.parent.type.keyType kdecoding.doSet, kdecoding.doGet = self.doSetKey, self.doGetKey vdecoding.parent = decoding vdecoding.isMandatory = True vdecoding.type = decoding.parent.type.valueType vdecoding.doSet, vdecoding.doGet = self.doSetValue, self.doGetValue karg = processingKey.execute(decoding=kdecoding, **keyargs) varg = processingValue.execute(decoding=vdecoding, **keyargs) assert isinstance(karg.decoding, DecodingItem), 'Invalid decoding %s' % karg.decoding assert isinstance(varg.decoding, DecodingItem), 'Invalid decoding %s' % varg.decoding if not karg.decoding.doDecode: log.error('Cannot decode dictionary key %s', decoding.parent.type.keyType) raise Abort(decoding) if not varg.decoding.doDecode: log.error('Cannot decode dictionary value %s', decoding.parent.type.valueType) raise Abort(decoding) decoding.doBegin = self.doBegin decoding.doDecode = self.createDecode(karg.decoding.doDecode, varg.decoding.doDecode, decoding) decoding.doEnd = self.createEnd(decoding.doSet)
def process(self, chain, register: Register, Element: ElementFilter, **keyargs): ''' @see: HandlerProcessor.process Process the filter calls. ''' assert isinstance(register, Register), 'Invalid register %s' % register assert issubclass(Element, ElementFilter), 'Invalid path element %s' % Element if not register.invokers: return if Register.hintsCall in register: if register.hintsCall is None: register.hintsCall = {} register.hintsCall[self.hintName] = self.hintDescription aborted = [] for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker if not invoker.call: continue # No call to process hints on. assert isinstance(invoker.call, TypeCall), 'Invalid call %s' % invoker.call if not self.hintName in invoker.call.hints: continue filterName = invoker.call.hints[self.hintName] if not isinstance(filterName, str) and filterName: log.error( 'Cannot use because invalid filter name \'%s\', expected a string value with at ' 'least one character, at:%s', filterName, invoker.location) aborted.append(invoker) continue if not invoker.method == GET: log.error( 'Cannot use because filter call needs to be a GET call, at:%s', invoker.location) aborted.append(invoker) continue assert isinstance(invoker.output, Type), 'Invalid output %s' % invoker.output if not invoker.output.isOf(bool): log.error( 'Cannot use because filter call has invalid output \'%s\', expected a boolean return, at:%s', invoker.output, invoker.location) aborted.append(invoker) continue if invoker.path is None: invoker.path = [] invoker.path.insert( 0, Element(name=self.typeModelAllowed.name, model=self.typeModelAllowed)) invoker.output = self.typePropertyAllowed if Invoker.filterName in invoker: invoker.filterName = filterName.strip() if aborted: raise Abort(*aborted)
def process(self, chain, processing, create: Create, invoker: Invoker, **keyargs): ''' HandlerBranching.process Process the path decoding. ''' assert isinstance(processing, Processing), 'Invalid processing %s' % processing assert isinstance(create, Create), 'Invalid create %s' % create assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker if not invoker.path: return nodeDecoding = {} if create.decodings: for decoding in create.decodings: assert isinstance(decoding, Decoding), 'Invalid decoding %s' % decoding if decoding.doDecode: continue if not decoding.input: continue assert isinstance(decoding.input, Input), 'Invalid input %s' % decoding.input for el in invoker.path: assert isinstance(el, Element), 'Invalid path element %s' % el if el.node and el.input == decoding.input: assert isinstance( decoding.type, TypeProperty ), 'Invalid input type %s' % decoding.type decoding.type = decoding.type.type nodeDecoding[el.node] = decoding if invoker.solved is None: invoker.solved = set() invoker.solved.add(decoding.input) break if create.pathInjected: nodeDecoding.update(create.pathInjected) if nodeDecoding: keyargs.update(create=create, invoker=invoker) for node, decoding in nodeDecoding.items(): arg = processing.execute(decoding=decoding, **keyargs) assert isinstance( arg.decoding, Decoding), 'Invalid decoding %s' % arg.decoding if arg.decoding.doDecode: if invoker.decodingsPath is None: invoker.decodingsPath = {} invoker.decodingsPath[node] = arg.decoding else: log.error('Cannot decode path item %s', decoding.input.type) raise Abort(decoding)
def process(self, chain, register: Register, **keyargs): ''' @see: HandlerProcessor.process Provides the conflict resolving. ''' assert isinstance(register, Register), 'Invalid register %s' % register if not register.nodes: return reported, aborted = set(), [] for node in register.nodes: assert isinstance(node, Node), 'Invalid node %s' % node if not node.conflicts: continue assert isinstance(node.conflicts, dict), 'Invalid conflicts %s' % node.conflicts for methodHTTP, invokers in node.conflicts.items(): if not invokers: continue assert isinstance(invokers, list), 'Invalid invokers %s' % invokers if len(invokers) > 1: locations, address = [], None for invoker in invokers: assert isinstance( invoker, Invoker), 'Invalid invoker %s' % invoker if address is None and invoker.path is not None: address = '/'.join(el.name or '*' for el in invoker.path) if invoker.location not in locations: locations.append(invoker.location) aborted.extend(invokers) if reported.isdisjoint(locations): log.error( 'Cannot use invokers because they have the same web address \'%s\', at:%s', address, ''.join(locations)) reported.update(locations) else: if node.invokers is None: node.invokers = {} node.invokers[methodHTTP] = invokers[0] invokers[0].node = node if aborted and register.hintsCall: available = [] for hname in sorted(register.hintsCall): available.append('\t%s: %s' % (hname, register.hintsCall[hname])) log.error( 'In order to make the invokers available please use one of the call hints:\n%s', '\n'.join(available)) raise Abort(*aborted)
def process(self, chain, processing, decoding: Decoding, **keyargs): ''' @see: HandlerBranching.process Create the model decode. ''' assert isinstance(processing, Processing), 'Invalid processing %s' % processing assert isinstance(decoding, Decoding), 'Invalid decoding %s' % decoding if not isinstance(decoding.type, TypeModel): return # If the type is not model just move along. assert isinstance(decoding.type, TypeModel) decoding.name = decoding.type.name if decoding.children is None: decoding.children = {} for prop in self.sortedTypes(decoding.type): assert isinstance(prop, TypeProperty), 'Invalid property %s' % prop assert isinstance( prop.parent, TypeModel), 'Invalid model property %s' % prop.parent pdecoding = decoding.__class__() assert isinstance(pdecoding, Decoding), 'Invalid decoding %s' % pdecoding pdecoding.name = prop.name pdecoding.parent = decoding pdecoding.property = prop pdecoding.type = prop.type pdecoding.doSet = self.createSet(decoding.doGet, decoding.doSet, prop) pdecoding.doGet = self.createGet(decoding.doGet, prop) consumed, arg = processing.execute(CONSUMED, decoding=pdecoding, **keyargs) if not consumed: continue assert isinstance(arg.decoding, Decoding), 'Invalid decoding %s' % arg.decoding if not arg.decoding.doDecode: log.error( 'Cannot decode property \'%s\' of %s', '.'.join( reversed( listing(arg.decoding, Decoding.parent, Decoding.name))), arg.decoding.type) raise Abort(decoding) decoding.children[pdecoding.name] = arg.decoding if decoding.children: decoding.doDecode = self.createDecode(decoding)
def process(self, chain, processing, register: Register, **keyargs): ''' @see: HandlerBranching.process Populate the encoder. ''' assert isinstance(processing, Processing), 'Invalid processing %s' % processing assert isinstance(register, Register), 'Invalid register %s' % register if not register.invokers: return aborted = [] for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker assert invoker.node, 'Invalid invoker %s with no node' % invoker if invoker.invokerGet: if invoker.isCollection: assert isinstance( invoker.output, Iter), 'Invalid output %s' % invoker.output if isModelId(invoker.output.itemType): invoker.hideProperties = True elif isModelId(invoker.output): invoker.hideProperties = True try: arg = processing.execute( FILL_ALL, create=processing.ctx.create(objType=invoker.output), node=invoker.node, invoker=invoker, **keyargs) except Abort: log.error( 'Cannot use because cannot create encoder for %s, at:%s', invoker.output, invoker.location) aborted.append(invoker) else: assert isinstance(arg.create, Create), 'Invalid create %s' % arg.create if arg.create.encoder is not None: invoker.encoder = arg.create.encoder if aborted: raise Abort(*aborted)
def process(self, chain, processing, register:Register, Decoding:DecodingRequest, **keyargs): ''' @see: HandlerBranching.process Process the decoding. ''' assert isinstance(processing, Processing), 'Invalid processing %s' % processing assert isinstance(register, Register), 'Invalid register %s' % register assert issubclass(Decoding, DecodingRequest), 'Invalid decoding class %s' % Decoding if not register.invokers: return # No invokers to process. aborted = [] keyargs.update(register=register, Decoding=Decoding) for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker assert invoker.node, 'Invalid invoker %s with no node' % invoker if invoker.inputs: decodings = [] for inp in invoker.inputs: assert isinstance(inp, Input), 'Invalid input %s' % inp if invoker.solved and inp in invoker.solved: continue # Already solved decoding = Decoding() decodings.append(decoding) assert isinstance(decoding, DecodingRequest), 'Invalid decoding %s' % decoding decoding.input = inp decoding.type = inp.type decoding.doGet = self.createGet(inp.name) decoding.doSet = self.createSet(inp.name) if decodings: keyargs.update(node=invoker.node, invoker=invoker) try: processing.execute(FILL_ALL, create=processing.ctx.create(decodings=decodings), **keyargs) except Abort: log.error('Cannot use because there is no valid decoder for %s, at:%s', decoding.input, invoker.location) aborted.append(invoker) if aborted: raise Abort(*aborted)
def process(self, chain, register:Register, **keyargs): ''' @see: HandlerProcessor.process Provides the HTTP method name. ''' assert isinstance(register, Register), 'Invalid register %s' % register if not register.invokers: return aborted = [] for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker invoker.methodHTTP = self.mappings.get(invoker.method) if invoker.methodHTTP is None: log.error('Cannot use because the method \'%s\' is not a valid HTTP method, at:%s', invoker.method, invoker.location) aborted.append(invoker) if aborted: raise Abort(*aborted)
def process(self, chain, processing, decoding: Decoding, **keyargs): ''' @see: HandlerBranching.process Create the property of model decode. ''' assert isinstance(processing, Processing), 'Invalid processing %s' % processing assert isinstance(decoding, Decoding), 'Invalid decoding %s' % decoding if not isinstance(decoding.type, TypeProperty): return # If the type is not property just move along. assert isinstance(decoding.type, TypeProperty) if not isinstance(decoding.type.parent, TypeModel): return # If the parent is not model just move along. pdecoding = decoding.__class__() assert isinstance(pdecoding, Decoding), 'Invalid decoding %s' % pdecoding pdecoding.name = decoding.type.name pdecoding.parent = decoding pdecoding.property = decoding.type pdecoding.type = decoding.type.type pdecoding.doSet = decoding.doSet pdecoding.doGet = decoding.doGet arg = processing.execute(decoding=pdecoding, **keyargs) assert isinstance(arg.decoding, Decoding), 'Invalid decoding %s' % arg.decoding if not arg.decoding.doDecode: log.error( 'Cannot decode property \'%s\' of %s', '.'.join( reversed( listing(arg.decoding, Decoding.parent, Decoding.name))), arg.decoding.type) raise Abort(arg.decoding) if decoding.children is None: decoding.children = {} decoding.children[arg.decoding.name] = arg.decoding decoding.doDecode = self.createDecode(decoding, arg.decoding.doDecode)
def process(self, chain, register: Register, Element: ElementUpdate, **keyargs): ''' @see: HandlerProcessor.process Provides the paths adjustments based on target models. ''' assert isinstance(register, Register), 'Invalid register %s' % register assert issubclass(Element, ElementUpdate), 'Invalid element %s' % Element if not register.invokers: return aborted = [] for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker if invoker.methodHTTP != HTTP_PUT: continue if not invoker.target: continue assert isinstance(invoker.target, TypeModel), 'Invalid target %s' % invoker.target if not invoker.target.propertyId: continue if invoker.path is None: invoker.path = [] for el in invoker.path: assert isinstance(el, ElementUpdate), 'Invalid element %s' % el if el.model == invoker.target: log.error( 'Cannot use for update because the %s is already present as input, at:%s', invoker.target, invoker.location) aborted.append(invoker) break else: invoker.path.append( Element(name=invoker.target.name, model=invoker.target)) invoker.path.append( Element(property=invoker.target.propertyId, isInjected=True)) if aborted: raise Abort(*aborted)
def process(self, chain, register:Register, **keyargs): ''' @see: HandlerProcessor.process Provides the domain based on elements models. ''' assert isinstance(register, Register), 'Invalid register %s' % register if not register.invokers: return if Register.hintsCall in register: if register.hintsCall is None: register.hintsCall = {} register.hintsCall[self.hintName] = self.hintDescription aborted = [] for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker if not invoker.call: continue # No call to process hints on. if not invoker.path: continue # No path to append the web name to. assert isinstance(invoker.call, TypeCall), 'Invalid call %s' % invoker.call if not self.hintName in invoker.call.hints: continue webName = invoker.call.hints[self.hintName] if not isinstance(webName, str) or not re.match('\w+$', webName): log.error('Cannot use because invalid web name \'%s\', can only contain alpha numeric characters at:%s', webName, invoker.location) aborted.append(invoker) break for el in reversed(invoker.path): assert isinstance(el, Element), 'Invalid element %s' % el if el.name: el.name = '%s%s' % (webName, el.name) break else: assert isinstance(register.doSuggest, IDo), 'Invalid do suggest %s' % register.doSuggest register.doSuggest('Could not process the web name at:%s', invoker.location) if aborted: raise Abort(*aborted)
def process(self, chain, register:Register, Element:ElementDomain, **keyargs): ''' @see: HandlerProcessor.process Provides the domain based on elements models. ''' assert isinstance(register, Register), 'Invalid register %s' % register assert issubclass(Element, ElementDomain), 'Invalid path element %s' % Element if not register.invokers: return if Register.hintsModel in register: if register.hintsModel is None: register.hintsModel = {} register.hintsModel[self.hintName] = self.hintDescription aborted = [] for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker if not invoker.path: continue # No path model to process for. assert isinstance(invoker.path, list), 'Invalid elements %s' % invoker.path for el in invoker.path: assert isinstance(el, ElementDomain), 'Invalid element %s' % el if not el.model: continue assert isinstance(el.model, TypeModel), 'Invalid model %s' % el.model if self.hintName in el.model.hints: domain = el.model.hints[self.hintName] if not isinstance(domain, str) or not domain: log.error('Cannot use invoker because the model %s domain \'%s\' is invalid, at:%s', el.model, domain, invoker.location) aborted.append(invoker) else: assert isinstance(domain, str) for name in reversed(domain.split('/')): if name: invoker.path.insert(0, Element(name=name)) break if aborted: raise Abort(*aborted)
def process(self, chain, register: RegisterNodes, **keyargs): ''' @see: HandlerProcessor.process Check if the shadows are required. ''' assert isinstance(register, RegisterNodes), 'Invalid register %s' % register if not register.nodes: return aborted = [] for node in register.nodes: assert isinstance(node, NodeRequired), 'Invalid node %s' % node if not node.invokers or HTTP_GET not in node.invokers: continue invoker = node.invokers[HTTP_GET] assert isinstance(invoker, InvokerRequired), 'Invalid invoker %s' % invoker if not invoker.shadowing: continue assert isinstance( invoker.shadowing, InvokerRequired), 'Invalid invoker %s' % invoker.shadowing assert isinstance( invoker.shadowing.node, NodeRequired), 'Invalid node %s' % invoker.shadowing.node if not node.invokersAccessible: aborted.append(invoker) else: assert isinstance( node.invokersAccessible, list ), 'Invalid accessible invokers %s' % node.invokersAccessible if invoker.shadowing.node.invokersAccessible: node.invokersAccessible.reverse() node.invokersAccessible.extend( invoker.shadowing.node.invokersAccessible) node.invokersAccessible.reverse() if aborted: raise Abort(*aborted)
def process(self, chain, processing, modelExtraProcessing, invoker: Invoker, create: DefineEncoder, **keyargs): ''' @see: HandlerBranching.process Create the model encoder. ''' assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker assert isinstance(create, DefineEncoder), 'Invalid create %s' % create if create.encoder is not None: return # There is already an encoder, nothing to do. if not isinstance(create.objType, TypeModel): return # The type is not for a model, nothing to do, just move along assert isinstance(create.objType, TypeModel) keyargs.update(invoker=invoker) extra, properties = None, [] if not invoker.hideProperties: for prop in self.sortedTypes(create.objType): assert isinstance( prop, TypeProperty), 'Invalid property type %s' % prop encoder = createEncoderNamed(processing, prop.name, prop, **keyargs) if encoder is None: log.error('Cannot encode %s', prop) raise Abort(create) properties.append((prop.name, encoder)) if modelExtraProcessing: extra = createEncoder(modelExtraProcessing, create.objType, **keyargs) create.encoder = EncoderModel(encoderName(create, create.objType.name), properties, extra, encoderSpecifiers(create))
def process(self, chain, register:Register, **keyargs): ''' @see: HandlerProcessor.process Process the invokers based on method. ''' assert isinstance(register, Register), 'Invalid register %s' % register if not register.invokers: return aborted = [] for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker keep = False if invoker.method == GET: keep = self.processGET(invoker) elif invoker.method == INSERT: keep = self.processINSERT(invoker) elif invoker.method == UPDATE: keep = self.processUPDATE(invoker) elif invoker.method == DELETE: keep = self.processDELETE(invoker) else: log.error('Cannot use because the method %s is not known, at:%s', invoker.method, invoker.location) keep = False if not keep: aborted.append(invoker) if aborted: raise Abort(*aborted)
def process(self, chain, register: Register, Node: NodeInvoker, **keyargs): ''' @see: HandlerProcessor.process Provides the path based on elements. ''' assert isinstance(register, Register), 'Invalid register %s' % register assert isinstance(register.exclude, set), 'Invalid exclude set %s' % register.exclude assert issubclass(Node, NodeInvoker), 'Invalid node class %s' % Node if not register.invokers: return # No invokers to process if register.nodes is None: register.nodes = [] if register.root is None: register.root = Node() register.nodes.append(register.root) aborted, checkReported = [], self.createReported() for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker assert isinstance( invoker.methodHTTP, str), 'Invalid HTTP method name %s' % invoker.methodHTTP node = register.root assert isinstance(node, NodeInvoker), 'Invalid node %s' % node valid = True if invoker.path: for el in invoker.path: assert isinstance(el, Element), 'Invalid element %s' % el if el.property: assert isinstance(el.property, TypeProperty) if not el.property.type.isPrimitive: if checkReported(invoker): log.error( 'Cannot use because the %s is not a primitive, at:%s', el.property, invoker.location) valid = False break if node.type is None: node.type = el.property.type elif node.type != el.property.type: if checkReported(invoker): log.error( 'Cannot use because the property %s is expected to be %s, at:%s', el.property, node.type, invoker.location) valid = False break assert isinstance( node.type, Type), 'Invalid node type %s' % node.type if node.type.isOf(str) and node.childByName: if checkReported(invoker): log.error( 'Cannot use because the node already has named children (%s) and cannot use with ' 'string property \'%s\', at:%s', ', '.join( str(childName) for childName in node.childByName), el.property, invoker.location) valid = False break el.node = node if node.child is None: node.child = Node(parent=node) register.nodes.append(node.child) node = node.child else: assert isinstance( el.name, str ) and el.name, 'Invalid element name %s' % el.name if node.type and node.type.isOf(str): if checkReported(invoker): log.error( 'Cannot use because the node represents a string property and cannot add name ' '\'%s\', at:%s', el.name, invoker.location) valid = False break el.node = node if node.childByName is None: node.childByName = {} cnode = node.childByName.get(el.name) if cnode is None: cnode = node.childByName[el.name] = Node( parent=node) register.nodes.append(cnode) node = cnode if not valid: aborted.append(invoker) else: if node.invokers is None: node.invokers = {invoker.methodHTTP: invoker} elif node.conflicts and invoker.methodHTTP in node.conflicts: node.conflicts[invoker.methodHTTP].append(invoker) continue elif invoker.methodHTTP in node.invokers: if node.conflicts is None: node.conflicts = {} conflicts = node.conflicts.get(invoker.methodHTTP) if conflicts is None: conflicts = node.conflicts[invoker.methodHTTP] = [ node.invokers.pop(invoker.methodHTTP) ] conflicts.append(invoker) continue else: node.invokers[invoker.methodHTTP] = invoker invoker.node = node if aborted: raise Abort(*aborted)
def process(self, chain, register: Register, **keyargs): ''' @see: HandlerProcessor.process Merge the filter invokers. ''' assert isinstance(register, Register), 'Invalid register %s' % register if not register.invokers: return invokers = {} for invoker in register.invokers: assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker if invoker.filterName is None: continue finvokers = invokers.get(invoker.filterName) if finvokers is None: finvokers = invokers[invoker.filterName] = [] finvokers.append(invoker) aborted, invokersFilters = [], [] for name, finvokers in invokers.items(): if len(finvokers) > 1: log.error( 'Cannot use filters invokers because they have the same name \'%s\', at:%s', name, ''.join(invk.location for invk in invokers)) aborted.extend(finvokers) invokersFilters.append(finvokers[0]) filters = [] for invoker in invokersFilters: filtre = Filter() filters.append(filtre) filtre.Name = invoker.filterName items = [] for el in invoker.path: assert isinstance(el, Element), 'Invalid element %s' % el if el.property: if Invoker.filterInjected in invoker and invoker.filterInjected and el in invoker.filterInjected: items.append(invoker.filterInjected[el]) else: if filtre.Signature is not None: log.error( 'Cannot use filter invoker because there are to many possible targets, at:%s', invoker.location) aborted.append(invoker) break filtre.Signature = signature(el.property) items.append('*') else: assert isinstance(el.name, str), 'Invalid element name %s' % el.name items.append(el.name) else: filtre.Path = '/'.join(items) if filtre.Signature is None: log.error( 'Cannot use filter invoker because there is no target, at:%s', invoker.location) aborted.append(invoker) if aborted: raise Abort(*aborted) self.mergeFilters(filters)
def process(self, chain, processing, decoding:Decoding, parameter:Parameter, invoker:Invoker, Definition:DefinitionQuery, **keyargs): ''' @see: HandlerBranching.process Create the query decodings. ''' assert isinstance(processing, Processing), 'Invalid processing %s' % processing assert isinstance(decoding, Decoding), 'Invalid decoding %s' % decoding assert isinstance(parameter, Parameter), 'Invalid parameter %s' % parameter assert isinstance(invoker, Invoker), 'Invalid invoker %s' % invoker assert issubclass(Definition, DefinitionQuery), 'Invalid definition class %s' % Definition if not isinstance(decoding.type, TypeQuery): return # If the type is not query just move along. assert isinstance(decoding.type, TypeQuery) # If the query is for the target model then we will use simple names. if invoker.target == decoding.type.target: qpath = () else: qpath = parameter.path keyargs.update(invoker=invoker, Definition=Definition) for cname, cprop in decoding.type.properties.items(): assert isinstance(cprop, TypeProperty), 'Invalid property %s' % cprop assert isinstance(cprop.type, TypeCriteria), 'Invalid criteria %s' % cprop.type cpath = list(qpath) cpath.append(cname) definitions = {} for name, prop in cprop.type.properties.items(): assert isinstance(prop, TypeProperty), 'Invalid property %s' % prop cdecoding = decoding.__class__() assert isinstance(cdecoding, Decoding), 'Invalid decoding %s' % cdecoding cdecoding.parent = decoding cdecoding.doSet = self.createSet(decoding.doGet, decoding.doSet, cprop, prop) cdecoding.doGet = self.createGet(decoding.doGet, cprop, prop) cdecoding.property = prop cdecoding.type = prop.type cparameter = parameter.__class__() assert isinstance(cparameter, Parameter), 'Invalid parameter %s' % cparameter cparameter.path = list(cpath) cparameter.path.append(name) consumed, arg = processing.execute(CONSUMED, decoding=cdecoding, parameter=cparameter, **keyargs) if not consumed: continue assert isinstance(arg.decoding, Decoding), 'Invalid decoding %s' % arg.decoding if not arg.decoding.doDecode: log.error('Cannot decode criteria property %s for query of %s', prop, decoding.type) raise Abort(decoding) if arg.decoding.parameterDefinition: definitions[name] = arg.decoding.parameterDefinition if cprop.type.main: mdecoding = decoding.__class__() assert isinstance(mdecoding, Decoding), 'Invalid decoding %s' % mdecoding prop = firstOf(cprop.type.main.values()) references = [defin for defin in map(definitions.get, cprop.type.main) if defin] mdecoding.parent = decoding mdecoding.doSet = self.createSet(decoding.doGet, decoding.doSet, cprop, *cprop.type.main.values()) mdecoding.doGet = self.createGet(decoding.doGet, cprop, prop) mdecoding.property = cprop mdecoding.type = prop.type mparameter = parameter.__class__() assert isinstance(mparameter, Parameter), 'Invalid parameter %s' % mparameter mparameter.path = cpath consumed, arg = processing.execute(CONSUMED, decoding=mdecoding, definition=Definition(references=references), parameter=mparameter, **keyargs) if not consumed: continue assert isinstance(arg.decoding, Decoding), 'Invalid decoding %s' % arg.decoding if not arg.decoding.doDecode: log.error('Cannot decode main criteria properties %s for query of %s', ', '.join(map(str, cprop.type.main.values())), decoding.type) raise Abort(decoding)