mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Listen to pylint and mypy
This commit is contained in:
@ -16,6 +16,8 @@ LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IliasAuthenticator(abc.ABC):
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
"""
|
||||
An authenticator that logs an existing requests session into an ILIAS
|
||||
account.
|
||||
@ -29,6 +31,8 @@ class IliasAuthenticator(abc.ABC):
|
||||
|
||||
|
||||
class KitShibbolethAuthenticator(IliasAuthenticator):
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
"""
|
||||
Authenticate via KIT's shibboleth system.
|
||||
"""
|
||||
|
@ -15,11 +15,8 @@ from .authenticators import IliasAuthenticator
|
||||
class ContentTypeException(Exception):
|
||||
"""Thrown when the content type of the ilias element can not be handled."""
|
||||
|
||||
def __init__(self, message: str):
|
||||
"""Create a new exception."""
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class IliasDownloader():
|
||||
"""A downloader for ILIAS."""
|
||||
|
||||
@ -43,24 +40,22 @@ class IliasDownloader():
|
||||
self._organizer.accept_file(tmp_file, target_path)
|
||||
|
||||
def _try_download(self, url: str, target_path: Path, params: Dict[str, Any]) -> bool:
|
||||
with self._session.get(url, params=params, stream=True) as r:
|
||||
content_type = r.headers["content-type"]
|
||||
with self._session.get(url, params=params, stream=True) as response:
|
||||
content_type = response.headers["content-type"]
|
||||
|
||||
if content_type.startswith("text/html"):
|
||||
# Dangit, we're probably not logged in.
|
||||
soup = soupify(r)
|
||||
|
||||
soup = soupify(response)
|
||||
if self._is_logged_in(soup):
|
||||
raise ContentTypeException(
|
||||
"Attempting to download a web page, not a file"
|
||||
)
|
||||
raise ContentTypeException("Attempting to download a web page, not a file")
|
||||
|
||||
return False
|
||||
else:
|
||||
# Yay, we got the file :)
|
||||
stream_to_path(r, target_path)
|
||||
return True
|
||||
|
||||
def _is_logged_in(self, soup: Any) -> bool:
|
||||
# Yay, we got the file :)
|
||||
stream_to_path(response, target_path)
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _is_logged_in(soup: bs4.BeautifulSoup) -> bool:
|
||||
userlog = soup.find("li", {"id": "userlog"})
|
||||
return userlog is not None
|
||||
|
Reference in New Issue
Block a user