Next / Previous / Contents / Shipman's homepage

14. class LocGroup: Sighting's locality

An instance of this class represents all the content defined in the loc-group pattern. See the definition of the loc-group pattern in the schema.

birdnotes.py
# - - - - -   c l a s s   L o c G r o u p

class LocGroup:
    """Represents locality information for sightings.

      Exports:
        LocGroup(loc=None, gps=None, locDetail=None):
          [ (loc is a locality as a Loc instance or None) and
            (gps is a Gps instance or None) and
            (locDetail is a Narrative instance or None) ->
              return a new LocGroup instance with those values ]
        .loc:          [ as passed to constructor, read-only ]
        .gps:          [ as passed to constructor, read-only ]
        .locDetail:    [ as passed to constructor, read-only ]
        LocGroup.readNode(node, dayNotes):   # Static method
          [ (node is an et.Element) and
            (dayNotes is a DayNotes instance) ->
              if node has any valid loc-group content ->
                return a new LocGroup instance representing that
                content
              else if node has loc-group content but there are
              any location codes undefined in dayNotes ->
                raise IOError
              else -> return None ]
        .inherit(parentGroup):
          [ parentGroup is a LocGroup instance ->
              return a new LocGroup whose attributes come from
              parentGroup except when they are overriden by
              corresponding attributes of self ]
        .writeNode(node):
          [ node is an et.Element ->
              node  :=  node with self added as XML ]
    """

14.1. LocGroup.__init__()

None of the three component attributes—location code, GPS waypoint, or location detail—are required. We allow each attribute to be optional in order to implement inheritance: each of these attributes may be inherited from a parent element.

birdnotes.py
# - - -   L o c G r o u p . _ _ i n i t _ _

    def __init__(self, loc=None, gps=None, locDetail=None):
        """Constructor for LocGroup
        """
        self.loc = loc
        self.gps = gps
        self.locDetail = locDetail