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

@@ -10,12 +10,16 @@ from documente_shared.domain.enums import (
10
10
  DocumentProcessCategory,
11
11
  )
12
12
 
13
+ def remove_slash_from_path(path: str) -> str:
14
+ if path and path.startswith('/'):
15
+ return path[1:]
16
+ return path
13
17
 
14
18
  @dataclass
15
19
  class DocumentProcess(object):
16
20
  digest: str
17
21
  status: DocumentProcessStatus
18
- file_path: str
22
+ file_path: Optional[str] = None
19
23
  file_bytes: Optional[bytes] = None
20
24
  category: Optional[DocumentProcessCategory] = None
21
25
  sub_category: Optional[DocumentProcessSubCategory] = None
@@ -77,6 +81,18 @@ class DocumentProcess(object):
77
81
  def deleted(self):
78
82
  self.status = DocumentProcessStatus.DELETED
79
83
 
84
+ @property
85
+ def file_key(self) -> str:
86
+ return remove_slash_from_path(self.file_path)
87
+
88
+ @property
89
+ def processed_csv_key(self) -> str:
90
+ return remove_slash_from_path(self.processed_csv_path)
91
+
92
+ @property
93
+ def processed_xlsx_key(self) -> str:
94
+ return remove_slash_from_path(self.processed_xlsx_path)
95
+
80
96
  @property
81
97
  def extended_filename(self) -> str:
82
98
  return self.file_path.split('/')[-1]
@@ -11,7 +11,7 @@ class DynamoDocumentProcessRepository(
11
11
  DocumentProcessRepository,
12
12
  ):
13
13
  def find(self, digest: str) -> Optional[DocumentProcess]:
14
- item = self.get(key=digest)
14
+ item = self.get(key={'digest': digest})
15
15
  if item:
16
16
  return DocumentProcess.from_dict(item)
17
17
  return None
@@ -13,7 +13,7 @@ class DynamoDBTable(object):
13
13
  def __post_init__(self):
14
14
  self._table = boto3.resource('dynamodb').Table(self.table_name)
15
15
 
16
- def get(self, key: str):
16
+ def get(self, key: dict):
17
17
  return self._table.get_item(Key=key).get('Item')
18
18
 
19
19
  def get_all(self):
@@ -3,6 +3,8 @@ import boto3
3
3
  from dataclasses import dataclass
4
4
  from typing import Optional
5
5
 
6
+ from documente_shared.domain.entities import remove_slash_from_path
7
+
6
8
 
7
9
  def remove_none_values(data: dict) -> dict: # noqa: WPS110
8
10
  return {key: value for key, value in data.items() if value is not None} # noqa: WPS110
@@ -22,7 +24,8 @@ class S3Bucket(object):
22
24
  return None
23
25
 
24
26
  def get_bytes(self, file_key: str) -> Optional[bytes]:
25
- file_context = self.get(file_key)
27
+ cleaned_file_key = remove_slash_from_path(file_key)
28
+ file_context = self.get(cleaned_file_key)
26
29
  if not file_context:
27
30
  return None
28
31
  return (
@@ -32,19 +35,22 @@ class S3Bucket(object):
32
35
  )
33
36
 
34
37
  def upload(self, file_key: str, file_content, content_type: Optional[str] = None):
38
+ cleaned_file_key = remove_slash_from_path(file_key)
35
39
  optional_params = {'ContentType': content_type}
