Skip to content

Commit 5bfa043

Browse files
committed
Merge branch 'release/v0.6.0'
2 parents 4a85312 + c1d4437 commit 5bfa043

File tree

9 files changed

+52
-14
lines changed

9 files changed

+52
-14
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ python:
66
- "3.3"
77
- "3.4"
88
- "3.5"
9+
- "3.6"
910
- "pypy"
1011

1112
env:
@@ -35,4 +36,4 @@ install:
3536

3637
script:
3738
- python -m unittest discover -v
38-
- if [[ $TRAVIS_PYTHON_VERSION != 3.2 ]]; then PYTHONPATH=.:$PYTHONPATH sphinx-build -b doctest -d doc/build/doctrees doc/source build/doctest; fi
39+
- if [[ "$TRAVIS_PYTHON_VERSION" != "3.2" && "$TRAVIS_PYTHON_VERSION" != "3.3" ]]; then PYTHONPATH=.:$PYTHONPATH sphinx-build -b doctest -d doc/build/doctrees doc/source build/doctest; fi

CHANGELOG

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
0.6.0
2+
=====
3+
- IMP: Adds support for passing a custom URL opener
4+
(e.g. to handle HTTP basic authentication)
5+
- IMP: Support added for Python 3.6
6+
17
0.5.1
28
=====
39
- FIX: Session file loading, read the `timeout` value as a float

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ It should work on next versions if `Odoo` keeps a stable API.
7979
Supported Python versions
8080
-------------------------
8181

82-
`OdooRPC` support Python 2.7, 3.2, 3.3, 3.4 and 3.5.
82+
`OdooRPC` support Python 2.7, 3.2, 3.3, 3.4, 3.5 and 3.6.
8383

8484
License
8585
-------

doc/source/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ It should work on next versions if `Odoo` keeps a stable API.
8585
Supported Python versions
8686
-------------------------
8787

88-
`OdooRPC` support Python 2.7, 3.2, 3.3, 3.4 and 3.5.
88+
`OdooRPC` support Python 2.7, 3.2, 3.3, 3.4, 3.5 and 3.6.
8989

9090
License
9191
-------

odoorpc/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
__author__ = 'ABF Osiell - Sebastien Alix'
2929
__email__ = '[email protected]'
3030
__licence__ = 'LGPL v3'
31-
__version__ = '0.5.1'
31+
__version__ = '0.6.0'
3232

3333
__all__ = ['ODOO', 'error']
3434

odoorpc/odoo.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ class ODOO(object):
4848
4949
>>> odoo = odoorpc.ODOO('localhost', version='10.0')
5050
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+
5165
*Python 2:*
5266
5367
:raise: :class:`odoorpc.error.InternalError`
@@ -62,7 +76,7 @@ class ODOO(object):
6276
"""
6377

6478
def __init__(self, host='localhost', protocol='jsonrpc',
65-
port=8069, timeout=120, version=None):
79+
port=8069, timeout=120, version=None, opener=None):
6680
if protocol not in ['jsonrpc', 'jsonrpc+ssl']:
6781
txt = ("The protocol '{0}' is not supported by the ODOO class. "
6882
"Please choose a protocol among these ones: {1}")
@@ -88,7 +102,7 @@ def __init__(self, host='localhost', protocol='jsonrpc',
88102
# Instanciate the server connector
89103
try:
90104
self._connector = rpc.PROTOCOLS[protocol](
91-
self._host, self._port, timeout, version)
105+
self._host, self._port, timeout, version, opener=opener)
92106
except rpc.error.ConnectorError as exc:
93107
raise error.InternalError(exc.message)
94108
# Dictionary of configuration options

odoorpc/rpc/__init__.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,16 @@ class ConnectorJSONRPC(Connector):
183183
True
184184
"""
185185
def __init__(self, host, port=8069, timeout=120, version=None,
186-
deserialize=True):
186+
deserialize=True, opener=None):
187187
super(ConnectorJSONRPC, self).__init__(host, port, timeout, version)
188188
self.deserialize = deserialize
189189
# One URL opener (with cookies handling) shared between
190190
# JSON and HTTP requests
191-
cookie_jar = CookieJar()
192-
self._opener = build_opener(
193-
HTTPCookieProcessor(cookie_jar))
191+
if opener is None:
192+
cookie_jar = CookieJar()
193+
opener = build_opener(
194+
HTTPCookieProcessor(cookie_jar))
195+
self._opener = opener
194196
self._proxy_json, self._proxy_http = self._get_proxies()
195197

196198
def _get_proxies(self):
@@ -250,8 +252,9 @@ class ConnectorJSONRPCSSL(ConnectorJSONRPC):
250252
... cnt = rpc.ConnectorJSONRPCSSL(HOST, port=PORT)
251253
"""
252254
def __init__(self, host, port=8069, timeout=120, version=None,
253-
deserialize=True):
254-
super(ConnectorJSONRPCSSL, self).__init__(host, port, timeout, version)
255+
deserialize=True, opener=None):
256+
super(ConnectorJSONRPCSSL, self).__init__(
257+
host, port, timeout, version, opener=opener)
255258
self._proxy_json, self._proxy_http = self._get_proxies()
256259

257260
@property

odoorpc/tests/test_init.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import sys
44
# Python 2
55
if sys.version_info.major < 3:
6-
from urllib2 import URLError
6+
from urllib2 import BaseHandler, URLError, build_opener
77
# Python >= 3
88
else:
99
from urllib.error import URLError
10+
from urllib.request import BaseHandler, build_opener
1011

1112
from odoorpc.tests import BaseTestCase
1213
import odoorpc
@@ -35,6 +36,17 @@ def test_init2(self):
3536
self.assertEqual(odoo.port, self.env['port'])
3637
self.assertEqual(odoo.config['timeout'], 42)
3738

39+
def test_init_opener(self):
40+
# Opener
41+
opener = build_opener(BaseHandler)
42+
odoo = odoorpc.ODOO(
43+
self.env['host'], self.env['protocol'], self.env['port'],
44+
opener=opener)
45+
connector = odoo._connector
46+
self.assertIs(connector._opener, opener)
47+
self.assertIs(connector._proxy_http._opener, opener)
48+
self.assertIs(connector._proxy_json._opener, opener)
49+
3850
def test_init_timeout_none(self):
3951
odoo = odoorpc.ODOO(
4052
self.env['host'], self.env['protocol'], self.env['port'], None)

setup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from distutils.core import setup
55

66
name = 'OdooRPC'
7-
version = '0.5.1'
7+
version = '0.6.0'
88
description = ("OdooRPC is a Python module providing an easy way to "
99
"pilot your Odoo servers through RPC.")
1010
keywords = ("openerp odoo server rpc client xml-rpc xmlrpc jsonrpc json-rpc "
@@ -63,10 +63,12 @@
6363
"Programming Language :: Python :: 3.3",
6464
"Programming Language :: Python :: 3.4",
6565
"Programming Language :: Python :: 3.5",
66+
"Programming Language :: Python :: 3.6",
6667
"Programming Language :: Python :: Implementation :: CPython",
6768
"Programming Language :: Python :: Implementation :: PyPy",
6869
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
6970
"Topic :: Software Development :: Libraries :: Python Modules",
71+
"Framework :: Odoo",
7072
],
7173
)
7274

0 commit comments

Comments
 (0)