config_file.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:cmdb 作者: jonmsawyer 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号