Skip to content

Commit

Permalink
add validation example
Browse files Browse the repository at this point in the history
  • Loading branch information
plq committed Mar 10, 2012
1 parent cd2c143 commit 2bac3e0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/multiple_protocols/presentation/pres.tex
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@
This example and the presentation are in:
\href{https://github.com/arskom/rpclib/tree/master/examples/multiple_protocols}{examples/multiple\_protocols}

\href{https://github.com/arskom/rpclib/tree/master/validation.py}{examples/validation.py}

\bigskip

\huge
Expand Down
36 changes: 36 additions & 0 deletions examples/validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

from datetime import datetime
from rpclib.model.primitive import Integer,Unicode
from rpclib.decorator import srpc
from rpclib.service import ServiceBase

class NameOfMonthService(ServiceBase):
@srpc(Integer(ge=1,le=12), _returns=Unicode)
def get_name_of_month(month):
return datetime(2000,month,1).strftime("%B")


from rpclib.application import Application
from rpclib.protocol.http import HttpRpc

rest = Application([NameOfMonthService],
tns='rpclib.examples.multiprot',
in_protocol=HttpRpc(validator='soft'),
out_protocol=HttpRpc()
)

import logging

from rpclib.server.wsgi import WsgiApplication
from wsgiref.simple_server import make_server

host = '127.0.0.1'
port = 9912

server = make_server(host, port, WsgiApplication(rest))


logging.basicConfig(level=logging.DEBUG)
logging.info("listening to http://%s:%d" % (host,port))

server.serve_forever()

0 comments on commit 2bac3e0

Please sign in to comment.