commonmeta-py 0.123__tar.gz → 0.125__tar.gz

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.
Files changed (90) hide show
  1. {commonmeta_py-0.123 → commonmeta_py-0.125}/PKG-INFO +1 -1
  2. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/__init__.py +1 -1
  3. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/api_utils.py +2 -2
  4. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/metadata.py +36 -49
  5. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/cff_reader.py +19 -16
  6. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/codemeta_reader.py +18 -15
  7. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/crossref_reader.py +31 -28
  8. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/datacite_reader.py +28 -25
  9. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/datacite_xml_reader.py +36 -33
  10. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/inveniordm_reader.py +28 -25
  11. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/kbase_reader.py +33 -30
  12. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/ris_reader.py +18 -15
  13. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/schema_utils.py +9 -4
  14. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/writers/crossref_xml_writer.py +9 -14
  15. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/writers/inveniordm_writer.py +150 -106
  16. {commonmeta_py-0.123 → commonmeta_py-0.125}/pyproject.toml +1 -1
  17. {commonmeta_py-0.123 → commonmeta_py-0.125}/.gitignore +0 -0
  18. {commonmeta_py-0.123 → commonmeta_py-0.125}/LICENSE +0 -0
  19. {commonmeta_py-0.123 → commonmeta_py-0.125}/README.md +0 -0
  20. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/author_utils.py +0 -0
  21. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/base_utils.py +0 -0
  22. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/cli.py +0 -0
  23. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/constants.py +0 -0
  24. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/date_utils.py +0 -0
  25. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/doi_utils.py +0 -0
  26. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/file_utils.py +0 -0
  27. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/__init__.py +0 -0
  28. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/bibtex_reader.py +0 -0
  29. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/commonmeta_reader.py +0 -0
  30. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/crossref_xml_reader.py +0 -0
  31. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/csl_reader.py +0 -0
  32. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/jsonfeed_reader.py +0 -0
  33. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/openalex_reader.py +0 -0
  34. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/readers/schema_org_reader.py +0 -0
  35. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/cff_v1.2.0.json +0 -0
  36. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/commonmeta_v0.12.json +0 -0
  37. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/commonmeta_v0.13.json +0 -0
  38. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/commonmeta_v0.14.json +0 -0
  39. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/commonmeta_v0.15.json +0 -0
  40. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/commonmeta_v0.16.json +0 -0
  41. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/AccessIndicators.xsd +0 -0
  42. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/JATS-journalpublishing1-3d2-mathml3-elements.xsd +0 -0
  43. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/JATS-journalpublishing1-3d2-mathml3.xsd +0 -0
  44. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/JATS-journalpublishing1-elements.xsd +0 -0
  45. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/JATS-journalpublishing1-mathml3-elements.xsd +0 -0
  46. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/JATS-journalpublishing1-mathml3.xsd +0 -0
  47. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/JATS-journalpublishing1.xsd +0 -0
  48. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/clinicaltrials.xsd +0 -0
  49. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/common5.4.0.xsd +0 -0
  50. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/crossref5.4.0.xsd +0 -0
  51. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/crossref_query_output3.0.xsd +0 -0
  52. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/doi_resources5.4.0.xsd +0 -0
  53. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/fundingdata5.4.0.xsd +0 -0
  54. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/fundref.xsd +0 -0
  55. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/languages5.4.0.xsd +0 -0
  56. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/mediatypes5.4.0.xsd +0 -0
  57. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/module-ali.xsd +0 -0
  58. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/relations.xsd +0 -0
  59. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/standard-modules/mathml3/mathml3-common.xsd +0 -0
  60. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/standard-modules/mathml3/mathml3-content.xsd +0 -0
  61. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/standard-modules/mathml3/mathml3-presentation.xsd +0 -0
  62. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/standard-modules/mathml3/mathml3-strict-content.xsd +0 -0
  63. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/standard-modules/mathml3/mathml3.xsd +0 -0
  64. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/standard-modules/mathml3/module-ali.xsd +0 -0
  65. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/standard-modules/module-ali.xsd +0 -0
  66. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/standard-modules/xlink.xsd +0 -0
  67. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/standard-modules/xml.xsd +0 -0
  68. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref/xml.xsd +0 -0
  69. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/crossref-v0.2.json +0 -0
  70. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/csl-data.json +0 -0
  71. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/datacite-v4.5.json +0 -0
  72. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/datacite-v4.5pr.json +0 -0
  73. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/spdx/licenses.json +0 -0
  74. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/spdx-schema.json +0 -0
  75. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/styles/apa.csl +0 -0
  76. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/styles/chicago-author-date.csl +0 -0
  77. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/styles/harvard-cite-them-right.csl +0 -0
  78. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/styles/ieee.csl +0 -0
  79. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/styles/modern-language-association.csl +0 -0
  80. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/resources/styles/vancouver.csl +0 -0
  81. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/translators.py +0 -0
  82. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/utils.py +0 -0
  83. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/writers/__init__.py +0 -0
  84. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/writers/bibtex_writer.py +0 -0
  85. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/writers/citation_writer.py +0 -0
  86. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/writers/commonmeta_writer.py +0 -0
  87. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/writers/csl_writer.py +0 -0
  88. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/writers/datacite_writer.py +0 -0
  89. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/writers/ris_writer.py +0 -0
  90. {commonmeta_py-0.123 → commonmeta_py-0.125}/commonmeta/writers/schema_org_writer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commonmeta-py
