Next / Previous / Contents / Shipman's homepage

11.2. Manifest constants

Names of constants are all uppercased.

abbr.py
# - - - - -   M a n i f e s t   c o n s t a n t s

11.2.1. ABBR_L

Length of a bird code, and related definitions.

abbr.py
ABBR_L = 6          # Maximum bird code length

11.2.2. BLANK_ABBR

A full-length blank bird code.

abbr.py
BLANK_ABBR = " " * ABBR_L   # Blank bird code

11.2.3. RE_ABBR

A regular expression that matches a free-field bird code.

abbr.py
RE_ABBR = re.compile (      # Regex for a bird code
    r'[a-zA-Z]{2,6}' )      # Two to six letters

11.2.4. Relationship codes

Relationship codes come in two sets: the external codes (displayed with compound bird names) and the internal codes (used in the BirdId.rel attribute). Here is a table that shows the equivalences.

ExternalInternal
' '' '
'x''^'
'/''|'

The first group of codes specifies the internal representations.

abbr.py
REL_HYBRID = '^'             # Relationship codes for hybrid...
REL_PAIR = '|'             # ...and species pair
REL_SIMPLE = ' '             # Simple (not compound) form

The next group define conventional external relationship codes.

abbr.py
OUTER_REL_HYBRID = 'x'
OUTER_REL_PAIR = '/'
OUTER_REL_SIMPLE = ' '

The STANDARD_REL dictionary translates either external or internal relationship codes to the internal form. It accepts several alternative values.

abbr.py
STANDARD_REL = {        # Maps external or internal to internal
  OUTER_REL_SIMPLE: REL_SIMPLE, REL_SIMPLE: REL_SIMPLE,
  None: REL_SIMPLE,
  OUTER_REL_PAIR: REL_PAIR, REL_PAIR: REL_PAIR,
  OUTER_REL_HYBRID: REL_HYBRID, REL_HYBRID: REL_HYBRID }

The REL_MAP translates internal to external form.

abbr.py
REL_MAP = {               # Maps rel codes to conventional form
    REL_PAIR: OUTER_REL_PAIR,
    REL_HYBRID: OUTER_REL_HYBRID,
    REL_SIMPLE: OUTER_REL_SIMPLE }

The RE_REL compiled regular expression matches an internal-form relationship code. The comment points out that “^” just inside a “[...]” group in a regular expression has special meaning, so that character must be second when matching either “|” or “^”.

abbr.py
#--
# 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) )

11.2.5. Color substitutions

abbr.py
#--
# 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" }