Skip to content

Commit

Permalink
Hide arguments of partial methods
Browse files Browse the repository at this point in the history
  • Loading branch information
florentx committed Mar 20, 2019
1 parent 748b300 commit 45cace9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions odooly.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ def dispatch_jsonrpc(url, service_name, method, args):
return resp['result']


class partial(functools.partial):
__slots__ = ()

def __repr__(self):
# Hide arguments on Python 3
return '%s(%r, ...)' % (self.__class__.__name__, self.func)


class Error(Exception):
"""An Odooly error."""

Expand Down Expand Up @@ -545,7 +553,7 @@ def _auth(self, user, password):

def _set_credentials(self, uid, password):
def env_auth(method): # Authenticated endpoints
return functools.partial(method, self.db_name, uid, password)
return partial(method, self.db_name, uid, password)
self._execute = env_auth(self.client._object.execute)
self._execute_kw = env_auth(self.client._object.execute_kw)
if self.client._report: # Odoo <= 10
Expand Down Expand Up @@ -922,15 +930,15 @@ def get_service(name):
def _proxy_dispatch(self, name):
if self._server._api_v7:
return self._server.netsvc.ExportService.getService(name).dispatch
return functools.partial(self._server.http.dispatch_rpc, name)
return partial(self._server.http.dispatch_rpc, name)

def _proxy_xmlrpc(self, name):
proxy = ServerProxy(self._server + '/' + name,
transport=self._transport, allow_none=True)
return proxy._ServerProxy__request

def _proxy_jsonrpc(self, name):
return functools.partial(dispatch_jsonrpc, self._server, name)
return partial(dispatch_jsonrpc, self._server, name)

@classmethod
def from_config(cls, environment, user=None, verbose=False):
Expand Down Expand Up @@ -1095,7 +1103,7 @@ def __new__(cls, env, name):
def _new(cls, env, name):
m = object.__new__(cls)
(m.env, m._name) = (env, name)
m._execute = functools.partial(env.execute, name)
m._execute = partial(env.execute, name)
return m

def __repr__(self):
Expand Down

0 comments on commit 45cace9

Please sign in to comment.