pyspj.utils.envs

string_to_env

pyspj.utils.envs.string_to_env(string: str)[source]
Overview:

Turn string KEY=VALUE to key-value tuple.

Arguments:
  • string (str): Original key-value string.

Returns:
  • (key, value): key and value

Examples::
>>> from pyspj.utils import string_to_env
>>> string_to_env('THIS=1')
('THIS', '1')
>>> string_to_env('THIS=1=2')
('THIS', '1=2')

list_to_envs

pyspj.utils.envs.list_to_envs(strings: List[str]) → Mapping[str, str][source]
Overview:

Turn a list of strings to key-value dict.

Arguments:
  • strings (List[str]): List of key-value strings.

Returns:
  • envs (Mapping[str, str]): Separated key-value dict.

Examples::
>>> from pyspj.utils import list_to_envs
>>> list_to_envs([
...     '1=2',
...     'THIS=',
...     'OK=kjsdlf-2398',
...     'THISX=1=2',
... ])
{'1': '2', 'THIS': '', 'OK': 'kjsdlf-2398', 'THISX': '1=2'}

env_to_string

pyspj.utils.envs.env_to_string(name, value) → str[source]
Overview:

Turn key and value to KEY=VALUE string.

Arguments:
  • name (str): Name of key.

  • value (str): Value.

Returns:
  • string (str): KEY=VALUE string.

Examples::
>>> from pyspj.utils import env_to_string
>>> env_to_string('THIS', '')
'THIS='
>>> env_to_string('THIS', '1=2')
'THIS=1=2'

envs_to_list

pyspj.utils.envs.envs_to_list(envs: Mapping[str, str]) → List[str][source]
Overview:

Turn key-value dict to list of KEY=VALUE strings.

Arguments:
  • envs (Mapping[str, str]): Key-value dict.

Returns:
  • lenvs (List[str]): List of KEY=VALUE strings.

Examples::
>>> from pyspj.utils import envs_to_list
>>> envs_to_list({
...     '1': '2',
...     'THIS': '',
...     'OK': 'kjsdlf-2398',
...     'THISX': '1=2',
... })
['1=2', 'THIS=', 'OK=kjsdlf-2398', 'THISX=1=2']