Skip to content

Commit 01e2e86

Browse files
committed
optional timeout for get dataset methods
1 parent f84b980 commit 01e2e86

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

dataverse/dataverse.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ def get_contents(self, refresh=False):
6565
self._contents_json = resp.json()['data']
6666
return self._contents_json
6767

68-
def get_collection_info(self, refresh=False):
68+
def get_collection_info(self, refresh=False, timeout=None):
6969
if not refresh and self._collection_info:
7070
return self._collection_info
7171

7272
self._collection_info = requests.get(
7373
self.collection.get('href'),
7474
auth=self.connection.auth,
75+
timeout=timeout,
7576
).content
7677
return self._collection_info
7778

@@ -133,16 +134,16 @@ def delete_dataset(self, dataset):
133134
dataset.is_deleted = True
134135
self.get_collection_info(refresh=True)
135136

136-
def get_datasets(self, refresh=False):
137-
collection_info = self.get_collection_info(refresh)
137+
def get_datasets(self, refresh=False, timeout=None):
138+
collection_info = self.get_collection_info(refresh, timeout=timeout)
138139
entries = get_elements(collection_info, tag='entry')
139140
return [Dataset.from_dataverse(entry, self) for entry in entries]
140141

141-
def get_dataset_by_doi(self, doi, refresh=False):
142-
return next((s for s in self.get_datasets(refresh) if s.doi == doi), None)
142+
def get_dataset_by_doi(self, doi, refresh=False, timeout=None):
143+
return next((s for s in self.get_datasets(refresh, timeout=timeout) if s.doi == doi), None)
143144

144-
def get_dataset_by_title(self, title, refresh=False):
145-
return next((s for s in self.get_datasets(refresh) if s.title == title), None)
145+
def get_dataset_by_title(self, title, refresh=False, timeout=None):
146+
return next((s for s in self.get_datasets(refresh, timeout=timeout) if s.title == title), None)
146147

147-
def get_dataset_by_string_in_entry(self, string, refresh=False):
148-
return next((s for s in self.get_datasets(refresh) if string in s.get_entry()), None)
148+
def get_dataset_by_string_in_entry(self, string, refresh=False, timeout=None):
149+
return next((s for s in self.get_datasets(refresh, timeout=timeout) if string in s.get_entry()), None)

0 commit comments

Comments
 (0)