Patterns
from hanna import Configurable, Integer, String
from pyhocon import ConfigTree
class Movie(Configurable):
# Restrict to titles with two words, containing only letters.
title = String(pattern='([A-Z][a-z]+\s?){2}')
movie = Movie(ConfigTree(title='Star Wars')) # Fine.
# raises ValueError: "title" does not match pattern '^([A-Z][a-z]+\s?){2}$' ('Star Wars: A New Hope')
movie = Movie(ConfigTree(title='Star Wars: A New Hope'))class Movie(Configurable):
year = Integer(pattern='^20[0-1][0-9]$') # Range in [2000, 2019].Illegal patterns
title = String()
title.illegal_patterns = String.illegal_patterns + ['^Star Wars'] # Too much Star Wars.Turning off pattern matching
Last updated