librus_apix.helpers

This module defines a function for checking access to Librus resources by examining the content of a BeautifulSoup object.

Functions: - no_access_check: Checks for access to Librus resources by examining the content of a BeautifulSoup object.

 1"""
 2This module defines a function for checking access to Librus resources by examining the content of a BeautifulSoup object.
 3
 4Functions:
 5    - no_access_check: Checks for access to Librus resources by examining the content of a BeautifulSoup object.
 6
 7"""
 8
 9from bs4 import BeautifulSoup
10from librus_apix.exceptions import TokenError
11
12
13def no_access_check(soup: BeautifulSoup) -> BeautifulSoup:
14    pattern = "Brak dostępu"
15    no_access = soup.select_one("h2.inside")
16    if not no_access:
17        return soup
18    if pattern in no_access.get_text():
19        raise TokenError("Malformed or expired token.")
20    else:
21        return soup
def no_access_check(soup: bs4.BeautifulSoup) -> bs4.BeautifulSoup:
14def no_access_check(soup: BeautifulSoup) -> BeautifulSoup:
15    pattern = "Brak dostępu"
16    no_access = soup.select_one("h2.inside")
17    if not no_access:
18        return soup
19    if pattern in no_access.get_text():
20        raise TokenError("Malformed or expired token.")
21    else:
22        return soup