Kekik 1.6.2__tar.gz → 1.6.4__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.

Potentially problematic release.


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

Files changed (48) hide show
  1. {kekik-1.6.2 → kekik-1.6.4}/Kekik/cache.py +57 -21
  2. {kekik-1.6.2 → kekik-1.6.4}/Kekik.egg-info/PKG-INFO +1 -1
  3. {kekik-1.6.2 → kekik-1.6.4}/PKG-INFO +1 -1
  4. {kekik-1.6.2 → kekik-1.6.4}/setup.py +1 -1
  5. {kekik-1.6.2 → kekik-1.6.4}/Kekik/BIST.py +0 -0
  6. {kekik-1.6.2 → kekik-1.6.4}/Kekik/Domain2IP.py +0 -0
  7. {kekik-1.6.2 → kekik-1.6.4}/Kekik/Nesne.py +0 -0
  8. {kekik-1.6.2 → kekik-1.6.4}/Kekik/Sifreleme/AESManager.py +0 -0
  9. {kekik-1.6.2 → kekik-1.6.4}/Kekik/Sifreleme/CryptoJS.py +0 -0
  10. {kekik-1.6.2 → kekik-1.6.4}/Kekik/Sifreleme/HexCodec.py +0 -0
  11. {kekik-1.6.2 → kekik-1.6.4}/Kekik/Sifreleme/NaysHash.py +0 -0
  12. {kekik-1.6.2 → kekik-1.6.4}/Kekik/Sifreleme/Packer.py +0 -0
  13. {kekik-1.6.2 → kekik-1.6.4}/Kekik/Sifreleme/StringCodec.py +0 -0
  14. {kekik-1.6.2 → kekik-1.6.4}/Kekik/Sifreleme/__init__.py +0 -0
  15. {kekik-1.6.2 → kekik-1.6.4}/Kekik/__init__.py +0 -0
  16. {kekik-1.6.2 → kekik-1.6.4}/Kekik/cli.py +0 -0
  17. {kekik-1.6.2 → kekik-1.6.4}/Kekik/csv2dict.py +0 -0
  18. {kekik-1.6.2 → kekik-1.6.4}/Kekik/dict2csv.py +0 -0
  19. {kekik-1.6.2 → kekik-1.6.4}/Kekik/dict2json.py +0 -0
  20. {kekik-1.6.2 → kekik-1.6.4}/Kekik/dosya2set.py +0 -0
  21. {kekik-1.6.2 → kekik-1.6.4}/Kekik/dosya_indir.py +0 -0
  22. {kekik-1.6.2 → kekik-1.6.4}/Kekik/hwid_kontrol.py +0 -0
  23. {kekik-1.6.2 → kekik-1.6.4}/Kekik/kisi_ver/__init__.py +0 -0
  24. {kekik-1.6.2 → kekik-1.6.4}/Kekik/kisi_ver/biyografiler.py +0 -0
  25. {kekik-1.6.2 → kekik-1.6.4}/Kekik/kisi_ver/isimler.py +0 -0
  26. {kekik-1.6.2 → kekik-1.6.4}/Kekik/kisi_ver/soyisimler.py +0 -0
  27. {kekik-1.6.2 → kekik-1.6.4}/Kekik/link_islemleri.py +0 -0
  28. {kekik-1.6.2 → kekik-1.6.4}/Kekik/list2html.py +0 -0
  29. {kekik-1.6.2 → kekik-1.6.4}/Kekik/liste_fetis.py +0 -0
  30. {kekik-1.6.2 → kekik-1.6.4}/Kekik/mail_gonder.py +0 -0
  31. {kekik-1.6.2 → kekik-1.6.4}/Kekik/okunabilir_byte.py +0 -0
  32. {kekik-1.6.2 → kekik-1.6.4}/Kekik/proxy_ver.py +0 -0
  33. {kekik-1.6.2 → kekik-1.6.4}/Kekik/qr_ver.py +0 -0
  34. {kekik-1.6.2 → kekik-1.6.4}/Kekik/ses_fetis.py +0 -0
  35. {kekik-1.6.2 → kekik-1.6.4}/Kekik/slugify.py +0 -0
  36. {kekik-1.6.2 → kekik-1.6.4}/Kekik/terminal_baslik.py +0 -0
  37. {kekik-1.6.2 → kekik-1.6.4}/Kekik/txt_fetis.py +0 -0
  38. {kekik-1.6.2 → kekik-1.6.4}/Kekik/unicode_tr.py +0 -0
  39. {kekik-1.6.2 → kekik-1.6.4}/Kekik/zaman_donustur.py +0 -0
  40. {kekik-1.6.2 → kekik-1.6.4}/Kekik.egg-info/SOURCES.txt +0 -0
  41. {kekik-1.6.2 → kekik-1.6.4}/Kekik.egg-info/dependency_links.txt +0 -0
  42. {kekik-1.6.2 → kekik-1.6.4}/Kekik.egg-info/entry_points.txt +0 -0
  43. {kekik-1.6.2 → kekik-1.6.4}/Kekik.egg-info/requires.txt +0 -0
  44. {kekik-1.6.2 → kekik-1.6.4}/Kekik.egg-info/top_level.txt +0 -0
  45. {kekik-1.6.2 → kekik-1.6.4}/LICENSE +0 -0
  46. {kekik-1.6.2 → kekik-1.6.4}/MANIFEST.in +0 -0
  47. {kekik-1.6.2 → kekik-1.6.4}/README.md +0 -0
  48. {kekik-1.6.2 → kekik-1.6.4}/setup.cfg +0 -0
@@ -1,8 +1,10 @@
1
1
  # ! https://github.com/Fatal1ty/aiocached
2
2
 
3
3
  import asyncio
4
- from functools import wraps
5
- from time import time
4
+ from functools import wraps
5
+ from time import time
6
+ from hashlib import md5
7
+ from urllib.parse import urlencode
6
8
 
7
9
  UNLIMITED = None
8
10
 
@@ -87,51 +89,85 @@ def _sync_maybe_cache(func, key, result, unless):
87
89
 
88
90
  async def _async_compute_and_cache(func, key, unless, *args, **kwargs):
89
91
  """
90
- Asenkron fonksiyon sonucu hesaplandıktan sonra, sonucu cachee ekler.
91
- Eğer `unless` koşulu sağlanıyorsa cache kaydı atlanır.
92
+ Asenkron fonksiyon sonucunu hesaplar ve cache'e ekler.
93
+ Aynı key için işlem devam ediyorsa, mevcut sonucu bekler.
94
+ Sonuç, unless(result) True değilse cache'e eklenir.
92
95
  """
93
- cache = func.__cache
96
+ # __cache'den cache nesnesini alıyoruz.
97
+ cache = func.__cache
98
+
99
+ # Aynı key için aktif bir future varsa, onun sonucunu döndür.
100
+ if key in cache.futures:
101
+ return await cache.futures[key]
102
+
103
+ # Yeni future oluşturuluyor ve cache.futures'e ekleniyor.
94
104
  future = asyncio.Future()
95
105
  cache.futures[key] = future
96
106
 
97
107
  try:
108
+ # Asenkron fonksiyonu çalıştır ve sonucu elde et.
98
109
  result = await func(*args, **kwargs)
110
+ future.set_result(result)
111
+
112
+ # unless koşuluna göre cache'e ekleme yap.
113
+ if unless is None or not unless(result):
114
+ await cache.set(key, result)
115
+
116
+ return result
99
117
  except Exception as exc:
100
- cache.futures.pop(key, None)
101
118
  future.cancel()
102
119
  raise exc
120
+ finally:
121
+ # İşlem tamamlandığında future'ı temizle.
122
+ cache.futures.pop(key, None)
123
+
124
+ async def make_cache_key(args, kwargs, is_fastapi=False):
125
+ """
126
+ Cache key'ini oluşturur.
127
+
128
+ :param is_fastapi (bool): Eğer True ise, ilk argümanın bir FastAPI Request nesnesi olduğu varsayılır.
129
+ Bu durumda, cache key, request nesnesinin URL yolunu (request.url.path) ve
130
+ isteğe ait verilerden (GET istekleri için query parametreleri; diğer istekler için JSON veya form verileri)
131
+ elde edilen verinin URL uyumlu halinin md5 hash'inin birleşiminden oluşturulur.
132
+ Böylece, aynı URL ve aynı istek verileri için her seferinde aynı cache key üretilecektir.
133
+ Eğer False ise, cache key args ve kwargs değerlerinden, sıralı bir tuple olarak oluşturulur.
134
+ """
135
+ if not is_fastapi:
136
+ return (args, tuple(sorted(kwargs.items())))
103
137
 
