"""Track rules.""" import re from switchboard_consumer.constants.track_sample_type import \ ACCEPTABLE_TRACK_SAMPLE_TYPES from switchboard_consumer.constants.track_type import \ ACCEPTABLE_TRACK_TYPES pline_regex = '^$|^(19|20)[0-9]{2}(\\,\\s(19|20)[0-9]{2})*\\s\\S.*$' def valid_track_type(track_type): """Check track_type is one of the of allowed track types.""" return track_type in ACCEPTABLE_TRACK_TYPES def valid_track_sample(track_sample_type): """Check sample_type is one of the allowed track sample types.""" return track_sample_type in ACCEPTABLE_TRACK_SAMPLE_TYPES def valid_pline(pline): """Check if pLine is valid.""" pattern = re.compile(pline_regex) return bool(pattern.match(str(pline)))