documente_shared 0.1.99__py3-none-any.whl → 0.1.100__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.

Potentially problematic release.


This version of documente_shared might be problematic. Click here for more details.

@@ -2,10 +2,7 @@ import base64
2
2
  from typing import Optional
3
3
  from dataclasses import dataclass
4
4
 
5
- from documente_shared.application.files import (
6
- remove_slash_from_path,
7
- get_filename_from_path,
8
- )
5
+ from documente_shared.application.files import get_filename_from_path
9
6
  from documente_shared.domain.exceptions import InMemoryDocumentContentError
10
7
 
11
8
 
@@ -15,19 +12,26 @@ class InMemoryDocument(object):
15
12
  file_bytes: Optional[bytes] = None
16
13
  file_base64: Optional[str] = None
17
14
 
15
+ def __post_init__(self):
16
+ if not self.file_path:
17
+ return
18
+ if self.file_base64 and not self.file_bytes:
19
+ self.file_bytes = base64.b64decode(self.file_base64)
20
+ elif self.file_bytes and not self.file_base64:
21
+ self.file_base64 = base64.b64encode(self.file_bytes).decode()
22
+
23
+
18
24
  @property
19
25
  def is_valid(self) -> bool:
20
- return bool(self.file_path) and self.file_bytes
26
+ return bool(self.file_path and self.file_bytes)
21
27
 
22
28
  @property
23
29
  def has_content(self) -> bool:
24
- return bool(self.file_bytes) or bool(self.file_base64)
30
+ return bool(self.file_bytes or self.file_base64)
25
31
 
26
32
  @property
27
33
  def file_name(self) -> Optional[str]:
28
- if not self.file_path:
29
- return None
30
- return get_filename_from_path(self.file_path)
34
+ return get_filename_from_path(self.file_path) if self.file_path else None
31
35
 
32
36
  @property
33
37
  def file_key(self) -> Optional[str]:
@@ -46,20 +50,20 @@ class InMemoryDocument(object):
46
50
 
47
51
  @classmethod
48
52
  def from_dict(cls, data: dict):
49
- has_bytes_content = data.get('file_bytes') and isinstance(data['file_bytes'], bytes)
50
- has_base64_content = data.get('file_base64') and isinstance(data['file_base64'], str)
53
+ file_bytes = data.get("file_bytes")
54
+ file_base64 = data.get("file_base64")
51
55
 
52
- if not has_bytes_content and not has_base64_content:
56
+ if not file_bytes and not file_base64:
53
57
  raise InMemoryDocumentContentError
54
58
 
55
- if has_bytes_content and not data.get('file_base64'):
56
- data['file_base64'] = base64.b64encode(data.get('file_bytes')).decode("utf-8")
59
+ if file_bytes and not file_base64:
60
+ file_base64 = base64.b64encode(file_bytes).decode()
57
61
 
58
- if has_base64_content and not data.get('file_bytes'):
59
- data['file_bytes'] = base64.b64decode(data.get('file_base64'))
62
+ if file_base64 and not file_bytes:
63
+ file_bytes = base64.b64decode(file_base64)
60
64
 
61
65
  return cls(
62
- file_path=data.get('file_path'),
63
- file_bytes=data.get('file_bytes'),
64
- file_base64=data.get('file_base64'),
66
+ file_path=data.get("file_path"),
67
+ file_bytes=file_bytes,
68
+ file_base64=file_base64,
65
69
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: documente_shared
3
- Version: 0.1.99
3
+ Version: 0.1.100
4
4
  Summary: Shared utilities for Documente AI projects
5
5
  License: MIT
6
6
  Author: Tech
@@ -14,7 +14,7 @@ documente_shared/domain/constants.py,sha256=NG5BGaXBr_FnzudjTRPxpDpyiSDdaB_PLCdl
14
14
  documente_shared/domain/entities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  documente_shared/domain/entities/document.py,sha256=xGZdrqqBkbvDbgoxUvIck6FplXjwLcZzFkcEsuh80u8,12819
16
16
  documente_shared/domain/entities/document_metadata.py,sha256=ygyFIC5qwxlm8DUM5kvVFny9zJfPQS8vNLM2br5XsQ8,2353
17
- documente_shared/domain/entities/in_memory_document.py,sha256=kNszkMfWtmPQHRrARkAqMOUgre-oAPq-bcW-Z-GYoA8,1961
17
+ documente_shared/domain/entities/in_memory_document.py,sha256=5MFG5V4EtNr-wwrLEFZusZPWvla52g5wuI6es5nQ4tM,1999
18
18
  documente_shared/domain/entities/processing_case.py,sha256=2wD256_ra5szb8LVmGsauTsFTbkAqT1srOv5zuZQXgA,5640
19
19
  documente_shared/domain/entities/processing_case_filters.py,sha256=harKyu7QEuL1bI_Z8_UxkVCMo5r9vHeNHyi_Ja07vjs,1953
20
20
  documente_shared/domain/entities/processing_case_item.py,sha256=VbVOqAUHtcCHfAF5VpG47IWkM8t6eSX4VuDifJe7ZzA,10108
@@ -51,6 +51,6 @@ documente_shared/infrastructure/services/http_scaling.py,sha256=cIo-61nfIwbtO86E
51
51
  documente_shared/infrastructure/sqs_queue.py,sha256=KZWeHZ9zmXmrxoNpOQX7GEdDhZ1knbPXgwSwFwJblGg,1504
52
52
  documente_shared/presentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
53
  documente_shared/presentation/presenters.py,sha256=GGAEwefmjCIVepsUA2oZOVLxXbhhiISPM0Jgt6dT6O0,423
54
- documente_shared-0.1.99.dist-info/METADATA,sha256=09wpHFc5YW6xO2679vIMvj-UU-VWNjoewbz7YOcgYo4,920
55
- documente_shared-0.1.99.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
56
- documente_shared-0.1.99.dist-info/RECORD,,
54
+ documente_shared-0.1.100.dist-info/METADATA,sha256=1KKQjyPWPCtuChtiVXn5tORQsB1c3wDrH-wgGlTPR_Y,921
55
+ documente_shared-0.1.100.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
56
+ documente_shared-0.1.100.dist-info/RECORD,,