table-stream 0.1.5__tar.gz → 0.1.6__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.
- {table_stream-0.1.5 → table_stream-0.1.6}/PKG-INFO +1 -1
- {table_stream-0.1.5 → table_stream-0.1.6}/pyproject.toml +1 -1
- table_stream-0.1.6/table_stream/__init__.py +12 -0
- table_stream-0.1.5/table_stream/io/__init__.py → table_stream-0.1.6/table_stream/io.py +11 -1
- table_stream-0.1.6/table_stream/notifier.py +170 -0
- table_stream-0.1.6/table_stream/sheet/__init__.py +10 -0
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream/sheet/check_mod.py +2 -1
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream/sheet/load.py +145 -133
- table_stream-0.1.6/table_stream/sheet/options.py +73 -0
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream/sheet/parse.py +84 -36
- table_stream-0.1.6/table_stream/sheet/save.py +168 -0
- table_stream-0.1.6/table_stream/state.py +284 -0
- table_stream-0.1.6/table_stream/thread.py +138 -0
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream.egg-info/PKG-INFO +1 -1
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream.egg-info/SOURCES.txt +9 -7
- table_stream-0.1.5/table_stream/__init__.py +0 -6
- table_stream-0.1.5/table_stream/sheet/__init__.py +0 -10
- table_stream-0.1.5/table_stream/sheet/options.py +0 -113
- table_stream-0.1.5/table_stream/sheet/save.py +0 -277
- table_stream-0.1.5/table_stream/thread/__init__.py +0 -368
- {table_stream-0.1.5 → table_stream-0.1.6}/README.md +0 -0
- {table_stream-0.1.5 → table_stream-0.1.6}/setup.cfg +0 -0
- /table_stream-0.1.5/table_stream/erros/__init__.py → /table_stream-0.1.6/table_stream/erros.py +0 -0
- /table_stream-0.1.5/table_stream/hash_map/__init__.py → /table_stream-0.1.6/table_stream/hash_map.py +0 -0
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream/pattner/__init__.py +0 -0
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream/pattner/adapter.py +0 -0
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream/pattner/observer.py +0 -0
- /table_stream-0.1.5/table_stream/sysfiles/__init__.py → /table_stream-0.1.6/table_stream/sysfiles.py +0 -0
- /table_stream-0.1.5/table_stream/workbook/__init__.py → /table_stream-0.1.6/table_stream/workbook.py +0 -0
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream.egg-info/dependency_links.txt +0 -0
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream.egg-info/requires.txt +0 -0
- {table_stream-0.1.5 → table_stream-0.1.6}/table_stream.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from .hash_map import HashMap, hashMapName, HashMapDataFrame, HashMapDict, ArrayList, K, T
|
|
2
|
+
from .notifier import ValueNotifier, ChangeNotifier, Provider, Consumer
|
|
3
|
+
from .thread import (
|
|
4
|
+
ControllerThread, ThreadStateContext, ConsumerThread, exceptionValue, stateName,
|
|
5
|
+
EventState, InvalidStateTransition,
|
|
6
|
+
)
|
|
7
|
+
from .sheet import (
|
|
8
|
+
SheetLoader, InterfaceSheetLoad, ParserData, CsvOptions, SplitData,
|
|
9
|
+
csvEncoding, csvSeparator, OptionsIOSheet, SaveData,
|
|
10
|
+
FactorySaveData, FactorySheetLoader, SheetType,
|
|
11
|
+
)
|
|
12
|
+
from .state import ContextState, EventState
|
|
@@ -104,6 +104,9 @@ class BytesOutputStream(OutputStream):
|
|
|
104
104
|
|
|
105
105
|
class InputStream(ABC):
|
|
106
106
|
|
|
107
|
+
def __init__(self) -> None:
|
|
108
|
+
super().__init__()
|
|
109
|
+
|
|
107
110
|
@abstractmethod
|
|
108
111
|
def clear(self):
|
|
109
112
|
pass
|
|
@@ -139,8 +142,12 @@ class InputStream(ABC):
|
|
|
139
142
|
class FileInputStream(InputStream):
|
|
140
143
|
|
|
141
144
|
def __init__(self, file_path: File):
|
|
145
|
+
super().__init__()
|
|
146
|
+
if not file_path.exists():
|
|
147
|
+
raise FileNotFoundError(f'{__class__.__name__} arquivo não encontrado')
|
|
148
|
+
|
|
142
149
|
self.file_path: File = file_path
|
|
143
|
-
self._file_buff = None
|
|
150
|
+
self._file_buff: BufferedReader | None = None
|
|
144
151
|
|
|
145
152
|
def to_io(self) -> BytesIO:
|
|
146
153
|
buff = self.get_buffer()
|
|
@@ -156,6 +163,8 @@ class FileInputStream(InputStream):
|
|
|
156
163
|
return self.get_buffer().read(size)
|
|
157
164
|
|
|
158
165
|
def close(self):
|
|
166
|
+
if self._file_buff is None:
|
|
167
|
+
return
|
|
159
168
|
self._file_buff.close()
|
|
160
169
|
|
|
161
170
|
def clear(self):
|
|
@@ -170,6 +179,7 @@ class FileInputStream(InputStream):
|
|
|
170
179
|
class BytesInputStream(InputStream):
|
|
171
180
|
|
|
172
181
|
def __init__(self, data: bytes):
|
|
182
|
+
super().__init__()
|
|
173
183
|
if not isinstance(data, (bytes, bytearray)):
|
|
174
184
|
raise TypeError("BytesInputStream aceita apenas bytes ou bytearray!")
|
|
175
185
|
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# notifier.py
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
from abc import ABC, abstractmethod, ABCMeta
|
|
4
|
+
from typing import Any, Callable, Optional, Type, TypeVar, cast
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
T = TypeVar("T")
|
|
8
|
+
P = TypeVar('P', bound="ChangeNotifier")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# ============================================================
|
|
12
|
+
# CHANGE NOTIFIER
|
|
13
|
+
# ============================================================
|
|
14
|
+
class ChangeNotifier[T]:
|
|
15
|
+
|
|
16
|
+
def __init__(self) -> None:
|
|
17
|
+
#super().__init__()
|
|
18
|
+
self._listeners: list[Callable[[], None]] = []
|
|
19
|
+
|
|
20
|
+
def add_listener(self, listener: Consumer) -> None:
|
|
21
|
+
if listener not in self._listeners:
|
|
22
|
+
self._listeners.append(listener.receiver_notifier)
|
|
23
|
+
|
|
24
|
+
def remove_listener(self, listener: Callable[[], None]) -> None:
|
|
25
|
+
if listener in self._listeners:
|
|
26
|
+
self._listeners.remove(listener)
|
|
27
|
+
|
|
28
|
+
def notify_listeners(self) -> None:
|
|
29
|
+
for listener in self._listeners: #.copy():
|
|
30
|
+
listener()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ValueNotifier[T](ChangeNotifier):
|
|
34
|
+
|
|
35
|
+
def __init__(self, value: T) -> None:
|
|
36
|
+
super().__init__()
|
|
37
|
+
self._value: T = value
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def value(self) -> T:
|
|
41
|
+
return self._value
|
|
42
|
+
|
|
43
|
+
@value.setter
|
|
44
|
+
def value(self, value: T) -> None:
|
|
45
|
+
self._value = value
|
|
46
|
+
self.notify_listeners()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class MapState[K, P]:
|
|
50
|
+
|
|
51
|
+
_instance: "MapState | None" = None
|
|
52
|
+
|
|
53
|
+
def __new__(cls, *args, **kwargs) -> "MapState":
|
|
54
|
+
if cls._instance is None:
|
|
55
|
+
cls._instance = super().__new__(cls)
|
|
56
|
+
return cls._instance
|
|
57
|
+
|
|
58
|
+
def __init__(self) -> None:
|
|
59
|
+
if not hasattr(self, "values"):
|
|
60
|
+
self.values: dict = dict()
|
|
61
|
+
|
|
62
|
+
def __setitem__(self, key: K, value: P):
|
|
63
|
+
self.values[key] = value
|
|
64
|
+
|
|
65
|
+
def __getitem__(self, key: K) -> P:
|
|
66
|
+
return self.values[key]
|
|
67
|
+
|
|
68
|
+
def contains_key(self, key: K) -> bool:
|
|
69
|
+
for k in self.values.keys():
|
|
70
|
+
if k == key:
|
|
71
|
+
return True
|
|
72
|
+
return False
|
|
73
|
+
|
|
74
|
+
def add(self, value: P):
|
|
75
|
+
_type_value: K = type(value)
|
|
76
|
+
if not self.contains_key(_type_value):
|
|
77
|
+
self.values[_type_value] = value
|
|
78
|
+
|
|
79
|
+
def read(self, key: type[P]) -> P:
|
|
80
|
+
return self.values[key]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class Provider(object):
|
|
84
|
+
|
|
85
|
+
_states: MapState = MapState()
|
|
86
|
+
_instance: "Provider | None" = None
|
|
87
|
+
|
|
88
|
+
def __new__(cls) -> "Provider":
|
|
89
|
+
if cls._instance is None:
|
|
90
|
+
cls._instance = super().__new__(cls)
|
|
91
|
+
return cls._instance
|
|
92
|
+
|
|
93
|
+
def __init__(self) -> None:
|
|
94
|
+
pass
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
def add_state(cls, notifier: P) -> None:
|
|
98
|
+
print(f'[DEBUG] ... Estado adicionado ... {notifier}')
|
|
99
|
+
cls._states.add(notifier)
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def read(cls, type_notifier: type[P]) -> P:
|
|
103
|
+
return cls._states.read(type_notifier)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class Consumer[P](ABC):
|
|
107
|
+
"""
|
|
108
|
+
Consumer(): observa um ChangeNotifier registrado no Provider() e
|
|
109
|
+
permite que o Widget/Element associado seja notificado (via
|
|
110
|
+
receiver_notifier) sempre que o estado observado mudar.
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
def __init__(self, type_notifier: type[P]) -> None:
|
|
114
|
+
super().__init__()
|
|
115
|
+
self.type_notifier: type[P] = type_notifier
|
|
116
|
+
self.func_read_notifier: Callable[[type[P]], P] = Provider.read
|
|
117
|
+
|
|
118
|
+
# Notifiers já observados por este Consumer (evita registrar o
|
|
119
|
+
# mesmo listener duas vezes a cada build(), e permite unwatch_all()).
|
|
120
|
+
self._watched: dict[type[P], P] = dict()
|
|
121
|
+
|
|
122
|
+
def read_notifier(self, type_notifier: type[P]) -> P:
|
|
123
|
+
return self.func_read_notifier(type_notifier)
|
|
124
|
+
|
|
125
|
+
def read(self) -> P:
|
|
126
|
+
return self.func_read_notifier(self.type_notifier)
|
|
127
|
+
|
|
128
|
+
def watch(self, type_notifier: type[P]) -> P:
|
|
129
|
+
"""
|
|
130
|
+
Lê o estado do Provider() e garante inscrição para receber
|
|
131
|
+
notificações de mudança. Uso típico dentro de build():
|
|
132
|
+
|
|
133
|
+
estado = self.watch(MeuNotifier)
|
|
134
|
+
"""
|
|
135
|
+
#type_notifier: type[ChangeNotifier] = type(type_notifier)
|
|
136
|
+
|
|
137
|
+
if not isinstance(type_notifier, ChangeNotifier):
|
|
138
|
+
print(
|
|
139
|
+
f'[ALERTA] ... {type_notifier.__name__} não é um ChangeNotifier e não '
|
|
140
|
+
f'pode ser observado via watch(). Use Provider.read() '
|
|
141
|
+
f'diretamente se só precisa ler o valor uma vez.'
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
notifier: ChangeNotifier = cast(ChangeNotifier, self.read_notifier(type_notifier))
|
|
145
|
+
|
|
146
|
+
if type_notifier not in self._watched:
|
|
147
|
+
notifier.add_listener(self)
|
|
148
|
+
self._watched[type_notifier] = notifier
|
|
149
|
+
return notifier
|
|
150
|
+
|
|
151
|
+
def unwatch_all(self) -> None:
|
|
152
|
+
"""
|
|
153
|
+
Remove este Consumer de todos os notifiers observados.
|
|
154
|
+
Deve ser chamado no dispose() do Element associado, para evitar
|
|
155
|
+
que um notifier segure referência viva de um widget já destruído.
|
|
156
|
+
"""
|
|
157
|
+
notifier: ChangeNotifier
|
|
158
|
+
for notifier in self._watched.values():
|
|
159
|
+
notifier.remove_listener(self.receiver_notifier)
|
|
160
|
+
self._watched.clear()
|
|
161
|
+
|
|
162
|
+
@abstractmethod
|
|
163
|
+
def receiver_notifier(self) -> None:
|
|
164
|
+
"""
|
|
165
|
+
Callback chamado pelo ChangeNotifier observado. Subclasses
|
|
166
|
+
(ex: um ConsumerElement) devem sobrescrever isto para disparar
|
|
167
|
+
o rebuild do widget associado.
|
|
168
|
+
"""
|
|
169
|
+
pass
|
|
170
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from .options import (
|
|
2
|
+
csvEncoding, csvSeparator, SheetType, CsvOptions, OptionsIOSheet
|
|
3
|
+
)
|
|
4
|
+
from .load import (
|
|
5
|
+
SheetLoader, FactorySheetLoader, InterfaceSheetLoad
|
|
6
|
+
)
|
|
7
|
+
from .save import FactorySaveData, SaveData
|
|
8
|
+
from .parse import ParserData, SplitData
|
|
9
|
+
|
|
10
|
+
|