3
- Version: 0.123
3
+ Version: 0.125
4
4
  Summary: Library for conversions to/from the Commonmeta scholarly metadata format
5
5
  Project-URL: Homepage, https://python.commonmeta.org
6
6
  Project-URL: Repository, https://github.com/front-matter/commonmeta-py
@@ -10,7 +10,7 @@ commonmeta-py is a Python library to convert scholarly metadata
10
10
  """
11
11
 
12
12
  __title__ = "commonmeta-py"
13
- __version__ = "0.123"
13
+ __version__ = "0.125"
14
14
  __author__ = "Martin Fenner"
15
15
  __license__ = "MIT"
16
16
 
@@ -1,7 +1,7 @@
1
1
  """API Utils module for commonmeta-py"""
2
2
 
3
3
  from datetime import datetime as date
4
- from typing import Optional
4
+ from typing import Dict, Optional
5
5
 
6
6
  import jwt
7
7
  import requests
@@ -31,7 +31,7 @@ def generate_ghost_token(key: str) -> str:
31
31
 
32
32
  def update_ghost_post_via_api(
33
33
  _id: str, api_key: Optional[str] = None, api_url: Optional[str] = None
34
- ) -> dict[str, str]:
34
+ ) -> Dict[str, str]:
35
35
  """Update Ghost post via API"""
36
36
  # get post doi and url from Rogue Scholar API
37
37
  # post url is needed to find post via Ghost API
@@ -1,7 +1,7 @@
1
1
  """Metadata"""
2
2
 
3
3
  from os import path
4
- from typing import Optional, Union
4
+ from typing import Any, Dict, List, Optional, Union
5
5
 
6
6
  import orjson as json
7
7
  import yaml
@@ -69,7 +69,7 @@ from .writers.schema_org_writer import write_schema_org, write_schema_org_list
69
69
  class Metadata:
70
70
  """Metadata"""
71
71
 
72
- def __init__(self, string: Optional[Union[str, dict]], **kwargs):
72
+ def __init__(self, string: Optional[Union[str, Dict[str, Any]]], **kwargs):
73
73
  if string is None or not isinstance(string, (str, dict)):
74
74
  raise ValueError("No input found")
75
75
  self.via = kwargs.get("via", None)
@@ -147,7 +147,7 @@ class Metadata:
147
147
  # Default fallback
148
148
  raise ValueError("No metadata found")
149
149
 
150
- def _get_metadata_from_pid(self, pid, via) -> dict:
150
+ def _get_metadata_from_pid(self, pid, via) -> Dict[str, Any]:
151
151
  """Helper method to get metadata from a PID."""
152
152
  if via == "schema_org":
153
153
  return get_schema_org(pid)
@@ -170,7 +170,7 @@ class Metadata:
170
170
  else:
171
171
  return {"pid": pid}
172
172
 
173
- def _get_metadata_from_string(self, string, via) -> dict:
173
+ def _get_metadata_from_string(self, string, via) -> Dict[str, Any]:
174
174
  """Helper method to get metadata from a string."""
175
175
  try:
176
176
  # XML formats
@@ -214,7 +214,7 @@ class Metadata:
214
214
  except (TypeError, json.JSONDecodeError) as error:
215
215
  return {"error": str(error)}
216
216
 
217
- def read_metadata(self, data: dict, **kwargs) -> dict:
217
+ def read_metadata(self, data: Dict[str, Any], **kwargs) -> Dict[str, Any]:
218
218
  """Read and parse metadata from various formats."""
219
219
  via = (isinstance(data, dict) and data.get("via")) or self.via
220
220
 
@@ -251,8 +251,8 @@ class Metadata:
251
251
  else:
252
252
  raise ValueError("No input format found")
253
253
 
254
- def write(self, to: str = "commonmeta", **kwargs) -> str:
255
- """Convert metadata into different formats."""
254
+ def write(self, to: str = "commonmeta", **kwargs) -> Union[str, bytes]:
255
+ """convert metadata list into different formats"""
256
256
  try:
257
257
  result = self._write_format(to, **kwargs)
258
258
  if result is None or result == "":
@@ -262,20 +262,9 @@ class Metadata:
262
262
  # More specific error message including the original JSONDecodeError details
263
263
  raise ValueError(f"Invalid JSON: {str(e)}")
264
264
 
265
- def _write_format(self, to: str, **kwargs) -> str:
265
+ def _write_format(self, to: str, **kwargs) -> Union[str, bytes]:
266
266
  """Helper method to handle writing to different formats."""
267
- # Split the format handling into multiple methods to reduce cyclomatic complexity
268
- if to in ["commonmeta", "datacite", "inveniordm", "schema_org"]:
269
- return self._write_json_format(to)
270
- elif to in ["bibtex", "csl", "citation", "ris"]:
271
- return self._write_text_format(to, **kwargs)
272
- elif to in ["crossref_xml"]:
273
- return self._write_xml_format(to, **kwargs)
274
- else:
275
- raise ValueError("No output format found")
276
-
277
- def _write_json_format(self, to: str) -> str:
278
- """Handle JSON-based output formats."""
267
+ # JSON-based output formats
279
268
  if to == "commonmeta":
280
269
  result = json.dumps(write_commonmeta(self))
281
270
  elif to == "datacite":
@@ -284,8 +273,22 @@ class Metadata:
284
273
  result = json.dumps(write_inveniordm(self))
285
274
  elif to == "schema_org":
286
275
  result = json.dumps(write_schema_org(self))
276
+ # Text-based output formats
277
+ elif to == "bibtex":
278
+ return write_bibtex(self)
279
+ elif to == "csl":
280
+ return self._write_csl(**kwargs)
281
+ elif to == "citation":
282
+ self.style = kwargs.get("style", "apa")
283
+ self.locale = kwargs.get("locale", "en-US")
284
+ return write_citation(self)
285
+ elif to == "ris":
286
+ return write_ris(self)
287
+ # XML-based output formats
288
+ elif to == "crossref_xml":
289
+ return self._write_crossref_xml(**kwargs)
287
290
  else:
288
- return "{}"
291
+ raise ValueError("No output format found")
289
292
 
290
293
  if isinstance(result, str):
291
294
  # Verify it's valid JSON
@@ -304,26 +307,6 @@ class Metadata:
304
307
  return "{}"
305
308
  return "{}"
306
309
 
307
- def _write_text_format(self, to: str, **kwargs) -> str:
308
- """Handle text-based output formats."""
309
- if to == "bibtex":
310
- return write_bibtex(self)
311
- elif to == "csl":
312
- return self._write_csl(**kwargs)
313
- elif to == "citation":
314
- self.style = kwargs.get("style", "apa")
315
- self.locale = kwargs.get("locale", "en-US")
316
- return write_citation(self)
317
- elif to == "ris":
318
- return write_ris(self)
319
- return ""
320
-
321
- def _write_xml_format(self, to: str, **kwargs) -> str:
322
- """Handle XML-based output formats."""
323
- if to == "crossref_xml":
324
- return self._write_crossref_xml(**kwargs)
325
- return ""
326
-
327
310
  def _write_csl(self, **kwargs) -> str:
328
311
  """Write in CSL format with error checking."""
329
312
  csl_output = write_csl(self)
@@ -366,8 +349,8 @@ class MetadataList:
366
349
  """MetadataList"""
367
350
 
368
351
  def __init__(
369
- self, dct: Optional[Union[str, dict]] = None, **kwargs
370
- ) -> Optional[dict]:
352
+ self, dct: Optional[Union[str, Dict[str, Any]]] = None, **kwargs
353
+ ) -> None:
371
354
  if dct is None or not isinstance(dct, (str, bytes, dict)):
372
355
  raise ValueError("No input found")
373
356
  if isinstance(dct, dict):
@@ -423,12 +406,12 @@ class MetadataList:
423
406
  else:
424
407
  raise ValueError("No input format found")
425
408
 
426
- def read_metadata_list(self, data: list, **kwargs) -> list:
409
+ def read_metadata_list(self, items, **kwargs) -> List[Metadata]:
427
410
  """read_metadata_list"""
428
411
  kwargs["via"] = kwargs.get("via", None) or self.via
429
- return [Metadata(i, **kwargs) for i in data]
412
+ return [Metadata(i, **kwargs) for i in items]
430
413
 
431
- def write(self, to: str = "commonmeta", **kwargs) -> str:
414
+ def write(self, to: str = "commonmeta", **kwargs) -> Union[str, bytes]:
432
415
  """convert metadata list into different formats"""
433
416
  if to == "bibtex":
434
417
  output = write_bibtex_list(self)
@@ -479,19 +462,23 @@ class MetadataList:
479
462
  else:
480
463
  raise ValueError("No valid output format found")
481
464
 
482
- def push(self, to: str = "commonmeta", **kwargs) -> str:
465
+ def push(self, to: str = "commonmeta", **kwargs) -> Union[str, bytes]:
483
466
  """push metadata list to external APIs"""
484
467
 
485
468
  if to == "crossref_xml":
486
469
  response = push_crossref_xml_list(
487
- self, login_id=self.login_id, login_passwd=self.login_passwd, legacy_key=self.legacy_key
470
+ self,
471
+ login_id=self.login_id,
472
+ login_passwd=self.login_passwd,
473
+ legacy_key=self.legacy_key,
488
474
  )
489
475
  return response
490
476
  elif to == "datacite":
491
477
  raise ValueError("Datacite not yet supported for metadata lists")
492
478
  elif to == "inveniordm":
479
+ kwargs = {"legacy_key": self.legacy_key}
493
480
  response = push_inveniordm_list(
494
- self, host=self.host, token=self.token, legacy_key=self.legacy_key
481
+ self, host=self.host, token=self.token, **kwargs
495
482
  )
496
483
  return response
497
484
  else:
@@ -99,22 +99,25 @@ def read_cff(data: Optional[dict], **kwargs) -> Commonmeta:
99
99
  state = "findable" if meta or read_options else "not_found"
100
100
 
101
101
  return {
102
- "id": _id,
103
- "type": _type,
104
- # 'identifiers' => identifiers,
105
- "url": url,
106
- "titles": titles,
107
- "contributors": presence(contributors),
108
- "publisher": publisher,
109
- "references": presence(references),
110
- "date": date,
111
- "descriptions": presence(descriptions),
112
- "license": license_,
113
- "version": meta.get("version", None),
114
- "subjects": presence(subjects),
115
- "provider": "DataCite" if _id else "GitHub",
116
- "state": state,
117
- } | read_options
102
+ **{
103
+ "id": _id,
104
+ "type": _type,
105
+ # 'identifiers' => identifiers,
106
+ "url": url,
107
+ "titles": titles,
108
+ "contributors": presence(contributors),
109
+ "publisher": publisher,
110
+ "references": presence(references),
111
+ "date": date,
112
+ "descriptions": presence(descriptions),
113
+ "license": license_,
114
+ "version": meta.get("version", None),
115
+ "subjects": presence(subjects),
116
+ "provider": "DataCite" if _id else "GitHub",
117
+ "state": state,
118
+ },
119
+ **read_options,
120
+ }
118
121
 
119
122
 
120
123
  def cff_contributors(contributors):
@@ -97,18 +97,21 @@ def read_codemeta(data: Optional[dict], **kwargs) -> Commonmeta:
97
97
  state = "findable" if meta or read_options else "not_found"
98
98
 
99
99
  return {
100
- "id": _id,
101
- "type": _type,
102
- "url": normalize_id(meta.get("codeRepository", None)),
103
- "identifiers": None,
104
- "titles": titles,
105
- "contributors": presence(contributors),
106
- "publisher": publisher,
107
- "date": compact(date),
108
- "descriptions": descriptions,
109
- "license": license_,
110
- "version": meta.get("version", None),
111
- "subjects": presence(subjects),
112
- "provider": provider,
113
- "state": state,
114
- } | read_options
100
+ **{
101
+ "id": _id,
102
+ "type": _type,
103
+ "url": normalize_id(meta.get("codeRepository", None)),
104
+ "identifiers": None,
105
+ "titles": titles,
106
+ "contributors": presence(contributors),
107
+ "publisher": publisher,
108
+ "date": compact(date),
109
+ "descriptions": descriptions,
110
+ "license": license_,
111
+ "version": meta.get("version", None),
112
+ "subjects": presence(subjects),
113
+ "provider": provider,
114
+ "state": state,
115
+ },
116
+ **read_options,
117
+ }
@@ -1,6 +1,6 @@
1
1
  """crossref reader for commonmeta-py"""
2
2
 
3
- from typing import Optional
3
+ from typing import List, Optional
4
4
  from xml.parsers.expat import ExpatError
5
5
 
6
6
  import requests
@@ -33,7 +33,7 @@ from ..utils import (
33
33
  )
34
34
 
35
35
 
36
- def get_crossref_list(query: dict, **kwargs) -> list[dict]:
36
+ def get_crossref_list(query: dict, **kwargs) -> List[dict]:
37
37
  """get_crossref list from Crossref API."""
38
38
  url = crossref_api_query_url(query, **kwargs)
39
39
  response = requests.get(url, timeout=30, **kwargs)
@@ -51,7 +51,7 @@ def get_crossref(pid: str, **kwargs) -> dict:
51
51
  response = requests.get(url, timeout=10, **kwargs)
52
52
  if response.status_code != 200:
53
53
  return {"state": "not_found"}
54
- return response.json().get("message", {}) | {"via": "crossref"}
54
+ return {**response.json().get("message", {}), "via": "crossref"}
55
55
 
56
56
 
57
57
  def read_crossref(data: Optional[dict], **kwargs) -> Commonmeta:
@@ -138,31 +138,34 @@ def read_crossref(data: Optional[dict], **kwargs) -> Commonmeta:
138
138
  )
139
139
 
140
140
  return {
141
- # required properties
142
- "id": _id,
143
- "type": _type,
144
- # recommended and optional properties
145
- "additionalType": additional_type,
146
- "archiveLocations": presence(archive_locations),
147
- "container": presence(container),
148
- "contributors": presence(contributors),
149
- "date": presence(date),
150
- "descriptions": presence(descriptions),
151
- "files": presence(files),
152
- "fundingReferences": presence(funding_references),
153
- "geoLocations": None,
154
- "identifiers": identifiers,
155
- "language": meta.get("language", None),
156
- "license": license_,
157
- "provider": "Crossref",
158
- "publisher": presence(publisher),
159
- "references": presence(references),
160
- "relations": presence(relations),
161
- "subjects": presence(subjects),
162
- "titles": presence(titles),
163
- "url": url,
164
- "version": meta.get("version", None),
165
- } | read_options
141
+ **{
142
+ # required properties
143
+ "id": _id,
144
+ "type": _type,
145
+ # recommended and optional properties
146
+ "additionalType": additional_type,
147
+ "archiveLocations": presence(archive_locations),
148
+ "container": presence(container),
149
+ "contributors": presence(contributors),
150
+ "date": presence(date),
151
+ "descriptions": presence(descriptions),
152
+ "files": presence(files),
153
+ "fundingReferences": presence(funding_references),
154
+ "geoLocations": None,
155
+ "identifiers": identifiers,
156
+ "language": meta.get("language", None),
157
+ "license": license_,
158
+ "provider": "Crossref",
159
+ "publisher": presence(publisher),
160
+ "references": presence(references),
161
+ "relations": presence(relations),
162
+ "subjects": presence(subjects),
163
+ "titles": presence(titles),
164
+ "url": url,
165
+ "version": meta.get("version", None),
166
+ },
167
+ **read_options,
168
+ }
166
169
 
167
170
 
168
171
  def get_titles(meta):
@@ -40,7 +40,7 @@ def get_datacite(pid: str, **kwargs) -> dict:
40
40
  response = requests.get(url, timeout=10, **kwargs)
41
41
  if response.status_code != 200:
42
42
  return {"state": "not_found"}
43
- return py_.get(response.json(), "data.attributes", {}) | {"via": "datacite"}
43
+ return {**py_.get(response.json(), "data.attributes", {}), "via": "datacite"}
44
44
  except ReadTimeout:
45
45
  return {"state": "timeout"}
46
46
 
@@ -114,30 +114,33 @@ def read_datacite(data: dict, **kwargs) -> Commonmeta:
114
114
  subjects = py_.uniq([format_subject(i) for i in wrap(meta.get("subjects", None))])
115
115
 
116
116
  return {
117
- # required properties
118
- "id": _id,
119
- "type": _type,
120
- # recommended and optional properties
121
- "additionalType": additional_type,
122
- "container": presence(container),
123
- "contributors": presence(contributors),
124
- "date": compact(date),
125
- "descriptions": presence(descriptions),
126
- "files": presence(files),
127
- "fundingReferences": presence(meta.get("fundingReferences", None)),
128
- "geoLocations": presence(geo_locations),
129
- "identifiers": presence(identifiers),
130
- "language": meta.get("language", None),
131
- "license": presence(license_),
132
- "provider": "DataCite",
133
- "publisher": publisher,
134
- "references": presence(references),
135
- "relations": presence(relations),
136
- "subjects": presence(subjects),
137
- "titles": presence(titles),
138
- "url": normalize_url(meta.get("url", None)),
139
- "version": meta.get("version", None),
140
- } | read_options
117
+ **{
118
+ # required properties
119
+ "id": _id,
120
+ "type": _type,
121
+ # recommended and optional properties
122
+ "additionalType": additional_type,
123
+ "container": presence(container),
124
+ "contributors": presence(contributors),
125
+ "date": compact(date),
126
+ "descriptions": presence(descriptions),
127
+ "files": presence(files),
128
+ "fundingReferences": presence(meta.get("fundingReferences", None)),
129
+ "geoLocations": presence(geo_locations),
130
+ "identifiers": presence(identifiers),
131
+ "language": meta.get("language", None),
132
+ "license": presence(license_),
133
+ "provider": "DataCite",
134
+ "publisher": publisher,
135
+ "references": presence(references),
136
+ "relations": presence(relations),
137
+ "subjects": presence(subjects),
138
+ "titles": presence(titles),
139
+ "url": normalize_url(meta.get("url", None)),
140
+ "version": meta.get("version", None),
141
+ },
142
+ **read_options,
143
+ }
141
144
 
142
145
 
143
146
  def get_identifiers(identifiers: list) -> list:
@@ -22,7 +22,7 @@ def get_datacite_xml(pid: str, **kwargs) -> dict:
22
22
  response = requests.get(url, timeout=10, **kwargs)
23
23
  if response.status_code != 200:
24
24
  return {"state": "not_found"}
25
- return py_.get(response.json(), "data.attributes", {}) | {"via": "datacite_xml"}
25
+ return {**py_.get(response.json(), "data.attributes", {}), "via": "datacite_xml"}
26
26
 
27
27
 
28
28
  def read_datacite_xml(data: dict, **kwargs) -> Commonmeta:
@@ -203,38 +203,41 @@ def read_datacite_xml(data: dict, **kwargs) -> Commonmeta:
203
203
  state = "findable" if _id or read_options else "not_found"
204
204
 
205
205
  return {
206
- # required properties
207
- "id": _id,
208
- "type": _type,
209
- "doi": doi_from_url(_id),
210
- "url": normalize_url(meta.get("url", None)),
211
- "contributors": presence(contributors),
212
- "titles": compact(titles),
213
- "publisher": publisher,
214
- "date": date,
215
- # recommended and optional properties
216
- "additionalType": presence(additional_type),
217
- "subjects": presence(subjects),
218
- "language": meta.get("language", None),
219
- "identifiers": identifiers,
220
- "version": meta.get("version", None),
221
- "license": presence(license_),
222
- "descriptions": presence(descriptions),
223
- "geoLocations": presence(geo_locations),
224
- "fundingReferences": presence(funding_references),
225
- "references": presence(references),
226
- "relations": presence(relations),
227
- # other properties
228
- "date_created": strip_milliseconds(meta.get("created", None)),
229
- "date_registered": strip_milliseconds(meta.get("registered", None)),
230
- "date_published": strip_milliseconds(meta.get("published", None)),
231
- "date_updated": strip_milliseconds(meta.get("updated", None)),
232
- "files": presence(files),
233
- "container": presence(meta.get("container", None)),
234
- "provider": "DataCite",
235
- "state": state,
236
- "schema_version": meta.get("xmlns", None),
237
- } | read_options
206
+ **{
207
+ # required properties
208
+ "id": _id,
209
+ "type": _type,
210
+ "doi": doi_from_url(_id),
211
+ "url": normalize_url(meta.get("url", None)),
212
+ "contributors": presence(contributors),
213
+ "titles": compact(titles),
214
+ "publisher": publisher,
215
+ "date": date,
216
+ # recommended and optional properties
217
+ "additionalType": presence(additional_type),
218
+ "subjects": presence(subjects),
219
+ "language": meta.get("language", None),
220
+ "identifiers": identifiers,
221
+ "version": meta.get("version", None),
222
+ "license": presence(license_),
223
+ "descriptions": presence(descriptions),
224
+ "geoLocations": presence(geo_locations),
225
+ "fundingReferences": presence(funding_references),
226
+ "references": presence(references),
227
+ "relations": presence(relations),
228
+ # other properties
229
+ "date_created": strip_milliseconds(meta.get("created", None)),
230
+ "date_registered": strip_milliseconds(meta.get("registered", None)),
231
+ "date_published": strip_milliseconds(meta.get("published", None)),
232
+ "date_updated": strip_milliseconds(meta.get("updated", None)),
233
+ "files": presence(files),
234
+ "container": presence(meta.get("container", None)),
235
+ "provider": "DataCite",
236
+ "state": state,
237
+ "schema_version": meta.get("xmlns", None),
238
+ },
239
+ **read_options,
240
+ }
238
241
 
239
242
 
240
243
  def get_xml_identifiers(identifiers: list) -> list:
@@ -122,31 +122,34 @@ def read_inveniordm(data: dict, **kwargs) -> Commonmeta:
122
122
  files = [get_file(i) for i in wrap(meta.get("files"))]
123
123
 
124
124
  return {
125
- # required properties
126
- "id": _id,
127
- "type": _type,
128
- "doi": doi_from_url(_id),
129
- "url": url,
130
- "contributors": presence(contributors),
131
- "titles": titles,
132
- "publisher": publisher,
133
- "date": compact(date),
134
- # recommended and optional properties
135
- # "additional_type": additional_type,
136
- "subjects": presence(subjects),
137
- "language": get_language(language),
138
- "version": py_.get(meta, "metadata.version"),
139
- "license": presence(license_),
140
- "descriptions": descriptions,
141
- "geoLocations": None,
142
- "fundingReferences": presence(funding_references),
143
- "references": presence(references),
144
- "relations": presence(relations),
145
- # other properties
146
- "files": files,
147
- "container": container,
148
- "provider": "DataCite",
149
- } | read_options
125
+ **{
126
+ # required properties
127
+ "id": _id,
128
+ "type": _type,
129
+ "doi": doi_from_url(_id),
130
+ "url": url,
131
+ "contributors": presence(contributors),
132
+ "titles": titles,
133
+ "publisher": publisher,
134
+ "date": compact(date),
135
+ # recommended and optional properties
136
+ # "additional_type": additional_type,
137
+ "subjects": presence(subjects),
138
+ "language": get_language(language),
139
+ "version": py_.get(meta, "metadata.version"),
140
+ "license": presence(license_),
141
+ "descriptions": descriptions,
142
+ "geoLocations": None,
143
+ "fundingReferences": presence(funding_references),
144
+ "references": presence(references),
145
+ "relations": presence(relations),
146
+ # other properties
147
+ "files": files,
148
+ "container": container,
149
+ "provider": "DataCite",
150
+ },
151
+ **read_options,
152
+ }
150
153
 
151
154
 
152
155
  def get_references(references: list) -> list: