def test_func_compose(): a = lambda x: x ** 3 b = lambda x: x * -4 c = lambda x: x + 5 assert func.compose(a, b, c)(5) == a(b(c(5))) w = lambda s: s.upper() x = lambda s: ''.join(reversed(s))[-2:] y = lambda s: s + 'abc' z = lambda s: s * 3 assert func.compose(w, x, y, z)('abc') == w(x(y(z('abc'))))
def test_func_compose(): a = lambda x: x**3 b = lambda x: x * -4 c = lambda x: x + 5 assert func.compose(a, b, c)(5) == a(b(c(5))) w = lambda s: s.upper() x = lambda s: ''.join(reversed(s))[-2:] y = lambda s: s + 'abc' z = lambda s: s * 3 assert func.compose(w, x, y, z)('abc') == w(x(y(z('abc'))))
from flask.ext.restful import \ Resource, fields, marshal_with, reqparse from google.appengine.ext import ndb from app.models import name from app.utils.reqparse import string_length from app.utils.func import compose # from app.utils.werkzeug_debugger import werkzeug_debugger name_validation = compose(name.Name.ensure_name_not_in_datastore, string_length(min_len=1, max_len=10)) request_parser = reqparse.RequestParser(trim=True, bundle_errors=True, namespace_class=dict) request_parser.add_argument( 'name', type=name_validation, # location='json', required=True) response_body_schema = {'name': fields.String} class Name(Resource): decorators = [marshal_with(response_body_schema)] def get(self): "return random Name" random_name = name.Name.random_key().get() return random_name
from flask.ext.restful import \ Resource, fields, marshal_with, reqparse from google.appengine.ext import ndb from app.models import name from app.utils.reqparse import string_length from app.utils.func import compose # from app.utils.werkzeug_debugger import werkzeug_debugger name_validation = compose( name.Name.ensure_name_not_in_datastore, string_length(min_len=1, max_len=10) ) request_parser = reqparse.RequestParser( trim=True, bundle_errors=True, namespace_class=dict ) request_parser.add_argument( 'name', type=name_validation, # location='json', required=True ) response_body_schema = { 'name': fields.String }