Names of constants are all uppercased.
# - - - - - M a n i f e s t c o n s t a n t s
Length of a bird code, and related definitions.
ABBR_L = 6 # Maximum bird code length
A full-length blank bird code.
BLANK_ABBR = " " * ABBR_L # Blank bird code
A regular expression that matches a free-field bird code.
RE_ABBR = re.compile ( # Regex for a bird code
r'[a-zA-Z]{2,6}' ) # Two to six letters
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.
| External | Internal |
|---|---|
' ' | ' ' |
'x' | '^' |
'/' | '|' |
The first group of codes specifies the internal representations.
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.
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.
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.
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 “^”.
#--
# 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) )