Jedutils 0.2.1__tar.gz → 0.2.3__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 (29) hide show
  1. {Jedutils-0.2.1 → Jedutils-0.2.3}/Jedutils.egg-info/PKG-INFO +1 -1
  2. {Jedutils-0.2.1 → Jedutils-0.2.3}/Jedutils.egg-info/SOURCES.txt +2 -0
  3. {Jedutils-0.2.1 → Jedutils-0.2.3}/PKG-INFO +1 -1
  4. Jedutils-0.2.3/jedutils/__init__.py +3 -0
  5. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/asyncio/_async_redis_pipe.py +15 -1
  6. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/asyncio/_concurrency_manager.py +6 -6
  7. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/asyncio/network/_dl.py +2 -2
  8. Jedutils-0.2.3/jedutils/base62/__init__.py +1 -0
  9. Jedutils-0.2.3/jedutils/base62/b62.py +70 -0
  10. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/databases/_in_memory.py +4 -4
  11. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/math/_number_formatter.py +6 -6
  12. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/strings/_chunked_text.py +1 -1
  13. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/strings/_random_string.py +2 -2
  14. Jedutils-0.2.1/jedutils/__init__.py +0 -3
  15. {Jedutils-0.2.1 → Jedutils-0.2.3}/Jedutils.egg-info/dependency_links.txt +0 -0
  16. {Jedutils-0.2.1 → Jedutils-0.2.3}/Jedutils.egg-info/requires.txt +0 -0
  17. {Jedutils-0.2.1 → Jedutils-0.2.3}/Jedutils.egg-info/top_level.txt +0 -0
  18. {Jedutils-0.2.1 → Jedutils-0.2.3}/LICENSE +0 -0
  19. {Jedutils-0.2.1 → Jedutils-0.2.3}/MANIFEST.in +0 -0
  20. {Jedutils-0.2.1 → Jedutils-0.2.3}/README.md +0 -0
  21. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/asyncio/__init__.py +0 -0
  22. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/asyncio/_run_async.py +0 -0
  23. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/asyncio/_rwlock.py +0 -0
  24. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/asyncio/network/__init__.py +0 -0
  25. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/databases/__init__.py +0 -0
  26. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/math/__init__.py +0 -0
  27. {Jedutils-0.2.1 → Jedutils-0.2.3}/jedutils/strings/__init__.py +0 -0
  28. {Jedutils-0.2.1 → Jedutils-0.2.3}/setup.cfg +0 -0
  29. {Jedutils-0.2.1 → Jedutils-0.2.3}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Jedutils
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Jedutils is a Python utilities package that provides a collection of useful helper functions.
5
5
  Home-page: https://github.com/AYMENJD/jedutils
6
6
  Author: AYMEN Mohammed
@@ -15,6 +15,8 @@ jedutils/asyncio/_run_async.py
15
15
  jedutils/asyncio/_rwlock.py
16
16
  jedutils/asyncio/network/__init__.py
17
17
  jedutils/asyncio/network/_dl.py
18
+ jedutils/base62/__init__.py
19
+ jedutils/base62/b62.py
18
20
  jedutils/databases/__init__.py
19
21
  jedutils/databases/_in_memory.py
20
22
  jedutils/math/__init__.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Jedutils
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Jedutils is a Python utilities package that provides a collection of useful helper functions.
5
5
  Home-page: https://github.com/AYMENJD/jedutils
6
6
  Author: AYMEN Mohammed
@@ -0,0 +1,3 @@
1
+ __version__ = "0.2.3"
2
+ __copyright__ = "Copyright (c) 2023-2024 AYMEN Mohammed ~ https://github.com/AYMENJD"
3
+ __license__ = "MIT License"
@@ -1,4 +1,5 @@
1
1
  import asyncio
2
+ import logging
2
3
 
3
4
  try:
4
5
  from redis import Redis
@@ -28,9 +29,10 @@ class AsyncRedisPipe:
28
29
  pipe_max_size: int = 200,
29
30
  workers: int = 8,
30
31
  loop: asyncio.AbstractEventLoop = None,
32
+ debug: bool = False,
31
33
  ) -> None:
32
34
  """
33
- Args:
35
+ Parameters:
34
36
  redis (``Redis``):
35
37
  The Redis client
36
38
 
@@ -42,6 +44,9 @@ class AsyncRedisPipe:
42
44
 
43
45
  loop (:py:class:`asyncio.AbstractEventLoop`, *optional*):
44
46
  The event loop to use. Defaults to :py:class:`asyncio.get_event_loop()`.
47
+
48
+ debug (``bool``, *optional*):
49
+ Whether to enable debug logging. Defaults to ``False``.
45
50
  """
46
51
 
47
52
  if not Redis:
@@ -49,6 +54,9 @@ class AsyncRedisPipe:
49
54
 
50
55
  self.redis = redis
51
56
  self.pipe_max_size = pipe_max_size
57
+ self.debug = debug
58
+ self.logger = logging.getLogger(__name__)
59
+
52
60
  self.__queue = asyncio.Queue()
