Commit cfb0fea0 authored by niv-openerp's avatar niv-openerp

Modif by al

parent 4106b96c
...@@ -190,6 +190,34 @@ class NetRPCConnector(Connector): ...@@ -190,6 +190,34 @@ 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 Exception handling
# This will be changed to be xmlrpc compatible
# OpenERPWarning code 1
# OpenERPException code 2
try:
result = openerp.netsvc.dispatch_rpc(service_name, method, args, None)
except openerp.netsvc.OpenERPDispatcherException, e:
fault = xmlrpclib.Fault(openerp.tools.exception_to_unicode(e.exception), e.traceback)
raise fault
except:
exc_type, exc_value, exc_tb = sys.exc_info()
fault = xmlrpclib.Fault(1, "%s:%s" % (exc_type, exc_value))
raise fault
return result
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.
...@@ -363,7 +391,7 @@ class Model(object): ...@@ -363,7 +391,7 @@ class Model(object):
records = self.read(record_ids, fields or [], context or {}) records = self.read(record_ids, fields or [], context or {})
return records return records
def get_connector(hostname, protocol="xmlrpc", port="auto"): def get_connector(hostname=None, protocol="xmlrpc", port="auto"):
""" """
A shortcut method to easily create a connector to a remote server using XMLRPC or NetRPC. A shortcut method to easily create a connector to a remote server using XMLRPC or NetRPC.
...@@ -377,10 +405,12 @@ def get_connector(hostname, protocol="xmlrpc", port="auto"): ...@@ -377,10 +405,12 @@ 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=None, protocol="xmlrpc", port='auto', database=None,
login=None, password=None, user_id=None): login=None, password=None, user_id=None):
""" """
A shortcut method to easily create a connection to a remote OpenERP server. A shortcut method to easily create a connection to a remote OpenERP server.
......
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