[REF] openerp.service.{rpc,route,handler} decorators moved to openerp.http.

bzr revid: vmt@openerp.com-20130201093727-pgcvauuo87o2a3p6
This commit is contained in:
Vo Minh Thu 2013-02-01 10:37:27 +01:00
parent a57b655e43
commit 665fc8d8f1
4 changed files with 42 additions and 20 deletions

View File

@ -3,6 +3,8 @@
Routing
=======
.. versionchanged:: 7.1
The OpenERP framework, as an HTTP server, serves a few hard-coded URLs
(``models``, ``db``, ...) to expose RPC endpoints. When running the web addons
(which is almost always the case), it also serves URLs without them being RPC
@ -13,6 +15,6 @@ In older version of OpenERP, adding RPC endpoints was done by subclassing the
registering them with the ``openerp.wsgi.register_wsgi_handler()`` function.
Starting with OpenERP 7.1, exposing a new arbitrary WSGI handler is done with
the ``openerp.service.handler`` decorator while adding an RPC endpoint is done
with the ``openerp.service.rpc`` decorator.
the ``openerp.http.handler`` decorator while adding an RPC endpoint is done
with the ``openerp.http.rpc`` decorator.

View File

@ -28,6 +28,7 @@ SUPERUSER_ID = 1
import addons
import cli
import conf
import http
import loglevels
import modules
import netsvc

37
openerp/http.py Normal file
View File

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
"""
Decorators to register WSGI and RPC endpoints handlers. See doc/routing.rst.
# TODO use sphinx ref to doc/routing.rst.
"""
from . import service
def handler():
"""
Decorator to register a WSGI handler. The handler must return None if it
does not handle the request.
"""
def decorator(f):
service.wsgi_server.register_wsgi_handler(f)
return decorator
def route(url):
"""
Same as then handler() decorator but register the handler under a specific
url. Not yet implemented.
"""
def decorator(f):
pass # TODO
return decorator
def rpc(endpoint):
"""
Decorator to register a RPC endpoint handler. The handler will receive
already unmarshalled RCP arguments.
"""
def decorator(f):
service.wsgi_server.register_rpc_endpoint(endpoint, f)
return decorator
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -150,22 +150,4 @@ def restart_server():
openerp.phoenix = True
os.kill(os.getpid(), signal.SIGINT)
def handler():
"""TODO"""
def decorator(f):
wsgi_server.register_wsgi_handler(f)
return decorator
def route(url):
"""TODO"""
def decorator(f):
pass # TODO Same as handler() but register the handler under a specific url.
return decorator
def rpc(endpoint):
"""TODO"""
def decorator(f):
wsgi_server.register_rpc_endpoint(endpoint, f)
return decorator
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: