def merge(self, walk, base, head, schema, meta, limit=None, unique=None, ignoreDups=True, **kwargs): # backwards compatibility if unique is False: ignoreDups = False if base.is_undef(): base = JSONValue(val=[], ref=base.ref) else: base = JSONValue(list(base.val), base.ref) if not ignoreDups or not base.val or base.val[-1]['value'] != head.val: base.val.append(walk.add_meta(head.val, meta)) if limit is not None: base.val = base.val[-limit:] return base
def merge(self, walk, base, head, schema, limit=None, unique=None, ignoreDups=True, metadata=None, **kwargs): # backwards compatibility if unique is False: ignoreDups = False if metadata is not None: if not walk.is_type(JSONValue(val=metadata), "object"): raise SchemaError( "'metadata' option does not contain an object") if base.is_undef(): base = JSONValue(val=[], ref=base.ref) last_entry = JSONValue(undef=True) else: if not walk.is_type(base, "array"): raise BaseInstanceError( "Base is not an array. " "Base not previously generated with this strategy?", base) base = JSONValue(list(base.val), base.ref) if base.val: last_entry = base[-1] if not walk.is_type(last_entry, "object"): raise BaseInstanceError( "Last entry in the versioned array is not an object. " "Base not previously generated with this strategy?", last_entry) if 'value' not in last_entry.val: raise BaseInstanceError( "Last entry in the versioned array has no 'value' property. " "Base not previously generated with this strategy?", last_entry) else: last_entry = JSONValue(undef=True) if not ignoreDups or last_entry.is_undef( ) or last_entry['value'].val != head.val: base.val.append(self.add_metadata(head.val, metadata)) if limit is not None: base.val = base.val[-limit:] return base
def merge(self, walk, base, head, schema, meta, incompatible=None, **kwargs): if incompatible is None: incompatible = [] else: incompatible = [set(terms) for terms in incompatible] if head is None or head.is_undef(): return base if not walk.is_type(head, "array"): head = JSONValue(val=[head.val], ref=head.ref) if base.is_undef(): base = JSONValue({}, base.ref) elif not walk.is_type(base, "array"): base = JSONValue(val=[base.val], ref=base.ref) else: base = JSONValue(list(base.val), base.ref) def valInArray(val, ary): if isinstance(val, JSONValue): val = val.val return val in [(isinstance(v, JSONValue) and v.val) or v for v in ary] def findIncompat(val): for _set in incompatible: if val in _set: return _set return set() for newval in head.val: if valInArray(newval, base.val): continue choices = findIncompat(newval) for choice in choices: if newval == choice: continue elif valInArray(choice, base): base.val = [v for v in base.val if v != choice] base.val.append(newval) return base
def merge(self, walk, base, head, schema, meta, limit=None, unique=None, ignoreDups=True, **kwargs): # backwards compatibility if unique is False: ignoreDups = False if base.is_undef(): base = JSONValue(val=[], ref=base.ref) else: base = JSONValue(list(base.val), base.ref) if not ignoreDups or not base.val or base.val[-1]['value'] != head.val: base.val.append(walk.add_meta(head.val, meta)) if limit is not None: base.val = base.val[-limit:] return base