def process(typed, data, configurable=None, ctx=None): if ctx is None: from nevow.testutil import FakeRequest from nevow import context fr = FakeRequest() if type(data) is dict: fr.args = data ctx = context.RequestContext(tag=fr) ctx.remember(fr, inevow.IRequest) ctx.remember(None, inevow.IData) try: return iformless.IInputProcessor(typed).process(ctx, configurable, data, autoConfigure=False) except TypeError: return iformless.IInputProcessor(typed).process(ctx, configurable, data)
def _process(): # note, _process only works because it is called IMMEDIATELY # in the loop, watch out for confusing behavior if it is called # later when 'i' has changed resulti = resultList[i] = iformless.IInputProcessor(sub).process(context, boundTo, data, autoConfigure = False) # Merge the valid value in case another fails results.update(resulti)
def _callback(binding): ctx.remember(binding, iformless.IBinding) ctx.remember(self, iformless.IConfigurable) rv = iformless.IInputProcessor(binding).process(ctx, self, args) ctx.remember(rv, inevow.IHand) ctx.remember('%r success.' % bindingName, inevow.IStatusMessage) return rv
def process(self, context, boundTo, data, autoConfigure=True): """Knows how to process a dictionary of lists where the dictionary may contain a key with the same name as the property binding's name. """ binding = self.original context.remember(binding, iformless.IBinding) result = {} try: result[binding.name] = iformless.IInputProcessor( binding.typedValue).process(context, boundTo, data.get(binding.name, [''])) except formless.InputError as e: result[binding.name] = data.get(binding.name, ['']) raise formless.ValidateError({binding.name: e.reason}, e.reason, result) if autoConfigure: try: return self.original.configure(boundTo, result) except formless.InputError as e: result[binding.name] = data.get(binding.name, ['']) raise formless.ValidateError({binding.name: e.reason}, e.reason, result) return result
def process(self, context, boundTo, data, autoConfigure = True): """Knows how to process a dictionary of lists where the dictionary may contain a key with the same name as some of the arguments to the MethodBinding instance. """ typedValue = self.original.typedValue results = {} failures = {} if '----' in data: ## ---- is the "direct object", the one argument you can specify using the command line without saying what the argument name is data[typedValue.arguments[0].name] = data['----'] del data['----'] for binding in typedValue.arguments: name = binding.name try: context = WovenContext(context, faketag) context.remember(binding, iformless.IBinding) results[name] = iformless.IInputProcessor(binding.typedValue).process(context, boundTo, data.get(name, [''])) except formless.InputError as e: results[name] = data.get(name, [''])[0] failures[name] = e.reason if failures: #print "There were validation errors. The errors were: ", failures raise formless.ValidateError(failures, "Error:", results) if autoConfigure: def _except(e): failures[''] = e.reason # self.original.name raise formless.ValidateError(failures, e.reason, results) return exceptblock(self.original.configure, _except, formless.InputError, boundTo, results) return results
def postForm(self, ctx, bindingName, args): """Accept a form post to the given bindingName. The bindingName can be dotted to indicate an attribute of this Configurable, eg addresses.0.changeEmail. The post arguments are given in args. Return a Resource which will be rendered in response. """ from formless import iformless from nevow.tags import invisible request = ctx.locate(inevow.IRequest) pathSegs = bindingName.split('.') configurable = self cf = ctx.locate(iformless.IConfigurableFactory) ## Get the first binding firstSeg = pathSegs.pop(0) binding = configurable.getBinding(ctx, firstSeg) ctx.remember(binding, IBinding) ctx.remember(configurable, IConfigurable) ## I don't think this works right now, it needs to be fixed. ## Most cases it won't be triggered, because we're just traversing a ## single binding name for seg in pathSegs: assert 1 == 0, "Sorry, this doesn't work right now" binding = configurable.getBinding(ctx, seg) child = self.boundTo if not isinstance(binding, GroupBinding): accessor = inevow.IContainer(configurable.boundTo, None) if accessor is None: child = getattr(configurable.boundTo, binding.name) else: child = accessor.child(ctx, binding.name) ## If it's a groupbinding, we don't do anything at all for this path segment ## This won't work right now. We need to push the previous configurable ## as the configurableFactory somehow and ask that for hte next binding ## we also need to support deferreds coming back from locateConfigurable assert 'black' is 'white', "Deferred support is pending" configurable = cf.locateConfigurable(ctx, child) ctx = WovenContext(ctx, invisible(key=seg)) ctx.remember(binding, IBinding) ctx.remember(configurable, IConfigurable) bindingProcessor = iformless.IInputProcessor(binding) rv = bindingProcessor.process(ctx, binding.boundTo, args) ctx.remember(rv, inevow.IHand) ctx.remember('%r success.' % bindingName, inevow.IStatusMessage) return rv
def process(self, context, boundTo, data, autoConfigure = True): """Knows how to process a dictionary of lists where the dictionary may contain a key with the same name as some of the arguments to the MethodBinding instance. """ typedValue = self.original.typedValue results = {} failures = {} if data.has_key('----'): ## ---- is the "direct object", the one argument you can specify using the command line without saying what the argument name is data[typedValue.arguments[0].name] = data['----'] del data['----'] for binding in typedValue.arguments: name = binding.name try: context = WovenContext(context, faketag) context.remember(binding, iformless.IBinding) results[name] = iformless.IInputProcessor(binding.typedValue).process(context, boundTo, data.get(name, [''])) except formless.InputError, e: results[name] = data.get(name, [''])[0] failures[name] = e.reason