Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
corepost
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
nexlab
corepost
Commits
9111f0fe
Commit
9111f0fe
authored
Sep 04, 2011
by
Jacek Furmankiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs
parent
5fdb78c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
1 deletion
+38
-1
README.md
README.md
+35
-0
setup.py
setup.py
+3
-1
No files found.
README.md
View file @
9111f0fe
...
...
@@ -114,6 +114,40 @@ Example:
def test(request,intarg,floatarg,stringarg,**kwargs):
pass
Argument validation
-------------------
CorePost integrates the popular 'formencode' package to implement form and query argument validation.
Validators can be specified using a
*formencode*
Schema object, or via custom field-specific validators, e.g.:
from corepost.web import CorePost, validate
from corepost.enums import Http
from formencode import Schema, validators
app = CorePost()
class TestSchema(Schema):
allow_extra_fields = True
childId = validators.Regex(regex="^value1|value2$")
@app.route("/validate/<int:rootId>/schema",Http.POST)
@validate(schema=TestSchema)
def postValidateSchema(request,rootId,childId,**kwargs):
'''Validate using a common schema'''
return "%s - %s - %s" % (rootId,childId,kwargs)
@app.route("/validate/<int:rootId>/custom",Http.POST)
@validate(childId=validators.Regex(regex="^value1|value2$"))
def postValidateCustom(request,rootId,childId,**kwargs):
'''Validate using argument-specific validators'
return "%s - %s - %s" % (rootId,childId,kwargs)
Please see the
`FormEncode <http://www.formencode.org/en/latest/Validator.html>`
_ Validator documentation
for list of available validators:
*
'Common
<http://www.formencode.org/en/latest/modules/validators.html#module-formencode.validators>
'_
*
'National
<http://www.formencode.org/en/latest/modules/national.html#module-formencode.national>
'_
@defer.inlineCallbacks support
------------------------------
...
...
@@ -138,6 +172,7 @@ Errors:
*
404 - not able to match any URL
*
400 - missing mandatory argument (driven from the arguments on the actual functions)
*
400 - argument failed validation
*
500 - server error
Performance
...
...
setup.py
View file @
9111f0fe
...
...
@@ -4,6 +4,7 @@ Twisted REST micro-framework
Based on *Flask* API, with integrated multiprocessing support for full usage of all CPUs.
Provides a more Flask/Sinatra-style API on top of the core *twisted.web* APIs.
Integrates FormEncode for path, form and query argument validation.
The simplest possible twisted.web CorePost REST application:
...
...
@@ -32,8 +33,9 @@ The simplest possible twisted.web CorePost REST application:
Links
`````
* `
w
ebsite <http://github.com/jacek99/corepost>`_
* `
W
ebsite <http://github.com/jacek99/corepost>`_
* `Twisted <http://twistedmatrix.com>`_
* `FormEncode <http://www.formencode.org/>`_
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment