Use shorter name for responses, like in the requests doc.

Change Organizer's __all__ to be more in line with the other __all__s.
This commit is contained in:
Joscha 2019-04-25 19:02:48 +00:00
parent 82adeb324f
commit f0c42ce8ec
2 changed files with 11 additions and 13 deletions

View File

@ -69,8 +69,8 @@ class ShibbolethAuthenticator:
"target": "/shib_login.php", "target": "/shib_login.php",
"home_organization_selection": "Mit KIT-Account anmelden", "home_organization_selection": "Mit KIT-Account anmelden",
} }
response = self._session.post(url, data=data) r = self._session.post(url, data=data)
soup = bs4.BeautifulSoup(response.text, "html.parser") soup = bs4.BeautifulSoup(r.text, "html.parser")
# Attempt to login using credentials, if necessary # Attempt to login using credentials, if necessary
while not self._login_successful(soup): while not self._login_successful(soup):
@ -92,8 +92,8 @@ class ShibbolethAuthenticator:
"j_username": username, "j_username": username,
"j_password": password, "j_password": password,
} }
response = self._session.post(url, data=data) r = self._session.post(url, data=data)
soup = bs4.BeautifulSoup(response.text, "html.parser") soup = bs4.BeautifulSoup(r.text, "html.parser")
if not self._login_successful(soup): if not self._login_successful(soup):
print("Incorrect credentials.") print("Incorrect credentials.")
@ -132,8 +132,8 @@ class ShibbolethAuthenticator:
while True: while True:
logger.debug(f"Getting {self.ILIAS_GOTO} {params}") logger.debug(f"Getting {self.ILIAS_GOTO} {params}")
response = self._session.get(self.ILIAS_GOTO, params=params) r = self._session.get(self.ILIAS_GOTO, params=params)
soup = bs4.BeautifulSoup(response.text, "html.parser") soup = bs4.BeautifulSoup(r.text, "html.parser")
if self._is_logged_in(soup): if self._is_logged_in(soup):
return soup return soup
@ -145,16 +145,16 @@ class ShibbolethAuthenticator:
return self.get_webpage(f"fold_{ref_id}") return self.get_webpage(f"fold_{ref_id}")
def _download(self, url, params, to_path): def _download(self, url, params, to_path):
with self._session.get(url, params=params, stream=True) as response: with self._session.get(url, params=params, stream=True) as r:
content_type = response.headers["content-type"] content_type = r.headers["content-type"]
if content_type in self.ALLOWED_CONTENT_TYPES: if content_type in self.ALLOWED_CONTENT_TYPES:
# Yay, we got the file :) # Yay, we got the file :)
stream_to_path(response, to_path) stream_to_path(r, to_path)
return True return True
elif content_type == "text/html": elif content_type == "text/html":
# Dangit, we're probably not logged in. # Dangit, we're probably not logged in.
soup = bs4.BeautifulSoup(response.text, "html.parser") soup = bs4.BeautifulSoup(r.text, "html.parser")
if self._is_logged_in(soup): if self._is_logged_in(soup):
raise ContentTypeException( raise ContentTypeException(
"Attempting to download a web page, not a file") "Attempting to download a web page, not a file")

View File

@ -5,9 +5,7 @@ import shutil
from . import utils from . import utils
__all__ = [ __all__ = ["Organizer"]
"Organizer",
]
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class Organizer: class Organizer: