1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-06 18:33:13 +03:00

Add paranoia checks to class and qualname finders

This commit is contained in:
Athanasius 2020-07-24 21:32:21 +01:00
parent 7951463fba
commit 89cadbc0eb

View File

@ -986,15 +986,15 @@ class EDMCContextFilter(logging.Filter):
if len(stack) < start + 1: if len(stack) < start + 1:
return '' return ''
class_name = [] class_name = ''
frame = stack[start] frame = stack[start]
if 'self' in frame.f_locals: if 'self' in frame.f_locals:
# I don't know any way to detect call from the object method # Paranoia checks
# XXX: there seems to be no way to detect static method call - it will frame_class = frame.f_locals['self'].__class__
# be just a function call if frame_class and frame_class.__qualname__:
class_name.append(frame.f_locals['self'].__class__.__qualname__) class_name = frame_class.__qualname__
return ".".join(class_name) return class_name
def caller_qualname(self, skip=5) -> str: def caller_qualname(self, skip=5) -> str:
""" """
@ -1019,15 +1019,16 @@ class EDMCContextFilter(logging.Filter):
if len(stack) < start + 1: if len(stack) < start + 1:
return '' return ''
class_name = [] qualname = ''
frame = stack[start] frame = stack[start]
if 'self' in frame.f_locals: if frame.f_locals and 'self' in frame.f_locals:
# I don't know any way to detect call from the object method # Paranoia checks
# XXX: there seems to be no way to detect static method call - it will if frame.f_code and frame.f_code.co_name:
# be just a function call fn = getattr(frame.f_locals['self'], frame.f_code.co_name)
class_name.append(getattr(frame.f_locals['self'], frame.f_code.co_name).__qualname__) if fn and fn.__qualname__:
qualname = n.__qualname__
return ".".join(class_name) return qualname
########################################################################### ###########################################################################