Welcome to parameter’s documentation!¶
Parameter is using to get and check HTTP parameters like use ORM.
Benefits¶
- Less code to check arguments.
- Pass http arguments to other function with a single object.
- IDE friendly, IDE can easily detect the complation.
- Easy to linter, the linter can easily detect attribute error.
Example with tornado¶
Normal pattern¶
from tornado import web
class DemoHandler(web.RequestHandler):
def get(self):
action = self.get_argument("action", None)
arg1 = self.get_argument("arg1", None)
arg2 = self.get_argument("arg2", None)
# ...
if action:
pass
if arg1:
pass
# ...
do(action, arg1, arg2, ...)
Parameter pattern¶
from tornado import web
from parameter import Model, Argument
from parameter import types
from parameter.adapter import TornadoAdapter
class DemoEntity(Model):
action = Argument(types.String, required=False,
miss_message="Please choose action",
invalid_message="Invalid action")
arg1 = Argument(types.Integer)
arg2 = Argument(types.Double)
# ...
class DemoHandler(web.RequestHandler):
def get(self):
demo = DemoEntity(TornadoAdapter(self))
do(demo)
Contents: