google-cloud-documentai-toolbox 0.17.2__tar.gz → 0.17.4__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.
- {google_cloud_documentai_toolbox-0.17.2/google_cloud_documentai_toolbox.egg-info → google_cloud_documentai_toolbox-0.17.4}/PKG-INFO +4 -3
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/converters/config/block.py +1 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/utilities/gcs_utilities.py +6 -3
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/version.py +1 -1
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/wrappers/document.py +14 -3
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4/google_cloud_documentai_toolbox.egg-info}/PKG-INFO +4 -3
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google_cloud_documentai_toolbox.egg-info/requires.txt +7 -2
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/setup.py +6 -2
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/test_document.py +49 -1
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/LICENSE +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/MANIFEST.in +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/README.rst +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/constants.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/converters/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/converters/config/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/converters/config/bbox_conversion.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/converters/converter.py +1 -1
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/converters/vision_helpers.py +1 -1
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/py.typed +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/templates/hocr_document_template.xml.j2 +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/utilities/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/utilities/docai_utilities.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/wrappers/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/wrappers/entity.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google/cloud/documentai_toolbox/wrappers/page.py +1 -1
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google_cloud_documentai_toolbox.egg-info/SOURCES.txt +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google_cloud_documentai_toolbox.egg-info/dependency_links.txt +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google_cloud_documentai_toolbox.egg-info/not-zip-safe +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/google_cloud_documentai_toolbox.egg-info/top_level.txt +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/setup.cfg +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/0/toolbox_invoice_test-0.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/1/toolbox_large_document_test-0.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/1/toolbox_large_document_test-1.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/1/toolbox_large_document_test-2.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/1/toolbox_large_document_test-3.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/1/toolbox_large_document_test-4.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/blank_document.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/classifier/custom_classifier_output.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/converters/test_config_type_1.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/converters/test_config_type_2.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/converters/test_config_type_3.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/converters/test_type_1.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/converters/test_type_2.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/converters/test_type_3.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/form_parser/pretrained-form-parser-v1.0-2020-09-23_full-output.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/hex_ids/patent.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/images/dl3-0.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/layout_parser/layout_parser.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/merged_document/merged_shards.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/missing_shard/Winnie_the_Pooh_50_Pages-0.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/missing_shard/Winnie_the_Pooh_50_Pages-1.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/missing_shard/Winnie_the_Pooh_50_Pages-3.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/missing_shard/Winnie_the_Pooh_50_Pages-4.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/multi_page/pretrained-ocr-v1.0-2020-09-23_output.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/pretrained-ocr-v2.0-2023-06-02_math_output.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/procurement_multi_document.pdf +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/splitter/procurement_splitter_output.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/toolbox_invoice_test-0-hocr-escape.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/toolbox_invoice_test-0-hocr-escape.xml +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/toolbox_invoice_test-0-vision.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/toolbox_invoice_test-with-symbols.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/toolbox_invoice_test.pdf +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/toolbox_invoice_test_0_hocr.xml +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/toolbox_large_document_test.pdf +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/unordered_shards/Winnie_the_Pooh_50_Pages-0.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/unordered_shards/Winnie_the_Pooh_50_Pages-1.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/unordered_shards/Winnie_the_Pooh_50_Pages-2.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/unordered_shards/Winnie_the_Pooh_50_Pages-3.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/resources/unordered_shards/Winnie_the_Pooh_50_Pages-4.json +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/test_bbox_conversion.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/test_block.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/test_converter.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/test_entity.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/test_gcs_utilities.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/test_packaging.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/test_page.py +0 -0
- {google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/unit/test_vision_helper.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: google-cloud-documentai-toolbox
|
|
3
|
-
Version: 0.17.
|
|
3
|
+
Version: 0.17.4
|
|
4
4
|
Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-documentai-toolbox
|
|
5
5
|
Author: Google LLC
|
|
6
6
|
Author-email: googleapis-packages@google.com
|
|
@@ -20,8 +20,9 @@ Requires-Python: >=3.10
|
|
|
20
20
|
Description-Content-Type: text/x-rst
|
|
21
21
|
License-File: LICENSE
|
|
22
22
|
Requires-Dist: google-api-core<3.0.0,>=2.25.0
|
|
23
|
-
Requires-Dist: pandas[gcp,performance]<3.0.0,>=2.0.0
|
|
24
|
-
Requires-Dist:
|
|
23
|
+
Requires-Dist: pandas[gcp,performance]<3.0.0,>=2.0.0; python_version < "3.15"
|
|
24
|
+
Requires-Dist: pandas[gcp]<3.0.0,>=2.0.0; python_version >= "3.15"
|
|
25
|
+
Requires-Dist: pyarrow>=15.0.0
|
|
25
26
|
Requires-Dist: tabulate<1.0.0,>=0.9.0
|
|
26
27
|
Requires-Dist: proto-plus<2.0.0,>=1.26.1
|
|
27
28
|
Requires-Dist: grpc-google-iam-v1<1.0.0,>=0.14.2
|
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
#
|
|
16
16
|
"""Google Cloud Storage utilities."""
|
|
17
|
+
|
|
17
18
|
import os
|
|
18
19
|
import re
|
|
19
20
|
from typing import Dict, List, Optional, Tuple
|
|
20
21
|
|
|
21
22
|
from google.api_core.gapic_v1 import client_info
|
|
22
23
|
|
|
23
|
-
from google.cloud import
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
from google.cloud import ( # type: ignore[attr-defined]
|
|
25
|
+
documentai,
|
|
26
|
+
documentai_toolbox,
|
|
27
|
+
storage,
|
|
28
|
+
)
|
|
26
29
|
from google.cloud.documentai_toolbox import constants
|
|
27
30
|
|
|
28
31
|
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
import collections
|
|
19
19
|
import copy
|
|
20
20
|
import dataclasses
|
|
21
|
-
from functools import cached_property
|
|
22
21
|
import glob
|
|
23
22
|
import os
|
|
24
23
|
import re
|
|
24
|
+
from functools import cached_property
|
|
25
25
|
from typing import Any, Dict, Iterable, Iterator, List, Optional, Type, Union
|
|
26
26
|
|
|
27
27
|
from google.api_core.client_options import ClientOptions
|
|
@@ -823,7 +823,17 @@ class Document:
|
|
|
823
823
|
input_filename, input_extension = os.path.splitext(os.path.basename(pdf_path))
|
|
824
824
|
with Pdf.open(pdf_path) as pdf:
|
|
825
825
|
for entity in self.entities:
|
|
826
|
-
|
|
826
|
+
# Entity types come from the parsed Document and may contain
|
|
827
|
+
# path separators (e.g. "vat/tax_amount") or traversal
|
|
828
|
+
# sequences. Flatten them so the split file stays inside
|
|
829
|
+
# output_path. ":" is also flattened since it is not a valid
|
|
830
|
+
# filename character on Windows.
|
|
831
|
+
subdoc_type = (
|
|
832
|
+
(entity.type_ or "subdoc")
|
|
833
|
+
.replace("/", "_")
|
|
834
|
+
.replace("\\", "_")
|
|
835
|
+
.replace(":", "_")
|
|
836
|
+
)
|
|
827
837
|
page_range = (
|
|
828
838
|
f"pg{entity.start_page + 1}"
|
|
829
839
|
if entity.start_page == entity.end_page
|
|
@@ -933,7 +943,8 @@ class Document:
|
|
|
933
943
|
A string hOCR version of the Document
|
|
934
944
|
"""
|
|
935
945
|
environment = Environment(
|
|
936
|
-
loader=PackageLoader("google.cloud.documentai_toolbox", "templates")
|
|
946
|
+
loader=PackageLoader("google.cloud.documentai_toolbox", "templates"),
|
|
947
|
+
autoescape=True,
|
|
937
948
|
)
|
|
938
949
|
template = environment.get_template("hocr_document_template.xml.j2")
|
|
939
950
|
content = template.render(pages=self.pages, title=title)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: google-cloud-documentai-toolbox
|
|
3
|
-
Version: 0.17.
|
|
3
|
+
Version: 0.17.4
|
|
4
4
|
Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-documentai-toolbox
|
|
5
5
|
Author: Google LLC
|
|
6
6
|
Author-email: googleapis-packages@google.com
|
|
@@ -20,8 +20,9 @@ Requires-Python: >=3.10
|
|
|
20
20
|
Description-Content-Type: text/x-rst
|
|
21
21
|
License-File: LICENSE
|
|
22
22
|
Requires-Dist: google-api-core<3.0.0,>=2.25.0
|
|
23
|
-
Requires-Dist: pandas[gcp,performance]<3.0.0,>=2.0.0
|
|
24
|
-
Requires-Dist:
|
|
23
|
+
Requires-Dist: pandas[gcp,performance]<3.0.0,>=2.0.0; python_version < "3.15"
|
|
24
|
+
Requires-Dist: pandas[gcp]<3.0.0,>=2.0.0; python_version >= "3.15"
|
|
25
|
+
Requires-Dist: pyarrow>=15.0.0
|
|
25
26
|
Requires-Dist: tabulate<1.0.0,>=0.9.0
|
|
26
27
|
Requires-Dist: proto-plus<2.0.0,>=1.26.1
|
|
27
28
|
Requires-Dist: grpc-google-iam-v1<1.0.0,>=0.14.2
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
google-api-core<3.0.0,>=2.25.0
|
|
2
|
-
|
|
3
|
-
pyarrow<23.0.0,>=15.0.0
|
|
2
|
+
pyarrow>=15.0.0
|
|
4
3
|
tabulate<1.0.0,>=0.9.0
|
|
5
4
|
proto-plus<2.0.0,>=1.26.1
|
|
6
5
|
grpc-google-iam-v1<1.0.0,>=0.14.2
|
|
@@ -14,3 +13,9 @@ pikepdf<11.0.0,>=8.0.0
|
|
|
14
13
|
immutabledict<5.0.0,>=2.0.0
|
|
15
14
|
Pillow<13.0.0,>=10.0.0
|
|
16
15
|
Jinja2<4.0.0,>=3.1.0
|
|
16
|
+
|
|
17
|
+
[:python_version < "3.15"]
|
|
18
|
+
pandas[gcp,performance]<3.0.0,>=2.0.0
|
|
19
|
+
|
|
20
|
+
[:python_version >= "3.15"]
|
|
21
|
+
pandas[gcp]<3.0.0,>=2.0.0
|
|
@@ -54,8 +54,12 @@ setuptools.setup(
|
|
|
54
54
|
},
|
|
55
55
|
install_requires=(
|
|
56
56
|
"google-api-core>=2.25.0, <3.0.0",
|
|
57
|
-
|
|
58
|
-
"
|
|
57
|
+
# For Python < 3.15: Install with performance extras (which includes numba)
|
|
58
|
+
"pandas[performance,gcp]>=2.0.0, <3.0.0; python_version < '3.15'",
|
|
59
|
+
# pandas[performance] requires numba which does not have 3.15 support yet
|
|
60
|
+
"pandas[gcp]>=2.0.0, <3.0.0;python_version>='3.15'",
|
|
61
|
+
# pyarrow is transitive dependency; not accessed by the library directly
|
|
62
|
+
"pyarrow>=15.0.0",
|
|
59
63
|
"tabulate>=0.9.0, <1.0.0",
|
|
60
64
|
"proto-plus>=1.26.1, <2.0.0",
|
|
61
65
|
"grpc-google-iam-v1>=0.14.2, <1.0.0",
|
|
@@ -21,8 +21,8 @@ import shutil
|
|
|
21
21
|
from unittest import mock
|
|
22
22
|
from xml.etree import ElementTree
|
|
23
23
|
|
|
24
|
-
from google.cloud.vision import AnnotateFileResponse
|
|
25
24
|
import pytest
|
|
25
|
+
from google.cloud.vision import AnnotateFileResponse
|
|
26
26
|
|
|
27
27
|
from google.cloud import documentai
|
|
28
28
|
from google.cloud.documentai_toolbox import document, gcs_utilities
|
|
@@ -790,6 +790,37 @@ def test_split_pdf_with_non_splitter(get_bytes_classifier_mock):
|
|
|
790
790
|
get_bytes_classifier_mock.assert_called_once()
|
|
791
791
|
|
|
792
792
|
|
|
793
|
+
@mock.patch("google.cloud.documentai_toolbox.wrappers.document.Pdf")
|
|
794
|
+
def test_split_pdf_sanitizes_entity_type_path_traversal(
|
|
795
|
+
mock_Pdf, get_bytes_splitter_mock
|
|
796
|
+
):
|
|
797
|
+
doc = document.Document.from_gcs(
|
|
798
|
+
gcs_bucket_name="test-directory", gcs_prefix="documentai/output/123456789/0"
|
|
799
|
+
)
|
|
800
|
+
mock_output_file = mock.Mock()
|
|
801
|
+
mock_Pdf.new.return_value = mock_output_file
|
|
802
|
+
|
|
803
|
+
# Entity types are read from the parsed Document and may carry path
|
|
804
|
+
# separators or traversal sequences.
|
|
805
|
+
doc.entities[0].type_ = "../../../../etc:passwd"
|
|
806
|
+
|
|
807
|
+
output_path = "splitter/output/"
|
|
808
|
+
actual = doc.split_pdf(
|
|
809
|
+
pdf_path="procurement_multi_document.pdf", output_path=output_path
|
|
810
|
+
)
|
|
811
|
+
|
|
812
|
+
get_bytes_splitter_mock.assert_called_once()
|
|
813
|
+
|
|
814
|
+
resolved_output = os.path.realpath(output_path)
|
|
815
|
+
for call in mock_output_file.save.call_args_list:
|
|
816
|
+
written_path = os.path.realpath(call.args[0])
|
|
817
|
+
assert written_path == resolved_output or written_path.startswith(
|
|
818
|
+
resolved_output + os.sep
|
|
819
|
+
)
|
|
820
|
+
|
|
821
|
+
assert actual[0] == "procurement_multi_document_pg1_.._.._.._.._etc_passwd.pdf"
|
|
822
|
+
|
|
823
|
+
|
|
793
824
|
def test_convert_document_to_annotate_file_response():
|
|
794
825
|
doc = document.Document.from_document_path(
|
|
795
826
|
document_path="tests/unit/resources/0/toolbox_invoice_test-0.json"
|
|
@@ -918,6 +949,23 @@ def test_export_hocr_str_with_escape_characters():
|
|
|
918
949
|
assert actual_hocr == expected
|
|
919
950
|
|
|
920
951
|
|
|
952
|
+
def test_export_hocr_str_escapes_title():
|
|
953
|
+
wrapped_document = document.Document.from_document_path(
|
|
954
|
+
document_path="tests/unit/resources/0/toolbox_invoice_test-0.json"
|
|
955
|
+
)
|
|
956
|
+
|
|
957
|
+
actual_hocr = wrapped_document.export_hocr_str(
|
|
958
|
+
title="</title><script>alert(1)</script>"
|
|
959
|
+
)
|
|
960
|
+
|
|
961
|
+
assert "<script>alert(1)</script>" not in actual_hocr
|
|
962
|
+
|
|
963
|
+
element = ElementTree.fromstring(actual_hocr)
|
|
964
|
+
assert element is not None
|
|
965
|
+
title_element = element.find(".//{http://www.w3.org/1999/xhtml}title")
|
|
966
|
+
assert title_element.text == "</title><script>alert(1)</script>"
|
|
967
|
+
|
|
968
|
+
|
|
921
969
|
def test_document_to_merged_documentai_document(get_bytes_multiple_files_mock):
|
|
922
970
|
wrapped_document = document.Document.from_gcs(
|
|
923
971
|
gcs_bucket_name="test-directory", gcs_prefix="documentai/output/123456789/1/"
|
|
File without changes
|
{google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/MANIFEST.in
RENAMED
|
File without changes
|
{google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/README.rst
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
#
|
|
16
16
|
"""Document.proto converters."""
|
|
17
17
|
|
|
18
|
-
from concurrent import futures
|
|
19
18
|
import os
|
|
20
19
|
import time
|
|
20
|
+
from concurrent import futures
|
|
21
21
|
from typing import Dict, List, Optional, Set, Tuple
|
|
22
22
|
|
|
23
23
|
from google.api_core.client_options import ClientOptions
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import dataclasses
|
|
19
19
|
from typing import List
|
|
20
20
|
|
|
21
|
+
import immutabledict
|
|
21
22
|
from google.cloud.documentai import Document
|
|
22
23
|
from google.cloud.vision import (
|
|
23
24
|
AnnotateImageResponse,
|
|
@@ -30,7 +31,6 @@ from google.cloud.vision import (
|
|
|
30
31
|
TextAnnotation,
|
|
31
32
|
Word,
|
|
32
33
|
)
|
|
33
|
-
import immutabledict
|
|
34
34
|
|
|
35
35
|
from google.cloud import vision
|
|
36
36
|
from google.cloud.documentai_toolbox.constants import ElementWithLayout
|
|
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
|
{google_cloud_documentai_toolbox-0.17.2 → google_cloud_documentai_toolbox-0.17.4}/tests/__init__.py
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
|