Abstract base classes complement duck-typing by providing a way to define interfaces when other techniques like hasattr() would be clumsy or subtly wrong (for example with magic methods). ABCs introduce virtual subclasses, which are classes that don’t inherit from a class but are still recognized by isinstance() and issubclass(); see the abc module documentation. Python comes with many built-in ABCs for data structures (in the collections.abc module), numbers (in the numbers module), streams (in the io module), import finders and loaders (in the importlib.abc module). You can create your own ABCs with the abc module.
Unlike Java abstract methods, these abstract methods may have an implementation. This implementation can be called via the super() mechanism from the class that overrides it. This could be useful as an end-point for a super-call in a framework that uses cooperative multiple-inheritance.
AbstractBaseAPIClient that specifies the abstractmethods necessary to propertly be handled. The AbstractBaseClass defines a minimal set of methods that establish the characteristic behavior for the APIClient.
Code that discriminates based on Abstract methods can trust that those methods will always be present.
Makes connection to the backend API and handles any exceptions.
Reads content.
Return text: | str |
---|
Routes to proper destination URL and proper encoding schemes.
Return url: | str |
---|
Implements the AbstractBaseAPIClient and talks to the google books api for querying and finding books.
Parameters: |
|
---|---|
Return self: | GoogleBooksAPIClient |
Context manager for HTTP Connection state and ensures proper handling of network sockets, sends a GET request.
Exception is raised at the yield statement.
Yield request: | FileIO<Socket> |
---|
Serializes json text stream into python dictionary.
Return dict: | json |
---|
Reads raw text from the connection stream. Ensures proper exception handling.
Return bytes: | request |
---|