def requireIfPresent_post_converter(conversion, state=None): if present in conversion.children.keys(): for field in fields: if not field in conversion.children.keys(): set_error( conversion, 'The field %r, required if %r is present, could not ' 'be found' % (field, present)) return
def requireIfPresent_post_converter(conversion, state=None): if present in conversion.children.keys(): for field in fields: if not field in conversion.children.keys(): set_error( conversion, 'The field %r, required if %r is present, could not ' 'be found'%(field, present) ) return
def exacltyOneFieldFrom_post_converter(conversion, state=None): found = [] for k in conversion.children.keys(): if k in fields: found.append(k) if len(found) == 2: set_error( conversion, 'You should only specify %r or %r, not both' % ( found[0], found[1], )) elif not found: set_error(conversion, 'You must specify one of the fields %r' % (fields, ))
def joinVars_post_converter(conversion, service=None): # There shouldn't have been problems with the conversions if not conversion.successful: return # First check they all received the same input variables # and while we're at it, make a list of all the matched variables children = conversion.children.values() if not children: raise NotImplementedError( 'Not sure what to do in this case, will wait until this is raised' ) set_result(conversion, result) input = children[0].result[0] matched = children[0].result[2] counter = 0 for child in children[1:]: counter += 1 for var in child.result[2]: if var not in matched: matched.append(var) if child.result[0] != input: raise URLConvertError( "Item %s of the generators didn't receive the same input " "variables as item 0" % counter) # Now we can start the real processing. # 1. Find out if all the variables which were matched variables = input['vars'].keys() #for k, v in add.items(): # if k in input['vars'].keys() and # variables.pop(variables.index(k)) variables.sort() matched.sort() if variables != matched: log.debug( ('Not all the input variables were matched against this rule. ' 'Input != Matched: %r != %r'), variables, matched, ) set_error( conversion, 'Not all the input variables were matched against this rule') return # 2. If they do, assemble the parts result = dict([(k, v[1]) for k, v in conversion.result.items()]) set_result(conversion, result)
def mergeParts_post_converter(conversion, service=None): if conversion.successful: result = {} for part, item in conversion.result.items(): # Any correctly converted parts exist only as a dictionary if isinstance(item, dict): for name, value in item.items(): if result.has_key(name): if result[name] != value: set_error( conversion, 'No match: different values %s and %s ' 'present for the variable %s' % (result[name], value, name)) return else: result[name] = value set_result(conversion, result)
def exacltyOneFieldFrom_post_converter(conversion, state=None): found = [] for k in conversion.children.keys(): if k in fields: found.append(k) if len(found) == 2: set_error( conversion, 'You should only specify %r or %r, not both'%( found[0], found[1], ) ) elif not found: set_error( conversion, 'You must specify one of the fields %r'%( fields, ) )