MCPcopy
hub / github.com/PDFMathTranslate/PDFMathTranslate / get

Method get

pdf2zh/config.py:94–117  ·  view source on GitHub ↗

获取配置值

(cls, key, default=None)

Source from the content-addressed store, hash-verified

92
93 @classmethod
94 def get(cls, key, default=None):
95 """获取配置值"""
96 instance = cls.get_instance()
97 # 读取时,加锁或不加锁都行。但为了统一,我们在修改配置前后都要加锁。
98 # get 只要最终需要保存,则会加锁 -> _save_config()
99 if key in instance._config_data:
100 return instance._config_data[key]
101
102 # 若环境变量中存在该 key,则使用环境变量并写回 config
103 if key in os.environ:
104 value = os.environ[key]
105 instance._config_data[key] = value
106 instance._save_config()
107 return value
108
109 # 若 default 不为 None,则设置并保存
110 if default is not None:
111 instance._config_data[key] = default
112 instance._save_config()
113 return default
114
115 # 找不到则抛出异常
116 # raise KeyError(f"{key} is not found in config file or environment variables.")
117 return default
118
119 @classmethod
120 def set(cls, key, value):

Callers 15

__init__Method · 0.45
translateMethod · 0.45
do_translateMethod · 0.45
find_sidMethod · 0.45
__init__Method · 0.45
do_translateMethod · 0.45
__init__Method · 0.45
gui.pyFile · 0.45
verify_recaptchaFunction · 0.45

Calls 2

get_instanceMethod · 0.80
_save_configMethod · 0.80

Tested by

no test coverage detected