Skip to content

Commit

Permalink
Refactor: abstract class reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanhed committed Jan 5, 2024
1 parent c5dc9f9 commit 307a7f9
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/mijnbib/login_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@


class LoginHandler(ABC):
@abstractmethod
def login(self) -> mechanize.Browser:
pass


class LoginByForm(LoginHandler):
def __init__(self, username, password, url: str, br: mechanize.Browser):
self._username = username
self._pwd = password
self._url = url
self._br = br

@abstractmethod
def login(self) -> mechanize.Browser:
pass


class LoginByForm(LoginHandler):
def login(self) -> mechanize.Browser:
response = self._log_in()
html = response.read().decode("utf-8") if response is not None else ""
Expand Down Expand Up @@ -59,7 +59,8 @@ def _log_in(self):
) from e
return response

def _validate_logged_in(self, html: str):
@staticmethod
def _validate_logged_in(html: str):
_log.debug("Checking if login is successful ...")
if "Profiel" not in html:
if (
Expand All @@ -75,11 +76,8 @@ def _validate_logged_in(self, html: str):


class LoginByOAuth(LoginHandler):
def __init__(self, username, password, url: str, br: mechanize.Browser):
self._username = username
self._pwd = password
self._br = br
self._url = url # e.g. "https://gent.bibliotheek.be/mijn-bibliotheek/aanmelden"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self._s = requests.Session()
# self._s.cookies = self._br.cookiejar # load cookies from earlier session(s)
Expand Down

0 comments on commit 307a7f9

Please sign in to comment.