This repository has been archived by the owner on Jun 7, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a419c4
commit 918c956
Showing
1 changed file
with
13 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
import pkgutil | ||
|
||
logger = logging.getLogger(__name__) | ||
__version__ = '1.0.0' | ||
__author__ = 'Ellison Leão' | ||
__email__ = '[email protected]' | ||
__license__ = 'GPLv3' | ||
__version__ = "1.0.1" | ||
__author__ = "Ellison Leão" | ||
__email__ = "[email protected]" | ||
__license__ = "GPLv3" | ||
|
||
|
||
class Shortener(object): | ||
|
@@ -26,21 +26,22 @@ class Shortener(object): | |
def __init__(self, **kwargs): | ||
self.kwargs = kwargs | ||
# validate some required fields | ||
self.kwargs['debug'] = bool(kwargs.pop('debug', False)) | ||
self.kwargs['timeout'] = int(kwargs.pop('timeout', 2)) | ||
self.kwargs['verify'] = bool(kwargs.pop('verify', True)) | ||
module = importlib.import_module('pyshorteners.shorteners') | ||
self.available_shorteners = [i.name for i in | ||
pkgutil.iter_modules(module.__path__)] | ||
self.kwargs["debug"] = bool(kwargs.pop("debug", False)) | ||
self.kwargs["timeout"] = int(kwargs.pop("timeout", 2)) | ||
self.kwargs["verify"] = bool(kwargs.pop("verify", True)) | ||
module = importlib.import_module("pyshorteners.shorteners") | ||
self.available_shorteners = [ | ||
i.name for i in pkgutil.iter_modules(module.__path__) | ||
] | ||
|
||
def __getattr__(self, attr): | ||
if attr not in self.available_shorteners: | ||
return self.__getattribute__(attr) | ||
|
||
# get instance of shortener class | ||
short_module = importlib.import_module( | ||
'{}.{}'.format('pyshorteners.shorteners', attr) | ||
"{}.{}".format("pyshorteners.shorteners", attr) | ||
) | ||
instance = getattr(short_module, 'Shortener')(**self.kwargs) | ||
instance = getattr(short_module, "Shortener")(**self.kwargs) | ||
|
||
return instance |