2022-06-03 11:52:18 -04:00
|
|
|
"""Fisture class for page functions."""
|
|
|
|
|
|
|
|
from urllib import request
|
|
|
|
from urllib.error import HTTPError
|
|
|
|
|
2022-06-22 12:03:17 -04:00
|
|
|
|
2022-06-03 11:52:18 -04:00
|
|
|
class Page:
|
|
|
|
"""Class for getting an individual page."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Init function."""
|
|
|
|
self.res = None
|
|
|
|
|
|
|
|
def request_url(self, url):
|
|
|
|
"""Make a page request."""
|
|
|
|
try:
|
2022-06-22 12:03:17 -04:00
|
|
|
page = request.urlopen(url)
|
2022-06-03 11:52:18 -04:00
|
|
|
except HTTPError as err:
|
|
|
|
self.res = err
|
2022-06-22 12:03:17 -04:00
|
|
|
else:
|
|
|
|
with page:
|
|
|
|
self.res = page
|
2022-06-03 11:52:18 -04:00
|
|
|
|
|
|
|
def get_status_code(self):
|
|
|
|
"""Return the status code."""
|
|
|
|
return self.res.status
|
2022-06-22 12:03:17 -04:00
|
|
|
|
|
|
|
def get_header(self, header):
|
|
|
|
"""Did a session id get set."""
|
|
|
|
return self.res.headers[header]
|