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