ds-caselaw-marklogic-api-client 24.0.0__tar.gz → 25.0.0__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.
Potentially problematic release.
This version of ds-caselaw-marklogic-api-client might be problematic. Click here for more details.
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/PKG-INFO +4 -2
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/README.md +2 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/pyproject.toml +9 -5
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/Client.py +28 -13
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/models/documents.py +3 -6
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/models/utilities/aws.py +2 -3
- ds_caselaw_marklogic_api_client-24.0.0/src/caselawclient/xml_tools.py +0 -129
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/LICENSE.md +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/__init__.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/client_helpers/__init__.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/client_helpers/search_helpers.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/content_hash.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/errors.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/models/__init__.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/models/judgments.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/models/neutral_citation_mixin.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/models/press_summaries.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/models/utilities/__init__.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/models/utilities/dates.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/models/utilities/move.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/py.typed +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/responses/__init__.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/responses/search_response.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/responses/search_result.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/responses/xsl/search_match.xsl +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/search_parameters.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xml_helpers.py +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/break_judgment_checkout.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/checkin_judgment.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/checkout_judgment.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/copy_document.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/delete_judgment.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/document_collections.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/document_exists.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_combined_stats_table.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_components_for_document.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_highest_enrichment_version.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_highest_parser_version.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_judgment.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_judgment_checkout_status.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_judgment_version.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_last_modified.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_pending_enrichment_for_version.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_pending_parse_for_version.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_properties_for_search_results.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_property.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_version_annotation.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/get_version_created.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/insert_document.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/list_judgment_versions.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/set_boolean_property.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/set_metadata_citation.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/set_metadata_court.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/set_metadata_jurisdiction.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/set_metadata_name.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/set_metadata_this_uri.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/set_metadata_work_expression_date.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/set_property.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/update_document.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/update_locked_judgment.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/user_has_privilege.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/user_has_role.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/validate_all_documents.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/validate_document.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/xslt.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery/xslt_transform.xqy +0 -0
- {ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/src/caselawclient/xquery_type_dicts.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ds-caselaw-marklogic-api-client
|
|
3
|
-
Version:
|
|
3
|
+
Version: 25.0.0
|
|
4
4
|
Summary: An API client for interacting with the underlying data in Find Caselaw.
|
|
5
5
|
Home-page: https://github.com/nationalarchives/ds-caselaw-custom-api-client
|
|
6
6
|
Keywords: national archives,caselaw
|
|
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.10
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
13
|
Requires-Dist: boto3 (>=1.26.112,<2.0.0)
|
|
14
|
-
Requires-Dist: certifi (>=2024.
|
|
14
|
+
Requires-Dist: certifi (>=2024.8.30,<2024.9.0)
|
|
15
15
|
Requires-Dist: charset-normalizer (>=3.0.0,<4.0.0)
|
|
16
16
|
Requires-Dist: django-environ (>=0.11.0,<0.12.0)
|
|
17
17
|
Requires-Dist: ds-caselaw-utils (>=1.4.1,<2.0.0)
|
|
@@ -93,3 +93,5 @@ To create a release:
|
|
|
93
93
|
8. Create a release in [Github releases](https://github.com/nationalarchives/ds-caselaw-custom-api-client/releases)
|
|
94
94
|
using the created tag
|
|
95
95
|
|
|
96
|
+
If the release fails to push to PyPI, you can delete the tag with `git pull`, `git push --delete origin v1.2.3` and try again.
|
|
97
|
+
|
|
@@ -63,3 +63,5 @@ To create a release:
|
|
|
63
63
|
7. Tag the merge commit on `main` with `v{major}.{minor}.{patch}` and push the tag
|
|
64
64
|
8. Create a release in [Github releases](https://github.com/nationalarchives/ds-caselaw-custom-api-client/releases)
|
|
65
65
|
using the created tag
|
|
66
|
+
|
|
67
|
+
If the release fails to push to PyPI, you can delete the tag with `git pull`, `git push --delete origin v1.2.3` and try again.
|
{ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/pyproject.toml
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "ds-caselaw-marklogic-api-client"
|
|
3
|
-
version = "
|
|
3
|
+
version = "25.0.0"
|
|
4
4
|
description = "An API client for interacting with the underlying data in Find Caselaw."
|
|
5
5
|
authors = ["The National Archives"]
|
|
6
6
|
homepage = "https://github.com/nationalarchives/ds-caselaw-custom-api-client"
|
|
@@ -12,7 +12,7 @@ packages = [
|
|
|
12
12
|
|
|
13
13
|
[tool.poetry.dependencies]
|
|
14
14
|
python = "^3.9"
|
|
15
|
-
certifi = ">=2024.
|
|
15
|
+
certifi = ">=2024.8.30,<2024.9.0"
|
|
16
16
|
charset-normalizer = "^3.0.0"
|
|
17
17
|
django-environ = "^0.11.0"
|
|
18
18
|
idna = "^3.4"
|
|
@@ -57,11 +57,15 @@ line-length = 120
|
|
|
57
57
|
|
|
58
58
|
[tool.ruff.lint]
|
|
59
59
|
ignore = ["E501", "G004", "PLR2004", "RUF005", "RUF012", "UP040"] # long lines, fstrings in logs, magic values, consider not concat, mutable classbits, type instead of TypeAlias
|
|
60
|
-
extend-select = ["W", "
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
extend-select = ["W", "I"]
|
|
61
|
+
# extend-select = [ "B", "Q", "C90", "I", "UP", "YTT", "ASYNC", "S", "BLE", "A", "COM", "C4", "DTZ", "T10", "DJ", "EM", "EXE", "FA",
|
|
62
|
+
# "ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET", "SLF", "SLOT", "SIM", "TID", "TCH", "INT", "PTH",
|
|
63
|
+
# "FIX", "PGH", "PL", "TRY", "FLY", "PERF", "RUF"]
|
|
63
64
|
unfixable = ["ERA"]
|
|
64
65
|
|
|
66
|
+
[tool.ruff.lint.extend-per-file-ignores]
|
|
67
|
+
"tests/*" = ["S101"] # `assert` is fine in tests
|
|
68
|
+
|
|
65
69
|
# things skipped:
|
|
66
70
|
# N: naming, possibly good
|
|
67
71
|
# D: docstrings missing throughout
|
|
@@ -8,7 +8,7 @@ from datetime import datetime, time, timedelta
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from typing import Any, Optional, Type, Union
|
|
10
10
|
from xml.etree import ElementTree
|
|
11
|
-
from xml.etree.ElementTree import Element
|
|
11
|
+
from xml.etree.ElementTree import Element, ParseError, fromstring
|
|
12
12
|
|
|
13
13
|
import environ
|
|
14
14
|
import requests
|
|
@@ -34,7 +34,6 @@ from caselawclient.xquery_type_dicts import (
|
|
|
34
34
|
MarkLogicPrivilegeURIString,
|
|
35
35
|
)
|
|
36
36
|
|
|
37
|
-
from . import xml_tools
|
|
38
37
|
from .content_hash import validate_content_hash
|
|
39
38
|
from .errors import (
|
|
40
39
|
DocumentNotFoundError,
|
|
@@ -129,7 +128,7 @@ def get_single_string_from_marklogic_response(
|
|
|
129
128
|
# relies on "" being falsy.
|
|
130
129
|
return ""
|
|
131
130
|
|
|
132
|
-
|
|
131
|
+
if part_count > 1:
|
|
133
132
|
raise MultipartResponseLongerThanExpected(
|
|
134
133
|
f"Response returned {part_count} multipart items, expected 1",
|
|
135
134
|
)
|
|
@@ -148,7 +147,7 @@ def get_single_bytestring_from_marklogic_response(
|
|
|
148
147
|
# relies on "" being falsy.
|
|
149
148
|
return b""
|
|
150
149
|
|
|
151
|
-
|
|
150
|
+
if part_count > 1:
|
|
152
151
|
raise MultipartResponseLongerThanExpected(
|
|
153
152
|
f"Response returned {part_count} multipart items, expected 1",
|
|
154
153
|
)
|
|
@@ -231,12 +230,11 @@ class MarklogicApiClient:
|
|
|
231
230
|
|
|
232
231
|
if DOCUMENT_COLLECTION_URI_JUDGMENT in collections:
|
|
233
232
|
return Judgment
|
|
234
|
-
|
|
233
|
+
if DOCUMENT_COLLECTION_URI_PRESS_SUMMARY in collections:
|
|
235
234
|
return PressSummary
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
)
|
|
235
|
+
raise DocumentHasNoTypeCollection(
|
|
236
|
+
f"The document at URI {uri} is not part of a valid document type collection.",
|
|
237
|
+
)
|
|
240
238
|
|
|
241
239
|
def _get_error_code_class(self, error_code: str) -> Type[MarklogicAPIError]:
|
|
242
240
|
"""
|
|
@@ -251,6 +249,23 @@ class MarklogicApiClient:
|
|
|
251
249
|
def _path_to_request_url(self, path: str) -> str:
|
|
252
250
|
return f"{self.base_url}/{path.lstrip('/')}"
|
|
253
251
|
|
|
252
|
+
@classmethod
|
|
253
|
+
def _get_error_code(cls, content_as_xml: Optional[str]) -> str:
|
|
254
|
+
logging.warning(
|
|
255
|
+
"XMLTools is deprecated and will be removed in later versions. "
|
|
256
|
+
"Use methods from MarklogicApiClient.Client instead.",
|
|
257
|
+
)
|
|
258
|
+
if not content_as_xml:
|
|
259
|
+
return "Unknown error, Marklogic returned a null or empty response"
|
|
260
|
+
try:
|
|
261
|
+
xml = fromstring(content_as_xml)
|
|
262
|
+
return xml.find(
|
|
263
|
+
"message-code",
|
|
264
|
+
namespaces={"": "http://marklogic.com/xdmp/error"},
|
|
265
|
+
).text # type: ignore
|
|
266
|
+
except (ParseError, TypeError, AttributeError):
|
|
267
|
+
return "Unknown error, Marklogic returned a null or empty response"
|
|
268
|
+
|
|
254
269
|
def _raise_for_status(self, response: requests.Response) -> None:
|
|
255
270
|
try:
|
|
256
271
|
response.raise_for_status()
|
|
@@ -269,7 +284,8 @@ class MarklogicApiClient:
|
|
|
269
284
|
|
|
270
285
|
if new_error_class == self.default_http_error_class:
|
|
271
286
|
# Attempt to decode the error code from the response
|
|
272
|
-
|
|
287
|
+
|
|
288
|
+
error_code = self._get_error_code(response.content.decode("utf-8"))
|
|
273
289
|
|
|
274
290
|
new_error_class = self._get_error_code_class(error_code)
|
|
275
291
|
|
|
@@ -498,9 +514,8 @@ class MarklogicApiClient:
|
|
|
498
514
|
court, jurisdiction = re.split("\\s*/\\s*", content)
|
|
499
515
|
self.set_document_court(document_uri, court)
|
|
500
516
|
return self.set_document_jurisdiction(document_uri, jurisdiction)
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
return self.set_document_jurisdiction(document_uri, "")
|
|
517
|
+
self.set_document_court(document_uri, content)
|
|
518
|
+
return self.set_document_jurisdiction(document_uri, "")
|
|
504
519
|
|
|
505
520
|
def set_judgment_this_uri(
|
|
506
521
|
self,
|
|
@@ -217,8 +217,7 @@ class Document:
|
|
|
217
217
|
def court_and_jurisdiction_identifier_string(self) -> CourtIdentifierString:
|
|
218
218
|
if self.jurisdiction != "":
|
|
219
219
|
return CourtIdentifierString("/".join((self.court, self.jurisdiction)))
|
|
220
|
-
|
|
221
|
-
return CourtIdentifierString(self.court)
|
|
220
|
+
return CourtIdentifierString(self.court)
|
|
222
221
|
|
|
223
222
|
@cached_property
|
|
224
223
|
def document_date_as_string(self) -> str:
|
|
@@ -263,8 +262,7 @@ class Document:
|
|
|
263
262
|
events = self.get_manifestation_datetimes(name)
|
|
264
263
|
if not events:
|
|
265
264
|
return None
|
|
266
|
-
|
|
267
|
-
return max(events)
|
|
265
|
+
return max(events)
|
|
268
266
|
|
|
269
267
|
def get_latest_manifestation_type(self) -> Optional[str]:
|
|
270
268
|
return max(
|
|
@@ -404,8 +402,7 @@ class Document:
|
|
|
404
402
|
GatewayTimeoutGettingHTMLWithQuery,
|
|
405
403
|
)
|
|
406
404
|
return self.content_as_html(version_uri)
|
|
407
|
-
|
|
408
|
-
raise e
|
|
405
|
+
raise e
|
|
409
406
|
|
|
410
407
|
def number_of_mentions(self, query: str) -> int:
|
|
411
408
|
html = self.content_as_html(query=query)
|
|
@@ -218,8 +218,7 @@ def build_new_key(old_key: str, new_uri: str) -> str:
|
|
|
218
218
|
if old_filename.endswith(".docx") or old_filename.endswith(".pdf"):
|
|
219
219
|
new_filename = new_uri.replace("/", "_")
|
|
220
220
|
return f"{new_uri}/{new_filename}.{old_filename.split('.')[-1]}"
|
|
221
|
-
|
|
222
|
-
return f"{new_uri}/{old_filename}"
|
|
221
|
+
return f"{new_uri}/{old_filename}"
|
|
223
222
|
|
|
224
223
|
|
|
225
224
|
def request_parse(
|
|
@@ -244,7 +243,7 @@ def request_parse(
|
|
|
244
243
|
"parameters": {
|
|
245
244
|
"s3Bucket": env("PRIVATE_ASSET_BUCKET"),
|
|
246
245
|
"s3Key": generate_docx_key(uri),
|
|
247
|
-
"reference": reference or f"FCL-{uuid.uuid4()}",
|
|
246
|
+
"reference": reference or f"FCL-{str(uuid.uuid4())[:-13]}", # uuid truncated at request of TRE
|
|
248
247
|
"originator": "FCL",
|
|
249
248
|
"parserInstructions": parser_instructions,
|
|
250
249
|
},
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
from typing import List, Optional
|
|
3
|
-
from xml.etree.ElementTree import (
|
|
4
|
-
Element,
|
|
5
|
-
ElementTree,
|
|
6
|
-
ParseError,
|
|
7
|
-
QName,
|
|
8
|
-
fromstring,
|
|
9
|
-
tostring,
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
akn_uk_namespaces = {
|
|
13
|
-
"akn": "http://docs.oasis-open.org/legaldocml/ns/akn/3.0",
|
|
14
|
-
"uk": "https://caselaw.nationalarchives.gov.uk/akn",
|
|
15
|
-
}
|
|
16
|
-
akn_namespace_uri = "http://docs.oasis-open.org/legaldocml/ns/akn/3.0"
|
|
17
|
-
uk_namespace_uri = "https://caselaw.nationalarchives.gov.uk/akn"
|
|
18
|
-
search_namespace = {"search": "http://marklogic.com/appservices/search"}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class JudgmentMissingMetadataError(IndexError):
|
|
22
|
-
pass
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def get_element(
|
|
26
|
-
xml: ElementTree,
|
|
27
|
-
xpath: str,
|
|
28
|
-
element_name: str = "FRBRname",
|
|
29
|
-
element_namespace: str = akn_namespace_uri,
|
|
30
|
-
has_value_attribute: bool = True,
|
|
31
|
-
) -> Element:
|
|
32
|
-
logging.warning(
|
|
33
|
-
"XMLTools is deprecated and will be removed in later versions. "
|
|
34
|
-
"Use methods from MarklogicApiClient.Client instead.",
|
|
35
|
-
)
|
|
36
|
-
name = xml.find(
|
|
37
|
-
xpath,
|
|
38
|
-
namespaces=akn_uk_namespaces,
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
if name is None:
|
|
42
|
-
element = Element(QName(element_namespace, element_name)) # type: ignore
|
|
43
|
-
if has_value_attribute:
|
|
44
|
-
element.set("value", "")
|
|
45
|
-
return element
|
|
46
|
-
|
|
47
|
-
return name
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def get_neutral_citation_element(xml: ElementTree) -> Element:
|
|
51
|
-
return get_element(xml, ".//uk:cite", "cite", uk_namespace_uri, False)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def get_neutral_citation_name_value(xml: ElementTree) -> Optional[str]:
|
|
55
|
-
return get_neutral_citation_element(xml).text
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def get_judgment_date_element(xml: ElementTree) -> Element:
|
|
59
|
-
logging.warning(
|
|
60
|
-
"XMLTools is deprecated and will be removed in later versions. "
|
|
61
|
-
"Use methods from MarklogicApiClient.Client instead.",
|
|
62
|
-
)
|
|
63
|
-
name = xml.find(
|
|
64
|
-
".//akn:FRBRWork/akn:FRBRdate",
|
|
65
|
-
namespaces=akn_uk_namespaces,
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
if name is None:
|
|
69
|
-
element = Element(QName(akn_namespace_uri, "FRBRdate")) # type: ignore
|
|
70
|
-
element.set("date", "")
|
|
71
|
-
element.set("name", "judgment")
|
|
72
|
-
|
|
73
|
-
return element
|
|
74
|
-
|
|
75
|
-
return name
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def get_judgment_date_value(xml: ElementTree) -> str:
|
|
79
|
-
return get_judgment_date_element(xml).attrib["date"]
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def get_court_element(xml: ElementTree) -> Element:
|
|
83
|
-
return get_element(xml, ".//uk:court", "court", uk_namespace_uri, False)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def get_court_value(xml: ElementTree) -> Optional[str]:
|
|
87
|
-
return get_court_element(xml).text
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def get_metadata_name_element(xml: ElementTree) -> Element:
|
|
91
|
-
return get_element(xml, ".//akn:FRBRname", "FRBRname", akn_namespace_uri, True)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def get_metadata_name_value(xml: ElementTree) -> str:
|
|
95
|
-
name = get_metadata_name_element(xml)
|
|
96
|
-
value = name.attrib["value"]
|
|
97
|
-
if value is None:
|
|
98
|
-
return ""
|
|
99
|
-
return value
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def get_search_matches(element: ElementTree) -> List[str]:
|
|
103
|
-
logging.warning(
|
|
104
|
-
"XMLTools is deprecated and will be removed in later versions. "
|
|
105
|
-
"Use methods from MarklogicApiClient.Client instead.",
|
|
106
|
-
)
|
|
107
|
-
nodes = element.findall(".//search:match", namespaces=search_namespace)
|
|
108
|
-
results = []
|
|
109
|
-
for node in nodes:
|
|
110
|
-
text = tostring(node, method="text", encoding="UTF-8")
|
|
111
|
-
results.append(text.decode("UTF-8").strip())
|
|
112
|
-
return results
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def get_error_code(content_as_xml: Optional[str]) -> str:
|
|
116
|
-
logging.warning(
|
|
117
|
-
"XMLTools is deprecated and will be removed in later versions. "
|
|
118
|
-
"Use methods from MarklogicApiClient.Client instead.",
|
|
119
|
-
)
|
|
120
|
-
if not content_as_xml:
|
|
121
|
-
return "Unknown error, Marklogic returned a null or empty response"
|
|
122
|
-
try:
|
|
123
|
-
xml = fromstring(content_as_xml)
|
|
124
|
-
return xml.find(
|
|
125
|
-
"message-code",
|
|
126
|
-
namespaces={"": "http://marklogic.com/xdmp/error"},
|
|
127
|
-
).text # type: ignore
|
|
128
|
-
except (ParseError, TypeError, AttributeError):
|
|
129
|
-
return "Unknown error, Marklogic returned a null or empty response"
|
{ds_caselaw_marklogic_api_client-24.0.0 → ds_caselaw_marklogic_api_client-25.0.0}/LICENSE.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|