def compatibleWithBase(self, base): if self.name != base.name: # this should never happen in real life because of the # way Template matches up messages by name return Incompatible("has different name: %s vs. %s in base" % (self.name, base.name)) if self.priority != base.priority: return Incompatible("has different priority: %s vs. %s in base" % (self.priority, base.priority)) if self.trust != base.trust: return Incompatible("has different trust: %s vs. %s in base" % (self.trust, base.trust)) if self.coding != base.coding: return Incompatible("has different coding: %s vs. %s in base" % (self.coding, base.coding)) if self.number != base.number: return Incompatible("has different number: %s vs. %s in base" % (self.number, base.number)) compatibility = Same() if self.deprecateLevel != base.deprecateLevel: if self.deprecateLevel < base.deprecateLevel: c = Older("is less deprecated: %s vs. %s in base" % (self.deprecations[self.deprecateLevel], self.deprecations[base.deprecateLevel])) else: c = Newer("is more deprecated: %s vs. %s in base" % (self.deprecations[self.deprecateLevel], self.deprecations[base.deprecateLevel])) compatibility = compatibility.combine(c) selflen = len(self.blocks) baselen = len(base.blocks) samelen = min(selflen, baselen) for i in xrange(0, samelen): selfblock = self.blocks[i] baseblock = base.blocks[i] c = selfblock.compatibleWithBase(baseblock) if not c.same(): c = Incompatible("block %d isn't identical" % i) compatibility = compatibility.combine(c) if selflen > baselen: c = Newer("has %d extra blocks" % (selflen - baselen)) elif selflen < baselen: c = Older("missing %d extra blocks" % (baselen - selflen)) else: c = Same() compatibility = compatibility.combine(c) return compatibility
def compatibleWithBase(self, base): if self.name != base.name: return Incompatible("has different name: %s vs. %s in base" % (self.name, base.name)) if self.repeat != base.repeat: return Incompatible("has different repeat: %s vs. %s in base" % (self.repeat, base.repeat)) if self.repeat in Block.repeatswithcount: if self.count != base.count: return Incompatible("has different count: %s vs. %s in base" % (self.count, base.count)) compatibility = Same() selflen = len(self.variables) baselen = len(base.variables) for i in xrange(0, min(selflen, baselen)): selfvar = self.variables[i] basevar = base.variables[i] c = selfvar.compatibleWithBase(basevar) if not c.same(): c = Incompatible("variable %d isn't identical" % i) compatibility = compatibility.combine(c) if selflen > baselen: c = Newer("has %d extra variables" % (selflen - baselen)) elif selflen < baselen: c = Older("missing %d extra variables" % (baselen - selflen)) else: c = Same() compatibility = compatibility.combine(c) return compatibility
def compatibleWithBase(self, base): messagenames = (ImmutableSet(self.messages.keys()) | ImmutableSet(base.messages.keys())) compatibility = Same() for name in messagenames: selfmessage = self.messages.get(name, None) basemessage = base.messages.get(name, None) if not selfmessage: c = Older("missing message %s, did you mean to deprecate?" % name) elif not basemessage: c = Newer("added message %s" % name) else: c = selfmessage.compatibleWithBase(basemessage) c.prefix("in message %s: " % name) compatibility = compatibility.combine(c) return compatibility
def compatibleWithBase(self, base): messagenames = ( frozenset(self.messages.keys()) | frozenset(base.messages.keys()) ) compatibility = Same() for name in messagenames: selfmessage = self.messages.get(name, None) basemessage = base.messages.get(name, None) if not selfmessage: c = Older("missing message %s, did you mean to deprecate?" % name) elif not basemessage: c = Newer("added message %s" % name) else: c = selfmessage.compatibleWithBase(basemessage) c.prefix("in message %s: " % name) compatibility = compatibility.combine(c) return compatibility
def compatibleWithBase(self, base): if self.name != base.name: # this should never happen in real life because of the # way Template matches up messages by name return Incompatible("has different name: %s vs. %s in base" % (self.name, base.name)) if self.priority != base.priority: return Incompatible("has different priority: %s vs. %s in base" % (self.priority, base.priority)) if self.trust != base.trust: return Incompatible("has different trust: %s vs. %s in base" % (self.trust, base.trust)) if self.coding != base.coding: return Incompatible("has different coding: %s vs. %s in base" % (self.coding, base.coding)) if self.number != base.number: return Incompatible("has different number: %s vs. %s in base" % (self.number, base.number)) compatibility = Same() if self.deprecateLevel != base.deprecateLevel: if self.deprecateLevel < base.deprecateLevel: c = Older("is less deprecated: %s vs. %s in base" % ( self.deprecations[self.deprecateLevel], self.deprecations[base.deprecateLevel])) else: c = Newer("is more deprecated: %s vs. %s in base" % ( self.deprecations[self.deprecateLevel], self.deprecations[base.deprecateLevel])) compatibility = compatibility.combine(c) selflen = len(self.blocks) baselen = len(base.blocks) samelen = min(selflen, baselen) for i in xrange(0, samelen): selfblock = self.blocks[i] baseblock = base.blocks[i] c = selfblock.compatibleWithBase(baseblock) if not c.same(): c = Incompatible("block %d isn't identical" % i) compatibility = compatibility.combine(c) if selflen > baselen: c = Newer("has %d extra blocks" % (selflen - baselen)) elif selflen < baselen: c = Older("missing %d extra blocks" % (baselen - selflen)) else: c = Same() compatibility = compatibility.combine(c) return compatibility