Skip to content

Commit 67aaf25

Browse files
committed
add session object to Render class
1 parent c89959e commit 67aaf25

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

renderapi/render.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ class Render(object):
3030
render project to which make_kwargs will default
3131
DEFAULT_CLIENT_SCRIPTS : str
3232
render client scripts path to which make_kwargs will default
33+
session : requests.sessions.Session
34+
session object to which make_kwargs will default
3335
3436
"""
3537

3638
def __init__(self, host=None, port=None, owner=None, project=None,
37-
client_scripts=None, **kwargs):
39+
client_scripts=None, session=None, **kwargs):
3840
self.DEFAULT_HOST = host
3941
self.DEFAULT_PORT = port
4042
self.DEFAULT_PROJECT = project
4143
self.DEFAULT_OWNER = owner
4244
self.DEFAULT_CLIENT_SCRIPTS = client_scripts
45+
self.session = session
4346

4447
logger.debug('Render object created with '
4548
'host={h}, port={p}, project={pr}, '
@@ -52,7 +55,8 @@ def __init__(self, host=None, port=None, owner=None, project=None,
5255
def DEFAULT_KWARGS(self):
5356
""""kwargs to which the render object falls back. Depends on:
5457
self.DEFAULT_HOST, self.DEFAULT_OWNER, self.DEFAULT_PORT,
55-
self.DEFAULT_PROJECT, self.DEFAULT_CLIENT_SCRIPTS
58+
self.DEFAULT_PROJECT, self.DEFAULT_CLIENT_SCRIPTS,
59+
self.session
5660
5761
Returns
5862
-------
@@ -62,7 +66,7 @@ def DEFAULT_KWARGS(self):
6266
return self.make_kwargs()
6367

6468
def make_kwargs(self, host=None, port=None, owner=None, project=None,
65-
client_scripts=None, **kwargs):
69+
client_scripts=None, session=None, **kwargs):
6670
"""make kwargs using this render object's defaults and any
6771
designated kwargs passed in
6872
@@ -78,22 +82,27 @@ def make_kwargs(self, host=None, port=None, owner=None, project=None,
7882
render webservice project
7983
client_scripts : str or None
8084
render java client script location
85+
session : requests.sessions.Session
86+
http session to use
8187
**kwargs
8288
all other keyword arguments passed through
8389
8490
Returns
8591
-------
8692
dict
8793
keyword arguments with missing
88-
host,port,owner,project,client_scripts filled in with defaults
94+
host,port,owner,project,client_scripts,session filled in with
95+
defaults
8996
"""
9097
processed_kwargs = {
9198
'host': self.DEFAULT_HOST if host is None else host,
9299
'port': self.DEFAULT_PORT if port is None else port,
93100
'owner': self.DEFAULT_OWNER if owner is None else owner,
94101
'project': self.DEFAULT_PROJECT if project is None else project,
95102
'client_scripts': (self.DEFAULT_CLIENT_SCRIPTS if client_scripts
96-
is None else client_scripts)}
103+
is None else client_scripts),
104+
'session': self.session if session is None else session,
105+
}
97106
processed_kwargs.update(kwargs)
98107
return processed_kwargs
99108

@@ -144,6 +153,8 @@ class RenderClient(Render):
144153
render project to which make_kwargs will default
145154
DEFAULT_CLIENT_SCRIPTS : str
146155
render client scripts path to which make_kwargs will default
156+
session : requests.sessions.Session
157+
session object to which make_kwargs will default
147158
client_script : str
148159
location of wrapper script for java client with input same as Render
149160
java client's run_ws_client.sh
@@ -220,7 +231,7 @@ def make_kwargs(self, *args, **kwargs):
220231
-------
221232
dict
222233
keyword arguments with missing
223-
host,port,owner,project,client_scripts,client_script,memGB
234+
host,port,owner,project,client_scripts,session,client_script,memGB
224235
filled in with defaults
225236
"""
226237
# hack to get dictionary defaults to work
@@ -235,7 +246,8 @@ def make_kwargs(self, *args, **kwargs):
235246

236247
def connect(host=None, port=None, owner=None, project=None,
237248
client_scripts=None, client_script=None, memGB=None,
238-
force_http=True, validate_client=True, web_only=False, **kwargs):
249+
force_http=True, validate_client=True, web_only=False,
250+
session=None, **kwargs):
239251
"""helper function to create a :class:`Render` instance, or
240252
:class:`RenderClient` if sufficent parameters are provided.
241253
Will default to using environment variables if not specified in call,
@@ -277,6 +289,8 @@ def connect(host=None, port=None, owner=None, project=None,
277289
web_only : bool
278290
whether to check environment variables/prompt user
279291
for client_scripts directory if not in arguments
292+
session : requests.sessions.Session
293+
http session to use
280294
281295
Returns
282296
-------
@@ -361,20 +375,21 @@ def connect(host=None, port=None, owner=None, project=None,
361375
host=host, port=port,
362376
owner=owner, project=project,
363377
client_scripts=client_scripts,
364-
validate_client=validate_client)
378+
validate_client=validate_client,
379+
session=session)
365380
except ClientScriptError as e:
366381
logger.info(e)
367382
logger.warning(
368383
'Could not initiate render Client -- falling back to web')
369384
return Render(host=host, port=port, owner=owner, project=project,
370-
client_scripts=client_scripts)
385+
client_scripts=client_scripts, session=session)
371386

372387

373388
@decorator
374389
def renderaccess(f, *args, **kwargs):
375-
"""Decorator allowing functions asking for host, port, owner, project
376-
to default to a connection defined by a :class:`Render` object
377-
using its :func:`RenderClient.make_kwargs` method.
390+
"""Decorator allowing functions asking for host, port, owner, project,
391+
and/or session to default to a connection defined by a :class:`Render`
392+
object using its :func:`RenderClient.make_kwargs` method.
378393
379394
You can if you wish specify any of the arguments, in which case they
380395
will not be filled in by the default values, but you don't have to.
@@ -478,7 +493,7 @@ def get_owners(host=None, port=None, session=None,
478493
render host (defaults to host from render)
479494
port : int
480495
render port (default to port from render)
481-
session : requests.Session
496+
session : requests.sessions.Session
482497
requests session
483498
render : RenderClient
484499
RenderClient connection object

0 commit comments

Comments
 (0)