def catch_factory(attr):
def _catch(s, *args, **kw):<EOL><INDENT>"""<STR_LIT>"""<EOL>def process(value):<EOL><INDENT>"""<STR_LIT>"""<EOL>if attr.startswith("<STR_LIT>"):<EOL><INDENT>return getattr(value, attr)(*args, **kw)<EOL><DEDENT>else:<EOL><INDENT>return getattr(u"<STR_LIT>".__class__, attr)(value, *args, **kw)<EOL><DEDENT><DEDENT>stack = inspect.stack()<EOL>mod = inspect.getmodule(stack[<NUM_LIT:1>][<NUM_LIT:0>])<EOL>if mod.__name__.split("<STR_LIT:.>")[-<NUM_LIT:1>] == s._module_name:<EOL><INDENT>return process(s._value)<EOL><DEDENT>if len(stack) < <NUM_LIT:3>:<EOL><INDENT>return process(s._private)<EOL><DEDENT>remote = not inspect.getmodule(stack[<NUM_LIT:2>][<NUM_LIT:0>]).__name__.startswith("<STR_LIT>")<EOL>valid = False<EOL>for frame in stack[<NUM_LIT:2>:]:<EOL><INDENT>mod = inspect.getmodule(frame[<NUM_LIT:0>])<EOL>if remote and mod.__name__.split("<STR_LIT:.>")[-<NUM_LIT:1>] == s._module_name:<EOL><INDENT>valid = True<EOL>break<EOL><DEDENT>if mod.__name__ == "<STR_LIT>" and frame[<NUM_LIT:3>] == "<STR_LIT>":<EOL><INDENT>valid = True<EOL>break<EOL><DEDENT>if mod.__name__.startswith("<STR_LIT>"):<EOL><INDENT>return process(s._private)<EOL><DEDENT><DEDENT>if valid:<EOL><INDENT>return process(s._value)<EOL><DEDENT>return process(s._private)<EOL><DEDENT>return _catch<EOL>
Factory returning a catch function