Merge lp:~toolpart/openerp-client-lib/xmlrpcs into lp:openerp-client-lib

Proposed by ViktorNagy
Status: Merged
Merged at revision: 35
Proposed branch: lp:~toolpart/openerp-client-lib/xmlrpcs
Merge into: lp:openerp-client-lib
Diff against target: 133 lines (+30/-16)
1 file modified
openerplib/main.py (+30/-16)
To merge this branch: bzr merge lp:~toolpart/openerp-client-lib/xmlrpcs
Reviewer Review Type Date Requested Status
Nicolas Vanhoren (OpenERP) Pending
Review via email: mp+76899@code.launchpad.net

Description of the change

Added secure xmlrpc (XML-RPC-S) connector.

To post a comment you must log in.
Revision history for this message
Nicolas Vanhoren (OpenERP) (niv-openerp) wrote :

Ok, I will discuss this with the rest of the team and see if we merge this.

But, please, in the future could you avoid automatic formatters? It makes an ugly diff.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openerplib/main.py'
--- openerplib/main.py 2011-09-22 15:45:57 +0000
+++ openerplib/main.py 2011-09-25 12:25:23 +0000
@@ -5,16 +5,16 @@
5# Copyright (C) 2011 Nicolas Vanhoren5# Copyright (C) 2011 Nicolas Vanhoren
6# Copyright (C) 2011 OpenERP s.a. (<http://openerp.com>).6# Copyright (C) 2011 OpenERP s.a. (<http://openerp.com>).
7# All rights reserved.7# All rights reserved.
8# 8#
9# Redistribution and use in source and binary forms, with or without9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions are met: 10# modification, are permitted provided that the following conditions are met:
11# 11#
12# 1. Redistributions of source code must retain the above copyright notice, this12# 1. Redistributions of source code must retain the above copyright notice, this
13# list of conditions and the following disclaimer. 13# list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright notice,14# 2. Redistributions in binary form must reproduce the above copyright notice,
15# this list of conditions and the following disclaimer in the documentation15# this list of conditions and the following disclaimer in the documentation
16# and/or other materials provided with the distribution. 16# and/or other materials provided with the distribution.
17# 17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE20# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -25,7 +25,7 @@
25# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28# 28#
29##############################################################################29##############################################################################
3030
31"""31"""
@@ -36,7 +36,7 @@
36"""36"""
3737
38import xmlrpclib38import xmlrpclib
39import logging 39import logging
40import socket40import socket
4141
42try:42try:
@@ -75,7 +75,7 @@
75 A type of connector that uses the XMLRPC protocol.75 A type of connector that uses the XMLRPC protocol.
76 """76 """
77 PROTOCOL = 'xmlrpc'77 PROTOCOL = 'xmlrpc'
78 78
79 __logger = _getChildLogger(_logger, 'connector.xmlrpc')79 __logger = _getChildLogger(_logger, 'connector.xmlrpc')
8080
81 def __init__(self, hostname, port=8069):81 def __init__(self, hostname, port=8069):
@@ -92,6 +92,18 @@
92 service = xmlrpclib.ServerProxy(url)92 service = xmlrpclib.ServerProxy(url)
93 return getattr(service, method)(*args)93 return getattr(service, method)(*args)
9494
95class XmlRPCSConnector(XmlRPCConnector):
96 """
97 A type of connector that uses the secured XMLRPC protocol.
98 """
99 PROTOCOL = 'xmlrpcs'
100
101 __logger = _getChildLogger(_logger, 'connector.xmlrpcs')
102
103 def __init__(self, hostname, port=8071):
104 super(XmlRPCSConnector, self).__init__(hostname, port)
105 self.url = 'https://%s:%d/xmlrpc' % (self.hostname, self.port)
106
95class NetRPC_Exception(Exception):107class NetRPC_Exception(Exception):
96 """108 """
97 Exception for NetRPC errors.109 Exception for NetRPC errors.
@@ -171,7 +183,7 @@
171 """183 """
172184
173 PROTOCOL = 'netrpc'185 PROTOCOL = 'netrpc'
174 186
175 __logger = _getChildLogger(_logger, 'connector.netrpc')187 __logger = _getChildLogger(_logger, 'connector.netrpc')
176188
177 def __init__(self, hostname, port=8070):189 def __init__(self, hostname, port=8070):
@@ -202,7 +214,7 @@
202 self.connector = connector214 self.connector = connector
203 self.service_name = service_name215 self.service_name = service_name
204 self.__logger = _getChildLogger(_getChildLogger(_logger, 'service'),service_name)216 self.__logger = _getChildLogger(_getChildLogger(_logger, 'service'),service_name)
205 217
206 def __getattr__(self, method):218 def __getattr__(self, method):
207 """219 """
208 :param method: The name of the method to execute on the service.220 :param method: The name of the method to execute on the service.
@@ -259,7 +271,7 @@
259 self.database, self.login, self.password = database, login, password271 self.database, self.login, self.password = database, login, password
260272
261 self.user_id = user_id273 self.user_id = user_id
262 274
263 def check_login(self, force=True):275 def check_login(self, force=True):
264 """276 """
265 Checks that the login information is valid. Throws an AuthenticationError if the277 Checks that the login information is valid. Throws an AuthenticationError if the
@@ -270,15 +282,15 @@
270 """282 """
271 if self.user_id and not force:283 if self.user_id and not force:
272 return284 return
273 285
274 if not self.database or not self.login or self.password is None:286 if not self.database or not self.login or self.password is None:
275 raise AuthenticationError("Creditentials not provided")287 raise AuthenticationError("Creditentials not provided")
276 288
277 self.user_id = self.get_service("common").login(self.database, self.login, self.password)289 self.user_id = self.get_service("common").login(self.database, self.login, self.password)
278 if not self.user_id:290 if not self.user_id:
279 raise AuthenticationError("Authentication failure")291 raise AuthenticationError("Authentication failure")
280 self.__logger.debug("Authenticated with user id %s", self.user_id)292 self.__logger.debug("Authenticated with user id %s", self.user_id)
281 293
282 def get_model(self, model_name):294 def get_model(self, model_name):
283 """295 """
284 Returns a Model instance to allow easy remote manipulation of an OpenERP model.296 Returns a Model instance to allow easy remote manipulation of an OpenERP model.
@@ -375,6 +387,8 @@
375 port = 8069 if protocol=="xmlrpc" else 8070387 port = 8069 if protocol=="xmlrpc" else 8070
376 if protocol == "xmlrpc":388 if protocol == "xmlrpc":
377 return XmlRPCConnector(hostname, port)389 return XmlRPCConnector(hostname, port)
390 elif protocol == "xmlrpcs":
391 return XmlRPCSConnector(hostname, port)
378 elif protocol == "netrpc":392 elif protocol == "netrpc":
379 return NetRPCConnector(hostname, port)393 return NetRPCConnector(hostname, port)
380 else:394 else:
@@ -396,4 +410,4 @@
396 already know it, in most cases you don't need to specify it.410 already know it, in most cases you don't need to specify it.
397 """411 """
398 return Connection(get_connector(hostname, protocol, port), database, login, password, user_id)412 return Connection(get_connector(hostname, protocol, port), database, login, password, user_id)
399 413

Subscribers

People subscribed via source and target branches