36
- return self._resource.Object(self.bucket_name, file_key).put(
40
+ return self._resource.Object(self.bucket_name, cleaned_file_key).put(
37
41
  Body=file_content,
38
42
  **remove_none_values(optional_params),
39
43
  )
40
44
 
41
45
  def delete(self, file_key: str):
42
- return self._resource.Object(self.bucket_name, file_key).delete()
46
+ cleaned_file_key = remove_slash_from_path(file_key)
47
+ return self._resource.Object(self.bucket_name, cleaned_file_key).delete()
43
48
 
44
49
  def get_url(self, file_key: str):
50
+ cleaned_file_key = remove_slash_from_path(file_key)
45
51
  return 'https://{bucket_url}.s3.amazonaws.com/{file_key}'.format(
46
52
  bucket_url=self.bucket_name,
47
- file_key=file_key,
53
+ file_key=cleaned_file_key,
48
54
  )
49
55
 
50
56
  def read(self, file_key: str) -> bytes:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: documente_shared
3
- Version: 0.1.23
3
+ Version: 0.1.25
4
4
  Summary: Shared utilities for Documente AI projects
5
5
  License: MIT
6
6
  Author: Tech
@@ -4,14 +4,14 @@ documente_shared/application/digest.py,sha256=Um6E8WfFri2_lly4RFWydJyvSfPZGFcOX-
4
4
  documente_shared/application/time_utils.py,sha256=XDH27cKgoTFO8ad1JgrxKaeT7sZ1fduuJqLkvHUjy-Q,309
5
5
  documente_shared/domain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  documente_shared/domain/base_enum.py,sha256=DojAfn-zQdtjtImeHUpBzE6TBTm07XrbMOdW3h8RVd8,1449
7
- documente_shared/domain/entities.py,sha256=zNYFjxxel5uEGAOqLk5Rs8OwHQlLMhgL2SmUnwqnKpI,5743
7
+ documente_shared/domain/entities.py,sha256=J4B5fMBcwyiVB5xQToPFsOvF5yWIchsmyicC6iq3eRs,6222
8
8
  documente_shared/domain/enums.py,sha256=wrMpM-1KgXFkd-He-3onNcqR3Zf53Q-_axjXGjx7MIY,435
9
9
  documente_shared/domain/repositories.py,sha256=EekvB2BE4AnT5myEhU3DfwHfF9MkNJZRbqRVGFxCEWM,509
10
10
  documente_shared/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- documente_shared/infrastructure/dynamo_repositories.py,sha256=A26S6ghyAsjKk8ySXIsR8_MDE8vbp7ZmNg7hqTOtMy0,748
12
- documente_shared/infrastructure/dynamo_table.py,sha256=5yF5EVQkHTZe4tLYZsfEDS8tp_iorMlMjNu-qn3Oj9E,2095
13
- documente_shared/infrastructure/s3_bucket.py,sha256=s4VWcl0HK6uhjjZmKefOYW5A3Dx74R9KCuMmXQKUXnQ,1582
11
+ documente_shared/infrastructure/dynamo_repositories.py,sha256=WULK8_N7PjA397vXTZd6QB7_Kw6dEXHaVMcd9nEvSvs,760
12
+ documente_shared/infrastructure/dynamo_table.py,sha256=Lod8vwUCGX65SNH_8hvlpG6rRUYb4jfZqoFHD1YloAA,2096
13
+ documente_shared/infrastructure/s3_bucket.py,sha256=RwcEyYPUUXQ0fFR-Zr1KfkFGGpO6qAIfZ70CWHu1V8M,1923
14
14
  documente_shared/infrastructure/sqs_queue.py,sha256=PSiTAnjXvQ-W-9mzLpH2UjbQJTvYkMiaxNaMecF-cR4,1505
15
- documente_shared-0.1.23.dist-info/METADATA,sha256=3IgMXZmsknUIO5xkfAXwGltpUj5XhnG3NxTz_Js-IpE,640
16
- documente_shared-0.1.23.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
17
- documente_shared-0.1.23.dist-info/RECORD,,
15
+ documente_shared-0.1.25.dist-info/METADATA,sha256=yEjSzweJsasaYAPUJgWkwdaCSl1ZT6jZBjDTSl8GdzE,640
16
+ documente_shared-0.1.25.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
17
+ documente_shared-0.1.25.dist-info/RECORD,,