gummy.gateways module¶
If you want to use your gateway (not listed here), please inherit GummyAbstGateWay
class and create your own class.
I would also appreciate if you could do “pull request” about your own class :)
The following information may be useful when you create your own class
content |
position |
---|---|
What is |
|
How to set a environment variables, or give a kwargs |
|
You can easily get (import) Gateway Class
by the following ways.
>>> from gummy import gateways
>>> gateway = gateways.get("useless")
<gummy.gateways.UselessGateWay at 0x124a4de50>
>>> from gummy.gateways import UselessGateWay
>>> useless = UselessGateWay()
>>> gateway = gateways.get(useless)
>>> gateway
<gummy.gateways.UselessGateWay at 0x124a08730>
>>> id(gateway) == id(useless)
True
-
class
gummy.gateways.
GummyAbstGateWay
(verbose=True, required_keynames={}, dotenv_path='/Users/iwasakishuto/.gummy/.env')[source]¶ Bases:
object
If you want to create your own gateway class, please inherit this class.
- Parameters
verbose (bool) – Whether to print message or not. (default=
True
)required_keynames (dict) – Required keynames for
passthrough_base
or_pass2{journal_name}
method. Seesetup
.dotenv_path (str) – where the dotenv file is. (default is
where_is_envfile()
)
-
required_keynames
¶ Required
kwargs
. (journal_name
->key_list
)- Type
dict
-
journal2method
¶ Which method to use. Use
_pass2others
for journal which does not exist in the key. (journal_name
->method
)- Type
dict
-
property
class_name
¶ Same as
self.__class__.__name__
.
-
property
name
¶ Gateway service name. It is used for converting key name to environment varname. see
keyname2envname
method.
-
setup
(required_keynames={})[source]¶ Setup
If you want to use your gateway service, you will probably need to
log in with your
username
andpassword
to use the gateway serviceprocess for each service. (it is expected that the required information or required process will differ for each journal)
To make it easier to add a supported journals,
1
will be handled bypassthrough_base
method, and2
will be handled by_pass2{journal_name}
method, so when adding a supported journal, only_pass2{journal_name}
needs to be added.If there is any information you have to fill in when using gateway service, you need to give
required_keynames
.>>> class UTokyoGateWay(GummyAbstGateWay): ... def __init__(self): ... super().__init__( ... required_keynames={ ... "base" : ["username", "password"] ... } ... )
"base"
is the key forpassthrough_base
method."{journal_name}"
is the key for_pass2{journal_name}
method.
- Parameters
required_keynames (dict) – Required
kwargs
forpassthrough
method.
-
keyname2envname
(keyname)[source]¶ Convert keyname to environment varname.
- Args
keyname (str) : Keyname for
passthrough_base
or_pass2{journal_name}
method.
Examples
>>> from gummy.gateways import UselessGateWay >>> gateway = UselessGateWay() >>> gateway.keyname2envname("name") 'TRANSLATION_GUMMY_GATEWAY_USELESS_NAME' >>> gateway.keyname2envname("hoge") 'TRANSLATION_GUMMY_GATEWAY_USELESS_HOGE'
-
property
required_env_varnames
¶ Required environment varnames.
Examples
>>> from gummy.gateways import UTokyoGateWay >>> gateway = UTokyoGateWay() >>> gateway.required_env_varname {'base': ['TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME', 'TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD']}
-
property
supported_journals
¶ Supported journals. Use
_pass2others
method for other journals.Examples
>>> from gummy.gateways import UTokyoGateWay >>> gateway = UTokyoGateWay() >>> gateway.supported_journals ['ieee', : 'wileyonlinelibrary']
-
get_required_keynames
(journal_type=None)[source]¶ Get required keynames for given
journal_type
.- Parameters
journal_type (str) – Journal name.
Examples
>>> from gummy.gateways import UTokyoGateWay >>> gateway = UTokyoGateWay() >>> gateway.get_required_keynames("ieee") ['password', 'username']
-
get_required_env_varnames
(journal_type=None)[source]¶ Get required keynames for given
journal_type
.- Parameters
journal_type (str) – Journal name.
Examples
>>> from gummy.gateways import UTokyoGateWay >>> gateway = UTokyoGateWay() >>> gateway.get_required_env_varnames("ieee") ['TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD', 'TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME']
-
get_val
(keyname, **gatewaykwargs)[source]¶ Get the value from
gatewaykwargs
or an environment variable.- Parameters
keyname (str) – Keyname for
passthrough_base
or_pass2{journal_name}
method.gatewaykwargs (dict) – Given
gatewaykwargs
.
Examples
>>> from gummy.gateways import UTokyoGateWay >>> gateway = UTokyoGateWay() >>> print(gateway.get_val("hoge")) None >>> print(gateway.get_val("username")) USERNAME_IN_ENVFILE >>> print(gateway.get_val("username", username=":)")) :)
-
abstract
passthrough_base
(driver, **gatewaykwargs)[source]¶ Perform necessary processing when using gateway service regardless of journal.
- Parameters
driver (WebDriver) – Selenium WebDriver.
gatewaykwargs (dict) – Given
gatewaykwargs
.
-
passthrough
(driver, url=None, journal_type=None, **gatewaykwargs)[source]¶ Perform the necessary procedures to access journals and return WebDriver and function which converts raw URL to ssl URL. When you use gateway service, you need to set environment variables in .env file, or call a method with keyword argment.
Set environment variables in .env file. (recommended):
>>> # Write and update `.env` file. >>> from gummy.utils import show_environ, write_environ, read_environ >>> write_environ( ... TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME="username", ... TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD="password", >>> ) >>> show_environ(default_dotenv_path) * TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME : "username" * TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD : "password" >>> # Call with no kwargs. >>> from gummy.utils import get_driver >>> from gummy import gateways >>> gateway = gateways.get("utokyo") >>> with get_drive() as driver: ... driver = gateway.passthrough(driver) ... :
Call a function with keyword argument:
>>> from gummy.utils import get_driver >>> from gummy import gateways >>> gateway = gateways.get("utokyo") >>> with get_drive() as driver: ... driver = gateway.passthrough(driver, username="username", password="password") ... :
- Parameters
driver (WebDriver) – Selenium WebDriver.
url (str) – URL you want to access using gateway.
journal_type (str) – journal type. Give if known in advance. (default=
None
)gatewaykwargs (dict) – kwargs for
_pass2{journal}
- Returns
(Selenium WebDriver, How to convert raw URL to sslURL)
- Return type
tuple (WebDriver, function)
-
class
gummy.gateways.
UselessGateWay
(verbose=True)[source]¶ Bases:
gummy.gateways.GummyAbstGateWay
Use this class when you do not use the gateway service.
-
class
gummy.gateways.
UTokyoGateWay
(verbose=True)[source]¶ Bases:
gummy.gateways.GummyAbstGateWay
Authentication Gateway Service for students at the University of Tokyo.
This class is not available except for students. Authentication Gateway Service is for faculty and staff members.
>>> from gummy import gateways >>> gateway = gateways.get("utokyo") >>> gateway.required_env_varnames {'base': ['TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME', 'TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD']} >>> gateway.required_keynames {'base': ['username', 'password']}
-
passthrough_base
(driver, **gatewaykwargs)[source]¶ Access SSL-VPN Gateway of Information Technology Center, The University of Tokyo and do the necessary processing.
-