Qwael 3.9.0__tar.gz → 3.9.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Qwael
3
- Version: 3.9.0
3
+ Version: 3.9.2
4
4
  Summary: Qwael: İşlevsel ve kolaylaştırılmış Python kütüphanesi
5
5
  Author: Bedirhan
6
6
  Author-email: bedirhan.oytpass@gmail.com
@@ -0,0 +1,325 @@
1
+ import os
2
+ import json
3
+
4
+ class MultiDB:
5
+ def __init__(self, filename="database.mdb"):
6
+ self.filename = filename
7
+ self.lockfile = filename + ".lock"
8
+
9
+ if not os.path.exists(self.filename):
10
+ with open(self.filename, "w", encoding="utf-8") as f:
11
+ f.write("")
12
+
13
+ # -----------------------------
14
+ # LOCK SYSTEM
15
+ # -----------------------------
16
+ def _lock(self):
17
+ with open(self.lockfile, "w") as f:
18
+ f.write("locked")
19
+
20
+ def _unlock(self):
21
+ if os.path.exists(self.lockfile):
22
+ os.remove(self.lockfile)
23
+
24
+ # -----------------------------
25
+ # FILE I/O
26
+ # -----------------------------
27
+ def _read(self):
28
+ with open(self.filename, "r", encoding="utf-8") as f:
29
+ return f.read().splitlines()
30
+
31
+ def _write(self, lines):
32
+ with open(self.filename, "w", encoding="utf-8") as f:
33
+ f.write("\n".join(lines))
34
+
35
+ # -----------------------------
36
+ # TABLE FINDER
37
+ # -----------------------------
38
+ def _find_table(self, lines, table):
39
+ for i, line in enumerate(lines):
40
+ if line.strip() == f"[TABLE {table}]":
41
+ return i
42
+ return -1
43
+
44
+ # -----------------------------
45
+ # RULE SPLITTER (25 LIMIT)
46
+ # -----------------------------
47
+ def _split_rules(self, rule):
48
+ if not rule:
49
+ return []
50
+
51
+ rule = rule.replace(" ", "").replace("+", ",").replace("#-", ",#-")
52
+ rules = [r for r in rule.split(",") if r]
53
+
54
+ if len(rules) > 25:
55
+ raise ValueError("Bir sütun için maksimum 25 kural eklenebilir!")
56
+
57
+ return rules
58
+
59
+ # -----------------------------
60
+ # CREATE TABLE
61
+ # -----------------------------
62
+ def create_table(self, name, columns):
63
+ self._lock()
64
+ lines = self._read()
65
+
66
+ if self._find_table(lines, name) != -1:
67
+ self._unlock()
68
+ raise ValueError("Bu tablo zaten var!")
69
+
70
+ col_names = []
71
+ rules = {}
72
+
73
+ for col in columns:
74
+ if isinstance(col, dict):
75
+ key = list(col.keys())[0]
76
+ rule = col[key]
77
+ col_names.append(key)
78
+ rules[key] = rule
79
+ else:
80
+ col_names.append(col)
81
+ rules[col] = ""
82
+
83
+ lines.append(f"[TABLE {name}]")
84
+ lines.append(json.dumps(col_names, ensure_ascii=False))
85
+ lines.append(json.dumps(rules, ensure_ascii=False))
86
+
87
+ self._write(lines)
88
+ self._unlock()
89
+
90
+ # -----------------------------
91
+ # VALIDATION
92
+ # -----------------------------
93
+ def _validate(self, value, rule, lines, table_pos, col_index):
94
+ rules = self._split_rules(rule)
95
+
96
+ for r in rules:
97
+ if r == "ID":
98
+ continue
99
+
100
+ if r == "number":
101
+ if not value.isdigit():
102
+ return False
103
+
104
+ if r == "gmail":
105
+ if not ("@" in value and value.endswith(".com")):
106
+ return False
107
+
108
+ if r == "big":
109
+ if not all(ch.isupper() or ch.isdigit() for ch in value):
110
+ return False
111
+
112
+ if r == "small":
113
+ # small kuralı artık tüm value için geçerli (domain dahil)
114
+ if not all(ch.islower() or ch.isdigit() or ch in "@." for ch in value):
115
+ return False
116
+
117
+ if r == "#-":
118
+ idx = table_pos + 3
119
+ while idx < len(lines) and not lines[idx].startswith("[TABLE"):
120
+ row = json.loads(lines[idx])
121
+ if row[col_index] == value:
122
+ return False
123
+ idx += 1
124
+
125
+ return True
126
+
127
+ # -----------------------------
128
+ # GIVE (True/False destekli)
129
+ # -----------------------------
130
+ def give(self, table, values, output_list=None):
131
+ try:
132
+ self._lock()
133
+ lines = self._read()
134
+
135
+ tpos = self._find_table(lines, table)
136
+ if tpos == -1:
137
+ raise ValueError("Tablo bulunamadı!")
138
+
139
+ col_names = json.loads(lines[tpos + 1])
140
+ rules = json.loads(lines[tpos + 2])
141
+
142
+ final_values = []
143
+
144
+ # AUTO ID
145
+ if len(values) + 1 == len(col_names) and "ID" in rules.values():
146
+ auto_id = 1
147
+ idx = tpos + 3
148
+ while idx < len(lines) and not lines[idx].startswith("[TABLE"):
149
+ row = json.loads(lines[idx])
150
+ auto_id = max(auto_id, int(row[0]) + 1)
151
+ idx += 1
152
+
153
+ final_values.append(str(auto_id))
154
+ final_values.extend(values)
155
+
156
+ elif len(values) != len(col_names):
157
+ raise ValueError("Gönderilen veri sayısı yanlış!")
158
+
159
+ else:
160
+ final_values = values[:]
161
+
162
+ # VALIDATION
163
+ for i, col in enumerate(col_names):
164
+ rule = rules[col]
165
+ if not self._validate(final_values[i], rule, lines, tpos, i):
166
+ raise ValueError(f"{col} alanı için veri kurala uymuyor: {rule}")
167
+
168
+ # Insert
169
+ lines.insert(tpos + 3, json.dumps(final_values, ensure_ascii=False))
170
+ self._write(lines)
171
+ self._unlock()
172
+
173
+ if output_list is not None:
174
+ output_list.append(True)
175
+
176
+ return True
177
+
178
+ except Exception:
179
+ if output_list is not None:
180
+ output_list.append(False)
181
+ return False
182
+ raise
183
+
184
+ finally:
185
+ self._unlock()
186
+
187
+ # -----------------------------
188
+ # READ FULL TABLE
189
+ # -----------------------------
190
+ def table_full(self, table):
191
+ lines = self._read()
192
+ tpos = self._find_table(lines, table)
193
+ if tpos == -1:
194
+ raise ValueError("Tablo yok!")
195
+
196
+ result = []
197
+ idx = tpos + 3
198
+ while idx < len(lines) and not lines[idx].startswith("[TABLE"):
199
+ result.append(json.loads(lines[idx]))
200
+ idx += 1
201
+ return result
202
+
203
+ # -----------------------------
204
+ # CLEAR DATA (Keep structure)
205
+ # -----------------------------
206
+ def clear_full(self, table):
207
+ self._lock()
208
+ lines = self._read()
209
+ tpos = self._find_table(lines, table)
210
+ if tpos == -1:
211
+ self._unlock()
212
+ raise ValueError("Tablo bulunamadı!")
213
+
214
+ new_lines = []
215
+ i = 0
216
+ while i < len(lines):
217
+ if i != tpos:
218
+ new_lines.append(lines[i])
219
+ i += 1
220
+ continue
221
+
222
+ new_lines.append(lines[i])
223
+ new_lines.append(lines[i + 1])
224
+ new_lines.append(lines[i + 2])
225
+
226
+ j = i + 3
227
+ while j < len(lines) and not lines[j].startswith("[TABLE"):
228
+ j += 1
229
+ i = j
230
+
231
+ self._write(new_lines)
232
+ self._unlock()
233
+
234
+ # -----------------------------
235
+ # UPDATE TABLE
236
+ # -----------------------------
237
+ def table_update(self, table, columns):
238
+ self._lock()
239
+ lines = self._read()
240
+ tpos = self._find_table(lines, table)
241
+ if tpos == -1:
242
+ self._unlock()
243
+ raise ValueError("Böyle bir tablo yok!")
244
+
245
+ col_names = []
246
+ rules = {}
247
+ for col in columns:
248
+ if isinstance(col, dict):
249
+ key = list(col.keys())[0]
250
+ col_names.append(key)
251
+ rules[key] = col[key]
252
+ else:
253
+ col_names.append(col)
254
+ rules[col] = ""
255
+
256
+ data_rows = []
257
+ idx = tpos + 3
258
+ while idx < len(lines) and not lines[idx].startswith("[TABLE"):
259
+ data_rows.append(json.loads(lines[idx]))
260
+ idx += 1
261
+
262
+ new_data_rows = []
263
+ old_cols = json.loads(lines[tpos + 1])
264
+ for row in data_rows:
265
+ new_row = []
266
+ for col in col_names:
267
+ if col in old_cols:
268
+ new_row.append(row[old_cols.index(col)])
269
+ else:
270
+ new_row.append("")
271
+ new_data_rows.append(new_row)
272
+
273
+ new_lines = []
274
+ i = 0
275
+ while i < len(lines):
276
+ if i == tpos:
277
+ new_lines.append(f"[TABLE {table}]")
278
+ new_lines.append(json.dumps(col_names, ensure_ascii=False))
279
+ new_lines.append(json.dumps(rules, ensure_ascii=False))
280
+ for row in new_data_rows:
281
+ new_lines.append(json.dumps(row, ensure_ascii=False))
282
+
283
+ j = tpos + 3
284
+ while j < len(lines) and not lines[j].startswith("[TABLE"):
285
+ j += 1
286
+ i = j
287
+ else:
288
+ new_lines.append(lines[i])
289
+ i += 1
290
+
291
+ self._write(new_lines)
292
+ self._unlock()
293
+
294
+ # -----------------------------
295
+ # CONTROL SYSTEM
296
+ # -----------------------------
297
+ def control(self, table, conditions: dict, output_list=None):
298
+ lines = self._read()
299
+ tpos = self._find_table(lines, table)
300
+ if tpos == -1:
301
+ raise ValueError("Tablo bulunamadı!")
302
+
303
+ col_names = json.loads(lines[tpos + 1])
304
+ col_indexes = {k: col_names.index(k) for k in conditions}
305
+
306
+ found = False
307
+ idx = tpos + 3
308
+ while idx < len(lines) and not lines[idx].startswith("[TABLE"):
309
+ row = json.loads(lines[idx])
310
+ match = True
311
+ for key, val in conditions.items():
312
+ if row[col_indexes[key]] != val:
313
+ match = False
314
+ break
315
+ if match:
316
+ found = True
317
+ break
318
+ idx += 1
319
+
320
+ if output_list is None:
321
+ print("Var" if found else "Yok")
322
+ else:
323
+ output_list.append(found)
324
+
325
+ return found
@@ -4,4 +4,5 @@ from .DRİVE import info
4
4
  from .DRİVE import delete
5
5
  from .DRİVE import get
6
6
  from .DoIP import IP
7
- from .filesz import EasyDB
7
+ from .filesz import EasyDB
8
+ from .MultiDB import MultiDB
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Qwael
3
- Version: 3.9.0
3
+ Version: 3.9.2
4
4
  Summary: Qwael: İşlevsel ve kolaylaştırılmış Python kütüphanesi
5
5
  Author: Bedirhan
6
6
  Author-email: bedirhan.oytpass@gmail.com
@@ -3,6 +3,7 @@ README.md
3
3
  setup.py
4
4
  Qwael/DRİVE.py
5
5
  Qwael/DoIP.py
6
+ Qwael/MultiDB.py
6
7
  Qwael/__init__.py
7
8
  Qwael/filesz.py
8
9
  Qwael.egg-info/PKG-INFO
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as f:
5
5
 
6
6
  setup(
7
7
  name="Qwael",
8
- version="3.9.0",
8
+ version="3.9.2",
9
9
  packages=find_packages(),
10
10
  install_requires=[
11
11
  "google-api-python-client",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes