Next / Previous / Contents / TCC Help System / NM Tech homepage

10.17. hist.cgi: fixOldAbbr(): Update an outdated bird code

hist.cgi
# - - -   f i x O l d A b b r

def fixOldAbbr(abbr, txny):
    '''Does this abbr have a modern equivalent?

      [ (abbr is a bird code in standard form) and
        (txny is an xnomo3.Txny instance) ->
          if abbr is not defined in txny ->
            raise KeyError
          if txny has an exact standard equivalent ->
            return that as a code in standard form
          else -> return None ]
    '''

To find out if the code has a modern equivalent, we first find the related Taxon. If the Taxon instance has an .abbr attribute value other than None, that attribute is the equivalent standard code.

hist.cgi
    #-- 1
    # [ if abbr is defined in txny ->
    #     taxon  :=  the related Taxon instance
    #   else -> raise KeyError ]
    taxon = txny.lookupAbbr(abbr)

    #-- 2
    # [ if taxon.abbr is None ->
    #     return None
    #   else ->
    #     return taxon.abbr ]
    return taxon.abbr