Skip to content

Commit

Permalink
strict mode
Browse files Browse the repository at this point in the history
Signed-off-by: lopho <[email protected]>
  • Loading branch information
lopho authored Nov 2, 2022
1 parent 2a9d86c commit 58bd918
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pickle_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,21 @@ def load(self):
return result


class BlockedException(Exception):
def __init__(self, msg):
self.msg = msg


class UnpickleControlled(UnpickleBase):
def find_class(self, result, module, name):
full_name = f'{module}.{name}'
in_blacklist = _check_list(full_name, self.config.blacklist)
in_whitelist = _check_list(full_name, self.config.whitelist)
if (in_blacklist and not in_whitelist) or (len(self.config.blacklist) < 1 and len(self.config.whitelist) > 0 and not in_whitelist):
return UnpickleInspector.find_class(self, result, module, name)
if self.config.strict:
raise lockedException(f'strict mode: {full_name} blocked')
else:
return UnpickleInspector.find_class(self, result, module, name)
self._print(full_name)
in_tracklist = _check_list(full_name, self.config.tracklist)
if self.config.record or full_name in self.config.tracklist:
Expand Down

0 comments on commit 58bd918

Please sign in to comment.