Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit c5e5589

Browse files
committed
Updates to default session implementation
Add a "path" kwarg so that different files can be used
1 parent f09d62f commit c5e5589

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/onedrivesdk/session.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,16 @@ def save_session(self, **save_session_kwargs):
7272
Remember, the access_token should be treated the same as a password.
7373
7474
Args:
75-
save_session_kwargs (dicr): Arguments to be passed
76-
to Session.save_session(). Not used in this implementation,
77-
but can be used by subclasses.
75+
save_session_kwargs (dicr): To be used by implementation
76+
of save_session, however save_session wants to use them. The
77+
default implementation (this one) takes a relative or absolute
78+
file path for pickle save location, under the name "path"
7879
"""
79-
with open("session.pickle", "wb") as session_file:
80+
path = "session.pickle"
81+
if "path" in save_session_kwargs:
82+
path = save_session_kwargs["path"]
83+
84+
with open(path, "wb") as session_file:
8085
import pickle
8186
# pickle.HIGHEST_PROTOCOL is binary format. Good perf.
8287
pickle.dump(self, session_file, pickle.HIGHEST_PROTOCOL)
@@ -90,13 +95,18 @@ def load_session(**load_session_kwargs):
9095
Remember, the access_token should be treated the same as a password.
9196
9297
Args:
93-
load_session_kwargs (dict): Arguments to be passed to
94-
Session.load_session(). Not used in this implementation,
95-
but can be used in subclasses.
98+
load_session_kwargs (dict): To be used by implementation
99+
of load_session, however load_session wants to use them. The
100+
default implementation (this one) takes a relative or absolute
101+
file path for pickle save location, under the name "path"
96102
97103
Returns:
98104
:class:`Session`: The loaded session
99105
"""
100-
with open("session.pickle", "rb") as session_file:
106+
path = "session.pickle"
107+
if "path" in load_session_kwargs:
108+
path = load_session_kwargs["path"]
109+
110+
with open(path, "rb") as session_file:
101111
import pickle
102112
return pickle.load(session_file)

0 commit comments

Comments
 (0)