convert-stream 2.3__tar.gz → 2.3.2__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 (36) hide show
  1. {convert_stream-2.3 → convert_stream-2.3.2}/PKG-INFO +1 -1
  2. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/__init__.py +8 -7
  3. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/doc_stream.py +25 -40
  4. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/image/img_object.py +55 -40
  5. convert_stream-2.3.2/convert_stream/mod_types/__init__.py +32 -0
  6. {convert_stream-2.3/convert_stream/enum_libs → convert_stream-2.3.2/convert_stream/mod_types}/enums.py +13 -9
  7. {convert_stream-2.3/convert_stream/enum_libs → convert_stream-2.3.2/convert_stream/mod_types}/modules.py +30 -20
  8. convert_stream-2.3.2/convert_stream/mod_types/table_types.py +408 -0
  9. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/pdf/__init__.py +2 -2
  10. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/pdf/image_to_pdf.py +17 -17
  11. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/pdf/pdf_document.py +122 -85
  12. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/pdf/pdf_page.py +27 -116
  13. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/pdf/pdf_to_image.py +6 -6
  14. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/sheets/load.py +2 -2
  15. convert_stream-2.3.2/convert_stream/table_files.py +142 -0
  16. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/text/__init__.py +1 -1
  17. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/text/date.py +1 -1
  18. convert_stream-2.3.2/convert_stream/text/string.py +50 -0
  19. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream.egg-info/PKG-INFO +1 -1
  20. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream.egg-info/SOURCES.txt +4 -3
  21. {convert_stream-2.3 → convert_stream-2.3.2}/pyproject.toml +2 -2
  22. convert_stream-2.3/convert_stream/enum_libs/__init__.py +0 -0
  23. convert_stream-2.3/convert_stream/table_files.py +0 -338
  24. convert_stream-2.3/convert_stream/text/string.py +0 -352
  25. {convert_stream-2.3 → convert_stream-2.3.2}/README.md +0 -0
  26. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/__main__.py +0 -0
  27. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/_version.py +0 -0
  28. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/image/__init__.py +0 -0
  29. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/sheets/__init__.py +0 -0
  30. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/sheets/parse.py +0 -0
  31. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/sheets/save.py +0 -0
  32. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream/text/terminal.py +0 -0
  33. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream.egg-info/dependency_links.txt +0 -0
  34. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream.egg-info/requires.txt +0 -0
  35. {convert_stream-2.3 → convert_stream-2.3.2}/convert_stream.egg-info/top_level.txt +0 -0
  36. {convert_stream-2.3 → convert_stream-2.3.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: convert_stream
3
- Version: 2.3
3
+ Version: 2.3.2
4
4
  Summary: Manipulação de documentos PDF e Imagens. Converter, Ler, rotacionar exportar etc.
5
5
  Author: Bruno Chaves
6
6
  Requires-Python: >=3.11
@@ -7,21 +7,22 @@ from soup_files import File, Directory, LibraryDocs, InputFiles
7
7
  from ._version import (
8
8
  __module_name__, __author__, __license__, __modify_date__, __version__
9
9
  )
10
- from convert_stream.enum_libs.enums import *
11
- from convert_stream.enum_libs.modules import (
10
+ from convert_stream.mod_types.enums import *
11
+ from convert_stream.mod_types.modules import (
12
12
  LibPDF, LibDate, LibImage, LibPdfToImage, LibImageToPdf,
13
13
  DEFAULT_LIB_PDF, DEFAULT_LIB_IMAGE, DEFAULT_LIB_PDF_TO_IMG,
14
14
  DEFAULT_LIB_IMAGE_TO_PDF, ModPdfToImage, ModPagePdf, ModuleImage,
15
15
  ModImageToPdf, MOD_FITZ, MOD_PYPDF, MOD_CANVAS, MOD_IMG_PIL, MOD_IMG_OPENCV,
16
16
  )
17
17
  from .text.terminal import print_title, print_line
18
- from .text.string import (
19
- FindText, ArrayString, MapText
20
- )
18
+ from .text.string import FindText
19
+ from .mod_types.table_types import ArrayString, ColumnsTable
21
20
  from .text.date import ConvertStringDate
21
+
22
22
  from convert_stream.image.img_object import (
23
23
  ImageObject, Image, MatLike, get_hash_from_bytes, CollectionImages,
24
24
  )
25
+
25
26
  from convert_stream.pdf import (
26
27
  PageDocumentPdf, DocumentPdf, ConvertImageToPdf, ConvertPdfToImages,
27
28
  ModImageToPdf, ModDocPdf, CollectionPagePdf, DEFAULT_LIB_PDF,
@@ -30,8 +31,8 @@ from convert_stream.pdf import (
30
31
  from .doc_stream import PdfStream, SplitPdf
31
32
  from .sheets import save_data, ReadFileSheet
32
33
  from .table_files import (
33
- get_void_df, create_df_from_file_pdf, create_map_from_values,
34
- FileToTable, ColumnsTable, PdfFinder, SearchableTextPdf
34
+ create_void_table, create_df_from_file_pdf, create_map_from_file_values,
35
+ FileToTable, PdfFinder, SearchableTextPdf
35
36
  )
36
37
 
37
38
 
@@ -4,38 +4,26 @@
4
4
  Módulo para trabalhar com pdfs e imagens
5
5
  """
6
6
  from __future__ import annotations
7
- from convert_stream.enum_libs.modules import (
7
+ from convert_stream.mod_types.modules import (
8
8
  DEFAULT_LIB_PDF, DEFAULT_LIB_IMAGE, DEFAULT_LIB_PDF_TO_IMG, DEFAULT_LIB_IMAGE_TO_PDF,
9
9
  )
10
- from convert_stream.enum_libs.enums import LibPDF, LibImage, LibImageToPdf, LibPdfToImage
10
+ from convert_stream.mod_types.enums import LibPDF, LibImage, LibPdfToImage
11
11
  from convert_stream.pdf.pdf_page import PageDocumentPdf
12
12
  from convert_stream.image.img_object import ImageObject, CollectionImages
13
13
  from convert_stream.pdf.pdf_document import DocumentPdf, CollectionPagePdf
14
14
  from convert_stream.pdf.image_to_pdf import LibImageToPdf, ConvertImageToPdf
15
15
  from convert_stream.pdf.pdf_to_image import ConvertPdfToImages
16
- from soup_files import File, Directory, ProgressBarAdapter, ABCProgressBar
17
-
18
-
19
- class VoidProgressBar(ABCProgressBar):
20
-
21
- def __init__(self):
22
- super().__init__()
23
-
24
- def set_percent(self, percent: float):
25
- pass
26
-
27
- def set_text(self, text: str):
28
- pass
16
+ from soup_files import File, Directory, ProgressBarAdapter
29
17
 
30
18
 
31
19
  class ImageStream(CollectionImages):
32
20
 
33
- def __init__(self, images: list[ImageObject] = []) -> None:
21
+ def __init__(self, images: list[ImageObject]) -> None:
34
22
  super().__init__(images)
35
23
 
36
24
  def add_image_bytes(self, bt: bytes) -> None:
37
25
  im = ImageObject.create_from_bytes(bt)
38
- self.images.append(im)
26
+ self.append(im)
39
27
 
40
28
 
41
29
  class PdfStream(object):
@@ -49,8 +37,8 @@ class PdfStream(object):
49
37
  lib_pdf_to_img: LibPdfToImage = DEFAULT_LIB_PDF_TO_IMG,
50
38
  ) -> None:
51
39
  self.progress: ProgressBarAdapter = pbar
52
- self.collection_pages: CollectionPagePdf = CollectionPagePdf()
53
- self.collection_images: CollectionImages = CollectionImages()
40
+ self.collection_pages: CollectionPagePdf = CollectionPagePdf([])
41
+ self.collection_images: CollectionImages = CollectionImages([])
54
42
  self.collection_images.set_pbar(pbar)
55
43
  self.collection_pages.set_pbar(pbar)
56
44
  self.lib_pdf: LibPDF = lib_pdf
@@ -61,7 +49,7 @@ class PdfStream(object):
61
49
 
62
50
  @property
63
51
  def is_empty(self) -> bool:
64
- return self.collection_pages.is_null
52
+ return self.collection_pages.is_empty
65
53
 
66
54
  def set_land_scape(self):
67
55
  self.collection_pages.set_land_scape()
@@ -109,28 +97,28 @@ class PdfStream(object):
109
97
 
110
98
  def to_document(self, *, land_scape: bool = False, a4: bool = False) -> DocumentPdf:
111
99
  """
112
-
113
100
  Converte os documentos adicionados em PdfStream (imagens/pdfs) em
114
101
  objeto do tipo DocumentPdf().
115
102
  """
116
- if self.collection_pages.is_null and self.collection_images.is_empty:
103
+ if self.collection_pages.is_empty and self.collection_images.is_empty:
117
104
  raise ValueError('Adicione imagens e/ou documentos para prosseguir!')
118
105
 
119
- _doc = None
106
+ _doc: DocumentPdf = None
120
107
  if not self.collection_images.is_empty:
121
108
  _convert = ConvertImageToPdf(self.collection_images, lib_img_to_pdf=self.lib_img_to_pdf)
109
+ _convert.set_pbar(self.progress)
122
110
  _doc: DocumentPdf = _convert.to_document(land_scape, a4=a4)
123
- if not self.collection_pages.is_null:
111
+ if not self.collection_pages.is_empty:
124
112
  if _doc is None:
125
113
  _doc: DocumentPdf = self.collection_pages.to_document(self.lib_pdf)
126
114
  else:
127
- _doc.add_pages(self.collection_pages.pages)
115
+ _doc.add_pages(self.collection_pages)
128
116
  return _doc
129
117
 
130
118
  def thresold(self, *, land_scape: bool = False, a4: bool = False, dpi=300) -> DocumentPdf:
131
- images: list[ImageObject] = self.collection_images.images
132
- if not self.collection_pages.is_null:
133
- tmp_doc = DocumentPdf.create_from_pages(self.collection_pages.pages)
119
+ images: list[ImageObject] = self.collection_images
120
+ if not self.collection_pages.is_empty:
121
+ tmp_doc = DocumentPdf.create_from_pages(self.collection_pages)
134
122
  conv_pdf_to_img = ConvertPdfToImages.create(tmp_doc)
135
123
  images.extend(conv_pdf_to_img.to_images(dpi=dpi))
136
124
  del tmp_doc
@@ -151,17 +139,17 @@ class PdfStream(object):
151
139
  land_scape: bool = False,
152
140
  dpi: int = 300,
153
141
  ) -> None:
154
- if self.collection_pages.is_null and self.collection_images.is_empty:
142
+ if self.collection_pages.is_empty and self.collection_images.is_empty:
155
143
  raise ValueError('Adicione imagens e/ou documentos para prosseguir!')
156
144
  self.progress.start()
157
145
 
158
- image_stream = ImageStream()
146
+ image_stream = ImageStream([])
159
147
  if not self.collection_images.is_empty:
160
- image_stream.add_images(self.collection_images.images)
161
- if not self.collection_pages.is_null:
148
+ image_stream.add_images(self.collection_images)
149
+ if not self.collection_pages.is_empty:
162
150
  self.progress.update_text('Processando Imagens')
163
151
  # Criar um documento a partir das páginas
164
- doc_pdf = DocumentPdf.create_from_pages(self.collection_pages.pages)
152
+ doc_pdf = DocumentPdf.create_from_pages(self.collection_pages)
165
153
  convert_pdf_to_img = ConvertPdfToImages.create(doc_pdf)
166
154
  # Converter as páginas PDF em imagens e adicionar a coleção já existe de imagens.
167
155
  _pdf_to_images: list[ImageObject] = convert_pdf_to_img.to_images(dpi=dpi)
@@ -178,11 +166,11 @@ class PdfStream(object):
178
166
  a4: bool = False,
179
167
  prefix: str = None,
180
168
  ) -> None:
181
- if self.collection_pages.is_null and self.collection_images.is_empty:
169
+ if self.collection_pages.is_empty and self.collection_images.is_empty:
182
170
  raise ValueError('Adicione imagens e/ou documentos para prosseguir!')
183
171
  pages_document = []
184
- if not self.collection_pages.is_null:
185
- pages_document.extend(self.collection_pages.pages)
172
+ if not self.collection_pages.is_empty:
173
+ pages_document.extend(self.collection_pages)
186
174
  if not self.collection_images.is_empty:
187
175
  img_to_pdf = ConvertImageToPdf(self.collection_images, lib_img_to_pdf=self.lib_img_to_pdf)
188
176
  tmp_document = img_to_pdf.to_document(land_scape, a4=a4)
@@ -201,7 +189,7 @@ class SplitPdf(object):
201
189
  self.__collection_pages.set_pbar(self.pbar)
202
190
 
203
191
  def is_empty(self) -> bool:
204
- return self.__collection_pages.is_null
192
+ return self.__collection_pages.is_empty
205
193
 
206
194
  def add_pages_pdf(self, pages: list[PageDocumentPdf]) -> None:
207
195
  self.__collection_pages.add_pages(pages)
@@ -212,6 +200,3 @@ class SplitPdf(object):
212
200
  return
213
201
  self.__collection_pages.to_files_pdf(output_dir, replace=replace, prefix=prefix)
214
202
  self.__collection_pages.clear()
215
-
216
-
217
-
@@ -6,29 +6,31 @@
6
6
  from __future__ import annotations
7
7
  from typing import Union
8
8
  from abc import ABC, abstractmethod
9
- from hashlib import md5 as md5_hash
10
9
  from soup_files import File, Directory, InputFiles, LibraryDocs, ProgressBarAdapter
11
10
  from io import BytesIO
12
11
  import numpy as np
13
12
  from scipy.ndimage import uniform_filter
14
- from convert_stream.enum_libs.enums import LibImage, RotationAngle
15
- from convert_stream.enum_libs.modules import (
13
+ from convert_stream.mod_types import get_void_metadata, get_hash_from_bytes
14
+ from convert_stream.mod_types.enums import LibImage, RotationAngle
15
+ from convert_stream.mod_types.table_types import ListItems
16
+ from convert_stream.mod_types.modules import (
16
17
  MOD_IMG_PIL, ModuleImage, DEFAULT_LIB_IMAGE,
17
18
  cv2, MatLike, Image, ImageFilter
18
19
  )
19
20
 
20
21
 
21
- def get_hash_from_bytes(bt: BytesIO) -> str:
22
- return md5_hash(bt.getvalue()).hexdigest().upper()
23
-
24
-
25
22
  class ABCImageObject(ABC):
26
23
 
27
- def __init__(self, module_image: ModuleImage, name: str) -> None:
28
- self.max_size: tuple[int, int] = (1980, 720) # Dimensões máximas, altere se necessário.
24
+ def __init__(self, module_image: ModuleImage) -> None:
25
+ # Dimensões máximas, altere se necessário.
26
+ self.max_size: tuple[int, int] = (1980, 720)
29
27
  self.module_image: ModuleImage = module_image
30
28
  self.lib_image: LibImage = LibImage.OPENCV
31
- self.name: str = name
29
+ self.metadata: dict[str, str | None] = get_void_metadata()
30
+
31
+ @property
32
+ def name(self) -> str | None:
33
+ return self.metadata['name']
32
34
 
33
35
  @abstractmethod
34
36
  def get_dimensions(self) -> tuple[int, int]:
@@ -89,8 +91,8 @@ class ABCImageObject(ABC):
89
91
 
90
92
 
91
93
  class ImplementOpenCv(ABCImageObject):
92
- def __init__(self, module_image: ModuleImage, name: str) -> None:
93
- super().__init__(module_image, name)
94
+ def __init__(self, module_image: ModuleImage) -> None:
95
+ super().__init__(module_image)
94
96
  self.lib_image = LibImage.OPENCV
95
97
 
96
98
  # Redimensionar se necessário
@@ -202,7 +204,13 @@ class ImplementOpenCv(ABCImageObject):
202
204
  img = cv2.imread(f.absolute())
203
205
  if img is None:
204
206
  raise ValueError(f"Não foi possível abrir a imagem: {f.absolute()}")
205
- return cls(img, f.name())
207
+ im_obj = cls(img)
208
+ im_obj.metadata['file_path'] = f.absolute()
209
+ im_obj.metadata['md5'] = f.md5()
210
+ im_obj.metadata['name'] = f.absolute()
211
+ im_obj.metadata['size'] = f.size()
212
+ im_obj.metadata['extension'] = f.extension()
213
+ return im_obj
206
214
 
207
215
  @classmethod
208
216
  def create_from_bytes(cls, bt: bytes) -> ABCImageObject:
@@ -211,14 +219,17 @@ class ImplementOpenCv(ABCImageObject):
211
219
  if img is None:
212
220
  raise ValueError("Não foi possível criar a imagem a partir dos bytes fornecidos.")
213
221
  bytes_io = BytesIO(bt)
214
- name = get_hash_from_bytes(bytes_io)
222
+ name: str = get_hash_from_bytes(bytes_io)
215
223
  bytes_io.close()
216
- return cls(img, name)
224
+ _obj = cls(img)
225
+ _obj.metadata['md5'] = name
226
+ _obj.metadata['name'] = name
227
+ return _obj
217
228
 
218
229
 
219
230
  class ImplementPIL(ABCImageObject):
220
- def __init__(self, module_image: ModuleImage, name: str):
221
- super().__init__(module_image, name)
231
+ def __init__(self, module_image: ModuleImage):
232
+ super().__init__(module_image)
222
233
  self.lib_image = LibImage.PIL
223
234
 
224
235
  # Redimensionar, se as dimensões estiverem maior que self.max_size.
@@ -342,7 +353,13 @@ class ImplementPIL(ABCImageObject):
342
353
  @classmethod
343
354
  def create_from_file(cls, f: File) -> ABCImageObject:
344
355
  img = Image.open(f.path)
345
- return cls(img, f.name())
356
+ im_obj = cls(img)
357
+ im_obj.metadata['file_path'] = f.absolute()
358
+ im_obj.metadata['md5'] = f.md5()
359
+ im_obj.metadata['name'] = f.absolute()
360
+ im_obj.metadata['size'] = f.size()
361
+ im_obj.metadata['extension'] = f.extension()
362
+ return im_obj
346
363
 
347
364
  @classmethod
348
365
  def create_from_bytes(cls, bt: bytes) -> ABCImageObject:
@@ -350,7 +367,10 @@ class ImplementPIL(ABCImageObject):
350
367
  bytes_io = BytesIO(bt)
351
368
  name = get_hash_from_bytes(bytes_io)
352
369
  bytes_io.close()
353
- return cls(img, name)
370
+ _obj = cls(img)
371
+ _obj.metadata['md5'] = name
372
+ _obj.metadata['name'] = name
373
+ return _obj
354
374
 
355
375
 
356
376
  class ImageObject(object):
@@ -398,6 +418,10 @@ class ImageObject(object):
398
418
  def name(self) -> str:
399
419
  return self.img_adapter.name
400
420
 
421
+ @property
422
+ def metadata(self) -> dict[str, str | None]:
423
+ return self.img_adapter.metadata
424
+
401
425
  def to_pil(self) -> Image.Image:
402
426
  """
403
427
  Converte o ImageObject para um objeto PIL.Image.
@@ -473,44 +497,35 @@ class ImageObject(object):
473
497
 
474
498
  @classmethod
475
499
  def create_from_pil(cls, pil: ModuleImage) -> ImageObject:
476
- name = get_hash_from_bytes(BytesIO(pil.tobytes()))
477
- return cls(ImplementPIL(pil, name))
500
+ return cls(ImplementPIL(pil))
478
501
 
479
502
 
480
- class CollectionImages(object):
503
+ class CollectionImages(ListItems):
481
504
 
482
- def __init__(self, images: list[ImageObject] = []) -> None:
505
+ def __init__(self, images: list[ImageObject]) -> None:
483
506
  """
484
507
  Gerir uma lista de Imagens
485
508
  :type images: list[ImageObject]
486
509
  """
487
- self.images: list[ImageObject] = images
510
+ super().__init__(images)
488
511
  self.pbar: ProgressBarAdapter = ProgressBarAdapter()
489
512
  self.__count: int = 0
490
513
 
491
- @property
492
- def length(self) -> int:
493
- return len(self.images)
494
-
495
- @property
496
- def is_empty(self) -> bool:
497
- return len(self.images) == 0
498
-
499
514
  def clear(self) -> None:
500
- self.images.clear()
515
+ self.clear()
501
516
  self.__count = 0
502
517
 
503
518
  def add_image(self, image: ImageObject) -> None:
504
519
  self.__count += 1
505
520
  self.pbar.update_text(f'Adicionando imagem {self.__count}')
506
- self.images.append(image)
521
+ self.append(image)
507
522
 
508
523
  def add_file_image(self, file: File) -> None:
509
524
  self.pbar.start()
510
525
  self.__count += 1
511
526
  self.pbar.update_text(f'Adicionando imagem {self.__count} {file.basename()}')
512
527
  im = ImageObject.create_from_file(file)
513
- self.images.append(im)
528
+ self.append(im)
514
529
  self.pbar.stop()
515
530
 
516
531
  def add_images(self, images: list[ImageObject]) -> None:
@@ -525,7 +540,7 @@ class CollectionImages(object):
525
540
  ((num+1) / max_num) * 100,
526
541
  f'Adicionando imagem: [{num+1} de {max_num}]'
527
542
  )
528
- self.images.append(ImageObject.create_from_file(f))
543
+ self.append(ImageObject.create_from_file(f))
529
544
  self.pbar.stop()
530
545
 
531
546
  def add_directory_images(self, d: Directory, max_files: int = 4000) -> None:
@@ -542,8 +557,8 @@ class CollectionImages(object):
542
557
  self.pbar.start()
543
558
  print()
544
559
  output_dir.mkdir()
545
- max_num = len(self.images)
546
- for n, img in enumerate(self.images):
560
+ max_num = self.length
561
+ for n, img in enumerate(self):
547
562
  filename = f'{img.name}.png'
548
563
  file_path = output_dir.join_file(filename)
549
564
  if (not replace) and (file_path.exists()):
@@ -566,13 +581,13 @@ class CollectionImages(object):
566
581
  self.pbar.stop()
567
582
 
568
583
  def set_land_scape(self):
569
- for im in self.images:
584
+ for im in self:
570
585
  im.set_landscape()
571
586
 
572
587
  def set_gausian_blur(self, sigma: float = 0.8) -> None:
573
588
  self.pbar.start()
574
589
  max_num: int = self.length
575
- for _num, im in enumerate(self.images):
590
+ for _num, im in enumerate(self):
576
591
  self.pbar.update(
577
592
  ((_num + 1) / max_num) * 100,
578
593
  f'Aplicando GausianBlur: [{_num + 1} de {max_num}]'
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env python3
2
+ #
3
+ from __future__ import annotations
4
+ from hashlib import md5 as md5_hash
5
+ from io import BytesIO
6
+ from .table_types import TextTable
7
+
8
+
9
+ def get_hash_from_bytes(bt: BytesIO | bytes) -> str:
10
+ if isinstance(bt, BytesIO):
11
+ return md5_hash(bt.getvalue()).hexdigest().upper()
12
+ elif isinstance(bt, bytes):
13
+ return md5_hash(bt).hexdigest().upper()
14
+ else:
15
+ raise TypeError(f"Unsupported type {type(bt)}")
16
+
17
+
18
+ def get_void_metadata() -> dict[str, str | None]:
19
+ """
20
+ Salvar os metadados básico de documentos/imagens lidas em disco.
21
+ """
22
+ return {
23
+ 'file_path': None,
24
+ 'dir_path': None,
25
+ 'name': None,
26
+ 'md5': None,
27
+ 'size': None,
28
+ 'extension': None,
29
+ 'origin_src': None,
30
+ }
31
+
32
+
@@ -1,33 +1,37 @@
1
1
  #!/usr/bin/env python3
2
-
3
2
  from enum import Enum
4
3
 
5
4
 
6
5
  class ColumnsTable(Enum):
6
+ """
7
+ Classe enum para padronizar os nomes das tabelas geradas por este módulo.
8
+ """
7
9
 
8
- NUM_LINHA = 'NUM_LINHA'
9
- NUM_PAGE = 'NUM_PÁGINA'
10
+ NUM_LINE = 'LINHA'
11
+ NUM_PAGE = 'PÁGINA'
10
12
  TEXT = 'TEXTO'
11
- FILE = 'ARQUIVO'
12
- FILENAME = 'NOME_ARQUIVO'
13
+ FILE_PATH = 'ARQUIVO'
14
+ FILE_NAME = 'NOME_ARQUIVO'
13
15
  DIR = 'PASTA'
14
16
  FILETYPE = 'TIPO_ARQUIVO'
17
+ KEY = 'KEY'
15
18
 
16
19
  @classmethod
17
20
  def to_list(cls) -> list[str]:
18
21
  return [
19
- cls.NUM_LINHA.value,
22
+ cls.NUM_LINE.value,
20
23
  cls.NUM_PAGE.value,
21
24
  cls.TEXT.value,
22
- cls.FILE.value,
23
- cls.FILENAME.value,
25
+ cls.FILE_PATH.value,
26
+ cls.FILE_NAME.value,
24
27
  cls.FILETYPE.value,
25
28
  cls.DIR.value,
29
+ cls.KEY.value,
26
30
  ]
27
31
 
28
32
 
29
33
  class LibPdfToImage(Enum):
30
-
34
+ """Enumerar as bibliotecas externas que convertem PDF em imagem"""
31
35
  PDF_TO_IMG_FITZ = 'fitz'
32
36
  NOT_IMPLEMENTED = 'null'
33
37
 
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
3
  from __future__ import annotations
4
- from typing import Union, TypeAlias, Any
5
- from convert_stream.enum_libs.enums import *
4
+ from typing import Union, TypeAlias
5
+ from convert_stream.mod_types.enums import *
6
6
 
7
7
  MOD_IMG_PIL: bool = False
8
8
  MOD_IMG_OPENCV: bool = False
@@ -10,6 +10,17 @@ MOD_PYPDF: bool = False
10
10
  MOD_FITZ: bool = False
11
11
  MOD_CANVAS: bool = False
12
12
 
13
+
14
+ class FakeType(object):
15
+ Image = object
16
+ MatLike = object
17
+ TextPage = object
18
+ Page = object
19
+
20
+ def __init__(self):
21
+ pass
22
+
23
+
13
24
  #=================================================================#
14
25
  # Módulos de Imagen, PIL e opencv
15
26
  #=================================================================#
@@ -18,16 +29,15 @@ try:
18
29
  from cv2.typing import MatLike
19
30
  MOD_IMG_OPENCV = True
20
31
  except ImportError:
21
- cv2.typing.MatLike = Any
22
- MatLike = Any
32
+ MatLike = FakeType
23
33
 
24
34
  try:
25
35
  from PIL import Image
26
36
  from PIL import ImageOps, ImageFilter
27
37
  MOD_IMG_PIL = True
28
38
  except ImportError:
29
- Image = Any
30
- Image.Image = Any
39
+ Image = FakeType
40
+ Image.Image = FakeType
31
41
 
32
42
  if MOD_IMG_OPENCV and MOD_IMG_PIL:
33
43
  ModuleImage: TypeAlias = Union[MatLike, Image.Image]
@@ -40,7 +50,7 @@ elif MOD_IMG_PIL:
40
50
  DEFAULT_LIB_IMAGE = LibImage.PIL
41
51
  else:
42
52
  DEFAULT_LIB_IMAGE = LibImage.NOT_IMPLEMENTED
43
- ModuleImage = Any # fallback para runtime
53
+ ModuleImage = FakeType
44
54
 
45
55
  #=================================================================#
46
56
  # Módulos para PDF fitz e pypdf
@@ -54,17 +64,17 @@ except ImportError:
54
64
  import pymupdf as fitz
55
65
  MOD_FITZ = True
56
66
  except ImportError:
57
- fitz = Any
58
- fitz.Page = Any
59
- fitz.TextPage = Any
67
+ fitz = FakeType
68
+ fitz.Page = FakeType
69
+ fitz.TextPage = FakeType
60
70
 
61
71
  try:
62
72
  from pypdf import PdfWriter, PdfReader, PageObject
63
73
  MOD_PYPDF = True
64
74
  except ImportError:
65
- PageObject = Any
66
- PdfReader = Any
67
- PdfWriter = Any
75
+ PageObject = FakeType
76
+ PdfReader = FakeType
77
+ PdfWriter = FakeType
68
78
 
69
79
 
70
80
  if MOD_FITZ and MOD_PYPDF:
@@ -80,8 +90,8 @@ elif MOD_PYPDF:
80
90
  ModDocPdf = Union[PdfWriter]
81
91
  DEFAULT_LIB_PDF = LibPDF.PYPDF
82
92
  else:
83
- ModPagePdf = Any # fallback para runtime
84
- ModDocPdf = Any
93
+ ModPagePdf = FakeType # fallback para runtime
94
+ ModDocPdf = FakeType
85
95
  DEFAULT_LIB_PDF = LibPDF.NOT_IMPLEMENTED
86
96
 
87
97
  #=================================================================#
@@ -95,10 +105,10 @@ try:
95
105
  from reportlab.lib.utils import ImageReader
96
106
  MOD_CANVAS = True
97
107
  except ImportError:
98
- canvas = Any
99
- Canvas = Any
108
+ canvas = FakeType
109
+ Canvas = FakeType
100
110
  letter = (612, 792)
101
- ImageReader = Any
111
+ ImageReader = FakeType
102
112
 
103
113
  if MOD_CANVAS and MOD_FITZ and MOD_IMG_PIL:
104
114
  ModImageToPdf: TypeAlias = Union[canvas, fitz.Page, Image]
@@ -113,7 +123,7 @@ elif MOD_IMG_PIL:
113
123
  ModImageToPdf: TypeAlias = Union[Image]
114
124
  DEFAULT_LIB_IMAGE_TO_PDF = LibImageToPdf.IMAGE_TO_PDF_PIL
115
125
  else:
116
- ModImageToPdf = Any
126
+ ModImageToPdf = FakeType
117
127
  DEFAULT_LIB_IMAGE_TO_PDF = LibImageToPdf.NOT_IMPLEMENTED
118
128
 
119
129
  #=================================================================#
@@ -125,4 +135,4 @@ if MOD_FITZ:
125
135
  ModPdfToImage: TypeAlias = Union[fitz]
126
136
  else:
127
137
  DEFAULT_LIB_PDF_TO_IMG = LibPdfToImage.NOT_IMPLEMENTED
128
- ModPdfToImage = Any
138
+ ModPdfToImage = FakeType