We start off with class Txny.
Here is its external interface:
# - - - - - c l a s s T x n y - - - - -
class Txny:
"""Object to represent the entire taxonomy and code system.
Exports:
Txny ( dataFile=None ):
[ dataFile is a string, defaulting to DEFAULT_FILE_NAME ->
if dataFile names a readable XML file that
validates against txny.rnc ->
return a new Txny object representing that file
else -> raise IOError ]
.genAbbrs():
[ generate all valid bird codes in self, in ascending
order ]
.genTxKeys():
[ generate all the taxonomy keys in self, in ascending
order ]
.lookupAbbr ( abbr ):
[ abbr is a string ->
if self contains a Taxon whose .abbr attribute
matches abbr, case-insensitive and blank-padded ->
return that Taxon
else -> raise KeyError ]
.lookupCollision ( abbr ):
[ abbr is a string ->
if self contains a collision code matching abbr,
case-insensitive ->
return a list of the valid alternative codes
else -> raise KeyError ]
.lookupSci ( sci ):
[ sci is a string ->
if self contains a taxon whose scientific name matches
sci ->
return that taxon as a Taxon object
else -> raise KeyError ]
.lookupTxKey ( txKey ):
[ txKey is a string ->
if self contains a Taxon whose .txKey attribute
matches txKey ->
return that Taxon
else -> raise KeyError ]
.abbrToEng ( abbr ):
[ abbr is a string ->
if abbr is a bird code in self ->
return the corresponding English name
else -> raise KeyError ]
.abbrToTex ( abbr ):
[ abbr is a string ->
if abbr is a bird code in self ->
return the corresponding TeX name
else -> raise KeyError ]
The various lookup functions require that we have internal
dictionaries to map the various names, keys and codes to Taxon objects.
State/Invariants:
.__abbrMap:
[ a dictionary whose keys are the bird codes in self,
uppercased, and their corresponding values are the related
Taxon objects ]
.__collMap:
[ a dictionary whose keys are the collision codes in self,
uppercased, and their corresponding values are lists
of the valid substite codes ]
.__sciMap:
[ a dictionary whose values are the Taxon objects in self
and the corresponding keys are their .sci attributes ]
.__txKeyMap:
[ a dictionary whose values are the Taxon objects in self
and the corresponding keys are their .txKey attributes ]
.__abbrEng:
[ a dictionary whose values are the English names from which
the bird codes in self were derived, and the corresponding
keys are those codes ]
.__abbrTex:
[ a dictionary whose values are the English names from which
the bird codes in self were derived, marked up with TeX
conventions, and the corresponding keys are those codes ]
"""
Generates the keys from the .__abbrMap
dictionary, in ascending order. Note that the keys are already
uppercased.
# - - - T x n y . g e n A b b r s - - -
def genAbbrs ( self ):
"""Generate all valid bird codes in self.
"""
keyList = self.__abbrMap.keys()
keyList.sort()
for key in keyList:
yield key
raise StopIteration