@@ -48,6 +48,20 @@ class ODOO(object):
48
48
49
49
>>> odoo = odoorpc.ODOO('localhost', version='10.0')
50
50
51
+ You can also define a custom URL opener to handle HTTP requests. A use
52
+ case is to manage a basic HTTP authentication in front of `Odoo`:
53
+
54
+ .. doctest::
55
+ :options: +SKIP
56
+
57
+ >>> import urllib.request
58
+ >>> import odoorpc
59
+ >>> pwd_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
60
+ >>> pwd_mgr.add_password(None, "http://example.net", "userName", "passWord")
61
+ >>> auth_handler = urllib.request.HTTPBasicAuthHandler(pwd_mgr)
62
+ >>> opener = urllib.request.build_opener(auth_handler)
63
+ >>> odoo = odoorpc.ODOO('example.net', port=80, opener=opener)
64
+
51
65
*Python 2:*
52
66
53
67
:raise: :class:`odoorpc.error.InternalError`
@@ -62,7 +76,7 @@ class ODOO(object):
62
76
"""
63
77
64
78
def __init__ (self , host = 'localhost' , protocol = 'jsonrpc' ,
65
- port = 8069 , timeout = 120 , version = None ):
79
+ port = 8069 , timeout = 120 , version = None , opener = None ):
66
80
if protocol not in ['jsonrpc' , 'jsonrpc+ssl' ]:
67
81
txt = ("The protocol '{0}' is not supported by the ODOO class. "
68
82
"Please choose a protocol among these ones: {1}" )
@@ -88,7 +102,7 @@ def __init__(self, host='localhost', protocol='jsonrpc',
88
102
# Instanciate the server connector
89
103
try :
90
104
self ._connector = rpc .PROTOCOLS [protocol ](
91
- self ._host , self ._port , timeout , version )
105
+ self ._host , self ._port , timeout , version , opener = opener )
92
106
except rpc .error .ConnectorError as exc :
93
107
raise error .InternalError (exc .message )
94
108
# Dictionary of configuration options
0 commit comments