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

36.8. CensusRowLabel._foBirdName()

cbchistlib.py
# - - -   C e n s u s R o w L a b e l . _ f o B i r d N a m e

    def _foBirdName(self, s, abbr):
        '''Format the English name for a given bird code in XSL-Fo.

          [ (s is a sox.Sox instance) and
            (abbr is a string) ->
              if abbr is defined in self.birdId.txny ->
                s  +:=  the corresponding English name, in inverted
                    order, as XSL-FO ]
        '''

There are two complications in proper formatting of bird names. Double-quote (“"”) characters should occur in pairs as opening and closing double-quotes; and they may contain italicized portions. Although the xnomo3 package has support for these features as XHTML, it does not support XSL-FO formatting.

The Txny class does have a method named .abbrToRawEng() that gives us the internal form, with underbars used to signify the start and end of italics. This will be our starting point. Example values: "Snipe, Wilson's"; 'Warbler, "Brewster's"'; "Redpoll, (_flammea_) Common".

cbchistlib.py
        #-- 1
        # [ if abbr is defined in self.birdId.txny ->
        #     rawEng  :=  the corresponding raw English name
        #   else -> raise ScriptError ]
        try:
            rawEng = self.birdId.txny.abbrToRawEng(abbr)
        except KeyError:
            raise ScriptError("Unknown bird code '%s'" % abbr)

Splitting rawEng on underbar characters gives us a list of strings in which the elements with even indexes are presented as-is and the ones with odd indexes are presented in italics. Consider, for example, that the expression 'small _Accipiter_ sp.'.split('_') yields the list ['small ', 'Accipiter', ' sp.']. For another example, "_Buteo_ sp.".split('_') yields ['', 'Buteo', ' sp.'].

cbchistlib.py
        #-- 2
        partList = rawEng.split('_')

Italicization is handled by Section 36.9, “CensusRowLabel._foItalicize(): Render in italics”; substitution of proper paired double-quotes is handled by Section 36.10, “CensusRowLabel._foRealQuotes().

cbchistlib.py
        #-- 3
        # [ s  +:=  elements of partList such that elements with even
        #       indices are presented as-is and elements with odd
        #       indices italicized, and double-quote characters in
        #       each element alternate between “ and
        #       ” ]
        for elx, part in enumerate(partList):
            #-- 3 body
            # [ if elx is even ->
            #     s  +:=  part with double-quote characters replaced
            #             alternately by “ and ”
            #   else ->
            #     s  +:=  part in italics, with double-quote characters
            #         replaced alternately by “ and ” ]
            if (elx % 2) == 0:
                self._foRealQuotes(s, part)
            else:
                self._foItalicize(s, part)