Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __post_init__(self):
log.debug(f'Initializing {self.__class__} object')
self.datafile = create_mapper(self)
if settings.HOOKS_ENABLED:
with hooks.disabled():
path = self.datafile.path
exists = self.datafile.exists
create = not self.datafile.manual
if path:
log.debug(f'Datafile path: {path}')
log.debug(f'Datafile exists: {exists}')
if exists:
self.datafile.load(_first_load=True)
elif path and create:
self.datafile.save()
hooks.apply(self, self.datafile)
def enabled(mapper, args) -> bool:
"""Determine if hooks are enabled for the current method."""
if not settings.HOOKS_ENABLED:
return False
if mapper is None:
return False
if mapper.manual:
return False
if args and isinstance(args[0], str):
if args[0] in {'Meta', 'datafile'}:
return False
if args[0].startswith('_'):
return False
return True
def disabled():
"""Globally disable method hooks, temporarily."""
enabled = settings.HOOKS_ENABLED
if enabled:
settings.HOOKS_ENABLED = False
try:
yield
finally:
settings.HOOKS_ENABLED = enabled
def disabled():
"""Globally disable method hooks, temporarily."""
enabled = settings.HOOKS_ENABLED
if enabled:
settings.HOOKS_ENABLED = False
try:
yield
finally:
settings.HOOKS_ENABLED = enabled
def disabled():
"""Globally disable method hooks, temporarily."""
enabled = settings.HOOKS_ENABLED
if enabled:
settings.HOOKS_ENABLED = False
try:
yield
finally:
settings.HOOKS_ENABLED = enabled