Beispiel #1
0
class Society(Object):
    id = attr.ib(validator=attr.validators.matches_re('[A-Za-z][A-Za-z0-9]+'))
    xd_id = attr.ib(validator=attr.validators.matches_re('xd[0-9]+'))
    pref_name_for_society = attr.ib()
    glottocode = attr.ib(validator=attr.validators.optional(
        attr.validators.matches_re('[a-z0-9]{4}[0-9]{4}$')))
    ORIG_name_and_ID_in_this_dataset = attr.ib()
    alt_names_by_society = attr.ib(converter=comma_split)
    main_focal_year = attr.ib()
    HRAF_name_ID = attr.ib(converter=HRAF.fromstring)
    HRAF_link = attr.ib(
        converter=lambda s: s.strip() or None,
        validator=attr.validators.optional(
            attr.validators.matches_re(
                r'http://ehrafworldcultures\.yale\.edu/collection\?owc=[A-Z0-9]+|in process',
            )))
    origLat = attr.ib(converter=float)
    origLong = attr.ib(converter=float)
    Lat = attr.ib(converter=float, validator=valid_range(-90, 90))
    Long = attr.ib(converter=float, validator=valid_range(-180, 180))
    Comment = attr.ib()
    glottocode_comment = attr.ib()

    def __str__(self):
        return '{0.pref_name_for_society} ({0.id})'.format(self)

    def astuple(self):
        return (
            self.id,
            self.xd_id,
            self.pref_name_for_society,
            self.glottocode,
            self.ORIG_name_and_ID_in_this_dataset,
            comma_join(self.alt_names_by_society),
            self.main_focal_year,
            '{0}'.format(self.HRAF_name_ID or ''),
            self.HRAF_link,
            format_float(self.origLat),
            format_float(self.origLong),
            format_float(self.Lat),
            format_float(self.Long),
            self.Comment,
            self.glottocode_comment,
        )
Beispiel #2
0
class Coordinate(object):
    latitude = attr.ib(converter=lambda s: float(lat(s.strip())), validator=valid_range(-90, 90))
    longitude = attr.ib(converter=lambda s: float(lon(s.strip())), validator=valid_range(-180, 180))
Beispiel #3
0
 class C(object):
     a = attr.ib(validator=valid_range(0, None))
Beispiel #4
0
 class C(object):
     a = attr.ib(validator=valid_range(-1, 5))
Beispiel #5
0
def longitude():
    return attr.ib(convert=lambda s: None
                   if s is None or s == '' else float(s),
                   validator=valid_range(-180, 180, nullable=True))