Next / Previous / Contents / Shipman's homepage

8. The abbr.py module

This module contains assorted functions for dealing with bird codes.

8.1. Prologue

The module starts with a short, pro-forma comment, a few imports, and the exported manifest constants.

abbr.py
"""abbr.py:  Six-letter bird code system for use with txny.py.

For full documentation, see:
    http://www.nmt.edu/~shipman/xnomo/
"""

#================================================================
# Imports
#----------------------------------------------------------------

import re                  # Standard Python regular expressions


#================================================================
# Manifest constants
#----------------------------------------------------------------

ABBR_L      =  6       # Maximum bird code length
BLANK_ABBR  =  " " * ABBR_L    # Blank bird code
RE_ABBR     =  re.compile (    # Regex for a bird code
    r'[a-zA-Z]{2,6}' )         # Two to six letters
REL_HYBRID  =  "^"             # Relationship codes for hybrid...
REL_PAIR    =  "|"             # ...and species pair
REL_SIMPLE  =  " "             # Simple (not compound) form
REL_MAP     =  {               # Maps rel codes to conventional form
    REL_HYBRID: "x",  REL_PAIR: "/",  REL_SIMPLE: " " }

#--
# Because REL_HYBRID has special meaning inside a regular expression
# of the form [...], it must not be the first character of the set.
#--
RE_REL      =  re.compile (    # Regex for a relationship code
    r'[%s%s]' % (REL_PAIR, REL_HYBRID) )

#--
# Substitutions for confusing color names
#--

COLOR_SUB_2  =  {
    "BLACK":    "BK",       "GRAY":     "GY",
    "BLUE":     "BU",       "GREY":     "GY",
    "BROWN":    "BN",       "GREEN":    "GN" } 

COLOR_SUB_3  =  {
    "BLACK":    "BLK",      "GRAY":     "GRY",
    "BLUE":     "BLU",      "GREY":     "GRY",
    "BROWN":    "BRN",      "GREEN":    "GRN" }