def check_issue_year(issue_year, *, required): if is_accepted(issue_year, required=required): issue_year = check_year(issue_year, MIN_ISSUE_YEAR, MAX_ISSUE_YEAR) return issue_year else: raise MissingRequiredValue( "This field cannot be empty, please provide a valid passport.")
def check_birth_year(birth_year, *, required): if is_accepted(birth_year, required=required): birth_year = check_year(birth_year, MIN_BIRTH_YEAR, MAX_BIRTH_YEAR) return birth_year else: raise MissingRequiredValue( "This field cannot be empty, please provide a valid passport.")
def check_expiration_year(expiration_year, *, required): if is_accepted(expiration_year, required=required): expiration_year = check_year(expiration_year, MIN_EXPIRATION_YEAR, MAX_EXPIRATION_YEAR) return expiration_year else: raise MissingRequiredValue( "This field cannot be empty, please provide a valid passport.")
def check_passport_id(passport_id, *, required): if is_accepted(passport_id, required=required): if re.match(PASSPORT_ID_PATTERN, passport_id): return passport_id else: raise InvalidValue( "A passport ID must conform to the following pattern: " + PASSPORT_ID_PATTERN + ".") else: raise MissingRequiredValue( "This field cannot be empty, please provide a valid passport.")
def check_eye_colour(eye_colour, *, required): if is_accepted(eye_colour, required=required): if eye_colour in ACCEPTED_EYE_COLOURS: return eye_colour else: raise InvalidValue( "An eye colour must be one of the following colours: " + str(ACCEPTED_EYE_COLOURS).strip('[]') + ".") else: raise MissingRequiredValue( "This field cannot be empty, please provide a valid passport.")
def check_hair_colour(hair_colour, *, required): if is_accepted(hair_colour, required=required): if re.match(HAIR_COLOUR_PATTERN, hair_colour): return hair_colour else: raise InvalidValue( "A hair colour must conform to the following pattern: " + HAIR_COLOUR_PATTERN + ".") else: raise MissingRequiredValue( "This field cannot be empty, please provide a valid passport.")
def check_height(height, *, required): if is_accepted(height, required=required): if height[-2:] == "cm": if not is_in_range(int(height[:-2]), MIN_CM_HEIGHT, MAX_CM_HEIGHT): raise InvalidValue("A height can be at least " + str(MIN_CM_HEIGHT) + " and at most " + str(MAX_CM_HEIGHT) + ".") elif height[-2:] == "in": if not is_in_range(int(height[:-2]), MIN_IN_HEIGHT, MAX_IN_HEIGHT): raise InvalidValue("A height can be at least " + str(MIN_CM_HEIGHT) + " and at most " + str(MAX_CM_HEIGHT) + ".") else: raise InvalidValue( "A height must be proceeded by \"cm\" or \"in\".") return height else: raise MissingRequiredValue( "This field cannot be empty, please provide a valid passport.")
def check_country_id(country_id, *, required): if is_accepted(country_id, required=required): return country_id else: raise MissingRequiredValue( "This field cannot be empty, please provide a valid passport.")