53
61
  self.__loop = (
54
62
  asyncio.get_event_loop()
@@ -83,6 +91,9 @@ class AsyncRedisPipe:
83
91
  except asyncio.QueueEmpty:
84
92
  break
85
93
  else:
94
+ if self.debug:
95
+ self.logger.debug(f"Executing command: {data[1]}")
96
+
86
97
  pipe.execute_command(*data[1])
87
98
  futures.append(data[0])
88
99
  count += 1
@@ -92,6 +103,9 @@ class AsyncRedisPipe:
92
103
  async def __handle_pipe_line(self, futures: list, pipe):
93
104
  results = await pipe.execute(False)
94
105
  for x, result in enumerate(results):
106
+ if self.debug:
107
+ self.logger.debug(f"Result: {result}")
108
+
95
109
  if isinstance(result, BaseException):
96
110
  futures[x].set_exception(result)
97
111
  else:
@@ -15,7 +15,7 @@ class ConcurrencyManager:
15
15
  """
16
16
  Acquire a lock for the specified ID
17
17
 
18
- Args:
18
+ Parameters:
19
19
  ID (``str``):
20
20
  Identifier for the operation
21
21
  """
@@ -28,7 +28,7 @@ class ConcurrencyManager:
28
28
  """
29
29
  Release a lock for the specified ID
30
30
 
31
- Args:
31
+ Parameters:
32
32
  ID (``str``):
33
33
  Identifier for the operation
34
34
 
@@ -50,7 +50,7 @@ class ConcurrencyManager:
50
50
  """
51
51
  Get the current count of operations for the specified ID
52
52
 
53
- Args:
53
+ Parameters:
54
54
  ID (``str``):
55
55
  Identifier for the operation
56
56
 
@@ -67,7 +67,7 @@ class ConcurrencyManager:
67
67
  """
68
68
  Create a context for the specified ID, acquiring and releasing a lock
69
69
 
70
- Args:
70
+ Parameters:
71
71
  ID (``str``):
72
72
  Identifier for the operation
73
73
  """
@@ -83,7 +83,7 @@ class ConcurrencyManager:
83
83
  """
84
84
  Create a context with a limit on the number of concurrent operations.
85
85
 
86
- Args:
86
+ Parameters:
87
87
  ID (``str``):
88
88
  Identifier for the operation.
89
89
 
@@ -109,7 +109,7 @@ class ConcurrencyManager:
109
109
  """
110
110
  Wait until the count for the specified ID reaches the target count
111
111
 
112
- Args:
112
+ Parameters:
113
113
  ID (``str``):
114
114
  Identifier for the operation
115
115
 
@@ -17,7 +17,7 @@ async def download_file(
17
17
  thread_pool=None,
18
18
  **kwargs,
19
19
  ) -> None:
20
- """
20
+ r"""
21
21
  Asynchronously download a file from the given URL and saves it to the specified filename using chunked downloading
22
22
 
23
23
  Example:
@@ -30,7 +30,7 @@ async def download_file(
30
30
 
31
31
  await download_file('https://example.com/large_file.zip', 'my_large_file.zip', progress_callback=my_callback)
32
32
 
33
- Args:
33
+ Parameters:
34
34
  url (``str``):
35
35
  The URL of the file to download
36
36
 
@@ -0,0 +1 @@
1
+ from .b62 import BASE62_CHARS, b62encode, b62decode
@@ -0,0 +1,70 @@
1
+ from typing import Union
2
+
3
+ BASE62_CHARS = list("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
4
+ BASE62_LOOKUP = {char: index for index, char in enumerate(BASE62_CHARS)}
5
+
6
+
7
+ def b62encode(data: Union[bytes, int]) -> str:
8
+ """
9
+ Encodes the given data into a base62 string
10
+
11
+ \Example:
12
+ .. code-block:: python
13
+ >>> b62encode(b'hello world')
14
+ 'AAwf93rvy4aWQVw'
15
+ >>> b62encode(123456789)
16
+ '8M0kX'
17
+
18
+ \Parameters:
19
+ data (``bytes`` or ``int``):
20
+ The data to be encoded. It must be either bytes or an integer
21
+
22
+ \Returns:
23
+ ``str``: The base62 encoded string
24
+ """
25
+
26
+ if isinstance(data, bytes):
27
+ num = int.from_bytes(data, byteorder="big")
28
+ elif isinstance(data, int):
29
+ num = data
30
+ else:
31
+ raise TypeError("data must be bytes or int")
32
+
33
+ base62 = []
34
+
35
+ while num > 0:
36
+ num, remainder = divmod(num, 62)
37
+ base62.append(BASE62_CHARS[remainder])
38
+
39
+ return "".join(reversed(base62))
40
+
41
+
42
+ def b62decode(b62_string: str, as_int: bool = False) -> Union[bytes, int]:
43
+ """
44
+ Decodes a Base62 encoded string
45
+
46
+ \Example:
47
+ .. code-block:: python
48
+ >>> b62decode("AAwf93rvy4aWQVw")
49
+ b'hello world'
50
+ >>> b62decode("8M0kX", as_int=True)
51
+ 123456789
52
+
53
+ \Parameters:
54
+ b62_string (``str``):
55
+ The Base62 encoded string to decode
56
+
57
+ as_int (``bool``, *optional*):
58
+ Pass ``True`` to return the decoded value as an integer. Default is ``False``
59
+
60
+ \Returns:
61
+ ``bytes`` or ``int``: The decoded value as bytes if ``as_int`` is ``False``, otherwise as an integer.
62
+ """
63
+
64
+ num = 0
65
+ for char in b62_string:
66
+ num = num * 62 + BASE62_LOOKUP[char]
67
+
68
+ if as_int:
69
+ return num
70
+ return num.to_bytes(((num.bit_length() + 7) // 8), byteorder="big")
@@ -21,7 +21,7 @@ class InMemoryDB:
21
21
  # Delete a key-value pair
22
22
  db.delete('key1')
23
23
 
24
- Args:
24
+ Parameters:
25
25
  max_keys (``int``, *optional*):
26
26
  The maximum number of keys that can be stored in the database
27
27
  If None (default), there is no limit on the number of keys
@@ -36,7 +36,7 @@ class InMemoryDB:
36
36
  """
37
37
  Sets the value associated with a key in the database
38
38
 
39
- Args:
39
+ Parameters:
40
40
  key (``str``):
41
41
  The key to set the value for
42
42
 
@@ -55,7 +55,7 @@ class InMemoryDB:
55
55
  """
56
56
  Gets the value associated with a key in the database
57
57
 
58
- Args:
58
+ Parameters:
59
59
  key (``str``):
60
60
  The key to get the value for
61
61
 
@@ -68,7 +68,7 @@ class InMemoryDB:
68
68
  """
69
69
  Deletes the key-value pair with the given key from the database
70
70
 
71
- Args:
71
+ Parameters:
72
72
  key (``str``):
73
73
  The key to delete
74
74
 
@@ -2,7 +2,7 @@ def format_bytes(size: int) -> str:
2
2
  """
3
3
  Converts a size in bytes to a human-readable format
4
4
 
5
- Args:
5
+ Parameters:
6
6
  size (``int``):
7
7
  The size in bytes
8
8
 
@@ -24,7 +24,7 @@ def parse_bytes(size_str: str) -> str:
24
24
  """
25
25
  Converts a size in a human-readable format to bytes
26
26
 
27
- Args:
27
+ Parameters:
28
28
  size_str (``str``):
29
29
  The size in a human-readable format, e.g., ``2.00 KB``
30
30
 
@@ -68,7 +68,7 @@ def format_duration(seconds: int, format_option: str = "short") -> str:
68
68
  """
69
69
  Formats the given duration in seconds into a human-readable string representation
70
70
 
71
- Args:
71
+ Parameters:
72
72
  seconds (``int``):
73
73
  The duration in seconds
74
74
 
@@ -125,7 +125,7 @@ def format_number_short(number: int) -> str:
125
125
  """
126
126
  Convert a number to a short format with a specified number of decimal places
127
127
 
128
- Args:
128
+ Parameters:
129
129
  number (``float``):
130
130
  The number to format
131
131
 
@@ -155,7 +155,7 @@ def convert_to_bytes(value: int, unit: str) -> int:
155
155
  """
156
156
  Convert a number with a unit prefix into bytes
157
157
 
158
- Args:
158
+ Parameters:
159
159
  value (``int``):
160
160
  The numerical value
161
161
 
@@ -188,7 +188,7 @@ def to_numeric(value: int, unit: str) -> int:
188
188
  """
189
189
  Convert a number with a unit prefix into its numerical value
190
190
 
191
- Args:
191
+ Parameters:
192
192
  value (``int``):
193
193
  The numerical value
194
194
 
@@ -14,7 +14,7 @@ def split_text(text: str, chunk_size: int = 4096):
14
14
  ... # Send each chunk as a separate message
15
15
  ... send_message(chunk)
16
16
 
17
- Args:
17
+ Parameters:
18
18
  text (``str``):
19
19
  The text to split
20
20
 
@@ -12,7 +12,7 @@ chars = string.ascii_letters + string.digits
12
12
  def random_string(length: int):
13
13
  """Generate a random string
14
14
 
15
- Args:
15
+ Parameters:
16
16
  length (``int``):
17
17
  The length of the string
18
18
  """
@@ -23,7 +23,7 @@ def random_string(length: int):
23
23
  def random_hex_string(length):
24
24
  """Generate a random hex string
25
25
 
26
- Args:
26
+ Parameters:
27
27
  length (``int``):
28
28
  The length of the string (in bytes)
29
29
  """
@@ -1,3 +0,0 @@
1
- __version__ = "0.2.1"
2
- __copyright__ = "Copyright (c) 2023 AYMEN Mohammed ~ https://github.com/AYMENJD"
3
- __license__ = "MIT License"
File without changes
File without changes
File without changes
File without changes
File without changes