api.util package¶
Submodules¶
api.util.patron module¶
- class api.util.patron.PatronUtility[source]¶
Bases:
object
Apply circulation-specific logic to Patron model objects.
- classmethod assert_borrowing_privileges(patron)[source]¶
Raise an exception unless the patron currently has borrowing privileges.
- Raises:
AuthorizationExpired – If the patron’s authorization has expired.
OutstandingFines – If the patron has too many outstanding fines.
- classmethod authorization_is_active(patron)[source]¶
Return True unless the patron’s authorization has expired.
- classmethod has_borrowing_privileges(patron)[source]¶
Is the given patron allowed to check out books?
- Returns:
A boolean
- classmethod has_excess_fines(patron)[source]¶
Does this patron have fines in excess of the maximum fine amount set for their library?
- Parameters:
Patron (a) –
- Returns:
A boolean
- classmethod needs_external_sync(patron)[source]¶
Could this patron stand to have their metadata synced with the remote?
By default, all patrons get synced once every twelve hours. Patrons who lack borrowing privileges can always stand to be synced, since their privileges may have just been restored.
api.util.short_client_token module¶
- class api.util.short_client_token.ShortClientTokenUtility(vendor_id, library_uri, library_short_name, secret, other_libraries={})[source]¶
Bases:
object
Generate authdata JWTs as per the Vendor ID Service spec: https://docs.google.com/document/d/1j8nWPVmy95pJ_iU4UTC-QgHK2QhDUSdQ0OQTFR2NE_0
Capable of encoding JWTs (for this library), and decoding them (from this library and potentially others).
Also generates and decodes JWT-like strings used to get around Adobe’s lack of support for authdata in deactivation.
- ADOBE_ACCOUNT_ID_PATRON_IDENTIFIER = 'Identifier for Adobe account ID purposes'¶
- ALGORITHM = 'HS256'¶
- EPOCH = datetime.datetime(1970, 1, 1, 0, 0, tzinfo=<UTC>)¶
- OTHER_LIBRARIES_KEY = 'other_libraries'¶
- VENDOR_ID_KEY = 'vendor_id'¶
- VENDOR_ID_UUID_TOKEN_TYPE = 'Vendor ID UUID'¶
- classmethod adobe_base64_encode(str_to_encode)[source]¶
A modified base64 encoding that avoids triggering an Adobe bug.
The bug seems to happen when the ‘password’ portion of a username/password pair contains a + character. So we replace + with :. We also replace / (another “suspicious” character) with ;. and strip newlines.
- classmethod adobe_relevant_credentials(patron)[source]¶
Find all Adobe-relevant Credential objects for the given patron. This includes the patron’s identifier for Adobe ID purposes, and (less likely) any Adobe IDs directly associated with the Patron. :return: A SQLAlchemy query
- decode_short_client_token(token)[source]¶
Attempt to interpret a ‘username’ and ‘password’ as a short client token identifying a patron of a specific library.
- Returns:
a 2-tuple (library_uri, patron_identifier)
- Raises:
ValueError – When the token is not valid for any reason.
- decode_two_part_short_client_token(username, password)[source]¶
Decode a short client token that has already been split into two parts.
- encode_short_client_token(patron_identifier)[source]¶
Generate a short client token suitable for putting in an OPDS feed, where it can be picked up by a client and sent to the delegation authority to look up an Adobe ID.
- Returns:
A 2-tuple (vendor ID, token)
- classmethod from_config(library, _db=None)[source]¶
Initialize an ShortClientTokenUtility from site configuration.
- Returns:
An ShortClientTokenUtility if one is configured; otherwise None.
- Raises:
CannotLoadConfiguration – If an ShortClientTokenUtility is incompletely configured.
api.util.url module¶
- class api.util.url.URLUtility[source]¶
Bases:
object
Contains different helper methods simplifying URL construction.
- static build_url(base_url, query_parameters)[source]¶
Construct a URL with specified query parameters.
- Parameters:
base_url (str) – Base URL
query_parameters (Dict) – Dictionary containing query parameters
- Returns:
Constructed URL
- Return type:
str
- static url_match_in_domain_list(url, domain_list)[source]¶
Attempts to match a candidate URL against a list of URL patterns, with wildcard matching of subdomains under a given root.
To be matched against, a value in ‘domain_list’ must be of the form:
(http|https)://[(<subdomain>|*).]<domain>.<tld>
Examples of valid domain_list entries:
` http://librarysimplified.org https://librarysimplified.org https://www.librarysimplified.org https://*.librarysimplified.org https://alpha.bravo.charlie.librarysimplified.org https://*.charlie.librarysimplified.org capacitor://*.vercel.app `
Note that the entry http://*.librarysimplified.org WILL NOT match the URL of the root domain http://librarysimplified.org. To match the root domain you must also include it as a separate, non-wildcard entry.