[IMP] web.common.sesion local backend part1
bzr revid: al@openerp.com-20110924163828-gbys8t65gyz0qkcu
This commit is contained in:
parent
522f90e7d5
commit
0a02a38739
|
@ -20,9 +20,5 @@ def wsgi_postload():
|
||||||
o.backend = 'local'
|
o.backend = 'local'
|
||||||
|
|
||||||
app = common.dispatch.Root(o)
|
app = common.dispatch.Root(o)
|
||||||
#import openerp.wsgi
|
|
||||||
openerp.wsgi.register_wsgi_handler(app)
|
openerp.wsgi.register_wsgi_handler(app)
|
||||||
|
|
||||||
# TODO
|
|
||||||
# if we detect that we are imported from the openerp server register common.Root() as a wsgi entry point
|
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,7 @@ import werkzeug.wsgi
|
||||||
import ast
|
import ast
|
||||||
import nonliterals
|
import nonliterals
|
||||||
import http
|
import http
|
||||||
# import backendlocal as backend
|
import session
|
||||||
import session as backend
|
|
||||||
import openerplib
|
import openerplib
|
||||||
|
|
||||||
__all__ = ['Root', 'jsonrequest', 'httprequest', 'Controller',
|
__all__ = ['Root', 'jsonrequest', 'httprequest', 'Controller',
|
||||||
|
@ -79,12 +78,12 @@ class WebRequest(object):
|
||||||
|
|
||||||
.. attribute:: session_id
|
.. attribute:: session_id
|
||||||
|
|
||||||
opaque identifier for the :class:`backend.OpenERPSession` instance of
|
opaque identifier for the :class:`session.OpenERPSession` instance of
|
||||||
the current request
|
the current request
|
||||||
|
|
||||||
.. attribute:: session
|
.. attribute:: session
|
||||||
|
|
||||||
:class:`~backend.OpenERPSession` instance for the current request
|
:class:`~session.OpenERPSession` instance for the current request
|
||||||
|
|
||||||
.. attribute:: context
|
.. attribute:: context
|
||||||
|
|
||||||
|
@ -100,13 +99,12 @@ class WebRequest(object):
|
||||||
self.httpresponse = None
|
self.httpresponse = None
|
||||||
self.httpsession = request.session
|
self.httpsession = request.session
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def init(self, params):
|
def init(self, params):
|
||||||
self.params = dict(params)
|
self.params = dict(params)
|
||||||
# OpenERP session setup
|
# OpenERP session setup
|
||||||
self.session_id = self.params.pop("session_id", None) or uuid.uuid4().hex
|
self.session_id = self.params.pop("session_id", None) or uuid.uuid4().hex
|
||||||
self.session = self.httpsession.setdefault(
|
self.session = self.httpsession.setdefault(self.session_id, session.OpenERPSession(self.config))
|
||||||
self.session_id, backend.OpenERPSession(
|
|
||||||
self.config.server_host, self.config.server_port))
|
|
||||||
self.context = self.params.pop('context', None)
|
self.context = self.params.pop('context', None)
|
||||||
self.debug = self.params.pop('debug', False) != False
|
self.debug = self.params.pop('debug', False) != False
|
||||||
|
|
||||||
|
|
|
@ -190,6 +190,22 @@ class NetRPCConnector(Connector):
|
||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
class LocalConnector(Connector):
|
||||||
|
"""
|
||||||
|
A type of connector that uses the XMLRPC protocol.
|
||||||
|
"""
|
||||||
|
PROTOCOL = 'local'
|
||||||
|
|
||||||
|
__logger = _getChildLogger(_logger, 'connector.local')
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def send(self, service_name, method, *args):
|
||||||
|
import openerp
|
||||||
|
# todo local
|
||||||
|
print service_name, method, args
|
||||||
|
|
||||||
class Service(object):
|
class Service(object):
|
||||||
"""
|
"""
|
||||||
A class to execute RPC calls on a specific service of the remote server.
|
A class to execute RPC calls on a specific service of the remote server.
|
||||||
|
@ -377,8 +393,10 @@ def get_connector(hostname, protocol="xmlrpc", port="auto"):
|
||||||
return XmlRPCConnector(hostname, port)
|
return XmlRPCConnector(hostname, port)
|
||||||
elif protocol == "netrpc":
|
elif protocol == "netrpc":
|
||||||
return NetRPCConnector(hostname, port)
|
return NetRPCConnector(hostname, port)
|
||||||
|
elif protocol == "local":
|
||||||
|
return LocalConnector()
|
||||||
else:
|
else:
|
||||||
raise ValueError("You must choose xmlrpc or netrpc")
|
raise ValueError("You must choose xmlrpc or netrpc or local")
|
||||||
|
|
||||||
def get_connection(hostname, protocol="xmlrpc", port='auto', database=None,
|
def get_connection(hostname, protocol="xmlrpc", port='auto', database=None,
|
||||||
login=None, password=None, user_id=None):
|
login=None, password=None, user_id=None):
|
||||||
|
|
|
@ -26,9 +26,8 @@ class OpenERPSession(object):
|
||||||
Used to store references to non-literal domains which need to be
|
Used to store references to non-literal domains which need to be
|
||||||
round-tripped to the client browser.
|
round-tripped to the client browser.
|
||||||
"""
|
"""
|
||||||
def __init__(self, server='127.0.0.1', port=8069):
|
def __init__(self, config):
|
||||||
self._server = server
|
self.config = config
|
||||||
self._port = port
|
|
||||||
self._db = False
|
self._db = False
|
||||||
self._uid = False
|
self._uid = False
|
||||||
self._login = False
|
self._login = False
|
||||||
|
@ -42,7 +41,7 @@ class OpenERPSession(object):
|
||||||
self.client_timezone = False
|
self.client_timezone = False
|
||||||
|
|
||||||
def build_connection(self):
|
def build_connection(self):
|
||||||
return openerplib.get_connection(hostname=self._server, port=self._port,
|
return openerplib.get_connection(hostname=self.config.server_host, port=self.config.server_port,
|
||||||
database=self._db, login=self._login,
|
database=self._db, login=self._login,
|
||||||
user_id=self._uid, password=self._password)
|
user_id=self._uid, password=self._password)
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ import web.common.dispatch
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
(options, args) = optparser.parse_args(sys.argv[1:])
|
(options, args) = optparser.parse_args(sys.argv[1:])
|
||||||
options.backend = 'rpc'
|
options.backend = 'xmlrpc'
|
||||||
|
|
||||||
os.environ["TZ"] = "UTC"
|
os.environ["TZ"] = "UTC"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue