1schema = Schema( 2 And({ 3 Optional("title", default=""): And( 4 [str], 5 Use(lambda x: x[0]), 6 lambda x: len(x) < 200, 7 error="\"title\" should be a string less than 200 characters long."), 8 Optional("language", default="autodetect"): And( 9 [str],10 Use(lambda x: x[0]),11 Use(lambda x: ALIAS_DICT.get(x, "autodetect")),12 error="\"language\" should be the name of a supported language."),13 Optional("duration", default=1440): And(14 [str],15 Use(lambda x: int(x[0])),16 lambda x: x > 0, Use(lambda x: min(x, 43200)),17 error="\"duration\" should be an integer number of minutes before the paste is deleted."),18 Optional("api_key", default=None):19 Use(lambda x: User.objects.get(api_key=x[0]), error="\"api_key\" must be a valid API key."),20 },21 # Make a named tuple out of the result.22 Use(lambda x: namedtuple('GenericDict', x.keys())(**x))23 )24)