dump-things-pyclient 0.2.3__py3-none-any.whl → 0.2.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dump_things_pyclient/commands/dtc_plugins/auto_curate.py +106 -46
- dump_things_pyclient/commands/dtc_plugins/clean_incoming.py +4 -1
- dump_things_pyclient/commands/dtc_plugins/{delete_record.py → delete_records.py} +13 -8
- dump_things_pyclient/commands/dtc_plugins/export.py +20 -11
- dump_things_pyclient/commands/dtc_plugins/get_records.py +16 -10
- dump_things_pyclient/commands/dtc_plugins/maintenance.py +80 -0
- dump_things_pyclient/commands/dtc_plugins/post_records.py +26 -13
- dump_things_pyclient/commands/dtc_plugins/read_pages.py +9 -2
- dump_things_pyclient/communicate.py +156 -25
- {dump_things_pyclient-0.2.3.dist-info → dump_things_pyclient-0.2.6.dist-info}/METADATA +1 -1
- dump_things_pyclient-0.2.6.dist-info/RECORD +21 -0
- dump_things_pyclient-0.2.3.dist-info/RECORD +0 -20
- {dump_things_pyclient-0.2.3.dist-info → dump_things_pyclient-0.2.6.dist-info}/WHEEL +0 -0
- {dump_things_pyclient-0.2.3.dist-info → dump_things_pyclient-0.2.6.dist-info}/entry_points.txt +0 -0
- {dump_things_pyclient-0.2.3.dist-info → dump_things_pyclient-0.2.6.dist-info}/top_level.txt +0 -0
|
@@ -9,6 +9,7 @@ from typing import (
|
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
import requests
|
|
12
|
+
from requests import Session
|
|
12
13
|
from requests.exceptions import HTTPError
|
|
13
14
|
|
|
14
15
|
from . import JSON
|
|
@@ -17,6 +18,7 @@ from . import JSON
|
|
|
17
18
|
__all__ = [
|
|
18
19
|
'HTTPError',
|
|
19
20
|
'JSON',
|
|
21
|
+
'get_session',
|
|
20
22
|
'get_paginated',
|
|
21
23
|
'get',
|
|
22
24
|
'collection_get_classes',
|
|
@@ -37,18 +39,29 @@ __all__ = [
|
|
|
37
39
|
'incoming_read_records_of_class',
|
|
38
40
|
'incoming_read_record_with_pid',
|
|
39
41
|
'incoming_write_record',
|
|
42
|
+
'maintenance',
|
|
43
|
+
'server',
|
|
40
44
|
]
|
|
41
45
|
|
|
42
46
|
|
|
43
47
|
logger = logging.getLogger('dump_things_pyclient')
|
|
44
48
|
|
|
45
49
|
|
|
50
|
+
def get_session() -> Session:
|
|
51
|
+
"""Return a session that can be used to reuse connections
|
|
52
|
+
|
|
53
|
+
:return: a Session-object that can be passed to most functions in this module
|
|
54
|
+
"""
|
|
55
|
+
return requests.Session()
|
|
56
|
+
|
|
57
|
+
|
|
46
58
|
def get_paginated(url: str,
|
|
47
59
|
token: str | None = None,
|
|
48
60
|
first_page: int = 1,
|
|
49
61
|
page_size: int = 100,
|
|
50
62
|
last_page: int | None = None,
|
|
51
63
|
parameters: dict[str, str] | None = None,
|
|
64
|
+
session: Session | None = None,
|
|
52
65
|
) -> Generator[tuple[JSON, int, int, int, int], None, None]:
|
|
53
66
|
"""Read all records from a paginated endpoint
|
|
54
67
|
|
|
@@ -60,6 +73,7 @@ def get_paginated(url: str,
|
|
|
60
73
|
:param last_page: [optional] last page to return (default: None (return all pages))
|
|
61
74
|
:param parameters: [optional] parameters to pass to the endpoint, the
|
|
62
75
|
parameter `page` is set automatically in this function
|
|
76
|
+
:param session: [optional] if set it will be used for making requests
|
|
63
77
|
|
|
64
78
|
:return: a Generator yielding tuples containing the current record, the
|
|
65
79
|
current page number, the total number of pages, the size of the pages,
|
|
@@ -70,7 +84,7 @@ def get_paginated(url: str,
|
|
|
70
84
|
return
|
|
71
85
|
|
|
72
86
|
for page in count(start=first_page):
|
|
73
|
-
result = _get_page(url, token, first_page=page, page_size=page_size, parameters=parameters)
|
|
87
|
+
result = _get_page(url, token, first_page=page, page_size=page_size, parameters=parameters, session=session)
|
|
74
88
|
total_pages, page_size, total_items = result['pages'], result['size'], result['total']
|
|
75
89
|
if total_pages == 0:
|
|
76
90
|
return
|
|
@@ -88,6 +102,7 @@ def get_paginated(url: str,
|
|
|
88
102
|
def get(url: str,
|
|
89
103
|
token: str | None = None,
|
|
90
104
|
parameters: dict[str, str] | None = None,
|
|
105
|
+
session: Session | None = None,
|
|
91
106
|
) -> JSON:
|
|
92
107
|
"""Read JSON object from a non-paginated endpoint
|
|
93
108
|
|
|
@@ -95,14 +110,16 @@ def get(url: str,
|
|
|
95
110
|
:param token: [optional] if str: token to authenticate against the endpoint,
|
|
96
111
|
if None: no token will be sent to the endpoint
|
|
97
112
|
:param parameters: [optional] parameters to pass to the endpoint
|
|
113
|
+
:param session: [optional] if set it will be used for making requests
|
|
98
114
|
|
|
99
115
|
:return: JSON object
|
|
100
116
|
"""
|
|
101
|
-
return _get_from_url(url, token, parameters)
|
|
117
|
+
return _get_from_url(url, token, parameters, session)
|
|
102
118
|
|
|
103
119
|
|
|
104
120
|
def collection_get_classes(service_url: str,
|
|
105
121
|
collection: str,
|
|
122
|
+
session: Session | None = None,
|
|
106
123
|
) -> Generator[str, None, None]:
|
|
107
124
|
"""Read classes that are supported by the collection
|
|
108
125
|
|
|
@@ -112,12 +129,17 @@ def collection_get_classes(service_url: str,
|
|
|
112
129
|
:param service_url: the base URL of the service, i.e., the URL up to
|
|
113
130
|
`/<collection>/...` or `/server`
|
|
114
131
|
:param collection: the name of the collection
|
|
132
|
+
:param session: [optional] if set it will be used for making requests
|
|
115
133
|
|
|
116
134
|
:return: a generator yielding names of the supported classes
|
|
117
135
|
"""
|
|
118
136
|
service_url = f'{service_url[:-1]}' if service_url.endswith('/') else service_url
|
|
119
137
|
matcher = re.compile(f'/{collection}/record/([A-Z][_a-zA-Z0-9]*)$')
|
|
120
|
-
open_api_spec = _get_from_url(
|
|
138
|
+
open_api_spec = _get_from_url(
|
|
139
|
+
service_url + '/openapi.json',
|
|
140
|
+
token=None,
|
|
141
|
+
session=session,
|
|
142
|
+
)
|
|
121
143
|
for path in open_api_spec['paths']:
|
|
122
144
|
match = matcher.match(path)
|
|
123
145
|
if match:
|
|
@@ -129,6 +151,7 @@ def collection_read_record_with_pid(service_url: str,
|
|
|
129
151
|
pid: str,
|
|
130
152
|
format: str = 'json',
|
|
131
153
|
token: str | None = None,
|
|
154
|
+
session: Session | None = None,
|
|
132
155
|
) -> dict | None:
|
|
133
156
|
"""Read record with the given pid from the collection on the service
|
|
134
157
|
|
|
@@ -144,13 +167,16 @@ def collection_read_record_with_pid(service_url: str,
|
|
|
144
167
|
either `json` or `ttl`
|
|
145
168
|
:param token: [optional] if set, a token to authenticate against
|
|
146
169
|
the endpoint, if None: no token will be sent to the endpoint
|
|
170
|
+
:param session: [optional] if set it will be used for making requests
|
|
147
171
|
|
|
148
172
|
:return: The record, if it exists, None otherwise.
|
|
149
173
|
"""
|
|
150
174
|
return get(
|
|
151
175
|
url=_build_url(service_url, collection, 'record'),
|
|
152
176
|
token=token,
|
|
153
|
-
parameters={'pid': pid, 'format': format}
|
|
177
|
+
parameters={'pid': pid, 'format': format},
|
|
178
|
+
session=session,
|
|
179
|
+
)
|
|
154
180
|
|
|
155
181
|
|
|
156
182
|
def collection_read_records(service_url: str,
|
|
@@ -161,6 +187,7 @@ def collection_read_records(service_url: str,
|
|
|
161
187
|
page: int = 1,
|
|
162
188
|
size: int = 100,
|
|
163
189
|
last_page: int | None = None,
|
|
190
|
+
session: Session | None = None,
|
|
164
191
|
) -> Generator[tuple[dict, int, int, int, int], None, None]:
|
|
165
192
|
"""Read records from the collection on the service
|
|
166
193
|
|
|
@@ -177,6 +204,7 @@ def collection_read_records(service_url: str,
|
|
|
177
204
|
:param size: int: the number of records in an individual pages (default: 100)
|
|
178
205
|
:param last_page: int | None: if int, the last page that should be returned
|
|
179
206
|
if None, all pages following `page` will be returned
|
|
207
|
+
:param session: [optional] if set it will be used for making requests
|
|
180
208
|
|
|
181
209
|
:return: A generator yielding tuples containing: the current record, the
|
|
182
210
|
current page number, the total number of pages, the size of the
|
|
@@ -190,7 +218,9 @@ def collection_read_records(service_url: str,
|
|
|
190
218
|
last_page=last_page,
|
|
191
219
|
parameters= {
|
|
192
220
|
'format': format,
|
|
193
|
-
**({'matching': matching} if matching else {})}
|
|
221
|
+
**({'matching': matching} if matching else {})},
|
|
222
|
+
session=session,
|
|
223
|
+
)
|
|
194
224
|
|
|
195
225
|
|
|
196
226
|
def collection_read_records_of_class(
|
|
@@ -203,6 +233,7 @@ def collection_read_records_of_class(
|
|
|
203
233
|
page: int = 1,
|
|
204
234
|
size: int = 100,
|
|
205
235
|
last_page: int | None = None,
|
|
236
|
+
session: Session | None = None,
|
|
206
237
|
) -> Generator[tuple[dict, int, int, int, int], None, None]:
|
|
207
238
|
"""Read records of the specified class from the collection on the service
|
|
208
239
|
|
|
@@ -220,6 +251,7 @@ def collection_read_records_of_class(
|
|
|
220
251
|
:param size: int: the number of records in an individual pages (default: 100)
|
|
221
252
|
:param last_page: int | None: if int, the last page that should be returned
|
|
222
253
|
if None, all pages following `page` will be returned
|
|
254
|
+
:param session: [optional] if set it will be used for making requests
|
|
223
255
|
|
|
224
256
|
:return: A generator yielding tuples containing: the current record, the
|
|
225
257
|
current page number, the total number of pages, the size of the
|
|
@@ -233,7 +265,9 @@ def collection_read_records_of_class(
|
|
|
233
265
|
last_page=last_page,
|
|
234
266
|
parameters= {
|
|
235
267
|
'format': format,
|
|
236
|
-
**({'matching': matching} if matching else {})}
|
|
268
|
+
**({'matching': matching} if matching else {})},
|
|
269
|
+
session=session,
|
|
270
|
+
)
|
|
237
271
|
|
|
238
272
|
|
|
239
273
|
def collection_write_record(
|
|
@@ -243,6 +277,7 @@ def collection_write_record(
|
|
|
243
277
|
record: dict | str,
|
|
244
278
|
format: str = 'json',
|
|
245
279
|
token: str | None = None,
|
|
280
|
+
session: Session | None = None,
|
|
246
281
|
) -> list[JSON]:
|
|
247
282
|
"""Write a record of the specified class to an inbox in the collection on the service
|
|
248
283
|
|
|
@@ -256,6 +291,7 @@ def collection_write_record(
|
|
|
256
291
|
:param token: [optional] if set, a token to authenticate against
|
|
257
292
|
the endpoint, if None: no token will be sent to the endpoint
|
|
258
293
|
The token must have write access to incoming area in the collection
|
|
294
|
+
:param session: [optional] if set it will be used for making requests
|
|
259
295
|
|
|
260
296
|
:return list[JSON]: a list of records that was written. There might be more
|
|
261
297
|
than one record due to inlined-relations extraction. The individual
|
|
@@ -266,7 +302,9 @@ def collection_write_record(
|
|
|
266
302
|
url=_build_url(service_url, collection, f'record/{class_name}'),
|
|
267
303
|
token=token,
|
|
268
304
|
params={'format': format},
|
|
269
|
-
|
|
305
|
+
session=session,
|
|
306
|
+
**(dict(json=record) if format == 'json' else dict(data=record)),
|
|
307
|
+
)
|
|
270
308
|
|
|
271
309
|
|
|
272
310
|
def collection_validate_record(
|
|
@@ -276,6 +314,7 @@ def collection_validate_record(
|
|
|
276
314
|
record: dict | str,
|
|
277
315
|
format: str = 'json',
|
|
278
316
|
token: str | None = None,
|
|
317
|
+
session: Session | None = None,
|
|
279
318
|
) -> list[JSON]:
|
|
280
319
|
"""Validate a record of the specified class in the collection on the service
|
|
281
320
|
|
|
@@ -292,6 +331,7 @@ def collection_validate_record(
|
|
|
292
331
|
:param token: [optional] if set, a token to authenticate against
|
|
293
332
|
the endpoint, if None: no token will be sent to the endpoint
|
|
294
333
|
The token must have write access to incoming area in the collection
|
|
334
|
+
:param session: [optional] if set it will be used for making requests
|
|
295
335
|
|
|
296
336
|
:return: True
|
|
297
337
|
"""
|
|
@@ -300,7 +340,9 @@ def collection_validate_record(
|
|
|
300
340
|
url=_build_url(service_url, collection, f'validate/{class_name}'),
|
|
301
341
|
token=token,
|
|
302
342
|
params={'format': format},
|
|
303
|
-
|
|
343
|
+
session=session,
|
|
344
|
+
**(dict(json=record) if format == 'json' else dict(data=record)),
|
|
345
|
+
)
|
|
304
346
|
|
|
305
347
|
|
|
306
348
|
def collection_delete_record(
|
|
@@ -308,6 +350,7 @@ def collection_delete_record(
|
|
|
308
350
|
collection: str,
|
|
309
351
|
pid: str,
|
|
310
352
|
token: str | None = None,
|
|
353
|
+
session: Session | None = None,
|
|
311
354
|
) -> bool:
|
|
312
355
|
"""Delete the record with the given pid from the collection on the service
|
|
313
356
|
|
|
@@ -317,19 +360,23 @@ def collection_delete_record(
|
|
|
317
360
|
:param pid: the PID of the record that should be deleted
|
|
318
361
|
:param token: [optional] if set, a token to authenticate against
|
|
319
362
|
the endpoint, if None: no token will be sent to the endpoint
|
|
363
|
+
:param session: [optional] if set it will be used for making requests
|
|
320
364
|
|
|
321
365
|
:return: True if the record was deleted, False otherwise
|
|
322
366
|
"""
|
|
323
367
|
return _delete_url(
|
|
324
368
|
url=_build_url(service_url, collection, 'record'),
|
|
325
369
|
token=token,
|
|
326
|
-
params={'pid': pid}
|
|
370
|
+
params={'pid': pid},
|
|
371
|
+
session=session,
|
|
372
|
+
)
|
|
327
373
|
|
|
328
374
|
|
|
329
375
|
def curated_read_record_with_pid(service_url: str,
|
|
330
376
|
collection: str,
|
|
331
377
|
pid: str,
|
|
332
378
|
token: str | None = None,
|
|
379
|
+
session: Session | None = None,
|
|
333
380
|
) -> dict | None:
|
|
334
381
|
"""Read record with the given pid from curated area of the collection on the service
|
|
335
382
|
|
|
@@ -343,13 +390,16 @@ def curated_read_record_with_pid(service_url: str,
|
|
|
343
390
|
:param token: [optional] if set, a token to authenticate against
|
|
344
391
|
the endpoint, if None: no token will be sent to the endpoint. A
|
|
345
392
|
token must have curator-rights
|
|
393
|
+
:param session: [optional] if set it will be used for making requests
|
|
346
394
|
|
|
347
395
|
:return: The record, if it exists, None otherwise
|
|
348
396
|
"""
|
|
349
397
|
return get(
|
|
350
398
|
url=_build_url(service_url, collection, 'curated/record'),
|
|
351
399
|
token=token,
|
|
352
|
-
parameters={'pid': pid}
|
|
400
|
+
parameters={'pid': pid},
|
|
401
|
+
session=session,
|
|
402
|
+
)
|
|
353
403
|
|
|
354
404
|
|
|
355
405
|
def curated_read_records(service_url: str,
|
|
@@ -359,6 +409,7 @@ def curated_read_records(service_url: str,
|
|
|
359
409
|
page: int = 1,
|
|
360
410
|
size: int = 100,
|
|
361
411
|
last_page: int | None = None,
|
|
412
|
+
session: Session | None = None,
|
|
362
413
|
) -> Generator[tuple[dict, int, int, int, int], None, None]:
|
|
363
414
|
"""Read records from the curated area the collection on the service
|
|
364
415
|
|
|
@@ -377,6 +428,7 @@ def curated_read_records(service_url: str,
|
|
|
377
428
|
:param size: int: the number of records in an individual pages (default: 100)
|
|
378
429
|
:param last_page: int | None: if int, the last page that should be returned
|
|
379
430
|
if None, all pages following `page` will be returned
|
|
431
|
+
:param session: [optional] if set it will be used for making requests
|
|
380
432
|
|
|
381
433
|
:return: A generator yielding tuples containing: the current record, the
|
|
382
434
|
current page number, the total number of pages, the size of the
|
|
@@ -388,7 +440,9 @@ def curated_read_records(service_url: str,
|
|
|
388
440
|
first_page=page,
|
|
389
441
|
page_size=size,
|
|
390
442
|
last_page=last_page,
|
|
391
|
-
parameters={'matching': matching} if matching else {}
|
|
443
|
+
parameters={'matching': matching} if matching else {},
|
|
444
|
+
session=session,
|
|
445
|
+
)
|
|
392
446
|
|
|
393
447
|
|
|
394
448
|
def curated_read_records_of_class(
|
|
@@ -400,6 +454,7 @@ def curated_read_records_of_class(
|
|
|
400
454
|
page: int = 1,
|
|
401
455
|
size: int = 100,
|
|
402
456
|
last_page: int | None = None,
|
|
457
|
+
session: Session | None = None,
|
|
403
458
|
) -> Generator[tuple[dict, int, int, int, int], None, None]:
|
|
404
459
|
"""Read records of class `class_name` from the curated area the collection on the service
|
|
405
460
|
|
|
@@ -419,6 +474,7 @@ def curated_read_records_of_class(
|
|
|
419
474
|
:param size: int: the number of records in an individual pages (default: 100)
|
|
420
475
|
:param last_page: int | None: if int, the last page that should be returned
|
|
421
476
|
if None, all pages following `page` will be returned
|
|
477
|
+
:param session: [optional] if set it will be used for making requests
|
|
422
478
|
|
|
423
479
|
:return: A generator yielding tuples containing: the current record, the
|
|
424
480
|
current page number, the total number of pages, the size of the
|
|
@@ -430,7 +486,9 @@ def curated_read_records_of_class(
|
|
|
430
486
|
first_page=page,
|
|
431
487
|
page_size=size,
|
|
432
488
|
last_page=last_page,
|
|
433
|
-
parameters={'matching': matching} if matching else {}
|
|
489
|
+
parameters={'matching': matching} if matching else {},
|
|
490
|
+
session=session,
|
|
491
|
+
)
|
|
434
492
|
|
|
435
493
|
|
|
436
494
|
def curated_write_record(
|
|
@@ -439,6 +497,7 @@ def curated_write_record(
|
|
|
439
497
|
class_name: str,
|
|
440
498
|
record: dict,
|
|
441
499
|
token: str | None = None,
|
|
500
|
+
session: Session | None = None,
|
|
442
501
|
) -> list[JSON]:
|
|
443
502
|
"""Write a record of the specified class to the curated area of the collection on the service
|
|
444
503
|
|
|
@@ -454,13 +513,16 @@ def curated_write_record(
|
|
|
454
513
|
:param token: [optional] if set, a token to authenticate against
|
|
455
514
|
the endpoint, if None: no token will be sent to the endpoint
|
|
456
515
|
A given token must have curator-rights for the collection
|
|
516
|
+
:param session: [optional] if set it will be used for making requests
|
|
457
517
|
|
|
458
518
|
:return list[JSON]: a list containing the record that was written
|
|
459
519
|
"""
|
|
460
520
|
return _post_to_url(
|
|
461
521
|
url=_build_url(service_url, collection, f'curated/record/{class_name}'),
|
|
462
522
|
token=token,
|
|
463
|
-
|
|
523
|
+
session=session,
|
|
524
|
+
json=record,
|
|
525
|
+
)
|
|
464
526
|
|
|
465
527
|
|
|
466
528
|
def curated_delete_record(
|
|
@@ -468,6 +530,7 @@ def curated_delete_record(
|
|
|
468
530
|
collection: str,
|
|
469
531
|
pid: str,
|
|
470
532
|
token: str | None = None,
|
|
533
|
+
session: Session | None = None,
|
|
471
534
|
) -> bool:
|
|
472
535
|
"""Delete the record with the given pid from the curated area of the collection on the service
|
|
473
536
|
|
|
@@ -478,17 +541,22 @@ def curated_delete_record(
|
|
|
478
541
|
:param token: [optional] if set, a token to authenticate against
|
|
479
542
|
the endpoint, if None: no token will be sent to the endpoint
|
|
480
543
|
A given token must have curator-rights for the collection
|
|
544
|
+
:param session: [optional] if set it will be used for making requests
|
|
545
|
+
|
|
481
546
|
:return: True if the record was deleted, False otherwise
|
|
482
547
|
"""
|
|
483
548
|
return _delete_url(
|
|
484
549
|
url=_build_url(service_url, collection, 'curated/record'),
|
|
485
550
|
token=token,
|
|
486
|
-
params={'pid': pid}
|
|
551
|
+
params={'pid': pid},
|
|
552
|
+
session=session,
|
|
553
|
+
)
|
|
487
554
|
|
|
488
555
|
|
|
489
556
|
def incoming_read_labels(service_url: str,
|
|
490
557
|
collection: str,
|
|
491
558
|
token: str | None = None,
|
|
559
|
+
session: Session | None = None,
|
|
492
560
|
) -> Generator[str, None, None]:
|
|
493
561
|
"""Read all incoming labels for the collection on the service.
|
|
494
562
|
|
|
@@ -498,12 +566,15 @@ def incoming_read_labels(service_url: str,
|
|
|
498
566
|
:param token: [optional] if set, a token to authenticate against
|
|
499
567
|
the endpoint, if None: no token will be sent to the endpoint
|
|
500
568
|
A given token must have curator-rights for the collection
|
|
569
|
+
:param session: [optional] if set it will be used for making requests
|
|
501
570
|
|
|
502
571
|
:return: list[str]: a list of incoming area labels
|
|
503
572
|
"""
|
|
504
573
|
yield from _get_from_url(
|
|
505
574
|
url=_build_url(service_url, collection,'incoming/'),
|
|
506
|
-
token=token
|
|
575
|
+
token=token,
|
|
576
|
+
session=session,
|
|
577
|
+
)
|
|
507
578
|
|
|
508
579
|
|
|
509
580
|
def incoming_read_record_with_pid(service_url: str,
|
|
@@ -511,6 +582,7 @@ def incoming_read_record_with_pid(service_url: str,
|
|
|
511
582
|
label: str,
|
|
512
583
|
pid: str,
|
|
513
584
|
token: str | None = None,
|
|
585
|
+
session: Session | None = None,
|
|
514
586
|
) -> dict | None:
|
|
515
587
|
"""Read record with the given pid from the specified incoming area of the collection on the service
|
|
516
588
|
|
|
@@ -525,13 +597,16 @@ def incoming_read_record_with_pid(service_url: str,
|
|
|
525
597
|
:param token: [optional] if set, a token to authenticate against
|
|
526
598
|
the endpoint, if None: no token will be sent to the endpoint. A
|
|
527
599
|
token must have curator-rights
|
|
600
|
+
:param session: [optional] if set it will be used for making requests
|
|
528
601
|
|
|
529
602
|
:return: The record, if it exists, None otherwise
|
|
530
603
|
"""
|
|
531
604
|
return get(
|
|
532
605
|
url=_build_incoming_url(service_url, collection, label, 'record'),
|
|
533
606
|
token=token,
|
|
534
|
-
parameters={'pid': pid}
|
|
607
|
+
parameters={'pid': pid},
|
|
608
|
+
session=session,
|
|
609
|
+
)
|
|
535
610
|
|
|
536
611
|
|
|
537
612
|
def incoming_read_records(service_url: str,
|
|
@@ -542,6 +617,7 @@ def incoming_read_records(service_url: str,
|
|
|
542
617
|
page: int = 1,
|
|
543
618
|
size: int = 100,
|
|
544
619
|
last_page: int | None = None,
|
|
620
|
+
session: Session | None = None,
|
|
545
621
|
) -> Generator[tuple[dict, int, int, int, int], None, None]:
|
|
546
622
|
"""Read records from the specified incoming area the collection on the service
|
|
547
623
|
|
|
@@ -561,6 +637,7 @@ def incoming_read_records(service_url: str,
|
|
|
561
637
|
:param size: int: the number of records in an individual pages (default: 100)
|
|
562
638
|
:param last_page: int | None: if int, the last page that should be returned
|
|
563
639
|
if None, all pages following `page` will be returned
|
|
640
|
+
:param session: [optional] if set it will be used for making requests
|
|
564
641
|
|
|
565
642
|
:return: A generator yielding tuples containing: the current record, the
|
|
566
643
|
current page number, the total number of pages, the size of the
|
|
@@ -572,7 +649,9 @@ def incoming_read_records(service_url: str,
|
|
|
572
649
|
first_page=page,
|
|
573
650
|
page_size=size,
|
|
574
651
|
last_page=last_page,
|
|
575
|
-
parameters={'matching': matching} if matching else {}
|
|
652
|
+
parameters={'matching': matching} if matching else {},
|
|
653
|
+
session=session,
|
|
654
|
+
)
|
|
576
655
|
|
|
577
656
|
|
|
578
657
|
def incoming_read_records_of_class(
|
|
@@ -585,6 +664,7 @@ def incoming_read_records_of_class(
|
|
|
585
664
|
page: int = 1,
|
|
586
665
|
size: int = 100,
|
|
587
666
|
last_page: int | None = None,
|
|
667
|
+
session: Session | None = None,
|
|
588
668
|
) -> Generator[tuple[dict, int, int, int, int], None, None]:
|
|
589
669
|
"""Read records of the specified class from the specified incoming area the collection on the service
|
|
590
670
|
|
|
@@ -605,6 +685,7 @@ def incoming_read_records_of_class(
|
|
|
605
685
|
:param size: int: the number of records in an individual pages (default: 100)
|
|
606
686
|
:param last_page: int | None: if int, the last page that should be returned
|
|
607
687
|
if None, all pages following `page` will be returned
|
|
688
|
+
:param session: [optional] if set it will be used for making requests
|
|
608
689
|
|
|
609
690
|
:return: A generator yielding tuples containing: the current record, the
|
|
610
691
|
current page number, the total number of pages, the size of the
|
|
@@ -616,7 +697,9 @@ def incoming_read_records_of_class(
|
|
|
616
697
|
first_page=page,
|
|
617
698
|
page_size=size,
|
|
618
699
|
last_page=last_page,
|
|
619
|
-
parameters={'matching': matching} if matching else {}
|
|
700
|
+
parameters={'matching': matching} if matching else {},
|
|
701
|
+
session=session,
|
|
702
|
+
)
|
|
620
703
|
|
|
621
704
|
|
|
622
705
|
def incoming_write_record(
|
|
@@ -626,6 +709,7 @@ def incoming_write_record(
|
|
|
626
709
|
class_name: str,
|
|
627
710
|
record: dict,
|
|
628
711
|
token: str | None = None,
|
|
712
|
+
session: Session | None = None,
|
|
629
713
|
) -> list[JSON]:
|
|
630
714
|
"""Write a record of the specified class to the specified incoming area of the collection on the service
|
|
631
715
|
|
|
@@ -642,13 +726,16 @@ def incoming_write_record(
|
|
|
642
726
|
:param token: [optional] if set, a token to authenticate against
|
|
643
727
|
the endpoint, if None: no token will be sent to the endpoint
|
|
644
728
|
A given token must have curator-rights for the collection
|
|
729
|
+
:param session: [optional] if set it will be used for making requests
|
|
645
730
|
|
|
646
731
|
:return list[JSON]: a list containing the record that was written
|
|
647
732
|
"""
|
|
648
733
|
return _post_to_url(
|
|
649
734
|
url=_build_incoming_url(service_url, collection, label, f'record/{class_name}'),
|
|
650
735
|
token=token,
|
|
651
|
-
json=record
|
|
736
|
+
json=record,
|
|
737
|
+
session=session,
|
|
738
|
+
)
|
|
652
739
|
|
|
653
740
|
|
|
654
741
|
def incoming_delete_record(
|
|
@@ -657,6 +744,7 @@ def incoming_delete_record(
|
|
|
657
744
|
label: str,
|
|
658
745
|
pid: str,
|
|
659
746
|
token: str | None = None,
|
|
747
|
+
session: Session | None = None,
|
|
660
748
|
) -> bool:
|
|
661
749
|
"""Delete the record with the given pid from the specified incoming area of the collection on the service
|
|
662
750
|
|
|
@@ -668,22 +756,27 @@ def incoming_delete_record(
|
|
|
668
756
|
:param token: [optional] if set, a token to authenticate against
|
|
669
757
|
the endpoint, if None: no token will be sent to the endpoint
|
|
670
758
|
A given token must have curator-rights for the collection
|
|
759
|
+
:param session: [optional] if set, it will be used for requests
|
|
671
760
|
|
|
672
761
|
:return: True if the record was deleted, False otherwise
|
|
673
762
|
"""
|
|
674
763
|
return _delete_url(
|
|
675
764
|
url=_build_incoming_url(service_url, collection, label,'record'),
|
|
676
765
|
token=token,
|
|
677
|
-
params={'pid': pid}
|
|
766
|
+
params={'pid': pid},
|
|
767
|
+
session=session,
|
|
768
|
+
)
|
|
678
769
|
|
|
679
770
|
|
|
680
771
|
def server(
|
|
681
772
|
service_url: str,
|
|
773
|
+
session: Session | None = None,
|
|
682
774
|
) -> JSON:
|
|
683
775
|
"""Get server-information from the service
|
|
684
776
|
|
|
685
777
|
:param service_url: the base URL of the service, i.e., the URL up to
|
|
686
778
|
`/<collection>/...` or `/server`
|
|
779
|
+
:param session: an optional requests.Session object to use for making requests
|
|
687
780
|
|
|
688
781
|
:return: information returned by the `<service_url>/server` endpoint
|
|
689
782
|
"""
|
|
@@ -691,29 +784,66 @@ def server(
|
|
|
691
784
|
(f'{service_url[:-1]}' if service_url.endswith('/') else service_url)
|
|
692
785
|
+ '/server'
|
|
693
786
|
)
|
|
694
|
-
|
|
787
|
+
method = session.get if session else requests.get
|
|
788
|
+
return _do_request(method, url=url, token=None, params=None)
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
def maintenance(
|
|
792
|
+
service_url: str,
|
|
793
|
+
collection: str,
|
|
794
|
+
active: bool,
|
|
795
|
+
token: str,
|
|
796
|
+
session: Session | None = None,
|
|
797
|
+
) -> None:
|
|
798
|
+
"""Activate or deactivate maintenance mode of a collection
|
|
799
|
+
|
|
800
|
+
:param service_url: the base URL of the service, i.e., the URL up to
|
|
801
|
+
`/<collection>/...`, `/maintenance`, or `/server`
|
|
802
|
+
:param collection: the name of the collection
|
|
803
|
+
:param active: whether maintenance mode should be active (`True`) or
|
|
804
|
+
non-active (`False`).
|
|
805
|
+
:param token: a token to authenticate against the endpoint, the token
|
|
806
|
+
must have curator-rights for the collection
|
|
807
|
+
:param session: an optional requests.Session object to use for making requests
|
|
808
|
+
"""
|
|
809
|
+
url = (
|
|
810
|
+
(f'{service_url[:-1]}' if service_url.endswith('/') else service_url)
|
|
811
|
+
+ '/maintenance'
|
|
812
|
+
)
|
|
813
|
+
_post_to_url(
|
|
814
|
+
url=url,
|
|
815
|
+
token=token,
|
|
816
|
+
session=session,
|
|
817
|
+
json={'collection': collection, 'active': active},
|
|
818
|
+
)
|
|
695
819
|
|
|
696
820
|
|
|
697
821
|
def _get_from_url(url: str,
|
|
698
822
|
token: str | None,
|
|
699
823
|
params: dict[str, str] | None = None,
|
|
824
|
+
session: Session | None = None,
|
|
700
825
|
) -> JSON:
|
|
701
|
-
|
|
826
|
+
method = session.get if session else requests.get
|
|
827
|
+
return _do_request(method, url, token, params=params)
|
|
702
828
|
|
|
703
829
|
|
|
704
830
|
def _post_to_url(url: str,
|
|
705
831
|
token: str | None,
|
|
706
832
|
params: dict[str, str] | None = None,
|
|
833
|
+
session: Session | None = None,
|
|
707
834
|
**kwargs,
|
|
708
835
|
) -> JSON:
|
|
709
|
-
|
|
836
|
+
method = session.post if session else requests.post
|
|
837
|
+
return _do_request(method, url, token, params=params, **kwargs)
|
|
710
838
|
|
|
711
839
|
|
|
712
840
|
def _delete_url(url: str,
|
|
713
841
|
token: str | None,
|
|
714
842
|
params: dict[str, str] | None = None,
|
|
843
|
+
session: Session | None = None,
|
|
715
844
|
) -> JSON:
|
|
716
|
-
|
|
845
|
+
method = session.delete if session else requests.delete
|
|
846
|
+
return _do_request(method, url, token, params=params)
|
|
717
847
|
|
|
718
848
|
|
|
719
849
|
def _do_request(method: Callable,
|
|
@@ -755,11 +885,12 @@ def _get_page(url_base: str,
|
|
|
755
885
|
first_page: int = 1,
|
|
756
886
|
page_size: int = 100,
|
|
757
887
|
parameters: dict | None = None,
|
|
888
|
+
session: Session | None = None,
|
|
758
889
|
) -> JSON:
|
|
759
890
|
parameters = parameters or {}
|
|
760
891
|
parameters['page'] = first_page
|
|
761
892
|
parameters['size'] = page_size
|
|
762
|
-
return _get_from_url(url_base, token, parameters)
|
|
893
|
+
return _get_from_url(url_base, token, parameters, session)
|
|
763
894
|
|
|
764
895
|
|
|
765
896
|
def _check_format_value(format: str) -> None:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
dump_things_pyclient/__init__.py,sha256=cn-U3TRIalN6aYHp1cMBRkQm1x98XBwquLFbgFEIf_Q,113
|
|
2
|
+
dump_things_pyclient/communicate.py,sha256=c46PO2TkrbGzhSg5IfWew9ecYW_Lo3xrf7PbnJGovnA,35910
|
|
3
|
+
dump_things_pyclient/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
dump_things_pyclient/commands/dtc.py,sha256=dxW5RuogqwhzfVujZ_EEsQMk8BcVMbZyMdg5c8EvYIA,1726
|
|
5
|
+
dump_things_pyclient/commands/json2ttl.py,sha256=8BkvdjLWZ_H0L6fTmuR2M2MglKiMUiuNUcuWr_w6_dQ,2133
|
|
6
|
+
dump_things_pyclient/commands/redirect.py,sha256=kl8pGj8khjxk4lhk8AJLfgtCIm5PtjeMAl0J6K5FB7M,264
|
|
7
|
+
dump_things_pyclient/commands/dtc_plugins/__init__.py,sha256=0YLByLiofhHkhJcDCkokldcCw3Jj0rsKJinRX4tt3Hc,514
|
|
8
|
+
dump_things_pyclient/commands/dtc_plugins/auto_curate.py,sha256=dIpTJ4IqaORqMH0j-h7dr-7aoxjsJADNALpUKbVskcs,9997
|
|
9
|
+
dump_things_pyclient/commands/dtc_plugins/clean_incoming.py,sha256=ikSPNTt254ax2tXhMK_gTgDCVkxMYJ_0NTAP8XsaRjk,2188
|
|
10
|
+
dump_things_pyclient/commands/dtc_plugins/delete_records.py,sha256=SRQTHz4cWofI-RVx_p_mUex3amTaGZ9xP_S4F12Pw64,3849
|
|
11
|
+
dump_things_pyclient/commands/dtc_plugins/export.py,sha256=s-uPWGLoZbyd4oyicNlk1_2f9MJWYDtSmLq7nTiKvE0,5232
|
|
12
|
+
dump_things_pyclient/commands/dtc_plugins/get_records.py,sha256=5v3RUrNjEO4T5Ku0ZwGBy39dNxG5K-UcOwUigL8N4Vo,7615
|
|
13
|
+
dump_things_pyclient/commands/dtc_plugins/list_incoming.py,sha256=tmM0Qs4MVwMMLyERsWCxWGTM90rSNOShLpHH32wObd8,1959
|
|
14
|
+
dump_things_pyclient/commands/dtc_plugins/maintenance.py,sha256=yTw1T_cvVTmwuzrTPteu6O6qiNCMxL5ZQoVF8yb72-M,1707
|
|
15
|
+
dump_things_pyclient/commands/dtc_plugins/post_records.py,sha256=0676miD7VTMmokBAo7JdA9Dr9FZwhs0auNuRltulcBw,3469
|
|
16
|
+
dump_things_pyclient/commands/dtc_plugins/read_pages.py,sha256=Libxf36L-0wUqAqfavotZPRMy5LjWJ37n_zSae1TgTA,3546
|
|
17
|
+
dump_things_pyclient-0.2.6.dist-info/METADATA,sha256=9U_JvtQrlduHw2UZboU4uWfcbbAryqwBvnxCe3hoCg4,999
|
|
18
|
+
dump_things_pyclient-0.2.6.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
19
|
+
dump_things_pyclient-0.2.6.dist-info/entry_points.txt,sha256=U1QhQtk767G_OXdZwPdTXYbIPfcDU13Z2u1d6exX8uE,470
|
|
20
|
+
dump_things_pyclient-0.2.6.dist-info/top_level.txt,sha256=Asvruw-SyLoYhWis1CFOx89RGxpjXoTZVGoq4JSGt88,21
|
|
21
|
+
dump_things_pyclient-0.2.6.dist-info/RECORD,,
|