def __init__(self, file_path, config_dict=None, encryption_key=None, binary_mode=False, *args, **kwargs):
self.config = {
'file_path': file_path,
'is_binary': None,
'is_encrypted': False,
'is_case_sensitive': None,
'is_disabled': None,
'mtime': -1,
'sha1_checksum': None,
'content': None,
'content_length': None,
}
self.is_resolved = False
self.is_file_not_found = None
self.path = Path(file_path)
self.stat = None
self.encryption_key = None
self.is_encryptable = False
self.binary_mode = False
self.config_file_type = None
self.config_dict = None
if isinstance(config_dict, dict):
self.config_dict = check_config(config_dict)
try:
self.stat = self.path.resolve().stat()
except:
self.stat = None
self.is_resolved = False
self.binary_mode = bool(binary_mode)
if encryption_key is not None:
key_len = 32
if not isinstance(encryption_key, str):
raise LocalConfigFileError('Encryption key must be a url-safe 32 character ascii string.')
if len(encryption_key[:key_len]) != key_len:
raise LocalConfigFileError('Encryption key must be a url-safe 32 character ascii string.')
self.encryption_key = base64.b64encode(encryption_key.encode('ascii'))
Fernet(self.encryption_key) # try it out, if no exception, we're good
self.is_encryptable = True
评论列表
文章目录