Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.0.3 #219

Merged
merged 4 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,11 @@ venv.bak/
# mypy
.mypy_cache/

.idea/
.idea/

*.bmp
*/cpp_module

CMakeLists.txt
MANIFEST.in
*.png
2 changes: 1 addition & 1 deletion cereja/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from . import scraping
from . import wcag

VERSION = "2.0.2.final.0"
VERSION = "2.0.3.final.0"

__version__ = get_version_pep440_compliant(VERSION)

Expand Down
4 changes: 2 additions & 2 deletions cereja/system/_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def _click(self, button: str, position=None, n_clicks=1, interval=0.0):
position = self.position
l_param = (position[1] << 16) | position[0]

self.send_event(self._hwnd, self._mouse_messages_map[f"{button}_down"], 0, l_param)
self.send_event(self._hwnd, self._mouse_messages_map[f"{button}_down"], 1, l_param)
self.send_event(self._hwnd, self._mouse_messages_map[f"{button}_up"], 0, l_param)

def click_left(self, position: Tuple[int, int] = None, n_clicks=1):
Expand All @@ -420,7 +420,7 @@ def drag_to(self, from_, to):
from_l_param = (from_[1] << 16) | from_[0]
to_l_param = (to[1] << 16) | to[0]

self.send_event(self._hwnd, self._mouse_messages_map["left_down"], 0, from_l_param)
self.send_event(self._hwnd, self._mouse_messages_map["left_down"], 1, from_l_param)
self.send_event(self._hwnd, self._mouse_messages_map["left_up"], 0, to_l_param)
else:
self.set_position(from_[0], from_[1])
Expand Down
23 changes: 23 additions & 0 deletions cereja/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import abc
import logging
import warnings
import random

__all__ = [
"depreciation",
Expand All @@ -38,6 +39,7 @@
"on_except",
"use_thread",
"on_elapsed",
"retry_on_failure",
]

from ..config.cj_types import PEP440
Expand Down Expand Up @@ -191,6 +193,27 @@ def wrapper(*args, **kwargs):
return register


def retry_on_failure(retries: int = 3, initial_delay: float = 0.1, backoff_factor=2, exceptions: tuple = (Exception,),
verbose: bool = False):
def register(func):
def wrapper(*args, **kwargs):
delay = initial_delay
for attempt in range(retries):
try:
return func(*args, **kwargs)
except exceptions as e:
if attempt < retries - 1:
if verbose:
warnings.warn(f"Retry {attempt + 1} of {retries}: {e}")
delay *= backoff_factor * (1 + random.random())
time.sleep(delay)
else:
raise e

return wrapper
return register


def singleton(cls):
instances = {}

Expand Down
Loading