Getting the context in which a function is running?

However you check for scope, consider doing it at the top level of an inherited script module, setting booleans like isDesigner and isGateway. Then just check the booleans everywhere else.

Something like this:

try:
    isDesigner = bool(system.util.getSystemFlags() & system.util.DESIGNER_FLAG)
    isGateway = False
except AttributeError:
    isDesigner = False
    isGateway = True