104
- future.set_result(result)
138
+ request = args[0] if args else kwargs.get("request")
105
139
 
106
- if unless is None or not unless(result):
107
- cache[key] = result
140
+ if request.method == "GET":
141
+ veri = dict(request.query_params) if request.query_params else None
108
142
  else:
109
- cache.futures.pop(key, None)
110
-
111
- return result
143
+ try:
144
+ veri = await request.json()
145
+ except Exception:
146
+ form_data = await request.form()
147
+ veri = dict(form_data.items())
112
148
 
113
- def make_cache_key(args, kwargs):
114
- """Fonksiyon argümanlarından cache için kullanılacak key’i oluşturur."""
115
- return (args, tuple(sorted(kwargs.items())))
149
+ args_hash = md5(urlencode(veri).encode()).hexdigest() if veri else ""
150
+ return f"{request.url.path}?{args_hash}"
116
151
 
117
152
 
118
- def kekik_cache(ttl=UNLIMITED, unless=None):
153
+ def kekik_cache(ttl=UNLIMITED, unless=None, is_fastapi=False):
119
154
  """
120
155
  Bir fonksiyon veya coroutine'in sonucunu cache'ler.
121
156
 
122
157
  :param ttl: Cache’in geçerlilik süresi (saniye). UNLIMITED ise süresizdir.
123
158
  :param unless: Fonksiyonun sonucunu argüman olarak alan bir callable.
124
159
  Eğer True dönerse, sonuç cache'e alınmaz.
125
-
160
+ :param is_fastapi: Eğer True ise, cache key'i oluştururken FastAPI request nesnesine özel şekilde davranır.
161
+
126
162
  Örnek kullanım:
127
163
 
128
164
  @kekik_cache(ttl=15, unless=lambda res: res is None)
129
- async def my_func(param):
165
+ async def bakalim(param):
130
166
  ...
131
167
  """
132
168
  # Parametresiz kullanıldığında
133
169
  if callable(ttl):
134
- return kekik_cache(UNLIMITED, unless=unless)(ttl)
170
+ return kekik_cache(UNLIMITED, unless=unless, is_fastapi=is_fastapi)(ttl)
135
171
 
136
172
  def decorator(func):
137
173
  func.__cache = AsyncCache(ttl)
@@ -139,7 +175,7 @@ def kekik_cache(ttl=UNLIMITED, unless=None):
139
175
  if asyncio.iscoroutinefunction(func):
140
176
  @wraps(func)
141
177
  async def async_wrapper(*args, **kwargs):
142
- key = make_cache_key(args, kwargs)
178
+ key = await make_cache_key(args, kwargs, is_fastapi)
143
179
 
144
180
  try:
145
181
  return await func.__cache.get(key)
@@ -150,7 +186,7 @@ def kekik_cache(ttl=UNLIMITED, unless=None):
150
186
  else:
151
187
  @wraps(func)
152
188
  def sync_wrapper(*args, **kwargs):
153
- key = make_cache_key(args, kwargs)
189
+ key = (args, tuple(sorted(kwargs.items())))
154
190
 
155
191
  try:
156
192
  return func.__cache[key]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: Kekik
3
- Version: 1.6.2
3
+ Version: 1.6.4
4
4
  Summary: İşlerimizi kolaylaştıracak fonksiyonların el altında durduğu kütüphane..
5
5
  Home-page: https://github.com/keyiflerolsun/Kekik
6
6
  Author: keyiflerolsun
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: Kekik
3
- Version: 1.6.2
3
+ Version: 1.6.4
4
4
  Summary: İşlerimizi kolaylaştıracak fonksiyonların el altında durduğu kütüphane..
5
5
  Home-page: https://github.com/keyiflerolsun/Kekik
6
6
  Author: keyiflerolsun
@@ -6,7 +6,7 @@ from io import open
6
6
  setup(
7
7
  # ? Genel Bilgiler
8
8
  name = "Kekik",
9
- version = "1.6.2",
9
+ version = "1.6.4",
10
10
  url = "https://github.com/keyiflerolsun/Kekik",
11
11
  description = "İşlerimizi kolaylaştıracak fonksiyonların el altında durduğu kütüphane..",
12
12
  keywords = ["Kekik", "KekikAkademi", "keyiflerolsun"],
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes