Commit c184036a authored by Jacek Furmankiewicz's avatar Jacek Furmankiewicz

cleaning up GH pages for docs

parent 17315ad8
Argument parsing
===================
CorePost can automatically parse query arguments, form arguments, as well as basic JSON, YAML and XML documents
and extract those as direct arguments to a REST router method.
Let's say we have a basic method that responds to GET, POST and PUT requests.
It expects a first name and last name and outputs them back in the response::
@router("/name",(Http.GET,Http.POST,Http.PUT))
def getName(self,request,first,last,**kwargs):
return "%s %s" % (first, last)
Query arguments
---------------
For GET requests, the query arguments will be automatically parsed, e.g.::
curl http://127.0.0.1/name?first=John&last=Doe
Form encoded arguments
----------------------
For POST/PUT requests, any form-encoded arguments will be automatically parsed, e.g.::
curl -X POST http://localhost/name -d "first=John&last=Doe"
JSON document arguments
-----------------------
For the same method, you could just post a JSON document instead that looks like this::
{"first":"John","last":"Doe"}
CorePost will automatically pass all the root elements of the document as arguments into a method.
Requires the *'application/json'* content type to be passed.
YAML document arguments
-----------------------
For the same method, you could just post a YAML document that looks like this::
first:John
last:Doe
CorePost will automatically pass all the root elements of the document as arguments into a method.
Requires the *'text/yaml'* content type to be passed.
XML document arguments
----------------------
XML documents are supported as well. In that case, CorePost will first parse all the attributes on the root node
and then all of the children underneath the main root node.
Hence all of the XML formats below are valid and would generate the same parameters to a method.
Attributes only::
<root first="John" last="Doe"/>
Mix of attributes and child nodes::
<root first="John">
<last>Doe</last>
</root>
Child nodes only::
<root>
<first>John</first>
<last>Doe</last>
</root>
Requires the *'text/xml'* OR *'application/xml'* content type to be passed.
As you can see from the examples above, a single CorePost router method can handle all these varied forms of argument parsing
for you without any additional effort.
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.
Example::
from corepost.web import validate, route
from corepost.enums import Http
from formencode import Schema, validators
class TestSchema(Schema):
allow_extra_fields = True
childId = validators.Regex(regex="^value1|value2$")
class MyApp():
@route("/validate/<int:rootId>/schema",Http.POST)
@validate(schema=TestSchema())
def postValidateSchema(self,request,rootId,childId,**kwargs):
'''Validate using a common schema'''
return "%s - %s - %s" % (rootId,childId,kwargs)
@route("/validate/<int:rootId>/custom",Http.POST)
@validate(childId=validators.Regex(regex="^value1|value2$"))
def postValidateCustom(self,request,rootId,childId,**kwargs):
'''Validate using argument-specific validators'''
return "%s - %s - %s" % (rootId,childId,kwargs)
Please see the *FormEncode* documentation:
http://www.formencode.org/en/latest/Validator.html
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
Asynchronous Operations
=======================
@defer.inlineCallbacks support
------------------------------
If you want a deferred async method, just use *defer.returnValue()*::
@route("/",Http.GET)
@defer.inlineCallbacks
def root(self,request,**kwargs):
val1 = yield db.query("SELECT ....")
val2 = yield db.query("SELECT ....")
defer.returnValue(val1 + val2)
This is standard Twisted functionality.
Content types
=============
CorePost integrates support for JSON, YAML and XML (partially) based on request content types.
Parsing of incoming content
---------------------------
Based on the incoming content type in POST/PUT requests,
the body will be automatically parsed to JSON, YAML and XML (ElementTree)
* request.json
* request.yaml
* request.xml
and attached to the request::
@route("/post/json",(Http.POST,Http.PUT))
def test_json(self,request,**kwargs):
return "%s" % json.dumps(request.json)
@route("/post/xml",(Http.POST,Http.PUT))
def test_xml(self,request,**kwargs):
return "%s" % ElementTree.tostring(request.xml)
@route("/post/yaml",(Http.POST,Http.PUT))
def test_yaml(self,request,**kwargs):
return "%s" % yaml.dump(request.yaml)
Converting Python objects to expected content type
--------------------------------------------------
Instead of returning string responses, the code can just return Python objects.
Depending whether the caller can accept JSON (default) or YAML, the Python objects will be automatically converted::
@route("/return/by/accept")
def test_return_content_by_accepts(self,request,**kwargs):
val = [{"test1":"Test1"},{"test2":"Test2"}]
return val
Calling this URL with "Accept: application/json" will return:
::
[{"test1": "Test1"}, {"test2": "Test2"}]
Calling it with "Accept: text/yaml" will return:
::
- {test1: Test1}
- {test2: Test2}
This diff is collapsed.
Filters
=======
There is support for CorePost resource filters via the two following *corepost.filter* interfaces::
class IRequestFilter(Interface):
"""Request filter interface"""
def filterRequest(self,request):
"""Allows to intercept and change an incoming request"""
pass
class IResponseFilter(Interface):
"""Response filter interface"""
def filterResponse(self,request,response):
"""Allows to intercept and change an outgoing response"""
pass
A filter class can implement either of them or both (for a wrap around filter), e.g.::
class AddCustomHeaderFilter():
"""Implements a request filter that adds a custom header to the incoming request"""
zope.interface.implements(IRequestFilter)
def filterRequest(self,request):
request.received_headers["Custom-Header"] = "Custom Header Value"
class Change404to503Filter():
"""Implements just a response filter that changes 404 to 503 statuses"""
zope.interface.implements(IResponseFilter)
def filterResponse(self,request,response):
if response.code == 404:
response.code = 503
class WrapAroundFilter():
"""Implements both types of filters in one class"""
zope.interface.implements(IRequestFilter,IResponseFilter)
def filterRequest(self,request):
request.received_headers["X-Wrap-Input"] = "Input"
def filterResponse(self,request,response):
response.headers["X-Wrap-Output"] = "Output"
In order to activate the filters on a RESTResource instance, you need to pass a list of them in the constructor as the *filters* parameter, e.g.::
class FilterApp:
@route("/",Http.GET)
def root(self,request,**kwargs):
return request.received_headers
def run_filter_app():
app = RESTResource(services=(FilterApp(),),filters=(Change404to503Filter(),AddCustomHeaderFilter(),WrapAroundFilter(),))
app.run(8083)
HTTP codes
==========
By default, CorePost returns the appropriate HTTP code based on the HTTP method:
Success:
* 200 (OK) - GET, DELETE, PUT
* 201 (Created) - POST
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
CorePost
====================================
A Twisted REST micro-framework
------------------------------
.. toctree::
:maxdepth: 4
intro
Features
--------
.. toctree::
:maxdepth: 4
url_routing
argument_parsing
arguments
content_types
filters
http_codes
async
modules
Introduction
============
What is CorePost?
-----------------
CorePost is a Python REST micro-framework. It is meant for building enterprise-grade REST server applications that provide
API services to other applications and/or a UI layer (coded in any framework or language).
More importantly, CorePost is an asynchronous I/O web framework (similar to Node.js).
Hence it relies on asynchronous I/O operations, which are extremely efficient, but somewhat more complicated to code.
Fortunately, CorePost does not create it's own async I/O library, but instead uses under the mature, well documented
and extremely well designed Twisted library, in particular its web layer (known simply as twisted.web)
Coupled with a JIT runtime like PyPy, this should give you the ability to develop REST server side applications
that will be extremely performant in production, yet (hopefully) fun and productive to develop.
What is Twisted?
----------------
Twisted is a very mature Python async I/O network toolkit:
http://twistedmatrix.com/trac/
Understanding core principles behind Twisted and its APIs is required (at least at a basic level) before coding any CorePost application.
Hence we recommend either reading the very thorough developer's guide:
http://twistedmatrix.com/documents/current/core/howto/book.pdf
or the excellent Twisted tutorials from Dave Peticolas:
http://krondo.com/blog/?page_id=1327
In particular, understanding the core Twisted Deferred object (and its productive inline callback approach) are crucial
to productive usage of Twisted APIs for writing asynchronous web applications.
What does CorePost add on top of Twisted Web?
---------------------------------------------
Mostly productivity features that take of low-level plumbing such as:
* routing request to handler methods
* automatic parsing of JSON/YAML/XML input
* automatic conversion of Python objects and classes to JSON / YAML / XML formats
* simplified exception handling
* custom request / response filters
However, this is a very thin layer. Once you get to write some serious code that interacts with an external system (e.g. a SQL database)
you are writing a hard-code Twisted web application. CorePost is just there to make it easier for you and let you focus on business logic,
while letting it take care of common required plumbing. That's it.
A CorePost application is nothing more than a *twisted.web* application under the hood.
Why would I use CorePost instead of Node.js?
--------------------------------------------
As you develop more Twisted code, you will realize how its elegant and powerful *Deferred* object
(and especially inline callbacks) make developing *readable* asynchronous code much more pleasant than any other solution.
\ No newline at end of file
Modular REST applications
=========================
A typical case in REST is where you have parent/child resources (business entities), e.g.
::
Customer
Customer Address
Customer Phone
Customer Order
Customer Invoice
Customer Invoice Payment
etc.
This can create a URL structure like:
::
/customer
/customer/<customerId>
/customer/<customerId>/address
/customer/<customerId>/address/<addressId>
/customer/<customerId>/phone
/customer/<customerId>/phone/<phoneId>
/customer/<customerId>/invoice
/customer/<customerId>/invoice/<invoiceId>
/customer/<customerId>/invoice/<invoiceId>/payment
/customer/<customerId>/invoice/<invoiceId>/payment/<paymentId>
CorePost allows you to write small, modular classes that implement a REST service for just a single entity,
driven by URL paths with dynamic elements in them (e.g. the *customerId*, *invoiceId*, *paymentId* path parameters in the sample above).
You do not have to mesh all these different entities in a single class.
At the end, you wrap all of the different REST services in a single *RESTResource* object (which extends the regular Twisted Web Resource object)
and it takes care of routing the request to the appropriate class.
Here is a full-blown example of two REST services for Customer and Customer Address::
from corepost import Response, NotFoundException, AlreadyExistsException
from corepost.web import RESTResource, route, Http
class CustomerRESTService():
path = "/customer"
@route("/")
def getAll(self,request):
return DB.getAllCustomers()
@route("/<customerId>")
def get(self,request,customerId):
return DB.getCustomer(customerId)
@route("/",Http.POST)
def post(self,request,customerId,firstName,lastName):
customer = Customer(customerId, firstName, lastName)
DB.saveCustomer(customer)
return Response(201)
@route("/<customerId>",Http.PUT)
def put(self,request,customerId,firstName,lastName):
c = DB.getCustomer(customerId)
(c.firstName,c.lastName) = (firstName,lastName)
return Response(200)
@route("/<customerId>",Http.DELETE)
def delete(self,request,customerId):
DB.deleteCustomer(customerId)
return Response(200)
@route("/",Http.DELETE)
def deleteAll(self,request):
DB.deleteAllCustomers()
return Response(200)
class CustomerAddressRESTService():
path = "/customer/<customerId>/address"
@route("/")
def getAll(self,request,customerId):
return DB.getCustomer(customerId).addresses
@route("/<addressId>")
def get(self,request,customerId,addressId):
return DB.getCustomerAddress(customerId, addressId)
@route("/",Http.POST)
def post(self,request,customerId,addressId,streetNumber,streetName,stateCode,countryCode):
c = DB.getCustomer(customerId)
address = CustomerAddress(streetNumber,streetName,stateCode,countryCode)
c.addresses[addressId] = address
return Response(201)
@route("/<addressId>",Http.PUT)
def put(self,request,customerId,addressId,streetNumber,streetName,stateCode,countryCode):
address = DB.getCustomerAddress(customerId, addressId)
(address.streetNumber,address.streetName,address.stateCode,address.countryCode) = (streetNumber,streetName,stateCode,countryCode)
return Response(200)
@route("/<addressId>",Http.DELETE)
def delete(self,request,customerId,addressId):
DB.getCustomerAddress(customerId, addressId) #validate address exists
del(DB.getCustomer(customerId).addresses[addressId])
return Response(200)
@route("/",Http.DELETE)
def deleteAll(self,request,customerId):
c = DB.getCustomer(customerId)
c.addresses = {}
return Response(200)
def run_rest_app():
app = RESTResource((CustomerRESTService(),CustomerAddressRESTService()))
app.run(8080)
if __name__ == "__main__":
run_rest_app()
URL Routing
=================
@route decorator
----------------
Via a simple *@route* decorator you can automatically route *twisted.web* Request objects to your class method
based on URL (with dynamic paths), HTTP method, expected content type, etc::
from corepost.web import route, RESTResource
from corepost.enums import Http
class RESTService():
@route("/",Http.GET)
def root(self,request,**kwargs):
return request.path
@route("/test",Http.GET)
def test(self,request,**kwargs):
return request.path
@route("/test/<int:numericid>",Http.GET)
def test_get_resources(self,request,numericid,**kwargs):
return "%s" % numericid
if __name__ == '__main__':
app = RESTResource((RESTService,))
app.run()
*Note*:
This piece of code::
app.run()
is just for convenience when showing code samples and writing unit tests.
In a real production application you would use existing Twisted *twistd* functionality:
* http://twistedmatrix.com/documents/current/core/howto/basics.html
* http://twistedmatrix.com/documents/current/core/howto/application.html
* http://twistedmatrix.com/documents/current/core/howto/tap.html
Path argument extraction
------------------------
CorePort can easily extract path arguments from an URL and convert them to the desired type.
The supported types are:
* *int*
* *float*
* *string*
Example::
@route("/int/<int:intarg>/float/<float:floatarg>/string/<stringarg>",Http.GET)
def test(self,request,intarg,floatarg,stringarg,**kwargs):
pass
Routing requests by incoming content type
-----------------------------------------
Based on the incoming content type in POST/PUT requests, the *same* URL can be hooked up to different router methods::
@route("/post/by/content",(Http.POST,Http.PUT),MediaType.APPLICATION_JSON)
def test_content_app_json(self,request,**kwargs):
return request.received_headers[HttpHeader.CONTENT_TYPE]
@route("/post/by/content",(Http.POST,Http.PUT),(MediaType.TEXT_XML,MediaType.APPLICATION_XML))
def test_content_xml(self,request,**kwargs):
return request.received_headers[HttpHeader.CONTENT_TYPE]
@route("/post/by/content",(Http.POST,Http.PUT),MediaType.TEXT_YAML)
def test_content_yaml(self,request,**kwargs):
return request.received_headers[HttpHeader.CONTENT_TYPE]
@route("/post/by/content",(Http.POST,Http.PUT))
def test_content_catch_all(self,request,**kwargs):
return MediaType.WILDCARD
/*
* basic.css
* ~~~~~~~~~
*
* Sphinx stylesheet -- basic theme.
*
* :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
/* -- main layout ----------------------------------------------------------- */
div.clearer {
clear: both;
}
/* -- relbar ---------------------------------------------------------------- */
div.related {
width: 100%;
font-size: 90%;
}
div.related h3 {
display: none;
}
div.related ul {
margin: 0;
padding: 0 0 0 10px;
list-style: none;
}
div.related li {
display: inline;
}
div.related li.right {
float: right;
margin-right: 5px;
}
/* -- sidebar --------------------------------------------------------------- */
div.sphinxsidebarwrapper {
padding: 10px 5px 0 10px;
}
div.sphinxsidebar {
float: left;
width: 230px;
margin-left: -100%;
font-size: 90%;
}
div.sphinxsidebar ul {
list-style: none;
}
div.sphinxsidebar ul ul,
div.sphinxsidebar ul.want-points {
margin-left: 20px;
list-style: square;
}
div.sphinxsidebar ul ul {
margin-top: 0;
margin-bottom: 0;
}
div.sphinxsidebar form {
margin-top: 10px;
}
div.sphinxsidebar input {
border: 1px solid #98dbcc;
font-family: sans-serif;
font-size: 1em;
}
div.sphinxsidebar input[type="text"] {
width: 170px;
}
div.sphinxsidebar input[type="submit"] {
width: 30px;
}
img {
border: 0;
}
/* -- search page ----------------------------------------------------------- */
ul.search {
margin: 10px 0 0 20px;
padding: 0;
}
ul.search li {
padding: 5px 0 5px 20px;
background-image: url(file.png);
background-repeat: no-repeat;
background-position: 0 7px;
}
ul.search li a {
font-weight: bold;
}
ul.search li div.context {
color: #888;
margin: 2px 0 0 30px;
text-align: left;
}
ul.keywordmatches li.goodmatch a {
font-weight: bold;
}
/* -- index page ------------------------------------------------------------ */
table.contentstable {
width: 90%;
}
table.contentstable p.biglink {
line-height: 150%;
}
a.biglink {
font-size: 1.3em;
}
span.linkdescr {
font-style: italic;
padding-top: 5px;
font-size: 90%;
}
/* -- general index --------------------------------------------------------- */
table.indextable {
width: 100%;
}
table.indextable td {
text-align: left;
vertical-align: top;
}
table.indextable dl, table.indextable dd {
margin-top: 0;
margin-bottom: 0;
}
table.indextable tr.pcap {
height: 10px;
}
table.indextable tr.cap {
margin-top: 10px;
background-color: #f2f2f2;
}
img.toggler {
margin-right: 3px;
margin-top: 3px;
cursor: pointer;
}
div.modindex-jumpbox {
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
margin: 1em 0 1em 0;
padding: 0.4em;
}
div.genindex-jumpbox {
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
margin: 1em 0 1em 0;
padding: 0.4em;
}
/* -- general body styles --------------------------------------------------- */
a.headerlink {
visibility: hidden;
}
h1:hover > a.headerlink,
h2:hover > a.headerlink,
h3:hover > a.headerlink,
h4:hover > a.headerlink,
h5:hover > a.headerlink,
h6:hover > a.headerlink,
dt:hover > a.headerlink {
visibility: visible;
}
div.body p.caption {
text-align: inherit;
}
div.body td {
text-align: left;
}
.field-list ul {
padding-left: 1em;
}
.first {
margin-top: 0 !important;
}
p.rubric {
margin-top: 30px;
font-weight: bold;
}
img.align-left, .figure.align-left, object.align-left {
clear: left;
float: left;
margin-right: 1em;
}
img.align-right, .figure.align-right, object.align-right {
clear: right;
float: right;
margin-left: 1em;
}
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left;
}
.align-center {
text-align: center;
}
.align-right {
text-align: right;
}
/* -- sidebars -------------------------------------------------------------- */
div.sidebar {
margin: 0 0 0.5em 1em;
border: 1px solid #ddb;
padding: 7px 7px 0 7px;
background-color: #ffe;
width: 40%;
float: right;
}
p.sidebar-title {
font-weight: bold;
}
/* -- topics ---------------------------------------------------------------- */
div.topic {
border: 1px solid #ccc;
padding: 7px 7px 0 7px;
margin: 10px 0 10px 0;
}
p.topic-title {
font-size: 1.1em;
font-weight: bold;
margin-top: 10px;
}
/* -- admonitions ----------------------------------------------------------- */
div.admonition {
margin-top: 10px;
margin-bottom: 10px;
padding: 7px;
}
div.admonition dt {
font-weight: bold;
}
div.admonition dl {
margin-bottom: 0;
}
p.admonition-title {
margin: 0px 10px 5px 0px;
font-weight: bold;
}
div.body p.centered {
text-align: center;
margin-top: 25px;
}
/* -- tables ---------------------------------------------------------------- */
table.docutils {
border: 0;
border-collapse: collapse;
}
table.docutils td, table.docutils th {
padding: 1px 8px 1px 5px;
border-top: 0;
border-left: 0;
border-right: 0;
border-bottom: 1px solid #aaa;
}
table.field-list td, table.field-list th {
border: 0 !important;
}
table.footnote td, table.footnote th {
border: 0 !important;
}
th {
text-align: left;
padding-right: 5px;
}
table.citation {
border-left: solid 1px gray;
margin-left: 1px;
}
table.citation td {
border-bottom: none;
}
/* -- other body styles ----------------------------------------------------- */
ol.arabic {
list-style: decimal;
}
ol.loweralpha {
list-style: lower-alpha;
}
ol.upperalpha {
list-style: upper-alpha;
}
ol.lowerroman {
list-style: lower-roman;
}
ol.upperroman {
list-style: upper-roman;
}
dl {
margin-bottom: 15px;
}
dd p {
margin-top: 0px;
}
dd ul, dd table {
margin-bottom: 10px;
}
dd {
margin-top: 3px;
margin-bottom: 10px;
margin-left: 30px;
}
dt:target, .highlighted {
background-color: #fbe54e;
}
dl.glossary dt {
font-weight: bold;
font-size: 1.1em;
}
.field-list ul {
margin: 0;
padding-left: 1em;
}
.field-list p {
margin: 0;
}
.refcount {
color: #060;
}
.optional {
font-size: 1.3em;
}
.versionmodified {
font-style: italic;
}
.system-message {
background-color: #fda;
padding: 5px;
border: 3px solid red;
}
.footnote:target {
background-color: #ffa;
}
.line-block {
display: block;
margin-top: 1em;
margin-bottom: 1em;
}
.line-block .line-block {
margin-top: 0;
margin-bottom: 0;
margin-left: 1.5em;
}
.guilabel, .menuselection {
font-family: sans-serif;
}
.accelerator {
text-decoration: underline;
}
.classifier {
font-style: oblique;
}
abbr, acronym {
border-bottom: dotted 1px;
cursor: help;
}
/* -- code displays --------------------------------------------------------- */
pre {
overflow: auto;
overflow-y: hidden; /* fixes display issues on Chrome browsers */
}
td.linenos pre {
padding: 5px 0px;
border: 0;
background-color: transparent;
color: #aaa;
}
table.highlighttable {
margin-left: 0.5em;
}
table.highlighttable td {
padding: 0 0.5em 0 0.5em;
}
tt.descname {
background-color: transparent;
font-weight: bold;
font-size: 1.2em;
}
tt.descclassname {
background-color: transparent;
}
tt.xref, a tt {
background-color: transparent;
font-weight: bold;
}
h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt {
background-color: transparent;
}
.viewcode-link {
float: right;
}
.viewcode-back {
float: right;
font-family: sans-serif;
}
div.viewcode-block:target {
margin: -1px -10px;
padding: 0 10px;
}
/* -- math display ---------------------------------------------------------- */
img.math {
vertical-align: middle;
}
div.body div.math p {
text-align: center;
}
span.eqno {
float: right;
}
/* -- printout stylesheet --------------------------------------------------- */
@media print {
div.document,
div.documentwrapper,
div.bodywrapper {
margin: 0 !important;
width: 100%;
}
div.sphinxsidebar,
div.related,
div.footer,
#top-link {
display: none;
}
}
\ No newline at end of file
/*
* default.css_t
* ~~~~~~~~~~~~~
*
* Sphinx stylesheet -- default theme.
*
* :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
@import url("basic.css");
/* -- page layout ----------------------------------------------------------- */
body {
font-family: sans-serif;
font-size: 100%;
background-color: #11303d;
color: #000;
margin: 0;
padding: 0;
}
div.document {
background-color: #1c4e63;
}
div.documentwrapper {
float: left;
width: 100%;
}
div.bodywrapper {
margin: 0 0 0 230px;
}
div.body {
background-color: #ffffff;
color: #000000;
padding: 0 20px 30px 20px;
}
div.footer {
color: #ffffff;
width: 100%;
padding: 9px 0 9px 0;
text-align: center;
font-size: 75%;
}
div.footer a {
color: #ffffff;
text-decoration: underline;
}
div.related {
background-color: #133f52;
line-height: 30px;
color: #ffffff;
}
div.related a {
color: #ffffff;
}
div.sphinxsidebar {
}
div.sphinxsidebar h3 {
font-family: 'Trebuchet MS', sans-serif;
color: #ffffff;
font-size: 1.4em;
font-weight: normal;
margin: 0;
padding: 0;
}
div.sphinxsidebar h3 a {
color: #ffffff;
}
div.sphinxsidebar h4 {
font-family: 'Trebuchet MS', sans-serif;
color: #ffffff;
font-size: 1.3em;
font-weight: normal;
margin: 5px 0 0 0;
padding: 0;
}
div.sphinxsidebar p {
color: #ffffff;
}
div.sphinxsidebar p.topless {
margin: 5px 10px 10px 10px;
}
div.sphinxsidebar ul {
margin: 10px;
padding: 0;
color: #ffffff;
}
div.sphinxsidebar a {
color: #98dbcc;
}
div.sphinxsidebar input {
border: 1px solid #98dbcc;
font-family: sans-serif;
font-size: 1em;
}
/* -- hyperlink styles ------------------------------------------------------ */
a {
color: #355f7c;
text-decoration: none;
}
a:visited {
color: #355f7c;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* -- body styles ----------------------------------------------------------- */
div.body h1,
div.body h2,
div.body h3,
div.body h4,
div.body h5,
div.body h6 {
font-family: 'Trebuchet MS', sans-serif;
background-color: #f2f2f2;
font-weight: normal;
color: #20435c;
border-bottom: 1px solid #ccc;
margin: 20px -20px 10px -20px;
padding: 3px 0 3px 10px;
}
div.body h1 { margin-top: 0; font-size: 200%; }
div.body h2 { font-size: 160%; }
div.body h3 { font-size: 140%; }
div.body h4 { font-size: 120%; }
div.body h5 { font-size: 110%; }
div.body h6 { font-size: 100%; }
a.headerlink {
color: #c60f0f;
font-size: 0.8em;
padding: 0 4px 0 4px;
text-decoration: none;
}
a.headerlink:hover {
background-color: #c60f0f;
color: white;
}
div.body p, div.body dd, div.body li {
text-align: justify;
line-height: 130%;
}
div.admonition p.admonition-title + p {
display: inline;
}
div.admonition p {
margin-bottom: 5px;
}
div.admonition pre {
margin-bottom: 5px;
}
div.admonition ul, div.admonition ol {
margin-bottom: 5px;
}
div.note {
background-color: #eee;
border: 1px solid #ccc;
}
div.seealso {
background-color: #ffc;
border: 1px solid #ff6;
}
div.topic {
background-color: #eee;
}
div.warning {
background-color: #ffe4e4;
border: 1px solid #f66;
}
p.admonition-title {
display: inline;
}
p.admonition-title:after {
content: ":";
}
pre {
padding: 5px;
background-color: #eeffcc;
color: #333333;
line-height: 120%;
border: 1px solid #ac9;
border-left: none;
border-right: none;
}
tt {
background-color: #ecf0f3;
padding: 0 1px 0 1px;
font-size: 0.95em;
}
th {
background-color: #ede;
}
.warning tt {
background: #efc2c2;
}
.note tt {
background: #d6d6d6;
}
.viewcode-back {
font-family: sans-serif;
}
div.viewcode-block:target {
background-color: #f4debf;
border-top: 1px solid #ac9;
border-bottom: 1px solid #ac9;
}
\ No newline at end of file
/*
* doctools.js
* ~~~~~~~~~~~
*
* Sphinx JavaScript utilities for all documentation.
*
* :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
/**
* select a different prefix for underscore
*/
$u = _.noConflict();
/**
* make the code below compatible with browsers without
* an installed firebug like debugger
if (!window.console || !console.firebug) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir",
"dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace",
"profile", "profileEnd"];
window.console = {};
for (var i = 0; i < names.length; ++i)
window.console[names[i]] = function() {};
}
*/
/**
* small helper function to urldecode strings
*/
jQuery.urldecode = function(x) {
return decodeURIComponent(x).replace(/\+/g, ' ');
}
/**
* small helper function to urlencode strings
*/
jQuery.urlencode = encodeURIComponent;
/**
* This function returns the parsed url parameters of the
* current request. Multiple values per key are supported,
* it will always return arrays of strings for the value parts.
*/
jQuery.getQueryParameters = function(s) {
if (typeof s == 'undefined')
s = document.location.search;
var parts = s.substr(s.indexOf('?') + 1).split('&');
var result = {};
for (var i = 0; i < parts.length; i++) {
var tmp = parts[i].split('=', 2);
var key = jQuery.urldecode(tmp[0]);
var value = jQuery.urldecode(tmp[1]);
if (key in result)
result[key].push(value);
else
result[key] = [value];
}
return result;
};
/**
* small function to check if an array contains
* a given item.
*/
jQuery.contains = function(arr, item) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] == item)
return true;
}
return false;
};
/**
* highlight a given string on a jquery object by wrapping it in
* span elements with the given class name.
*/
jQuery.fn.highlightText = function(text, className) {
function highlight(node) {
if (node.nodeType == 3) {
var val = node.nodeValue;
var pos = val.toLowerCase().indexOf(text);
if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) {
var span = document.createElement("span");
span.className = className;
span.appendChild(document.createTextNode(val.substr(pos, text.length)));
node.parentNode.insertBefore(span, node.parentNode.insertBefore(
document.createTextNode(val.substr(pos + text.length)),
node.nextSibling));
node.nodeValue = val.substr(0, pos);
}
}
else if (!jQuery(node).is("button, select, textarea")) {
jQuery.each(node.childNodes, function() {
highlight(this);
});
}
}
return this.each(function() {
highlight(this);
});
};
/**
* Small JavaScript module for the documentation.
*/
var Documentation = {
init : function() {
this.fixFirefoxAnchorBug();
this.highlightSearchWords();
this.initIndexTable();
},
/**
* i18n support
*/
TRANSLATIONS : {},
PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; },
LOCALE : 'unknown',
// gettext and ngettext don't access this so that the functions
// can safely bound to a different name (_ = Documentation.gettext)
gettext : function(string) {
var translated = Documentation.TRANSLATIONS[string];
if (typeof translated == 'undefined')
return string;
return (typeof translated == 'string') ? translated : translated[0];
},
ngettext : function(singular, plural, n) {
var translated = Documentation.TRANSLATIONS[singular];
if (typeof translated == 'undefined')
return (n == 1) ? singular : plural;
return translated[Documentation.PLURALEXPR(n)];
},
addTranslations : function(catalog) {
for (var key in catalog.messages)
this.TRANSLATIONS[key] = catalog.messages[key];
this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')');
this.LOCALE = catalog.locale;
},
/**
* add context elements like header anchor links
*/
addContextElements : function() {
$('div[id] > :header:first').each(function() {
$('<a class="headerlink">\u00B6</a>').
attr('href', '#' + this.id).
attr('title', _('Permalink to this headline')).
appendTo(this);
});
$('dt[id]').each(function() {
$('<a class="headerlink">\u00B6</a>').
attr('href', '#' + this.id).
attr('title', _('Permalink to this definition')).
appendTo(this);
});
},
/**
* workaround a firefox stupidity
*/
fixFirefoxAnchorBug : function() {
if (document.location.hash && $.browser.mozilla)
window.setTimeout(function() {
document.location.href += '';
}, 10);
},
/**
* highlight the search words provided in the url in the text
*/
highlightSearchWords : function() {
var params = $.getQueryParameters();
var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : [];
if (terms.length) {
var body = $('div.body');
window.setTimeout(function() {
$.each(terms, function() {
body.highlightText(this.toLowerCase(), 'highlighted');
});
}, 10);
$('<p class="highlight-link"><a href="javascript:Documentation.' +
'hideSearchWords()">' + _('Hide Search Matches') + '</a></p>')
.appendTo($('#searchbox'));
}
},
/**
* init the domain index toggle buttons
*/
initIndexTable : function() {
var togglers = $('img.toggler').click(function() {
var src = $(this).attr('src');
var idnum = $(this).attr('id').substr(7);
$('tr.cg-' + idnum).toggle();
if (src.substr(-9) == 'minus.png')
$(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
else
$(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
}).css('display', '');
if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) {
togglers.click();
}
},
/**
* helper function to hide the search marks again
*/
hideSearchWords : function() {
$('#searchbox .highlight-link').fadeOut(300);
$('span.highlighted').removeClass('highlighted');
},
/**
* make the url absolute
*/
makeURL : function(relativeURL) {
return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL;
},
/**
* get the current relative url
*/
getCurrentURL : function() {
var path = document.location.pathname;
var parts = path.split(/\//);
$.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
if (this == '..')
parts.pop();
});
var url = parts.join('/');
return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
}
};
// quick alias for translations
_ = Documentation.gettext;
$(document).ready(function() {
Documentation.init();
});
This diff is collapsed.
.highlight .hll { background-color: #ffffcc }
.highlight { background: #eeffcc; }
.highlight .c { color: #408090; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #007020; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #007020 } /* Comment.Preproc */
.highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */
.highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #303030 } /* Generic.Output */
.highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0040D0 } /* Generic.Traceback */
.highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #007020 } /* Keyword.Pseudo */
.highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #902000 } /* Keyword.Type */
.highlight .m { color: #208050 } /* Literal.Number */
.highlight .s { color: #4070a0 } /* Literal.String */
.highlight .na { color: #4070a0 } /* Name.Attribute */
.highlight .nb { color: #007020 } /* Name.Builtin */
.highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
.highlight .no { color: #60add5 } /* Name.Constant */
.highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
.highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #007020 } /* Name.Exception */
.highlight .nf { color: #06287e } /* Name.Function */
.highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
.highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #bb60d5 } /* Name.Variable */
.highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #208050 } /* Literal.Number.Float */
.highlight .mh { color: #208050 } /* Literal.Number.Hex */
.highlight .mi { color: #208050 } /* Literal.Number.Integer */
.highlight .mo { color: #208050 } /* Literal.Number.Oct */
.highlight .sb { color: #4070a0 } /* Literal.String.Backtick */
.highlight .sc { color: #4070a0 } /* Literal.String.Char */
.highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #4070a0 } /* Literal.String.Double */
.highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */
.highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
.highlight .sx { color: #c65d09 } /* Literal.String.Other */
.highlight .sr { color: #235388 } /* Literal.String.Regex */
.highlight .s1 { color: #4070a0 } /* Literal.String.Single */
.highlight .ss { color: #517918 } /* Literal.String.Symbol */
.highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #bb60d5 } /* Name.Variable.Class */
.highlight .vg { color: #bb60d5 } /* Name.Variable.Global */
.highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */
.highlight .il { color: #208050 } /* Literal.Number.Integer.Long */
\ No newline at end of file
This diff is collapsed.
/*
* sidebar.js
* ~~~~~~~~~~
*
* This script makes the Sphinx sidebar collapsible.
*
* .sphinxsidebar contains .sphinxsidebarwrapper. This script adds
* in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton
* used to collapse and expand the sidebar.
*
* When the sidebar is collapsed the .sphinxsidebarwrapper is hidden
* and the width of the sidebar and the margin-left of the document
* are decreased. When the sidebar is expanded the opposite happens.
* This script saves a per-browser/per-session cookie used to
* remember the position of the sidebar among the pages.
* Once the browser is closed the cookie is deleted and the position
* reset to the default (expanded).
*
* :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
$(function() {
// global elements used by the functions.
// the 'sidebarbutton' element is defined as global after its
// creation, in the add_sidebar_button function
var bodywrapper = $('.bodywrapper');
var sidebar = $('.sphinxsidebar');
var sidebarwrapper = $('.sphinxsidebarwrapper');
// for some reason, the document has no sidebar; do not run into errors
if (!sidebar.length) return;
// original margin-left of the bodywrapper and width of the sidebar
// with the sidebar expanded
var bw_margin_expanded = bodywrapper.css('margin-left');
var ssb_width_expanded = sidebar.width();
// margin-left of the bodywrapper and width of the sidebar
// with the sidebar collapsed
var bw_margin_collapsed = '.8em';
var ssb_width_collapsed = '.8em';
// colors used by the current theme
var dark_color = $('.related').css('background-color');
var light_color = $('.document').css('background-color');
function sidebar_is_collapsed() {
return sidebarwrapper.is(':not(:visible)');
}
function toggle_sidebar() {
if (sidebar_is_collapsed())
expand_sidebar();
else
collapse_sidebar();
}
function collapse_sidebar() {
sidebarwrapper.hide();
sidebar.css('width', ssb_width_collapsed);
bodywrapper.css('margin-left', bw_margin_collapsed);
sidebarbutton.css({
'margin-left': '0',
'height': bodywrapper.height()
});
sidebarbutton.find('span').text('»');
sidebarbutton.attr('title', _('Expand sidebar'));
document.cookie = 'sidebar=collapsed';
}
function expand_sidebar() {
bodywrapper.css('margin-left', bw_margin_expanded);
sidebar.css('width', ssb_width_expanded);
sidebarwrapper.show();
sidebarbutton.css({
'margin-left': ssb_width_expanded-12,
'height': bodywrapper.height()
});
sidebarbutton.find('span').text('«');
sidebarbutton.attr('title', _('Collapse sidebar'));
document.cookie = 'sidebar=expanded';
}
function add_sidebar_button() {
sidebarwrapper.css({
'float': 'left',
'margin-right': '0',
'width': ssb_width_expanded - 28
});
// create the button
sidebar.append(
'<div id="sidebarbutton"><span>&laquo;</span></div>'
);
var sidebarbutton = $('#sidebarbutton');
light_color = sidebarbutton.css('background-color');
// find the height of the viewport to center the '<<' in the page
var viewport_height;
if (window.innerHeight)
viewport_height = window.innerHeight;
else
viewport_height = $(window).height();
sidebarbutton.find('span').css({
'display': 'block',
'margin-top': (viewport_height - sidebar.position().top - 20) / 2
});
sidebarbutton.click(toggle_sidebar);
sidebarbutton.attr('title', _('Collapse sidebar'));
sidebarbutton.css({
'color': '#FFFFFF',
'border-left': '1px solid ' + dark_color,
'font-size': '1.2em',
'cursor': 'pointer',
'height': bodywrapper.height(),
'padding-top': '1px',
'margin-left': ssb_width_expanded - 12
});
sidebarbutton.hover(
function () {
$(this).css('background-color', dark_color);
},
function () {
$(this).css('background-color', light_color);
}
);
}
function set_position_from_cookie() {
if (!document.cookie)
return;
var items = document.cookie.split(';');
for(var k=0; k<items.length; k++) {
var key_val = items[k].split('=');
var key = key_val[0];
if (key == 'sidebar') {
var value = key_val[1];
if ((value == 'collapsed') && (!sidebar_is_collapsed()))
collapse_sidebar();
else if ((value == 'expanded') && (sidebar_is_collapsed()))
expand_sidebar();
}
}
}
add_sidebar_button();
var sidebarbutton = $('#sidebarbutton');
set_position_from_cookie();
});
// Underscore.js 0.5.5
// (c) 2009 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore is freely distributable under the terms of the MIT license.
// Portions of Underscore are inspired by or borrowed from Prototype.js,
// Oliver Steele's Functional, and John Resig's Micro-Templating.
// For all details and documentation:
// http://documentcloud.github.com/underscore/
(function(){var j=this,n=j._,i=function(a){this._wrapped=a},m=typeof StopIteration!=="undefined"?StopIteration:"__break__",b=j._=function(a){return new i(a)};if(typeof exports!=="undefined")exports._=b;var k=Array.prototype.slice,o=Array.prototype.unshift,p=Object.prototype.toString,q=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;b.VERSION="0.5.5";b.each=function(a,c,d){try{if(a.forEach)a.forEach(c,d);else if(b.isArray(a)||b.isArguments(a))for(var e=0,f=a.length;e<f;e++)c.call(d,
a[e],e,a);else{var g=b.keys(a);f=g.length;for(e=0;e<f;e++)c.call(d,a[g[e]],g[e],a)}}catch(h){if(h!=m)throw h;}return a};b.map=function(a,c,d){if(a&&b.isFunction(a.map))return a.map(c,d);var e=[];b.each(a,function(f,g,h){e.push(c.call(d,f,g,h))});return e};b.reduce=function(a,c,d,e){if(a&&b.isFunction(a.reduce))return a.reduce(b.bind(d,e),c);b.each(a,function(f,g,h){c=d.call(e,c,f,g,h)});return c};b.reduceRight=function(a,c,d,e){if(a&&b.isFunction(a.reduceRight))return a.reduceRight(b.bind(d,e),c);
var f=b.clone(b.toArray(a)).reverse();b.each(f,function(g,h){c=d.call(e,c,g,h,a)});return c};b.detect=function(a,c,d){var e;b.each(a,function(f,g,h){if(c.call(d,f,g,h)){e=f;b.breakLoop()}});return e};b.select=function(a,c,d){if(a&&b.isFunction(a.filter))return a.filter(c,d);var e=[];b.each(a,function(f,g,h){c.call(d,f,g,h)&&e.push(f)});return e};b.reject=function(a,c,d){var e=[];b.each(a,function(f,g,h){!c.call(d,f,g,h)&&e.push(f)});return e};b.all=function(a,c,d){c=c||b.identity;if(a&&b.isFunction(a.every))return a.every(c,
d);var e=true;b.each(a,function(f,g,h){(e=e&&c.call(d,f,g,h))||b.breakLoop()});return e};b.any=function(a,c,d){c=c||b.identity;if(a&&b.isFunction(a.some))return a.some(c,d);var e=false;b.each(a,function(f,g,h){if(e=c.call(d,f,g,h))b.breakLoop()});return e};b.include=function(a,c){if(b.isArray(a))return b.indexOf(a,c)!=-1;var d=false;b.each(a,function(e){if(d=e===c)b.breakLoop()});return d};b.invoke=function(a,c){var d=b.rest(arguments,2);return b.map(a,function(e){return(c?e[c]:e).apply(e,d)})};b.pluck=
function(a,c){return b.map(a,function(d){return d[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);var e={computed:-Infinity};b.each(a,function(f,g,h){g=c?c.call(d,f,g,h):f;g>=e.computed&&(e={value:f,computed:g})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);var e={computed:Infinity};b.each(a,function(f,g,h){g=c?c.call(d,f,g,h):f;g<e.computed&&(e={value:f,computed:g})});return e.value};b.sortBy=function(a,c,d){return b.pluck(b.map(a,
function(e,f,g){return{value:e,criteria:c.call(d,e,f,g)}}).sort(function(e,f){e=e.criteria;f=f.criteria;return e<f?-1:e>f?1:0}),"value")};b.sortedIndex=function(a,c,d){d=d||b.identity;for(var e=0,f=a.length;e<f;){var g=e+f>>1;d(a[g])<d(c)?(e=g+1):(f=g)}return e};b.toArray=function(a){if(!a)return[];if(a.toArray)return a.toArray();if(b.isArray(a))return a;if(b.isArguments(a))return k.call(a);return b.values(a)};b.size=function(a){return b.toArray(a).length};b.first=function(a,c,d){return c&&!d?k.call(a,
0,c):a[0]};b.rest=function(a,c,d){return k.call(a,b.isUndefined(c)||d?1:c)};b.last=function(a){return a[a.length-1]};b.compact=function(a){return b.select(a,function(c){return!!c})};b.flatten=function(a){return b.reduce(a,[],function(c,d){if(b.isArray(d))return c.concat(b.flatten(d));c.push(d);return c})};b.without=function(a){var c=b.rest(arguments);return b.select(a,function(d){return!b.include(c,d)})};b.uniq=function(a,c){return b.reduce(a,[],function(d,e,f){if(0==f||(c===true?b.last(d)!=e:!b.include(d,
e)))d.push(e);return d})};b.intersect=function(a){var c=b.rest(arguments);return b.select(b.uniq(a),function(d){return b.all(c,function(e){return b.indexOf(e,d)>=0})})};b.zip=function(){for(var a=b.toArray(arguments),c=b.max(b.pluck(a,"length")),d=new Array(c),e=0;e<c;e++)d[e]=b.pluck(a,String(e));return d};b.indexOf=function(a,c){if(a.indexOf)return a.indexOf(c);for(var d=0,e=a.length;d<e;d++)if(a[d]===c)return d;return-1};b.lastIndexOf=function(a,c){if(a.lastIndexOf)return a.lastIndexOf(c);for(var d=
a.length;d--;)if(a[d]===c)return d;return-1};b.range=function(a,c,d){var e=b.toArray(arguments),f=e.length<=1;a=f?0:e[0];c=f?e[0]:e[1];d=e[2]||1;e=Math.ceil((c-a)/d);if(e<=0)return[];e=new Array(e);f=a;for(var g=0;1;f+=d){if((d>0?f-c:c-f)>=0)return e;e[g++]=f}};b.bind=function(a,c){var d=b.rest(arguments,2);return function(){return a.apply(c||j,d.concat(b.toArray(arguments)))}};b.bindAll=function(a){var c=b.rest(arguments);if(c.length==0)c=b.functions(a);b.each(c,function(d){a[d]=b.bind(a[d],a)});
return a};b.delay=function(a,c){var d=b.rest(arguments,2);return setTimeout(function(){return a.apply(a,d)},c)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(b.rest(arguments)))};b.wrap=function(a,c){return function(){var d=[a].concat(b.toArray(arguments));return c.apply(c,d)}};b.compose=function(){var a=b.toArray(arguments);return function(){for(var c=b.toArray(arguments),d=a.length-1;d>=0;d--)c=[a[d].apply(this,c)];return c[0]}};b.keys=function(a){if(b.isArray(a))return b.range(0,a.length);
var c=[];for(var d in a)q.call(a,d)&&c.push(d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=function(a){return b.select(b.keys(a),function(c){return b.isFunction(a[c])}).sort()};b.extend=function(a,c){for(var d in c)a[d]=c[d];return a};b.clone=function(a){if(b.isArray(a))return a.slice(0);return b.extend({},a)};b.tap=function(a,c){c(a);return a};b.isEqual=function(a,c){if(a===c)return true;var d=typeof a;if(d!=typeof c)return false;if(a==c)return true;if(!a&&c||a&&!c)return false;
if(a.isEqual)return a.isEqual(c);if(b.isDate(a)&&b.isDate(c))return a.getTime()===c.getTime();if(b.isNaN(a)&&b.isNaN(c))return true;if(b.isRegExp(a)&&b.isRegExp(c))return a.source===c.source&&a.global===c.global&&a.ignoreCase===c.ignoreCase&&a.multiline===c.multiline;if(d!=="object")return false;if(a.length&&a.length!==c.length)return false;d=b.keys(a);var e=b.keys(c);if(d.length!=e.length)return false;for(var f in a)if(!b.isEqual(a[f],c[f]))return false;return true};b.isEmpty=function(a){return b.keys(a).length==
0};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=function(a){return!!(a&&a.concat&&a.unshift)};b.isArguments=function(a){return a&&b.isNumber(a.length)&&!b.isArray(a)&&!r.call(a,"length")};b.isFunction=function(a){return!!(a&&a.constructor&&a.call&&a.apply)};b.isString=function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)};b.isNumber=function(a){return p.call(a)==="[object Number]"};b.isDate=function(a){return!!(a&&a.getTimezoneOffset&&a.setUTCFullYear)};b.isRegExp=function(a){return!!(a&&
a.test&&a.exec&&(a.ignoreCase||a.ignoreCase===false))};b.isNaN=function(a){return b.isNumber(a)&&isNaN(a)};b.isNull=function(a){return a===null};b.isUndefined=function(a){return typeof a=="undefined"};b.noConflict=function(){j._=n;return this};b.identity=function(a){return a};b.breakLoop=function(){throw m;};var s=0;b.uniqueId=function(a){var c=s++;return a?a+c:c};b.template=function(a,c){a=new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+a.replace(/[\r\t\n]/g,
" ").replace(/'(?=[^%]*%>)/g,"\t").split("'").join("\\'").split("\t").join("'").replace(/<%=(.+?)%>/g,"',$1,'").split("<%").join("');").split("%>").join("p.push('")+"');}return p.join('');");return c?a(c):a};b.forEach=b.each;b.foldl=b.inject=b.reduce;b.foldr=b.reduceRight;b.filter=b.select;b.every=b.all;b.some=b.any;b.head=b.first;b.tail=b.rest;b.methods=b.functions;var l=function(a,c){return c?b(a).chain():a};b.each(b.functions(b),function(a){var c=b[a];i.prototype[a]=function(){var d=b.toArray(arguments);
o.call(d,this._wrapped);return l(c.apply(b,d),this._chain)}});b.each(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var c=Array.prototype[a];i.prototype[a]=function(){c.apply(this._wrapped,arguments);return l(this._wrapped,this._chain)}});b.each(["concat","join","slice"],function(a){var c=Array.prototype[a];i.prototype[a]=function(){return l(c.apply(this._wrapped,arguments),this._chain)}});i.prototype.chain=function(){this._chain=true;return this};i.prototype.value=function(){return this._wrapped}})();
This diff is collapsed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Argument parsing &mdash; CorePost 0.0.14 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '0.0.14',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="CorePost 0.0.14 documentation" href="index.html" />
<link rel="next" title="Argument validation" href="arguments.html" />
<link rel="prev" title="URL Routing" href="url_routing.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="arguments.html" title="Argument validation"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="url_routing.html" title="URL Routing"
accesskey="P">previous</a> |</li>
<li><a href="index.html">CorePost 0.0.14 documentation</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="argument-parsing">
<h1>Argument parsing<a class="headerlink" href="#argument-parsing" title="Permalink to this headline"></a></h1>
<p>CorePost can automatically parse query arguments, form arguments, as well as basic JSON, YAML and XML documents
and extract those as direct arguments to a REST router method.</p>
<p>Let&#8217;s say we have a basic method that responds to GET, POST and PUT requests.
It expects a first name and last name and outputs them back in the response:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@router</span><span class="p">(</span><span class="s">&quot;/name&quot;</span><span class="p">,(</span><span class="n">Http</span><span class="o">.</span><span class="n">GET</span><span class="p">,</span><span class="n">Http</span><span class="o">.</span><span class="n">POST</span><span class="p">,</span><span class="n">Http</span><span class="o">.</span><span class="n">PUT</span><span class="p">))</span>
<span class="k">def</span> <span class="nf">getName</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">request</span><span class="p">,</span><span class="n">first</span><span class="p">,</span><span class="n">last</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">return</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">first</span><span class="p">,</span> <span class="n">last</span><span class="p">)</span>
</pre></div>
</div>
<div class="section" id="query-arguments">
<h2>Query arguments<a class="headerlink" href="#query-arguments" title="Permalink to this headline"></a></h2>
<p>For GET requests, the query arguments will be automatically parsed, e.g.:</p>
<div class="highlight-python"><pre>curl http://127.0.0.1/name?first=John&amp;last=Doe</pre>
</div>
</div>
<div class="section" id="form-encoded-arguments">
<h2>Form encoded arguments<a class="headerlink" href="#form-encoded-arguments" title="Permalink to this headline"></a></h2>
<p>For POST/PUT requests, any form-encoded arguments will be automatically parsed, e.g.:</p>
<div class="highlight-python"><pre>curl -X POST http://localhost/name -d "first=John&amp;last=Doe"</pre>
</div>
</div>
<div class="section" id="json-document-arguments">
<h2>JSON document arguments<a class="headerlink" href="#json-document-arguments" title="Permalink to this headline"></a></h2>
<p>For the same method, you could just post a JSON document instead that looks like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">{</span><span class="s">&quot;first&quot;</span><span class="p">:</span><span class="s">&quot;John&quot;</span><span class="p">,</span><span class="s">&quot;last&quot;</span><span class="p">:</span><span class="s">&quot;Doe&quot;</span><span class="p">}</span>
</pre></div>
</div>
<p>CorePost will automatically pass all the root elements of the document as arguments into a method.
Requires the <em>&#8216;application/json&#8217;</em> content type to be passed.</p>
</div>
<div class="section" id="yaml-document-arguments">
<h2>YAML document arguments<a class="headerlink" href="#yaml-document-arguments" title="Permalink to this headline"></a></h2>
<p>For the same method, you could just post a YAML document that looks like this:</p>
<div class="highlight-python"><pre>first:John
last:Doe</pre>
</div>
<p>CorePost will automatically pass all the root elements of the document as arguments into a method.
Requires the <em>&#8216;text/yaml&#8217;</em> content type to be passed.</p>
</div>
<div class="section" id="xml-document-arguments">
<h2>XML document arguments<a class="headerlink" href="#xml-document-arguments" title="Permalink to this headline"></a></h2>
<p>XML documents are supported as well. In that case, CorePost will first parse all the attributes on the root node
and then all of the children underneath the main root node.</p>
<p>Hence all of the XML formats below are valid and would generate the same parameters to a method.</p>
<p>Attributes only:</p>
<div class="highlight-python"><pre>&lt;root first="John" last="Doe"/&gt;</pre>
</div>
<p>Mix of attributes and child nodes:</p>
<div class="highlight-python"><pre>&lt;root first="John"&gt;
&lt;last&gt;Doe&lt;/last&gt;
&lt;/root&gt;</pre>
</div>
<p>Child nodes only:</p>
<div class="highlight-python"><pre>&lt;root&gt;
&lt;first&gt;John&lt;/first&gt;
&lt;last&gt;Doe&lt;/last&gt;
&lt;/root&gt;</pre>
</div>
<p>Requires the <em>&#8216;text/xml&#8217;</em> OR <em>&#8216;application/xml&#8217;</em> content type to be passed.</p>
<p>As you can see from the examples above, a single CorePost router method can handle all these varied forms of argument parsing
for you without any additional effort.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Argument parsing</a><ul>
<li><a class="reference internal" href="#query-arguments">Query arguments</a></li>
<li><a class="reference internal" href="#form-encoded-arguments">Form encoded arguments</a></li>
<li><a class="reference internal" href="#json-document-arguments">JSON document arguments</a></li>
<li><a class="reference internal" href="#yaml-document-arguments">YAML document arguments</a></li>
<li><a class="reference internal" href="#xml-document-arguments">XML document arguments</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="url_routing.html"
title="previous chapter">URL Routing</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="arguments.html"
title="next chapter">Argument validation</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/argument_parsing.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="arguments.html" title="Argument validation"
>next</a> |</li>
<li class="right" >
<a href="url_routing.html" title="URL Routing"
>previous</a> |</li>
<li><a href="index.html">CorePost 0.0.14 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2012, Jacek Furmankiewicz.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Argument validation &mdash; CorePost 0.0.14 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '0.0.14',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="CorePost 0.0.14 documentation" href="index.html" />
<link rel="next" title="Content types" href="content_types.html" />
<link rel="prev" title="Argument parsing" href="argument_parsing.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="content_types.html" title="Content types"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="argument_parsing.html" title="Argument parsing"
accesskey="P">previous</a> |</li>
<li><a href="index.html">CorePost 0.0.14 documentation</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="argument-validation">
<h1>Argument validation<a class="headerlink" href="#argument-validation" title="Permalink to this headline"></a></h1>
<p>CorePost integrates the popular &#8216;formencode&#8217; package to implement form and query argument validation.
Validators can be specified using a <em>formencode</em> Schema object, or via custom field-specific validators.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">corepost.web</span> <span class="kn">import</span> <span class="n">validate</span><span class="p">,</span> <span class="n">route</span>
<span class="kn">from</span> <span class="nn">corepost.enums</span> <span class="kn">import</span> <span class="n">Http</span>
<span class="kn">from</span> <span class="nn">formencode</span> <span class="kn">import</span> <span class="n">Schema</span><span class="p">,</span> <span class="n">validators</span>
<span class="k">class</span> <span class="nc">TestSchema</span><span class="p">(</span><span class="n">Schema</span><span class="p">):</span>
<span class="n">allow_extra_fields</span> <span class="o">=</span> <span class="bp">True</span>
<span class="n">childId</span> <span class="o">=</span> <span class="n">validators</span><span class="o">.</span><span class="n">Regex</span><span class="p">(</span><span class="n">regex</span><span class="o">=</span><span class="s">&quot;^value1|value2$&quot;</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">MyApp</span><span class="p">():</span>
<span class="nd">@route</span><span class="p">(</span><span class="s">&quot;/validate/&lt;int:rootId&gt;/schema&quot;</span><span class="p">,</span><span class="n">Http</span><span class="o">.</span><span class="n">POST</span><span class="p">)</span>
<span class="nd">@validate</span><span class="p">(</span><span class="n">schema</span><span class="o">=</span><span class="n">TestSchema</span><span class="p">())</span>
<span class="k">def</span> <span class="nf">postValidateSchema</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">request</span><span class="p">,</span><span class="n">rootId</span><span class="p">,</span><span class="n">childId</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Validate using a common schema&#39;&#39;&#39;</span>
<span class="k">return</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> - </span><span class="si">%s</span><span class="s"> - </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">rootId</span><span class="p">,</span><span class="n">childId</span><span class="p">,</span><span class="n">kwargs</span><span class="p">)</span>
<span class="nd">@route</span><span class="p">(</span><span class="s">&quot;/validate/&lt;int:rootId&gt;/custom&quot;</span><span class="p">,</span><span class="n">Http</span><span class="o">.</span><span class="n">POST</span><span class="p">)</span>
<span class="nd">@validate</span><span class="p">(</span><span class="n">childId</span><span class="o">=</span><span class="n">validators</span><span class="o">.</span><span class="n">Regex</span><span class="p">(</span><span class="n">regex</span><span class="o">=</span><span class="s">&quot;^value1|value2$&quot;</span><span class="p">))</span>
<span class="k">def</span> <span class="nf">postValidateCustom</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">request</span><span class="p">,</span><span class="n">rootId</span><span class="p">,</span><span class="n">childId</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Validate using argument-specific validators&#39;&#39;&#39;</span>
<span class="k">return</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> - </span><span class="si">%s</span><span class="s"> - </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">rootId</span><span class="p">,</span><span class="n">childId</span><span class="p">,</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</div>
<p>Please see the <em>FormEncode</em> documentation:</p>
<p><a class="reference external" href="http://www.formencode.org/en/latest/Validator.html">http://www.formencode.org/en/latest/Validator.html</a></p>
<p>for list of available validators:</p>
<ul class="simple">
<li>Common : <a class="reference external" href="http://www.formencode.org/en/latest/modules/validators.html#module-formencode.validators">http://www.formencode.org/en/latest/modules/validators.html#module-formencode.validators</a></li>
<li>National : <a class="reference external" href="http://www.formencode.org/en/latest/modules/national.html#module-formencode.national">http://www.formencode.org/en/latest/modules/national.html#module-formencode.national</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="argument_parsing.html"
title="previous chapter">Argument parsing</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="content_types.html"
title="next chapter">Content types</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/arguments.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="content_types.html" title="Content types"
>next</a> |</li>
<li class="right" >
<a href="argument_parsing.html" title="Argument parsing"
>previous</a> |</li>
<li><a href="index.html">CorePost 0.0.14 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2012, Jacek Furmankiewicz.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Asynchronous Operations &mdash; CorePost 0.0.14 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '0.0.14',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="CorePost 0.0.14 documentation" href="index.html" />
<link rel="next" title="Modular REST applications" href="modules.html" />
<link rel="prev" title="HTTP codes" href="http_codes.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="modules.html" title="Modular REST applications"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="http_codes.html" title="HTTP codes"
accesskey="P">previous</a> |</li>
<li><a href="index.html">CorePost 0.0.14 documentation</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="asynchronous-operations">
<h1>Asynchronous Operations<a class="headerlink" href="#asynchronous-operations" title="Permalink to this headline"></a></h1>
<div class="section" id="defer-inlinecallbacks-support">
<h2>&#64;defer.inlineCallbacks support<a class="headerlink" href="#defer-inlinecallbacks-support" title="Permalink to this headline"></a></h2>
<p>If you want a deferred async method, just use <em>defer.returnValue()</em>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@route</span><span class="p">(</span><span class="s">&quot;/&quot;</span><span class="p">,</span><span class="n">Http</span><span class="o">.</span><span class="n">GET</span><span class="p">)</span>
<span class="nd">@defer.inlineCallbacks</span>
<span class="k">def</span> <span class="nf">root</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">request</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">val1</span> <span class="o">=</span> <span class="k">yield</span> <span class="n">db</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s">&quot;SELECT ....&quot;</span><span class="p">)</span>
<span class="n">val2</span> <span class="o">=</span> <span class="k">yield</span> <span class="n">db</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s">&quot;SELECT ....&quot;</span><span class="p">)</span>
<span class="n">defer</span><span class="o">.</span><span class="n">returnValue</span><span class="p">(</span><span class="n">val1</span> <span class="o">+</span> <span class="n">val2</span><span class="p">)</span>
</pre></div>
</div>
<p>This is standard Twisted functionality.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Asynchronous Operations</a><ul>
<li><a class="reference internal" href="#defer-inlinecallbacks-support">&#64;defer.inlineCallbacks support</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="http_codes.html"
title="previous chapter">HTTP codes</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="modules.html"
title="next chapter">Modular REST applications</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/async.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="modules.html" title="Modular REST applications"
>next</a> |</li>
<li class="right" >
<a href="http_codes.html" title="HTTP codes"
>previous</a> |</li>
<li><a href="index.html">CorePost 0.0.14 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2012, Jacek Furmankiewicz.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
</div>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=pdflatex 2012.2.29) 19 MAR 2012 13:56 This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=pdflatex 2012.3.27) 17 APR 2012 16:18
entering extended mode entering extended mode
%&-line parsing enabled. %&-line parsing enabled.
**CorePost.tex **CorePost.tex
...@@ -928,7 +928,7 @@ ype1/urw/helvetic/uhvb8a.pfb></usr/share/texmf-texlive/fonts/type1/urw/helvetic ...@@ -928,7 +928,7 @@ ype1/urw/helvetic/uhvb8a.pfb></usr/share/texmf-texlive/fonts/type1/urw/helvetic
/uhvbo8a.pfb></usr/share/texmf-texlive/fonts/type1/urw/times/utmb8a.pfb></usr/s /uhvbo8a.pfb></usr/share/texmf-texlive/fonts/type1/urw/times/utmb8a.pfb></usr/s
hare/texmf-texlive/fonts/type1/urw/times/utmr8a.pfb></usr/share/texmf-texlive/f hare/texmf-texlive/fonts/type1/urw/times/utmr8a.pfb></usr/share/texmf-texlive/f
onts/type1/urw/times/utmri8a.pfb> onts/type1/urw/times/utmri8a.pfb>
Output written on CorePost.pdf (15 pages, 149329 bytes). Output written on CorePost.pdf (15 pages, 149328 bytes).
PDF statistics: PDF statistics:
192 PDF objects out of 1000 (max. 8388607) 192 PDF objects out of 1000 (max. 8388607)
42 named destinations out of 1000 (max. 500000) 42 named destinations out of 1000 (max. 500000)
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
\title{CorePost Documentation} \title{CorePost Documentation}
\date{March 19, 2012} \date{April 17, 2012}
\release{0.0.14} \release{0.0.14}
\author{Jacek Furmankiewicz} \author{Jacek Furmankiewicz}
\newcommand{\sphinxlogo}{} \newcommand{\sphinxlogo}{}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
logo.png

67.1 KB

This diff is collapsed.
This diff is collapsed.
Search.setIndex({objects:{},terms:{all:[2,3],code:[0,1,4,5,6,8],partial:5,queri:[2,0,7,9],formencod:7,iresponsefilt:8,follow:8,children:2,rootid:7,depend:5,received_head:[8,4],readabl:6,specif:7,under:6,string:[5,4],veri:6,level:6,list:[7,8],localhost:2,small:3,pleas:7,enterpris:6,fortun:6,abil:6,direct:2,design:6,pass:[2,8,4],val2:9,val1:9,phoneid:3,index:[],what:[0,6],savecustom:3,abl:1,current:[6,4],delet:[3,1],intarg:4,filterrespons:8,method:[2,9,6,1,4],can:[2,3,4,5,7,8],full:3,restservic:4,gener:2,here:3,bodi:5,modular:[0,3],intercept:8,let:[2,6],floatarg:4,address:3,path:[0,3,4],statecod:3,valu:8,convert:[5,0,4],convers:6,extrem:6,chang:8,via:[7,8,4],activ:8,modul:7,countrycod:3,api:6,select:9,regex:7,from:[1,2,3,4,6,7],would:[2,0,6,4],two:[3,8],handler:6,call:5,value2:7,value1:7,recommend:6,type:[2,0,5,8,4],more:6,desir:4,test_yaml:5,phone:3,indic:[],particular:6,known:6,effort:2,customerid:3,content_typ:4,postvalidateschema:7,focu:6,del:3,thin:6,root:[2,9,8,4],def:[2,3,4,5,7,8,9],defer:[0,6,9],tap:4,give:6,accept:5,want:9,multipl:[],write:[6,3,4],how:6,instead:[2,0,6,5],simpl:4,product:[6,4],resourc:[3,8],befor:6,mesh:3,end:3,httpheader:4,tutori:6,seriou:6,element:[2,3],callback:6,allow:[3,8],first:2,order:[3,8],vari:2,dynam:[3,4],entiti:3,yaml:[2,0,6,5],jit:6,main:2,easier:6,them:[2,3,8,4],application_json:4,"return":[1,2,3,4,5,7,8],python:[5,0,6],nation:7,underneath:2,framework:[0,6],introduct:[0,6],name:2,trac:6,easili:4,wraparoundfilt:8,side:6,status:8,hard:6,expect:[2,0,5,4],paymentid:3,extract:[2,0,4],network:6,develop:6,crucial:6,content:[2,0,5,4],restresourc:[3,8,4],deleteal:3,test_content_app_json:4,integr:[5,7],standard:9,pleasant:6,base:[5,1,4],put:[2,5,3,1,4],org:7,care:[6,3],addressid:3,could:2,filter:[0,6,8],router:[2,4],principl:6,interact:6,testschema:7,oper:[0,6,9],note:4,blown:3,grade:6,onc:6,lastnam:3,test_json:5,getallcustom:3,hook:4,miss:1,hood:6,differ:[3,4],addcustomheaderfilt:8,getcustomeraddress:3,customeraddress:3,top:[0,6],system:6,least:6,attach:5,conveni:4,schema:7,customeraddressrestservic:3,specifi:7,pars:[2,0,6,5],streetnumb:3,mostli:6,than:6,john:2,instanc:8,provid:6,structur:3,sai:2,ani:[2,6,1],packag:7,have:[2,3],"__main__":[3,4],need:8,inlinecallback:[0,9],test_return_content_by_accept:5,self:[2,3,4,5,7,8,9],especi:6,thorough:6,stringarg:4,mix:2,without:2,take:[6,3],which:[6,3],noth:6,singl:[2,3],simplifi:6,importantli:6,deletecustom:3,regular:3,why:[0,6],url:[5,0,3,1,4],request:[0,2,3,4,5,6,7,8,9],doe:[2,0,6],test_content_xml:4,runtim:6,wildcard:4,numericid:4,somewhat:6,show:4,text:[2,5],xml:[2,0,6,5],onli:2,just:[2,3,4,5,6,8,9],solut:6,plumb:6,should:6,busi:[6,3],meant:6,get:[1,2,3,4,6,8,9],pypi:6,requir:[2,6],run_filter_app:8,change404to503filt:8,yield:9,"default":[5,1],common:[6,7],deleteallcustom:3,where:3,valid:[2,0,3,1,7],respond:2,dump:5,see:[2,7],mandatori:1,respons:[2,5,6,3,8],fail:1,extend:3,hopefulli:6,databas:6,behind:6,"import":[3,7,4],paramet:[2,3,8],approach:6,attribut:2,parent:3,addit:2,both:8,last:2,howev:6,test_content_catch_al:4,etc:[3,4],text_xml:4,logic:6,pdf:6,com:[6,4],simpli:6,header:8,guid:6,coupl:6,json:[2,0,6,5],much:6,basic:[2,6,4],search:[],argument:[2,0,1,7,4],notfoundexcept:3,dave:6,run_rest_app:3,child:[2,3],those:2,"case":[2,3],look:2,tostr:5,servic:[6,3,8],"while":6,abov:[2,3],error:1,fun:6,exist:[3,4],layer:6,twistedmatrix:[6,4],tabl:[],henc:[2,6],toolkit:6,kwarg:[2,4,5,7,8,9],myapp:7,postvalidatecustom:7,incom:[5,0,8,4],twistd:4,decor:[0,4],allow_extra_field:7,perform:6,make:6,same:[2,4],handl:[2,6],html:[7,4],zope:8,document:[2,0,6,7,4],breakdown:[],http:[0,1,2,3,4,5,6,7,8,9],driven:[3,1],extern:6,typic:3,appropri:[3,1],eleg:6,well:[2,6],coreport:4,exampl:[2,3,7,4],thi:[2,3,4,5,6,9],rout:[0,3,4,5,6,7,8,9],latest:7,test1:5,test2:5,firstnam:3,when:4,rest:[2,0,6,3],filterapp:8,test_content_yaml:4,yet:6,languag:6,web:[0,6,3,7,4],application_xml:4,except:6,getal:3,blog:6,add:[0,6,8],book:6,input:[6,8],app:[3,8,4],match:1,build:6,real:4,applic:[0,2,3,4,5,6],around:8,format:[2,6],read:6,irequestfilt:8,howto:[6,4],piec:4,realiz:6,like:[2,6,3],success:1,filterrequest:8,test_get_resourc:4,either:[6,8],popular:7,output:[2,8],page:[],childid:7,www:7,some:6,back:2,sampl:[3,4],server:[6,1],librari:6,kei:[],getcustom:3,micro:[0,6],peticola:6,outgo:8,unit:4,test_xml:5,complic:6,getnam:2,core:[6,4],object:[0,3,4,5,6,7],run:[3,8,4],power:6,payment:3,"enum":[7,4],usag:6,alreadyexistsexcept:3,async:[9,6],"__name__":[3,4],post:[1,2,3,4,5,7],actual:1,constructor:8,other:6,own:6,effici:6,"float":4,encod:[2,0],automat:[2,5,6,4],wrap:[3,8],your:4,invoiceid:3,val:5,support:[0,2,4,5,8,9],custom:[6,3,7,8],avail:7,reli:6,interfac:8,low:6,"function":[9,1,4],returnvalu:9,form:[2,0,7],streetnam:3,inlin:6,"true":7,whether:5,page_id:6,caller:5,asynchron:[0,6,9],below:2,similar:6,featur:[0,6],creat:[6,3,1],"int":[7,4],customerrestservic:3,twist:[0,6,3,9,4],implement:[3,7,8],curl:2,krondo:6,excel:6,elementtre:5,field:7,corepost:[0,1,2,3,4,5,6,7,8],test:4,you:[2,3,4,6,8,9],node:[2,0,6],matur:6,mediatyp:4,"class":[6,3,7,8,4],sql:6,text_yaml:4,understand:6,invoic:3},objtypes:{},titles:["CorePost","HTTP codes","Argument parsing","Modular REST applications","URL Routing","Content types","Introduction","Argument validation","Filters","Asynchronous Operations"],objnames:{},filenames:["index","http_codes","argument_parsing","modules","url_routing","content_types","intro","arguments","filters","async"]})
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment