diff --git a/doc/routing.rst b/doc/routing.rst index 1e4f76d25b8..b2e93de8ef9 100644 --- a/doc/routing.rst +++ b/doc/routing.rst @@ -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. diff --git a/openerp/__init__.py b/openerp/__init__.py index 307170b9033..dc09113adff 100644 --- a/openerp/__init__.py +++ b/openerp/__init__.py @@ -28,6 +28,7 @@ SUPERUSER_ID = 1 import addons import cli import conf +import http import loglevels import modules import netsvc diff --git a/openerp/http.py b/openerp/http.py new file mode 100644 index 00000000000..004542f3100 --- /dev/null +++ b/openerp/http.py @@ -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: diff --git a/openerp/service/__init__.py b/openerp/service/__init__.py index db5d4542bf4..9db73223029 100644 --- a/openerp/service/__init__.py +++ b/openerp/service/__init__.py @@ -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: