Created
January 12, 2012 12:50
-
-
Save Deepwalker/1600324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contract as c | |
import datetime | |
date_tuple = c.Dict(year=c.Int, month=c.Int, day=c.Int) >> (lambda d: datetime.datetime(**d)) | |
task = c.Dict({ | |
'key': c.String(), | |
c.Key('timestamp', optional=True): date_tuple, | |
}) | |
try: | |
print task.check({'key': 'foo', 'timestamp': {'year': 2012, 'month': 1, 'day': 12}}) | |
except c.ContractValidationError as e: | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment