def process_options(debugger_name, pkg_version, sys_argv, option_list=None):

usage_str="""<STR_LIT>"""<EOL>optparser = OptionParser(usage=usage_str, option_list=option_list,<EOL>version="<STR_LIT>" % pkg_version)<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=False,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=False,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=False,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action='<STR_LIT:store_true>',<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store>", type='<STR_LIT:string>', metavar='<STR_LIT>',<EOL>help="<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store>", type='<STR_LIT:string>', metavar='<STR_LIT>',<EOL>help="<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=True,<EOL>help="<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=False,<EOL>help="<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=True,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>", type="<STR_LIT:string>",<EOL>help="<STR_LIT>" +<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT:host>", default='<STR_LIT:127.0.0.1>',<EOL>action="<STR_LIT:store>", type='<STR_LIT:string>', metavar='<STR_LIT>',<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store>", type='<STR_LIT:string>',<EOL>metavar='<STR_LIT>',<EOL>default='<STR_LIT>',<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action='<STR_LIT:store_true>', default=False,<EOL>help="<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=True,<EOL>help="<STR_LIT>"<EOL>)<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT>", default=True,<EOL>help="<STR_LIT>"<EOL>)<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action='<STR_LIT:store_true>', default=True,<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action='<STR_LIT>', default=True,<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=False,<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>", metavar='<STR_LIT>',<EOL>action="<STR_LIT:store>", type='<STR_LIT:string>',<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT:port>", default=<NUM_LIT>,<EOL>action="<STR_LIT:store>", type='<STR_LIT:int>',<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action='<STR_LIT:store_true>',<EOL>help="<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=False,<EOL>help="<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT:target>",<EOL>help=("<STR_LIT>"<EOL>"<STR_LIT>")),<EOL>optparser.add_option("<STR_LIT>", dest='<STR_LIT>', action='<STR_LIT:store_true>',<EOL>default=False, help="<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", default=<NUM_LIT:0>, type="<STR_LIT:int>",<EOL>help="<STR_LIT>")<EOL>optparser.disable_interspersed_args()<EOL>sys.argv = list(sys_argv)<EOL>(opts, sys.argv) = optparser.parse_args()<EOL>dbg_opts = {'<STR_LIT>': opts.from_ipython}<EOL>dbg_initfiles = []<EOL>if not opts.noexecute:<EOL><INDENT>add_startup_file(dbg_initfiles)<EOL><DEDENT>if opts.command:<EOL><INDENT>dbg_initfiles.append(opts.command)<EOL>pass<EOL><DEDENT>dbg_opts['<STR_LIT>'] = {'<STR_LIT>': dbg_initfiles}<EOL>if opts.cd:<EOL><INDENT>os.chdir(opts.cd)<EOL>pass<EOL><DEDENT>if opts.output:<EOL><INDENT>try:<EOL><INDENT>dbg_opts['<STR_LIT>'] = Moutput.DebuggerUserOutput(opts.output)<EOL><DEDENT>except IOError:<EOL><INDENT>_, xxx_todo_changeme, _ = sys.exc_info()<EOL>(errno, strerror) = xxx_todo_changeme.args<EOL>print("<STR_LIT>" % opts.output)<EOL>print("<STR_LIT>" % (errno, strerror))<EOL><DEDENT>except:<EOL><INDENT>print("<STR_LIT>" %<EOL>opts.output)<EOL>print(sys.exc_info()[<NUM_LIT:0>])<EOL>sys.exit(<NUM_LIT:2>)<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>return opts, dbg_opts, sys.argv<EOL>

Handle debugger options. Set `option_list' if you are writing
    another main program and want to extend the existing set of debugger
    options.

    The options dicionary from optparser is returned. sys_argv is
    also updated.


<EOL>print_events = []<EOL>if opts.fntrace:   print_events = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>if opts.linetrace: print_events += ['<STR_LIT>']<EOL>if len(print_events):<EOL><INDENT>dbg.settings['<STR_LIT>'] = frozenset(print_events)<EOL>pass<EOL><DEDENT>for setting in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>dbg.settings[setting] = getattr(opts, setting)<EOL>pass<EOL><DEDENT>if getattr(opts, '<STR_LIT>'):<EOL><INDENT>dbg.settings['<STR_LIT>'] = opts.highlight<EOL><DEDENT>else:<EOL><INDENT>dbg.settings['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>dbg.settings['<STR_LIT>'] = None<EOL>if not opts.private:<EOL><INDENT>Mdebugger.debugger_obj = dbg<EOL>pass<EOL><DEDENT>if opts.post_mortem:<EOL><INDENT>Mapi.debugger_on_post_mortem()<EOL>pass<EOL><DEDENT>return<EOL>

Handle options (`opts') that feed into the debugger (`dbg')


def process_options(pkg_version, sys_argv, option_list=None):

usage_str="""<STR_LIT>"""<EOL>optparser = OptionParser(usage=usage_str, option_list=option_list,<EOL>version="<STR_LIT>" % pkg_version)<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT:host>", default='<STR_LIT:127.0.0.1>',<EOL>action="<STR_LIT:store>", type='<STR_LIT:string>', metavar='<STR_LIT>',<EOL>help="<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT:port>", default=<NUM_LIT>,<EOL>action="<STR_LIT:store>", type='<STR_LIT:int>', metavar='<STR_LIT>',<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>", default=<NUM_LIT:0>,<EOL>action="<STR_LIT:store>", type='<STR_LIT:int>', metavar='<STR_LIT>',<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.disable_interspersed_args()<EOL>sys.argv = list(sys_argv)<EOL>(opts, sys.argv) = optparser.parse_args()<EOL>return opts, sys.argv<EOL>

Handle debugger options. Set `option_list' if you are writing
    another main program and want to extend the existing set of debugger
    options.

    The options dicionary from opt_parser is return. sys_argv is
    also updated.


usage_str="""<STR_LIT>"""<EOL>optparser = OptionParser(usage=usage_str, option_list=option_list,<EOL>version="<STR_LIT>" % pkg_version)<EOL>optparser.add_option("<STR_LIT>", "<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=False,<EOL>help="<STR_LIT>" +<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=False,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.add_option("<STR_LIT>", dest="<STR_LIT>",<EOL>action="<STR_LIT:store_true>", default=True,<EOL>help="<STR_LIT>"<EOL>"<STR_LIT>")<EOL>optparser.disable_interspersed_args()<EOL>sys.argv = list(sys_argv)<EOL>(opts, sys.argv) = optparser.parse_args()<EOL>dbg_opts = {}<EOL>return opts, dbg_opts, sys.argv<EOL>


<EOL>print_events = []<EOL>if opts.fntrace:   print_events = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>if len(print_events):<EOL><INDENT>dbg.settings['<STR_LIT>'] = frozenset(print_events)<EOL>pass<EOL><DEDENT>for setting in ('<STR_LIT>', '<STR_LIT>',):<EOL><INDENT>dbg.settings[setting] = getattr(opts, setting)<EOL>pass<EOL><DEDENT>dbg.settings['<STR_LIT>'] = '<STR_LIT>'<EOL>Mdebugger.debugger_obj = dbg<EOL>return<EOL>


global __title__<EOL>orig_sys_argv = list(sys_argv)<EOL>opts, dbg_opts, sys_argv  = process_options(__title__, __version__,<EOL>sys_argv)<EOL>dbg_opts['<STR_LIT>'] = sys_argv<EOL>dbg_opts['<STR_LIT>']     = Mbullwinkle.BWInterface()<EOL>dbg_opts['<STR_LIT>']     = '<STR_LIT>'<EOL>if dbg is None:<EOL><INDENT>dbg = Mdebugger.Trepan(dbg_opts)<EOL>dbg.core.add_ignore(main)<EOL>pass<EOL><DEDENT>_postprocess_options(dbg, opts)<EOL>if len(sys_argv) == <NUM_LIT:0>:<EOL><INDENT>mainpyfile = None<EOL><DEDENT>else:<EOL><INDENT>mainpyfile = sys_argv[<NUM_LIT:0>]  <EOL>if not os.path.isfile(mainpyfile):<EOL><INDENT>mainpyfile=Mclifns.whence_file(mainpyfile)<EOL>is_readable = Mfile.readable(mainpyfile)<EOL>if is_readable is None:<EOL><INDENT>print("<STR_LIT>"<EOL>% (__title__, mainpyfile,))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>elif not is_readable:<EOL><INDENT>print("<STR_LIT>"<EOL>% (__title__, mainpyfile,))<EOL>sys.exit(<NUM_LIT:1>)<EOL>return<EOL><DEDENT><DEDENT>mainpyfile_noopt = Mfile.file_pyc2py(mainpyfile)<EOL>if mainpyfile != mainpyfile_nooptand Mfile.readable(mainpyfile_noopt):<EOL><INDENT>print("<STR_LIT>"<EOL>% __title__)<EOL>print("<STR_LIT>" % (<EOL>__title__, mainpyfile_noopt,))<EOL>mainpyfile = mainpyfile_noopt<EOL>pass<EOL><DEDENT>sys.path[<NUM_LIT:0>] = dbg.main_dirname = os.path.dirname(mainpyfile)<EOL><DEDENT>dbg.sig_received = False<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>if dbg.program_sys_argv and mainpyfile:<EOL><INDENT>normal_termination = dbg.run_script(mainpyfile)<EOL>if not normal_termination: break<EOL><DEDENT>else:<EOL><INDENT>dbg.core.execution_status = '<STR_LIT>'<EOL>dbg.core.processor.process_commands()<EOL>pass<EOL><DEDENT>dbg.core.execution_status = '<STR_LIT>'<EOL>dbg.intf[-<NUM_LIT:1>].msg("<STR_LIT>")<EOL>dbg.core.processor.process_commands()<EOL><DEDENT>except Mexcept.DebuggerQuit:<EOL><INDENT>break<EOL><DEDENT>except Mexcept.DebuggerRestart:<EOL><INDENT>dbg.core.execution_status = '<STR_LIT>'<EOL>if dbg.program_sys_argv:<EOL><INDENT>sys.argv = list(dbg.program_sys_argv)<EOL>part1 = ('<STR_LIT>' %<EOL>dbg.core.filename(mainpyfile))<EOL>args  = '<STR_LIT:U+0020>'.join(dbg.program_sys_argv[<NUM_LIT:1>:])<EOL>dbg.intf[-<NUM_LIT:1>].msg(Mmisc.wrapped_lines(part1, args,<EOL>dbg.settings['<STR_LIT:width>']))<EOL><DEDENT>else: break<EOL><DEDENT>except SystemExit:<EOL><INDENT>break<EOL><DEDENT>pass<EOL><DEDENT>sys.argv = orig_sys_argv<EOL>return<EOL>

Routine which gets run if we were invoked directly


try:<EOL><INDENT>if inspect.istraceback(sys.last_traceback):<EOL><INDENT>return sys.last_type, sys.last_value, sys.last_traceback<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>return sys.exc_info()<EOL>

Intended to be used going into post mortem routines.  If
    sys.last_traceback is set, we will return that and assume that
    this is what post-mortem will want. If sys.last_traceback has not
    been set, then perhaps we *about* to raise an error and are
    fielding an exception. So assume that sys.exc_info()[2]
    is where we want to look.


post_mortem(get_last_or_frame_exception(), frameno, dbg=dbg)<EOL>return<EOL>

Set up post-mortem debugging using the last traceback.  But if
    there is no traceback, we'll assume that sys.exc_info() contains
    what we want and frameno is the index location of where we want
    to start.

    'dbg', is an optional trepan.Trepan object.


def post_mortem(exc=None, frameno=<NUM_LIT:1>, dbg=None):

if dbg is None:<EOL><INDENT>if Mdebugger.debugger_obj is None:<EOL><INDENT>Mdebugger.debugger_obj = Mdebugger.Trepan()<EOL>pass<EOL><DEDENT>dbg = Mdebugger.debugger_obj<EOL>pass<EOL><DEDENT>re_bogus_file = re.compile("<STR_LIT>")<EOL>if exc[<NUM_LIT:0>] is None:<EOL><INDENT>exc = get_last_or_frame_exception()<EOL>if exc[<NUM_LIT:0>] is None:<EOL><INDENT>print("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>return<EOL><DEDENT>pass<EOL><DEDENT>exc_type, exc_value, exc_tb = exc<EOL>dbg.core.execution_status = ('<STR_LIT>'<EOL>% exc_type)<EOL>if exc_tb is not None:<EOL><INDENT>while exc_tb.tb_next is not None:<EOL><INDENT>filename = exc_tb.tb_frame.f_code.co_filename<EOL>if (dbg.mainpyfile and <NUM_LIT:0> == len(dbg.mainpyfile)<EOL>and not re_bogus_file.match(filename)):<EOL><INDENT>dbg.mainpyfile = filename<EOL>pass<EOL><DEDENT>exc_tb = exc_tb.tb_next<EOL>pass<EOL><DEDENT>dbg.core.processor.curframe = exc_tb.tb_frame<EOL>pass<EOL><DEDENT>if <NUM_LIT:0> == len(dbg.program_sys_argv):<EOL><INDENT>dbg.program_sys_argv = list(sys.argv[<NUM_LIT:1>:])<EOL>dbg.program_sys_argv[:<NUM_LIT:0>] = [dbg.mainpyfile]<EOL><DEDENT>try:<EOL><INDENT>f = exc_tb.tb_frame<EOL>if f and f.f_lineno != exc_tb.tb_lineno : f = f.f_back<EOL>dbg.core.processor.event_processor(f, '<STR_LIT>', exc, '<STR_LIT>')<EOL><DEDENT>except DebuggerRestart:<EOL><INDENT>while True:<EOL><INDENT>sys.argv = list(dbg._program_sys_argv)<EOL>dbg.msg("<STR_LIT>"<EOL>% (dbg.filename(dbg.mainpyfile),<EOL>"<STR_LIT:U+0020>".join(dbg._program_sys_argv[<NUM_LIT:1>:])))<EOL>try:<EOL><INDENT>dbg.run_script(dbg.mainpyfile)<EOL><DEDENT>except DebuggerRestart:<EOL><INDENT>pass<EOL><DEDENT>pass<EOL><DEDENT><DEDENT>except DebuggerQuit:<EOL><INDENT>pass<EOL><DEDENT>return<EOL>

Enter debugger read loop after your program has crashed.

    exc is a triple like you get back from sys.exc_info.  If no exc
    parameter, is supplied, the values from sys.last_type,
    sys.last_value, sys.last_traceback are used. And if these don't
    exist either we'll assume that sys.exc_info() contains what we
    want and frameno is the index location of where we want to start.

    'frameno' specifies how many frames to ignore in the traceback.
    The default is 1, that is, we don't need to show the immediate
    call into post_mortem. If you have wrapper functions that call
    this one, you may want to increase frameno.


self.input.close()<EOL>self.output.close()<EOL>return<EOL>


return self.msg(msg)<EOL>

Common routine for reporting debugger error messages.


coded_line = self.inout.read_msg()<EOL>if isinstance(coded_line, bytes):<EOL><INDENT>coded_line = coded_line.decode("<STR_LIT:utf-8>")<EOL><DEDENT>control = coded_line[<NUM_LIT:0>]<EOL>remote_line = coded_line[<NUM_LIT:1>:]<EOL>return (control, remote_line)<EOL>

Send a message back to the server (in contrast to
        the local user output channel).


<EOL>return self.inout.writeline(code + msg)<EOL>


self.input.close()<EOL>return<EOL>

Closes input. (We don't have an output.)


return self.default_confirm<EOL>

Called when a dangerous action is about to be done, to make
        sure it's okay.


def errmsg(self, msg, prefix="<STR_LIT>"):

<EOL>if not self.verbose:<EOL><INDENT>location = ("<STR_LIT>"<EOL>% (self.script_name, self.input_lineno))<EOL>msg = "<STR_LIT>" %(prefix, location, prefix, msg)<EOL><DEDENT>else:<EOL><INDENT>msg = "<STR_LIT>" %(prefix, msg)<EOL>pass<EOL><DEDENT>self.msg(msg)<EOL>if self.abort_on_error:<EOL><INDENT>raise EOFError<EOL><DEDENT>return<EOL>


self.input_lineno += <NUM_LIT:1><EOL>line = self.readline()<EOL>if self.verbose:<EOL><INDENT>location = "<STR_LIT>" % (self.script_name, self.input_lineno)<EOL>self.msg('<STR_LIT>' % (location, line))<EOL>pass<EOL><DEDENT>return line<EOL>

Script interface to read a command. `prompt' is a parameter for
        compatibilty and is ignored.


return self.input.readline()<EOL>

Script interface to read a line. `prompt' is a parameter for
        compatibilty and is ignored.


if self.inout:<EOL><INDENT>self.inout.close()<EOL><DEDENT>return<EOL>


while True:<EOL><INDENT>try:<EOL><INDENT>self.write_confirm(prompt, default)<EOL>reply = self.readline('<STR_LIT>').strip().lower()<EOL><DEDENT>except EOFError:<EOL><INDENT>return default<EOL><DEDENT>if reply in ('<STR_LIT:y>', '<STR_LIT:yes>'):<EOL><INDENT>return True<EOL><DEDENT>elif reply in ('<STR_LIT:n>', '<STR_LIT>'):<EOL><INDENT>return False<EOL><DEDENT>else:<EOL><INDENT>self.msg("<STR_LIT>")<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>return default<EOL>

Called when a dangerous action is about to be done to make sure
        it's okay. `prompt' is printed; user response is returned.


def errmsg(self, str, prefix="<STR_LIT>"):

return self.msg("<STR_LIT>" %(prefix, str))<EOL>


return self.inout and '<STR_LIT>' == self.inout.state<EOL>


self.inout.writeline(Mcomcodes.PRINT + msg)<EOL>return<EOL>

used to write to a debugger that is connected to this
        server; `str' written will have a newline added to it


self.inout.write(Mcomcodes.PRINT +  msg)<EOL>return<EOL>

used to write to a debugger that is connected to this
        server; `str' written will not have a newline added to it


return self.inout.state<EOL>


try:<EOL><INDENT>self.input.close()<EOL>self.output.close()<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>return<EOL>


if default:<EOL><INDENT>prompt += '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>prompt += '<STR_LIT>'<EOL>pass<EOL><DEDENT>while True:<EOL><INDENT>try:<EOL><INDENT>reply = self.readline(prompt)<EOL>reply = reply.strip().lower()<EOL><DEDENT>except EOFError:<EOL><INDENT>return default<EOL><DEDENT>if reply in ('<STR_LIT:y>', '<STR_LIT:yes>'):<EOL><INDENT>return True<EOL><DEDENT>elif reply in ('<STR_LIT:n>', '<STR_LIT>'):<EOL><INDENT>return False<EOL><DEDENT>else:<EOL><INDENT>self.msg("<STR_LIT>")<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>return default<EOL>

Called when a dangerous action is about to be done, to make
        sure it's okay. Expect a yes/no answer to `prompt' which is printed,
        suffixed with a question mark and the default value.  The user
        response converted to a boolean is returned.


return self.msg("<STR_LIT>" %(prefix, msg))<EOL>


term = environ.get('<STR_LIT>', None)<EOL>if term:<EOL><INDENT>if (term.startswith('<STR_LIT>',) or term.startswith('<STR_LIT>')<EOL>or term == '<STR_LIT>'):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>

Get bacground from
    default values based on the TERM environment variable


try:<EOL><INDENT>midpoint = int(environ.get('<STR_LIT>', None))<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>if not midpoint:<EOL><INDENT>term = environ.get('<STR_LIT>', None)<EOL>print("<STR_LIT>", midpoint, '<STR_LIT>',  (<NUM_LIT:16>*<NUM_LIT:5> + <NUM_LIT:16>*g + <NUM_LIT:16>*b))<EOL>midpoint = <NUM_LIT> if term and term == '<STR_LIT>' else <NUM_LIT><EOL><DEDENT>if ( (<NUM_LIT:16>*<NUM_LIT:5> + <NUM_LIT:16>*g + <NUM_LIT:16>*b) < midpoint ):<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Pass as parameters R G B values in hex
    On return, variable is_dark_bg is set


dark_bg = environ.get('<STR_LIT>', None)<EOL>if dark_bg is not None:<EOL><INDENT>return dark_bg != '<STR_LIT:0>'<EOL><DEDENT>color_fg_bg = environ.get('<STR_LIT>', None)<EOL>if color_fg_bg:<EOL><INDENT>if color_fg_bg in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>return True<EOL><DEDENT>elif color_fg_bg in ('<STR_LIT>', '<STR_LIT>' ):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>return None<EOL>

Consult (environment) variables DARK_BG and COLORFGB
    On return, variable is_dark_bg is set


try:<EOL><INDENT>return obj_name + inspect.formatargspec(*inspect.getargspec(obj))<EOL><DEDENT>except:<EOL><INDENT>return None<EOL><DEDENT>return<EOL>

A slightly decorated version of inspect.format_argspec


def print_obj(arg, frame, format=None, short=False):

try:<EOL><INDENT>if not frame:<EOL><INDENT>obj = eval(arg, None, None)<EOL><DEDENT>else:<EOL><INDENT>obj = eval(arg, frame.f_globals, frame.f_locals)<EOL>pass<EOL><DEDENT><DEDENT>except:<EOL><INDENT>return '<STR_LIT>' + arg + '<STR_LIT>'<EOL><DEDENT>what = arg<EOL>if format:<EOL><INDENT>what = format + '<STR_LIT:U+0020>' + arg<EOL>obj = printf(obj, format)<EOL><DEDENT>s = '<STR_LIT>' % (what, obj)<EOL>if not short:<EOL><INDENT>s += '<STR_LIT>' % type(obj)<EOL>if callable(obj):<EOL><INDENT>argspec = print_argspec(obj, arg)<EOL>if argspec:<EOL><INDENT>s += '<STR_LIT>'<EOL>if inspect.isclass(obj):<EOL><INDENT>s += '<STR_LIT>'<EOL>obj = obj.__init__<EOL><DEDENT>elif isinstance(obj, types.InstanceType):<EOL><INDENT>obj = obj.__call__<EOL>pass<EOL><DEDENT>s+= argspec<EOL><DEDENT>pass<EOL><DEDENT>s = print_dict(s, obj, "<STR_LIT>")<EOL>if hasattr(obj, "<STR_LIT>"):<EOL><INDENT>s = print_dict(s, obj.__class__, "<STR_LIT>")<EOL>pass<EOL><DEDENT><DEDENT>return s<EOL>

Return a string representation of an object


if not frame: return None<EOL>code = frame.f_code<EOL>return (code.co_name, code.co_filename, code.co_firstlineno)<EOL>

return suitable frame signature to key display expressions off of.


found = False<EOL>s = []<EOL>for display in self.list:<EOL><INDENT>if not found:<EOL><INDENT>s.append("""<STR_LIT>""")<EOL>found = True<EOL>pass<EOL><DEDENT>s.append(display.format())<EOL><DEDENT>return s<EOL>

List all display items; return 0 if none


self.list = []<EOL>return<EOL>


old_size = len(self.list)<EOL>self.list = [disp for disp in self.list<EOL>if display_number != disp.number]<EOL>return old_size != len(self.list)<EOL>

Delete display expression *display_number*


if not frame: return<EOL>s = []<EOL>sig = signature(frame)<EOL>for display in self.list:<EOL><INDENT>if display.signature == sig and display.enabled:<EOL><INDENT>s.append(display.to_s(frame))<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>return s<EOL>


what = '<STR_LIT>'<EOL>if show_enabled:<EOL><INDENT>if self.enabled:<EOL><INDENT>what += '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>what += '<STR_LIT>'<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>if self.fmt:<EOL><INDENT>what += self.fmt + '<STR_LIT:U+0020>'<EOL>pass<EOL><DEDENT>what += self.arg<EOL>return '<STR_LIT>' % (self.number, what)<EOL>


return True if filename[-<NUM_LIT:4>:].lower() in ('<STR_LIT>', '<STR_LIT>') else False<EOL>

Given a file name, return True if the suffix is pyo or pyc (an
optimized bytecode file).


try:<EOL><INDENT>st = os.stat(path)<EOL>return <NUM_LIT:0> != st.st_mode & READABLE_MASK<EOL><DEDENT>except os.error:<EOL><INDENT>return None<EOL><DEDENT>return True<EOL>

Test whether a path exists and is readable.  Returns None for
    broken symbolic links or a failing stat() and False if
    the file exists but does not have read permission. True is returned
    if the file is readable.


if sys.modules.get(name):<EOL><INDENT>return (sys.modules[name], sys.modules[name].__file__)<EOL><DEDENT>if os.path.isabs(name) and readable(name):<EOL><INDENT>return (None, name)<EOL><DEDENT>f = os.path.join(sys.path[<NUM_LIT:0>], name)<EOL>if readable(f):<EOL><INDENT>return (None, f)<EOL><DEDENT>root, ext = os.path.splitext(name)<EOL>if ext == '<STR_LIT>':<EOL><INDENT>name = name + '<STR_LIT>'<EOL>pass<EOL><DEDENT>if os.path.isabs(name):<EOL><INDENT>return (None, name)<EOL><DEDENT>for dirname in sys.path:<EOL><INDENT>while os.path.islink(dirname):<EOL><INDENT>dirname = os.readlink(dirname)<EOL>pass<EOL><DEDENT>fullname = os.path.join(dirname, name)<EOL>if readable(fullname):<EOL><INDENT>return (None, fullname)<EOL><DEDENT>pass<EOL><DEDENT>return (None, None)<EOL>

lookupmodule()->(module, file) translates a possibly incomplete
    file or module name into an absolute file name. None can be
    returned for either of the values positions of module or file when
    no or module or file is found.


colon = arg.rfind('<STR_LIT::>')<EOL>if colon >= <NUM_LIT:0>:<EOL><INDENT>filename = arg[:colon].rstrip()<EOL>m, f = lookupmodule(filename)<EOL>if not f:<EOL><INDENT>errmsg("<STR_LIT>" % filename)<EOL>return (None, None, None)<EOL><DEDENT>else:<EOL><INDENT>filename = pyficache.pyc2py(f)<EOL>arg = arg[colon+<NUM_LIT:1>:].lstrip()<EOL>pass<EOL><DEDENT>try:<EOL><INDENT>lineno = int(arg)<EOL><DEDENT>except TypeError:<EOL><INDENT>errmsg("<STR_LIT>", str(arg))<EOL>return (None, filename, None)<EOL><DEDENT>return (None, filename, lineno)<EOL><DEDENT>return (None, None, None)<EOL>

parse_position(errmsg, arg)->(fn, name, lineno)

    Parse arg as [filename|module:]lineno
    Make sure it works for C:\foo\bar.py:12


if not b.funcname:<EOL><INDENT>if b.line != frame.f_lineno:<EOL><INDENT>return False<EOL><DEDENT>return True<EOL><DEDENT>if frame.f_code.co_name != b.funcname:<EOL><INDENT>return False<EOL><DEDENT>if not b.func_first_executable_line:<EOL><INDENT>b.func_first_executable_line = frame.f_lineno<EOL><DEDENT>if b.func_first_executable_line != frame.f_lineno:<EOL><INDENT>return False<EOL><DEDENT>return True<EOL>

Check whether we should break here because of `b.funcname`.


return ["<STR_LIT>" % bp.number for bp in self.bpbynumber if<EOL>bp is not None]<EOL>

Returns a list of strings of breakpoint numbers


bpnum = bp.number<EOL>self.bpbynumber[bpnum] = None   <EOL>index = (bp.filename, bp.line)<EOL>if index not in self.bplist: return False<EOL>self.bplist[index].remove(bp)<EOL>if not self.bplist[index]:<EOL><INDENT>del self.bplist[index]<EOL><DEDENT>return True<EOL>


success, msg, bp = self.get_breakpoint(bpnum)<EOL>if not success:<EOL><INDENT>return False, msg<EOL><DEDENT>self.delete_breakpoint(bp)<EOL>return (True, '<STR_LIT>')<EOL>

Remove a breakpoint given its breakpoint number.


def en_disable_all_breakpoints(self,  do_enable=True):

bp_list = [bp for bp in self.bpbynumber if bp]<EOL>bp_nums = []<EOL>if do_enable:<EOL><INDENT>endis = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>endis = '<STR_LIT>'<EOL>pass<EOL><DEDENT>if not bp_list:<EOL><INDENT>return "<STR_LIT>" % endis<EOL><DEDENT>for bp in bp_list:<EOL><INDENT>bp.enabled = do_enable<EOL>bp_nums.append(str(bp.number))<EOL>pass<EOL><DEDENT>return ("<STR_LIT>" % (endis, "<STR_LIT:U+002CU+0020>".join(bp_nums)))<EOL>


def en_disable_breakpoint_by_number(self, bpnum, do_enable=True):

success, msg, bp = self.get_breakpoint(bpnum)<EOL>if not success:<EOL><INDENT>return success, msg<EOL><DEDENT>if do_enable:<EOL><INDENT>endis = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>endis = '<STR_LIT>'<EOL>pass<EOL><DEDENT>if bp.enabled == do_enable:<EOL><INDENT>return (False, ('<STR_LIT>' %<EOL>(str(bpnum), endis,)))<EOL><DEDENT>bp.enabled = do_enable<EOL>return (True, '<STR_LIT>')<EOL>

Enable or disable a breakpoint given its breakpoint number.


def delete_breakpoints_by_lineno(self, filename, lineno):

if (filename, lineno) not in self.bplist:<EOL><INDENT>return []<EOL><DEDENT>breakpoints = self.bplist[(filename, lineno)]<EOL>bpnums = [bp.number for bp in breakpoints]<EOL>for bp in list(breakpoints):<EOL><INDENT>self.delete_breakpoint(bp)<EOL><DEDENT>return bpnums<EOL>

Removes all breakpoints at a give filename and line number.
        Returns a list of breakpoints numbers deleted.


def find_bp(self, filename, lineno, frame):

possibles = self.bplist[filename, lineno]<EOL>for i in range(<NUM_LIT:0>, len(possibles)):<EOL><INDENT>b = possibles[i]<EOL>if not b.enabled:<EOL><INDENT>continue<EOL><DEDENT>if not checkfuncname(b, frame):<EOL><INDENT>continue<EOL><DEDENT>b.hits += <NUM_LIT:1><EOL>if not b.condition:<EOL><INDENT>if b.ignore > <NUM_LIT:0>:<EOL><INDENT>b.ignore = b.ignore -<NUM_LIT:1><EOL>continue<EOL><DEDENT>else:<EOL><INDENT>return (b, True)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>val = eval(b.condition, frame.f_globals, frame.f_locals)<EOL>if val:<EOL><INDENT>if b.ignore > <NUM_LIT:0>:<EOL><INDENT>b.ignore = b.ignore -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>return (b, True)<EOL><DEDENT><DEDENT><DEDENT>except:<EOL><INDENT>return (b, False)<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>return (None, None)<EOL>

Determine which breakpoint for this file:line is to be acted upon.

        Called only if we know there is a bpt at this
        location.  Returns breakpoint that was triggered and a flag
        that indicates if it is ok to delete a temporary breakpoint.


self.bpbynumber = [None]<EOL>self.bplist = {}<EOL>self.fnlist  = {}<EOL>return<EOL>

A list of breakpoints by breakpoint number.  Each entry is
        None or an instance of Breakpoint.  Index 0 is unused, except
        for marking an effective break .... see effective().


if self.temporary : return '<STR_LIT:t>'<EOL>elif self.enabled:  return '<STR_LIT:B>'<EOL>else: return '<STR_LIT:b>'<EOL>return<EOL>

Return a one-character "icon" giving the state of the breakpoint
        't': temporary breakpoint
        'B': enabled breakpoint
        'b': disabled breakpoint


def __init__(self, debugger, opts=None):

import trepan.bwprocessor as Mbwproc<EOL>get_option       = lambda key: Mmisc.option_set(opts, key,<EOL>self.DEFAULT_INIT_OPTS)<EOL>self.bpmgr           = breakpoint.BreakpointManager()<EOL>self.current_bp      = None<EOL>self.debugger        = debugger<EOL>self.debugger_lock   = threading.Lock()<EOL>self.filename_cache  = {}<EOL>self.event           = None<EOL>self.execution_status = '<STR_LIT>'<EOL>self.main_dirname    = os.curdir<EOL>self.processor = get_option('<STR_LIT>')<EOL>proc_opts      = get_option('<STR_LIT>')<EOL>if not self.processor:<EOL><INDENT>self.processor   = Mcmdproc.CommandProcessor(self, opts=proc_opts)<EOL><DEDENT>elif self.processor == '<STR_LIT>':<EOL><INDENT>self.processor   = Mbwproc.BWProcessor(self, opts=proc_opts)<EOL>pass<EOL><DEDENT>self.step_events     = None<EOL>self.step_ignore     = get_option('<STR_LIT>')<EOL>self.last_frame      = None<EOL>self.last_level      = <NUM_LIT><EOL>self.last_thread     = None<EOL>self.stop_level      = None<EOL>self.stop_on_finish  = False<EOL>self.last_lineno     = None<EOL>self.last_filename   = None<EOL>self.different_line  = None<EOL>self.stop_reason     = '<STR_LIT>'<EOL>self.trace_processor = Mtrace.PrintProcessor(self)<EOL>self.ignore_filter = get_option('<STR_LIT>')<EOL>self.search_path     = sys.path  <EOL>self.trace_hook_suspend = False<EOL>self.until_condition = get_option('<STR_LIT>')<EOL>return<EOL>

Create a debugger object. But depending on the value of
        key 'start' inside hash `opts', we may or may not initially
        start tracing events (i.e. enter the debugger).

        See also `start' and `stop'.


for frame_or_fn in frames_or_fns:<EOL><INDENT>rc = self.ignore_filter.add_include(frame_or_fn)<EOL>pass<EOL><DEDENT>return rc<EOL>

Add `frame_or_fn' to the list of functions that are not to
        be debugged


if filename == "<STR_LIT:<>" + filename[<NUM_LIT:1>:-<NUM_LIT:1>] + "<STR_LIT:>>":<EOL><INDENT>return filename<EOL><DEDENT>canonic = self.filename_cache.get(filename)<EOL>if not canonic:<EOL><INDENT>lead_dir = filename.split(os.sep)[<NUM_LIT:0>]<EOL>if lead_dir == os.curdir or lead_dir == os.pardir:<EOL><INDENT>canonic = os.path.abspath(os.path.join(self.main_dirname,<EOL>filename))<EOL><DEDENT>else:<EOL><INDENT>canonic = os.path.abspath(filename)<EOL>pass<EOL><DEDENT>if not os.path.isfile(canonic):<EOL><INDENT>canonic = Mclifns.search_file(filename, self.search_path,<EOL>self.main_dirname)<EOL>if not canonic: canonic = filename<EOL>pass<EOL><DEDENT>canonic = os.path.realpath(os.path.normcase(canonic))<EOL>self.filename_cache[filename] = canonic<EOL><DEDENT>return canonic<EOL>

Turns `filename' into its canonic representation and returns this
        string. This allows a user to refer to a given file in one of several
        equivalent ways.

        Relative filenames need to be fully resolved, since the current working
        directory might change over the course of execution.

        If filename is enclosed in < ... >, then we assume it is
        one of the bogus internal Python names like <string> which is seen
        for example when executing "exec cmd".


return self.canonic(frame.f_code.co_filename)<EOL>

Picks out the file name from `frame' and returns its
         canonic() value, a string.


if filename is None:<EOL><INDENT>if self.debugger.mainpyfile:<EOL><INDENT>filename = self.debugger.mainpyfile<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>if self.debugger.settings['<STR_LIT>']:<EOL><INDENT>return(os.path.basename(filename))<EOL><DEDENT>return filename<EOL>

Return filename or the basename of that depending on the
        basename setting


return (tracer.is_started() and<EOL>not self.trace_hook_suspend<EOL>and tracer.find_hook(self.trace_dispatch))<EOL>

Return True if debugging is in progress.


return self.ignore_filter.remove_include(frame_or_fn)<EOL>

Remove `frame_or_fn' to the list of functions that are not to
        be debugged


<EOL>try:<EOL><INDENT>self.trace_hook_suspend = True<EOL>get_option = lambda key: Mmisc.option_set(opts, key,<EOL>default.START_OPTS)<EOL>add_hook_opts = get_option('<STR_LIT>')<EOL>if not tracer.is_started() or get_option('<STR_LIT>'):<EOL><INDENT>tracer_start_opts = default.START_OPTS.copy()<EOL>if opts:<EOL><INDENT>tracer_start_opts.update(opts.get('<STR_LIT>', {}))<EOL><DEDENT>tracer_start_opts['<STR_LIT>'] = self.trace_dispatch<EOL>tracer_start_opts['<STR_LIT>'] = add_hook_opts<EOL>tracer.start(tracer_start_opts)<EOL><DEDENT>elif not tracer.find_hook(self.trace_dispatch):<EOL><INDENT>tracer.add_hook(self.trace_dispatch, add_hook_opts)<EOL>pass<EOL><DEDENT>self.execution_status = '<STR_LIT>'<EOL><DEDENT>finally:<EOL><INDENT>self.trace_hook_suspend = False<EOL><DEDENT>return<EOL>

We've already created a debugger object, but here we start
        debugging in earnest. We can also turn off debugging (but have
        the hooks suspended or not) using 'stop'.

        'opts' is a hash of every known value you might want to set when
        starting the debugger. See START_OPTS of module default.


def is_stop_here(self, frame, event, arg):

<EOL>lineno = frame.f_lineno<EOL>filename = frame.f_code.co_filename<EOL>if self.different_line and event == '<STR_LIT>':<EOL><INDENT>if self.last_lineno == lineno and self.last_filename == filename:<EOL><INDENT>return False<EOL><DEDENT>pass<EOL><DEDENT>self.last_lineno   = lineno<EOL>self.last_filename = filename<EOL>if self.stop_level is not None:<EOL><INDENT>if frame != self.last_frame:<EOL><INDENT>self.last_level = Mstack.count_frames(frame)<EOL>self.last_frame = frame<EOL>pass<EOL><DEDENT>if self.last_level > self.stop_level:<EOL><INDENT>return False<EOL><DEDENT>elif self.last_level == self.stop_level andself.stop_on_finish and event in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>self.stop_level = None<EOL>self.stop_reason = "<STR_LIT>"<EOL>return True<EOL><DEDENT>pass<EOL><DEDENT>if self._is_step_next_stop(event):<EOL><INDENT>self.stop_reason = '<STR_LIT>'<EOL>return True<EOL><DEDENT>return False<EOL>

Does the magic to determine if we stop here and run a
        command processor or not. If so, return True and set
        self.stop_reason; if not, return False.

        Determining factors can be whether a breakpoint was
        encountered, whether we are stepping, next'ing, finish'ing,
        and, if so, whether there is an ignore counter.


def set_next(self, frame, step_ignore=<NUM_LIT:0>, step_events=None):

self.step_events      = None  <EOL>self.stop_level       = Mstack.count_frames(frame)<EOL>self.last_level       = self.stop_level<EOL>self.last_frame       = frame<EOL>self.stop_on_finish   = False<EOL>self.step_ignore      = step_ignore<EOL>return<EOL>

Sets to stop on the next event that happens in frame 'frame'.


def trace_dispatch(self, frame, event, arg):

<EOL>try:<EOL><INDENT>self.debugger_lock.acquire()<EOL>if self.trace_hook_suspend:<EOL><INDENT>return None<EOL><DEDENT>self.event = event<EOL>if self.ignore_filter and self.ignore_filter.is_included(frame):<EOL><INDENT>return True<EOL><DEDENT>if self.debugger.settings['<STR_LIT>']:<EOL><INDENT>print_event_set = self.debugger.settings['<STR_LIT>']<EOL>if self.event in print_event_set:<EOL><INDENT>self.trace_processor.event_processor(frame,<EOL>self.event, arg)<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>if self.until_condition:<EOL><INDENT>if not self.matches_condition(frame): return True<EOL>pass<EOL><DEDENT>trace_event_set = self.debugger.settings['<STR_LIT>']<EOL>if trace_event_set is None or self.event not in trace_event_set:<EOL><INDENT>return True<EOL><DEDENT>if ( self.is_stop_here(frame, event, arg) or<EOL>self.is_break_here(frame, arg) ):<EOL><INDENT>return self.processor.event_processor(frame, self.event, arg)<EOL><DEDENT>return True<EOL><DEDENT>finally:<EOL><INDENT>try:<EOL><INDENT>self.debugger_lock.release()<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL>

A trace event occurred. Filter or pass the information to a
        specialized event processor. Note that there may be more filtering
        that goes on in the command processor (e.g. to force a
        different line). We could put that here, but since that seems
        processor-specific I think it best to distribute the checks.


if type(b) != bool:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>if b:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>return "<STR_LIT>"<EOL>

Return 'Yes' for True and 'No' for False, and ?? for anything
    else.


signames = signal.__dict__<EOL>num = abs(num)<EOL>for signame in list(signames.keys()):<EOL><INDENT>if signame.startswith('<STR_LIT>') and signames[signame] == num:<EOL><INDENT>return signame<EOL><DEDENT>pass<EOL><DEDENT>return None<EOL>

Find the corresponding signal name for 'num'. Return None
    if 'num' is invalid.


uname = name.upper()<EOL>if (uname.startswith('<STR_LIT>') and hasattr(signal, uname)):<EOL><INDENT>return getattr(signal, uname)<EOL><DEDENT>else:<EOL><INDENT>uname = "<STR_LIT>"+uname<EOL>if hasattr(signal, uname):<EOL><INDENT>return getattr(signal, uname)<EOL><DEDENT>return None<EOL><DEDENT>return<EOL>

Find the corresponding signal number for 'name'. Return None
    if 'name' is invalid.


signum = lookup_signum(name_num)<EOL>if signum is None:<EOL><INDENT>try:<EOL><INDENT>num = int(name_num)<EOL>signame = lookup_signame(num)<EOL>if signame is None:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>except:<EOL><INDENT>return False<EOL><DEDENT>return signame<EOL><DEDENT>signame = name_num.upper()<EOL>if not signame.startswith('<STR_LIT>'): return '<STR_LIT>'+signame<EOL>return signame<EOL>

Return a signal name for a signal name or signal
    number.  Return None is name_num is an int but not a valid signal
    number and False if name_num is a not number. If name_num is a
    signal name or signal number, the canonic if name is returned.


def set_signal_replacement(self, signum, handle):

signame = lookup_signame(signum)<EOL>if signame is None:<EOL><INDENT>self.dbgr.intf[-<NUM_LIT:1>].errmsg(("<STR_LIT>"<EOL>"<STR_LIT>")  % signum)<EOL>return False<EOL><DEDENT>self.sigs[signame].pass_along = True<EOL>if self.check_and_adjust_sighandler(signame, self.sigs):<EOL><INDENT>self.sigs[signame].old_handler = handle<EOL>return True<EOL><DEDENT>return False<EOL>

A replacement for signal.signal which chains the signal behind
        the debugger's handler


def check_and_adjust_sighandler(self, signame, sigs):

signum = lookup_signum(signame)<EOL>try:<EOL><INDENT>old_handler = signal.getsignal(signum)<EOL><DEDENT>except ValueError:<EOL><INDENT>if signame in self.sigs:<EOL><INDENT>sigs.pop(signame)<EOL>pass<EOL><DEDENT>return None<EOL><DEDENT>if old_handler != self.sigs[signame].handle:<EOL><INDENT>if old_handler not in [signal.SIG_IGN, signal.SIG_DFL]:<EOL><INDENT>sigs[signame].old_handler = old_handler<EOL>pass<EOL><DEDENT>try:<EOL><INDENT>self._orig_set_signal(signum, self.sigs[signame].handle)<EOL><DEDENT>except ValueError:<EOL><INDENT>return False<EOL><DEDENT>except KeyError:<EOL><INDENT>return False<EOL><DEDENT>pass<EOL><DEDENT>return True<EOL>

Check to see if a single signal handler that we are interested
in has changed or has not been set initially. On return
self.sigs[signame] should have our signal handler. True is
returned if the same or adjusted, False or None if error or
not found.


for signame in list(self.sigs.keys()):<EOL><INDENT>if not self.check_and_adjust_sighandler(signame, self.sigs):<EOL><INDENT>break<EOL><DEDENT>pass<EOL><DEDENT>return<EOL>

Check to see if any of the signal handlers we are interested in have
        changed or is not initially set. Change any that are not right.


if signame in signal_description:<EOL><INDENT>description=signal_description[signame]<EOL><DEDENT>else:<EOL><INDENT>description="<STR_LIT>"<EOL>pass<EOL><DEDENT>if signame not in list(self.sigs.keys()):<EOL><INDENT>self.dbgr.intf[-<NUM_LIT:1>].msg(self.info_fmt<EOL>% (signame, '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>description))<EOL>return<EOL><DEDENT>sig_obj = self.sigs[signame]<EOL>self.dbgr.intf[-<NUM_LIT:1>].msg(self.info_fmt %<EOL>(signame,<EOL>YN(sig_obj.b_stop),<EOL>YN(sig_obj.print_method is not None),<EOL>YN(sig_obj.print_stack),<EOL>YN(sig_obj.pass_along),<EOL>description))<EOL>return<EOL>

Print status for a single signal name (signame)


if len(args) == <NUM_LIT:0>: return None<EOL>signame = args[<NUM_LIT:0>]<EOL>if signame in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>if len(args) == <NUM_LIT:1>:<EOL><INDENT>self.dbgr.core.processor.section(self.header)<EOL>for signame in self.siglist:<EOL><INDENT>self.print_info_signal_entry(signame)<EOL><DEDENT>return True<EOL><DEDENT>else:<EOL><INDENT>signame = args[<NUM_LIT:1>]<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>signame = self.is_name_or_number(signame)<EOL>self.dbgr.core.processor.section(self.header)<EOL>self.print_info_signal_entry(signame)<EOL>return True<EOL>


if not arg:<EOL><INDENT>self.info_signal(['<STR_LIT>'])<EOL>return True<EOL><DEDENT>args = arg.split()<EOL>signame = args[<NUM_LIT:0>]<EOL>signame = self.is_name_or_number(args[<NUM_LIT:0>])<EOL>if not signame: return<EOL>if len(args) == <NUM_LIT:1>:<EOL><INDENT>self.info_signal([signame])<EOL>return True<EOL><DEDENT>if signame in fatal_signals:<EOL><INDENT>return None<EOL><DEDENT>if signame not in list(self.sigs.keys()):<EOL><INDENT>if not self.initialize_handler(signame): return None<EOL>pass<EOL><DEDENT>for attr in args[<NUM_LIT:1>:]:<EOL><INDENT>if attr.startswith('<STR_LIT>'):<EOL><INDENT>on = False<EOL>attr = attr[<NUM_LIT:2>:]<EOL><DEDENT>else:<EOL><INDENT>on = True<EOL><DEDENT>if '<STR_LIT>'.startswith(attr):<EOL><INDENT>self.handle_stop(signame, on)<EOL><DEDENT>elif '<STR_LIT>'.startswith(attr) and len(attr) >= <NUM_LIT:2>:<EOL><INDENT>self.handle_print(signame, on)<EOL><DEDENT>elif '<STR_LIT>'.startswith(attr):<EOL><INDENT>self.handle_pass(signame, on)<EOL><DEDENT>elif '<STR_LIT:ignore>'.startswith(attr):<EOL><INDENT>self.handle_ignore(signame, on)<EOL><DEDENT>elif '<STR_LIT>'.startswith(attr):<EOL><INDENT>self.handle_print_stack(signame, on)<EOL><DEDENT>else:<EOL><INDENT>self.dbgr.intf[-<NUM_LIT:1>].errmsg('<STR_LIT>')<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>return self.check_and_adjust_sighandler(signame, self.sigs)<EOL>

Delegate the actions specified in 'arg' to another
        method.


def handle_print_stack(self, signame, print_stack):

self.sigs[signame].print_stack = print_stack<EOL>return print_stack<EOL>

Set whether we stop or not when this signal is caught.
        If 'set_stop' is True your program will stop when this signal
        happens.


def handle_stop(self, signame, set_stop):

if set_stop:<EOL><INDENT>self.sigs[signame].b_stop       = True<EOL>self.sigs[signame].print_method = self.dbgr.intf[-<NUM_LIT:1>].msg<EOL>self.sigs[signame].pass_along   = False<EOL><DEDENT>else:<EOL><INDENT>self.sigs[signame].b_stop       = False<EOL>pass<EOL><DEDENT>return set_stop<EOL>


def handle_pass(self, signame, set_pass):

self.sigs[signame].pass_along = set_pass<EOL>if set_pass:<EOL><INDENT>self.sigs[signame].b_stop = False<EOL>pass<EOL><DEDENT>return set_pass<EOL>

Set whether we pass this signal to the program (or not)
        when this signal is caught. If set_pass is True, Dbgr should allow
        your program to see this signal.


def handle_ignore(self, signame, set_ignore):

self.handle_pass(signame, not set_ignore)<EOL>return set_ignore<EOL>

pass' and 'noignore' are synonyms. 'nopass and 'ignore' are
        synonyms.


def handle_print(self, signame, set_print):

if set_print:<EOL><INDENT>self.sigs[signame].print_method = self.dbgr.intf[-<NUM_LIT:1>].msg<EOL><DEDENT>else:<EOL><INDENT>self.sigs[signame].print_method = None<EOL>pass<EOL><DEDENT>return set_print<EOL>

Set whether we print or not when this signal is caught.


if self.print_method:<EOL><INDENT>self.print_method('<STR_LIT>'<EOL>% self.signame)<EOL><DEDENT>if self.print_stack:<EOL><INDENT>import traceback<EOL>strings = traceback.format_stack(frame)<EOL>for s in strings:<EOL><INDENT>if s[-<NUM_LIT:1>] == '<STR_LIT:\n>': s = s[<NUM_LIT:0>:-<NUM_LIT:1>]<EOL>self.print_method(s)<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>if self.b_stop:<EOL><INDENT>core = self.dbgr.core<EOL>old_trace_hook_suspend = core.trace_hook_suspend<EOL>core.trace_hook_suspend = True<EOL>core.stop_reason = ('<STR_LIT>' %<EOL>(self.signame, signum))<EOL>core.processor.event_processor(frame, '<STR_LIT>', signum)<EOL>core.trace_hook_suspend = old_trace_hook_suspend<EOL>pass<EOL><DEDENT>if self.pass_along:<EOL><INDENT>if self.old_handler:<EOL><INDENT>self.old_handler(signum, frame)<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>return<EOL>

This method is called when a signal is received.


def pprint_simple_array(val, displaywidth, msg_nocr, msg, lineprefix='<STR_LIT>'):

if type(val) != list:<EOL><INDENT>return False<EOL><DEDENT>numeric = True<EOL>for i in range(len(val)):<EOL><INDENT>if not (type(val[i]) in [bool, float, int]):<EOL><INDENT>numeric = False<EOL>if not (type(val[i]) in [bool, float, int, bytes]):<EOL><INDENT>return False<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>mess = columnize([repr(v) for v in val],<EOL>opts={"<STR_LIT>": True,<EOL>"<STR_LIT>": lineprefix,<EOL>"<STR_LIT>": int(displaywidth)-<NUM_LIT:3>,<EOL>'<STR_LIT>': not numeric})<EOL>msg_nocr(mess)<EOL>return True<EOL>

Try to pretty print a simple case where a list is not nested.
    Return True if we can do it and False if not.


def complete_token_filtered_with_next(aliases, prefix, expanded, commands):

complete_ary = list(aliases.keys())<EOL>expanded_ary = list(expanded.keys())<EOL>result = []<EOL>for cmd in complete_ary:<EOL><INDENT>if cmd.startswith(prefix):<EOL><INDENT>if cmd in aliases and (<EOL><NUM_LIT:0> == len(set(expanded_ary) - set([aliases[cmd]]))):<EOL><INDENT>result.append([cmd, aliases[cmd]])<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL>return sorted(result, key=lambda pair: pair[<NUM_LIT:0>])<EOL>

Find all starting matches in dictionary *aliases* that start
    with *prefix*, but filter out any matches already in
    *expanded*.


def complete_token_filtered(aliases, prefix, expanded):

complete_ary = aliases.keys()<EOL>return [cmd for cmd in complete_ary if cmd.startswith(prefix)]<EOL>

Find all starting matches in dictionary *aliases* that start
     with *prefix*, but filter out any matches already in *expanded*


look_at = str[start_pos:]<EOL>match = re.search('<STR_LIT>', look_at)<EOL>if match:<EOL><INDENT>pos = match.start()<EOL><DEDENT>else:<EOL><INDENT>pos = <NUM_LIT:0><EOL>pass<EOL><DEDENT>next_nonblank_pos = start_pos + pos<EOL>next_match = re.search('<STR_LIT>', str[next_nonblank_pos:])<EOL>if next_match:<EOL><INDENT>next_blank_pos = next_nonblank_pos + next_match.start()<EOL><DEDENT>else:<EOL><INDENT>next_blank_pos = len(str)<EOL>pass<EOL><DEDENT>return [next_blank_pos, str[next_nonblank_pos:next_blank_pos+<NUM_LIT:1>].rstrip()]<EOL>

Find the next token in str string from start_pos, we return
    the token and the next blank position after the token or
    str.size if this is the last token. Tokens are delimited by
    white space.


try:<EOL><INDENT>c = compile(source, name, '<STR_LIT>')<EOL><DEDENT>except SyntaxError:<EOL><INDENT>c = compile(source, name, '<STR_LIT>')<EOL><DEDENT>return c<EOL>

Attempts to compile the given source, first as an expression and
       then as a statement if the first approach fails.

       Utility function to accept strings in functions that otherwise
       expect code objects


def dis(msg, msg_nocr, section, errmsg, x=None, start_line=-<NUM_LIT:1>, end_line=None,<EOL>relative_pos = False, highlight='<STR_LIT>', start_offset=<NUM_LIT:0>, end_offset=None,<EOL>include_header=False):

lasti = -<NUM_LIT:1><EOL>if x is None:<EOL><INDENT>distb()<EOL>return None, None<EOL><DEDENT>if start_offset is None:<EOL><INDENT>start_offset = <NUM_LIT:0><EOL><DEDENT>mess = '<STR_LIT>'<EOL>if start_line > <NUM_LIT:1>:<EOL><INDENT>mess += "<STR_LIT>" % start_line<EOL><DEDENT>elif start_offset > <NUM_LIT:1>:<EOL><INDENT>mess = "<STR_LIT>" % start_offset<EOL><DEDENT>if end_line:<EOL><INDENT>mess += "<STR_LIT>" % end_line<EOL><DEDENT>elif end_offset:<EOL><INDENT>mess += "<STR_LIT>" % end_offset<EOL><DEDENT>sectioned = False<EOL>if hasattr(types, '<STR_LIT>') and isinstance(x, types.InstanceType):<EOL><INDENT>x = x.__class__<EOL><DEDENT>if inspect.ismethod(x):<EOL><INDENT>section("<STR_LIT>" % (x, mess))<EOL>sectioned = True<EOL>x = x.im_func<EOL><DEDENT>elif inspect.isfunction(x) or inspect.isgeneratorfunction(x):<EOL><INDENT>section("<STR_LIT>" % (x, mess))<EOL>x = x.func_code<EOL>sectioned = True<EOL><DEDENT>elif inspect.isgenerator(x):<EOL><INDENT>section("<STR_LIT>" % (x, mess))<EOL>frame = x.gi_frame<EOL>lasti = frame.f_last_i<EOL>x = x.gi_code<EOL>sectioned = True<EOL><DEDENT>elif inspect.isframe(x):<EOL><INDENT>section("<STR_LIT>" % (x, mess))<EOL>sectioned = True<EOL>if hasattr(x, '<STR_LIT>'):<EOL><INDENT>lasti = x.f_lasti<EOL>if lasti == -<NUM_LIT:1>: lasti = <NUM_LIT:0><EOL>pass<EOL><DEDENT>opc = get_opcode(PYTHON_VERSION, IS_PYPY)<EOL>x = x.f_code<EOL>if include_header:<EOL><INDENT>header_lines = Bytecode(x, opc).info().split("<STR_LIT:\n>")<EOL>header = '<STR_LIT:\n>'.join([format_token(Mformat.Comment, h) for h in header_lines])<EOL>msg(header)<EOL><DEDENT>pass<EOL><DEDENT>elif inspect.iscode(x):<EOL><INDENT>pass<EOL><DEDENT>if hasattr(x, '<STR_LIT>'):  <EOL><INDENT>items = sorted(x.__dict__.items())<EOL>for name, x1 in items:<EOL><INDENT>if isinstance(x1, _have_code):<EOL><INDENT>if not sectioned:<EOL><INDENT>section("<STR_LIT>" % x)<EOL><DEDENT>try:<EOL><INDENT>dis(msg, msg_nocr, section, errmsg, x1,<EOL>start_line=start_line, end_line=end_line,<EOL>relative_pos = relative_pos)<EOL>msg("<STR_LIT>")<EOL><DEDENT>except TypeError:<EOL><INDENT>_, msg, _ = sys.exc_info()<EOL>errmsg("<STR_LIT>", msg)<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>elif hasattr(x, '<STR_LIT>'):  <EOL><INDENT>if not sectioned:<EOL><INDENT>section("<STR_LIT>" % x)<EOL><DEDENT>return disassemble(msg, msg_nocr, section, x, lasti=lasti,<EOL>start_line=start_line, end_line=end_line,<EOL>relative_pos = relative_pos,<EOL>highlight = highlight,<EOL>start_offset = start_offset,<EOL>end_offset = end_offset)<EOL><DEDENT>elif isinstance(x, str):    <EOL><INDENT>return disassemble_string(msg, msg_nocr, x,)<EOL><DEDENT>else:<EOL><INDENT>errmsg("<STR_LIT>" %<EOL>type(x).__name__)<EOL><DEDENT>return None, None<EOL>

Disassemble classes, methods, functions, or code.

    With no argument, disassemble the last traceback.


def disassemble(msg, msg_nocr, section, co, lasti=-<NUM_LIT:1>, start_line=-<NUM_LIT:1>,<EOL>end_line=None, relative_pos=False, highlight='<STR_LIT>',<EOL>start_offset=<NUM_LIT:0>, end_offset=None):

return disassemble_bytes(msg, msg_nocr, co.co_code, lasti, co.co_firstlineno,<EOL>start_line, end_line, relative_pos,<EOL>co.co_varnames, co.co_names, co.co_consts,<EOL>co.co_cellvars, co.co_freevars,<EOL>dict(findlinestarts(co)), highlight,<EOL>start_offset=start_offset, end_offset=end_offset)<EOL>


def disassemble_string(msg, msg_nocr, source):

return disassemble_bytes(msg, msg_nocr, _try_compile(source, '<STR_LIT>'))<EOL>

Compile the source string, then disassemble the code object.


def disassemble_bytes(orig_msg, orig_msg_nocr, code, lasti=-<NUM_LIT:1>, cur_line=<NUM_LIT:0>,<EOL>start_line=-<NUM_LIT:1>, end_line=None, relative_pos=False,<EOL>varnames=(), names=(), constants=(), cells=(),<EOL>freevars=(), linestarts={}, highlight='<STR_LIT>',<EOL>start_offset=<NUM_LIT:0>, end_offset=None):

statement_count = <NUM_LIT><EOL>if end_line is None:<EOL><INDENT>end_line = <NUM_LIT><EOL><DEDENT>elif relative_pos:<EOL><INDENT>end_line += start_line -<NUM_LIT:1><EOL>pass<EOL><DEDENT>labels = findlabels(code)<EOL>null_print = lambda x: None<EOL>if start_line > cur_line:<EOL><INDENT>msg_nocr = null_print<EOL>msg = null_print<EOL><DEDENT>else:<EOL><INDENT>msg_nocr = orig_msg_nocr<EOL>msg = orig_msg<EOL><DEDENT>for instr in get_instructions_bytes(code, opc, varnames, names,<EOL>constants, cells, linestarts):<EOL><INDENT>offset = instr.offset<EOL>if end_offset and offset > end_offset:<EOL><INDENT>break<EOL><DEDENT>if instr.starts_line:<EOL><INDENT>if offset:<EOL><INDENT>msg("<STR_LIT>")<EOL><DEDENT>cur_line = instr.starts_line<EOL>if (start_line and ((start_line > cur_line) or<EOL>start_offset and start_offset > offset)) :<EOL><INDENT>msg_nocr = null_print<EOL>msg = null_print<EOL><DEDENT>else:<EOL><INDENT>statement_count -= <NUM_LIT:1><EOL>msg_nocr = orig_msg_nocr<EOL>msg = orig_msg<EOL>pass<EOL><DEDENT>if ((cur_line > end_line) or<EOL>(end_offset and offset > end_offset)):<EOL><INDENT>break<EOL><DEDENT>msg_nocr(format_token(Mformat.LineNumber,<EOL>"<STR_LIT>" % cur_line,<EOL>highlight=highlight))<EOL><DEDENT>else:<EOL><INDENT>if start_offset and offset and start_offset <= offset:<EOL><INDENT>msg_nocr = orig_msg_nocr<EOL>msg = orig_msg<EOL>pass<EOL><DEDENT>msg_nocr('<STR_LIT:U+0020>')<EOL><DEDENT>if offset == lasti: msg_nocr(format_token(Mformat.Arrow, '<STR_LIT>',<EOL>highlight=highlight))<EOL>else: msg_nocr('<STR_LIT:U+0020>')<EOL>if offset in labels: msg_nocr(format_token(Mformat.Arrow, '<STR_LIT>',<EOL>highlight=highlight))<EOL>else: msg_nocr('<STR_LIT:U+0020>')<EOL>msg_nocr(repr(offset).rjust(<NUM_LIT:4>))<EOL>msg_nocr('<STR_LIT:U+0020>')<EOL>msg_nocr(format_token(Mformat.Opcode,<EOL>instr.opname.ljust(<NUM_LIT:20>),<EOL>highlight=highlight))<EOL>msg_nocr(repr(instr.arg).ljust(<NUM_LIT:10>))<EOL>msg_nocr('<STR_LIT:U+0020>')<EOL>msg(format_token(Mformat.Name,<EOL>instr.argrepr.ljust(<NUM_LIT:20>),<EOL>highlight=highlight))<EOL>pass<EOL><DEDENT>return code, offset<EOL>

Disassemble byte string of code. If end_line is negative
    it counts the number of statement linestarts to use.


count = -count_start<EOL>while frame:<EOL><INDENT>count += <NUM_LIT:1><EOL>frame = frame.f_back<EOL><DEDENT>return count<EOL>


def format_stack_entry(dbg_obj, frame_lineno, lprefix='<STR_LIT>',<EOL>include_location=True, color='<STR_LIT>'):

frame, lineno = frame_lineno<EOL>filename = frame2file(dbg_obj.core, frame)<EOL>s = '<STR_LIT>'<EOL>if frame.f_code.co_name:<EOL><INDENT>funcname = frame.f_code.co_name<EOL><DEDENT>else:<EOL><INDENT>funcname = "<STR_LIT>"<EOL>pass<EOL><DEDENT>s = format_token(Mformat.Function, funcname, highlight=color)<EOL>args, varargs, varkw, local_vars = inspect.getargvalues(frame)<EOL>if '<STR_LIT>' == funcname and ([], None, None,) == (args, varargs, varkw,):<EOL><INDENT>is_module = True<EOL>if is_exec_stmt(frame):<EOL><INDENT>fn_name = format_token(Mformat.Function, '<STR_LIT>', highlight=color)<EOL>source_text = deparse_source_from_code(frame.f_code)<EOL>s += '<STR_LIT>' % (format_token(Mformat.Function, fn_name,<EOL>highlight=color), source_text)<EOL><DEDENT>else:<EOL><INDENT>fn_name = get_call_function_name(frame)<EOL>if fn_name:<EOL><INDENT>source_text = deparse_source_from_code(frame.f_code)<EOL>if fn_name: s += '<STR_LIT>' % (format_token(Mformat.Function, fn_name,<EOL>highlight=color), source_text)<EOL><DEDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>is_module = False<EOL>parms=inspect.formatargvalues(args, varargs, varkw, local_vars)<EOL>maxargstrsize = dbg_obj.settings['<STR_LIT>']<EOL>if len(parms) >= maxargstrsize:<EOL><INDENT>parms = "<STR_LIT>" % parms[<NUM_LIT:0>:maxargstrsize]<EOL>pass<EOL><DEDENT>s += parms<EOL>pass<EOL><DEDENT>if len(s) >= <NUM_LIT>: s += "<STR_LIT>"<EOL>if '<STR_LIT>' in frame.f_locals:<EOL><INDENT>rv = frame.f_locals['<STR_LIT>']<EOL>s += '<STR_LIT>'<EOL>s += format_token(Mformat.Return, Mrepr.repr(rv),<EOL>highlight=color)<EOL>pass<EOL><DEDENT>if include_location:<EOL><INDENT>is_pseudo_file = _re_pseudo_file.match(filename)<EOL>add_quotes_around_file = not is_pseudo_file<EOL>if is_module:<EOL><INDENT>if filename == '<STR_LIT>':<EOL><INDENT>s += '<STR_LIT>'<EOL><DEDENT>elif not is_exec_stmt(frame) and not is_pseudo_file:<EOL><INDENT>s += '<STR_LIT>'<EOL><DEDENT><DEDENT>elif s == '<STR_LIT>':<EOL><INDENT>if is_exec_stmt(frame):<EOL><INDENT>s = '<STR_LIT>'<EOL><DEDENT>elif not is_pseudo_file:<EOL><INDENT>s = '<STR_LIT>'<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>elif not is_pseudo_file:<EOL><INDENT>s += '<STR_LIT>'<EOL>pass<EOL><DEDENT>if add_quotes_around_file: filename = "<STR_LIT>" % filename<EOL>s += "<STR_LIT>" % (<EOL>format_token(Mformat.Filename, filename,<EOL>highlight=color),<EOL>format_token(Mformat.LineNumber, "<STR_LIT>" % lineno,<EOL>highlight=color)<EOL>)<EOL><DEDENT>return s<EOL>

Format and return a stack entry gdb-style.
    Note: lprefix is not used. It is kept for compatibility.


return hasattr(frame, '<STR_LIT>') and get_call_function_name(frame) == '<STR_LIT>'<EOL>

Return True if we are looking at an exec statement


f_back = frame.f_back<EOL>if not f_back: return None<EOL>if '<STR_LIT>' != Mbytecode.op_at_frame(f_back): return None<EOL>co         = f_back.f_code<EOL>code       = co.co_code<EOL>linestarts = dict(dis.findlinestarts(co))<EOL>offset     = f_back.f_lasti<EOL>while offset >= <NUM_LIT:0>:<EOL><INDENT>if offset in linestarts:<EOL><INDENT>op = code[offset]<EOL>offset += <NUM_LIT:1><EOL>arg = code[offset]<EOL>extended_arg = <NUM_LIT:0><EOL>while True:<EOL><INDENT>if PYTHON_VERSION >= <NUM_LIT>:<EOL><INDENT>if op == opc.EXTENDED_ARG:<EOL><INDENT>extended_arg += (arg << <NUM_LIT:8>)<EOL>continue<EOL><DEDENT>arg = code[offset] + extended_arg<EOL><DEDENT>else:<EOL><INDENT>if op == opc.EXTENDED_ARG:<EOL><INDENT>extended_arg += (arg << <NUM_LIT>)<EOL>continue<EOL><DEDENT>arg = code[offset] + code[offset+<NUM_LIT:1>]*<NUM_LIT> + extended_arg<EOL><DEDENT>break<EOL><DEDENT>return co.co_names[arg]<EOL><DEDENT>offset -= <NUM_LIT:1><EOL>pass<EOL><DEDENT>return None<EOL>

If f_back is looking at a call function, return
    the name for it. Otherwise return None


def print_stack_trace(proc_obj, count=None, color='<STR_LIT>', opts={}):

if count is None:<EOL><INDENT>n=len(proc_obj.stack)<EOL><DEDENT>else:<EOL><INDENT>n=min(len(proc_obj.stack), count)<EOL><DEDENT>try:<EOL><INDENT>for i in range(n):<EOL><INDENT>print_stack_entry(proc_obj, i, color=color, opts=opts)<EOL><DEDENT><DEDENT>except KeyboardInterrupt:<EOL><INDENT>pass<EOL><DEDENT>return<EOL>


def eval_print_obj(arg, frame, format=None, short=False):

try:<EOL><INDENT>if not frame:<EOL><INDENT>val = eval(arg, None, None)<EOL><DEDENT>else:<EOL><INDENT>val = eval(arg, frame.f_globals, frame.f_locals)<EOL>pass<EOL><DEDENT><DEDENT>except:<EOL><INDENT>return '<STR_LIT>' + arg + '<STR_LIT>'<EOL><DEDENT>return print_obj(arg, val, format, short)<EOL>

Return a string representation of an object


def print_obj(arg, val, format=None, short=False):

what = arg<EOL>if format:<EOL><INDENT>what = format + '<STR_LIT:U+0020>' + arg<EOL>val = Mprint.printf(val, format)<EOL>pass<EOL><DEDENT>s = '<STR_LIT>' % (what, val)<EOL>if not short:<EOL><INDENT>s += '<STR_LIT>' % type(val)<EOL>s = print_dict(s, val, "<STR_LIT>")<EOL>if hasattr(val, "<STR_LIT>"):<EOL><INDENT>s = print_dict(s, val.__class__, "<STR_LIT>")<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>return s<EOL>


n = len(code)<EOL>while offset < n:<EOL><INDENT>op = code[offset]<EOL>offset += <NUM_LIT:1><EOL>if op >= HAVE_ARGUMENT:<EOL><INDENT>offset += <NUM_LIT:2><EOL>pass<EOL><DEDENT>yield op, offset<EOL>pass<EOL><DEDENT>yield -<NUM_LIT:100>, -<NUM_LIT:1000><EOL>pass<EOL>

Return the next opcode and offset as a tuple. Tuple (-100,
    -1000) is returned when reaching the end.


<EOL>return (line and _re_def.match(line) and op_at_frame(frame)=='<STR_LIT>'<EOL>and stmt_contains_opcode(frame.f_code, frame.f_lineno,<EOL>'<STR_LIT>'))<EOL>

Return True if we are looking at a def statement


return (line and _re_class.match(line)<EOL>and stmt_contains_opcode(frame.f_code, frame.f_lineno,<EOL>'<STR_LIT>'))<EOL>

Return True if we are looking at a class definition statement


f_prev = f = frame<EOL>while f is not None and f.f_trace is None:<EOL><INDENT>f_prev = f<EOL>f = f.f_back<EOL>pass<EOL><DEDENT>if f_prev:<EOL><INDENT>val = f_prev.f_locals.get('<STR_LIT>')<EOL>if val == f_prev:<EOL><INDENT>if f_prev.f_back:<EOL><INDENT>f_prev = f_prev.f_back<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>else:<EOL><INDENT>return frame<EOL><DEDENT>return f_prev<EOL>

Find the first frame that is a debugged frame. We do this
    Generally we want traceback information without polluting it with
    debugger frames. We can tell these because those are frames on the
    top which don't have f_trace set. So we'll look back from the top
    to find the fist frame where f_trace is set.


name2id = {}<EOL>for thread_id in list(threading._active.keys()):<EOL><INDENT>thread = threading._active[thread_id]<EOL>name = thread.getName()<EOL>if name not in list(name2id.keys()):<EOL><INDENT>name2id[name] = thread_id<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>return name2id<EOL>


raise NotImplementedError(NotImplementedMessage)<EOL>return<EOL>


raise NotImplementedError(NotImplementedMessage)<EOL>

Called when a dangerous action is about to be done to make sure
        it's okay. `prompt' is printed; user response is returned.


def errmsg(self, str, prefix="<STR_LIT>"):

Common routine for reporting debugger error messages.


if hasattr(self.output, '<STR_LIT>'):<EOL><INDENT>self.output.writeline(msg)<EOL><DEDENT>elif hasattr(self.output, '<STR_LIT>'):<EOL><INDENT>self.output.writelines(msg + "<STR_LIT:\n>")<EOL>pass<EOL><DEDENT>return<EOL>

used to write to a debugger that is connected to this
        server; `str' written will have a newline added to it


self.output.write(msg)<EOL>return<EOL>

used to write to a debugger that is connected to this
        server; `str' written will not have a newline added to it


def get_stack(f, t, botframe, proc_obj=None):

exclude_frame = lambda f: False<EOL>if proc_obj:<EOL><INDENT>settings = proc_obj.debugger.settings<EOL>if not settings['<STR_LIT>']:<EOL><INDENT>exclude_frame = lambda f:proc_obj.core.ignore_filter.is_included(f)<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>stack = []<EOL>if t and t.tb_frame is f:<EOL><INDENT>t = t.tb_next<EOL><DEDENT>while f is not None:<EOL><INDENT>if exclude_frame(f): break  <EOL>stack.append((f, f.f_lineno))<EOL>f = f.f_back<EOL>pass<EOL><DEDENT>stack.reverse()<EOL>i = max(<NUM_LIT:0>, len(stack) - <NUM_LIT:1>)<EOL>while t is not None:<EOL><INDENT>stack.append((t.tb_frame, t.tb_lineno))<EOL>t = t.tb_next<EOL>pass<EOL><DEDENT>return stack, i<EOL>

Return a stack of frames which the debugger will use for in
    showing backtraces and in frame switching. As such various frame
    that are really around may be excluded unless we are debugging the
    sebugger. Also we will add traceback frame on top if that
    exists.


for hook in hooks:<EOL><INDENT>if hook(obj, *args): return True<EOL>pass<EOL><DEDENT>return False<EOL>


def adjust_frame(self, pos, absolute_pos):

if not self.curframe:<EOL><INDENT>Mmsg.errmsg(self, "<STR_LIT>")<EOL>return<EOL><DEDENT>if absolute_pos:<EOL><INDENT>if pos >= <NUM_LIT:0>:<EOL><INDENT>pos = len(self.stack)-pos-<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>pos = -pos-<NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>pos += self.curindex<EOL><DEDENT>if pos < <NUM_LIT:0>:<EOL><INDENT>Mmsg.errmsg(self,<EOL>"<STR_LIT>")<EOL>return<EOL><DEDENT>elif pos >= len(self.stack):<EOL><INDENT>Mmsg.errmsg(self,<EOL>"<STR_LIT>")<EOL>return<EOL><DEDENT>self.curindex = pos<EOL>self.curframe = self.stack[self.curindex][<NUM_LIT:0>]<EOL>self.print_location()<EOL>self.list_lineno = None<EOL>return<EOL>

Adjust stack frame by pos positions. If absolute_pos then
        pos is an absolute number. Otherwise it is a relative number.

        A negative number indexes from the other end.


filename = self.curframe.f_code.co_filename<EOL>if filename == '<STR_LIT>' and self.debugger.mainpyfile:<EOL><INDENT>filename = self.debugger.mainpyfile<EOL>pass<EOL><DEDENT>return filename<EOL>


def event_processor(self, frame, event, event_arg, prompt='<STR_LIT>'):

self.frame     = frame<EOL>self.event     = event<EOL>self.event_arg = event_arg<EOL>filename = frame.f_code.co_filename<EOL>lineno   = frame.f_lineno<EOL>line     = linecache.getline(filename, lineno, frame.f_globals)<EOL>if not line:<EOL><INDENT>opts = {'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': self.settings('<STR_LIT>'),<EOL>'<STR_LIT>': False}<EOL>line = pyficache.getline(filename, lineno, opts)<EOL><DEDENT>self.current_source_text = line<EOL>if self.settings('<STR_LIT>') is not None:<EOL><INDENT>if Mbytecode.is_def_stmt(line, frame):<EOL><INDENT>return True<EOL><DEDENT>if Mbytecode.is_class_def(line, frame):<EOL><INDENT>return True<EOL><DEDENT>pass<EOL><DEDENT>self.thread_name = Mthread.current_thread_name()<EOL>self.frame_thread_name = self.thread_name<EOL>self.process_commands()<EOL>return True<EOL>

command event processor: reading a commands do something with them.


self.stack       = []<EOL>self.curindex    = <NUM_LIT:0><EOL>self.curframe    = None<EOL>self.thread_name = None<EOL>self.frame_thread_name = None<EOL>return<EOL>

Remove memory of state variables set in the command processor


try:<EOL><INDENT>return eval(arg, self.curframe.f_globals,<EOL>self.curframe.f_locals)<EOL><DEDENT>except:<EOL><INDENT>t, v = sys.exc_info()[:<NUM_LIT:2>]<EOL>if isinstance(t, str):<EOL><INDENT>exc_type_name = t<EOL>pass<EOL><DEDENT>else: exc_type_name = t.__name__<EOL>Mmsg.errmsg(self, str("<STR_LIT>" % (exc_type_name, arg)))<EOL>raise<EOL><DEDENT>return None<EOL>

Eval string arg in the current frame context.


def ok_for_running(self, cmd_obj, name, cmd_hash):

if hasattr(cmd_obj, '<STR_LIT>'):<EOL><INDENT>if not (self.core.execution_status in cmd_obj.execution_set):<EOL><INDENT>part1 = ("<STR_LIT>"<EOL>"<STR_LIT>" % name)<EOL>Mmsg.errmsg(self,<EOL>Mmisc.<EOL>wrapped_lines(part1,<EOL>self.core.execution_status,<EOL>self.debugger.settings['<STR_LIT:width>']))<EOL>return False<EOL><DEDENT>pass<EOL><DEDENT>if self.frame is None and cmd_obj.need_stack:<EOL><INDENT>self.intf[-<NUM_LIT:1>].errmsg("<STR_LIT>"<EOL>% name)<EOL>return False<EOL><DEDENT>return True<EOL>

We separate some of the common debugger command checks here:
        whether it makes sense to run the command in this execution state,
        if the command has the right number of arguments and so on.


if self.core.execution_status != '<STR_LIT>':<EOL><INDENT>self.setup()<EOL>Mlocation.print_location(self, self.event)<EOL>pass<EOL><DEDENT>leave_loop = run_hooks(self, self.preloop_hooks)<EOL>self.continue_running = False<EOL>while not leave_loop:<EOL><INDENT>try:<EOL><INDENT>run_hooks(self, self.precmd_hooks)<EOL>leave_loop = self.process_command()<EOL>if leave_loop or self.continue_running: break<EOL><DEDENT>except EOFError:<EOL><INDENT>if len(self.debugger.intf) > <NUM_LIT:1>:<EOL><INDENT>del self.debugger.intf[-<NUM_LIT:1>]<EOL>self.last_command = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>if self.debugger.intf[-<NUM_LIT:1>].output:<EOL><INDENT>self.debugger.intf[-<NUM_LIT:1>].output.writeline('<STR_LIT>')<EOL>raise Mexcept.DebuggerQuit<EOL>pass<EOL><DEDENT>break<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>return run_hooks(self, self.postcmd_hooks)<EOL>


self.forget()<EOL>if self.settings('<STR_LIT>'):<EOL><INDENT>self.frame = inspect.currentframe()<EOL>pass<EOL><DEDENT>if self.event in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>exc_type, exc_value, exc_traceback = self.event_arg<EOL><DEDENT>else:<EOL><INDENT>_, _, exc_traceback = (None, None, None,)  <EOL>pass<EOL><DEDENT>if self.frame or exc_traceback:<EOL><INDENT>self.stack, self.curindex =get_stack(self.frame, exc_traceback, None, self)<EOL>self.curframe = self.stack[self.curindex][<NUM_LIT:0>]<EOL>self.thread_name = Mthread.current_thread_name()<EOL><DEDENT>else:<EOL><INDENT>self.stack = self.curframe =self.botframe = None<EOL>pass<EOL><DEDENT>if self.curframe:<EOL><INDENT>self.list_lineno =max(<NUM_LIT:1>, inspect.getlineno(self.curframe))<EOL><DEDENT>else:<EOL><INDENT>self.list_lineno = None<EOL>pass<EOL><DEDENT>return False<EOL>

Initialization done before entering the debugger-command
        loop. In particular we set up the call stack used for local
        variable lookup and frame/up/down commands.

        We return True if we should NOT enter the debugger-command
        loop.


Mmsg.errmsg(self, '<STR_LIT>' % cmd)<EOL>return<EOL>

Error message when a command doesn't exist


cmd_instances = []<EOL>from trepan.bwprocessor import command as Mcommand<EOL>eval_cmd_template = '<STR_LIT>'<EOL>for mod_name in Mcommand.__modules__:<EOL><INDENT>import_name = "<STR_LIT>" + mod_name<EOL>try:<EOL><INDENT>command_mod = getattr(__import__(import_name), mod_name)<EOL><DEDENT>except:<EOL><INDENT>print('<STR_LIT>' % (mod_name, sys.exc_info()[<NUM_LIT:0>]))<EOL>continue<EOL><DEDENT>classnames = [ tup[<NUM_LIT:0>] for tup in<EOL>inspect.getmembers(command_mod, inspect.isclass)<EOL>if ('<STR_LIT>' != tup[<NUM_LIT:0>] and<EOL>tup[<NUM_LIT:0>].endswith('<STR_LIT>')) ]<EOL>for classname in classnames:<EOL><INDENT>eval_cmd = eval_cmd_template % classname<EOL>try:<EOL><INDENT>instance = eval(eval_cmd)<EOL>cmd_instances.append(instance)<EOL><DEDENT>except:<EOL><INDENT>print('<STR_LIT>' %<EOL>(classname, mod_name, sys.exc_info()[<NUM_LIT:0>]))<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>pass<EOL><DEDENT>return cmd_instances<EOL>

Create an instance of each of the debugger
        commands. Commands are found by importing files in the
        directory 'command'. Some files are excluded via an array set
        in __init__.  For each of the remaining files, we import them
        and scan for class names inside those files and for each class
        name, we will create an instance of that class. The set of
        DebuggerCommand class instances form set of possible debugger
        commands.


self.commands = {}<EOL>for cmd_instance in self.cmd_instances:<EOL><INDENT>cmd_name = cmd_instance.name<EOL>self.commands[cmd_name] = cmd_instance<EOL>pass<EOL><DEDENT>return<EOL>


i_stack = proc_obj.curindex<EOL>if i_stack is None or proc_obj.stack is None:<EOL><INDENT>return False<EOL><DEDENT>location = {}<EOL>core_obj = proc_obj.core<EOL>dbgr_obj = proc_obj.debugger<EOL>while i_stack >= <NUM_LIT:0>:<EOL><INDENT>frame_lineno = proc_obj.stack[i_stack]<EOL>i_stack -= <NUM_LIT:1><EOL>frame, lineno = frame_lineno<EOL>filename = Mstack.frame2file(core_obj, frame)<EOL>location['<STR_LIT:filename>'] = filename<EOL>location['<STR_LIT>']  = frame.f_code.co_name<EOL>location['<STR_LIT>']   = lineno<EOL>if '<STR_LIT>' == filename and dbgr_obj.eval_string:<EOL><INDENT>filename = pyficache.unmap_file(filename)<EOL>if '<STR_LIT>' == filename:<EOL><INDENT>fd = tempfile.NamedTemporaryFile(suffix='<STR_LIT>',<EOL>prefix='<STR_LIT>',<EOL>delete=False)<EOL>fd.write(bytes(dbgr_obj.eval_string, '<STR_LIT>'))<EOL>fd.close()<EOL>pyficache.remap_file(fd.name, '<STR_LIT>')<EOL>filename = fd.name<EOL>pass<EOL><DEDENT>pass<EOL><DEDENT>opts = {<EOL>'<STR_LIT>' : proc_obj.settings('<STR_LIT>'),<EOL>'<STR_LIT>'           : '<STR_LIT>'<EOL>}<EOL>line = pyficache.getline(filename, lineno, opts)<EOL>if not line:<EOL><INDENT>line = linecache.getline(filename, lineno,<EOL>proc_obj.curframe.f_globals)<EOL>pass<EOL><DEDENT>if line and len(line.strip()) != <NUM_LIT:0>:<EOL><INDENT>location['<STR_LIT:text>'] = line<EOL>pass<EOL><DEDENT>if '<STR_LIT>' != filename: break<EOL>pass<EOL><DEDENT>return location<EOL>

Show where we are. GUI's and front-end interfaces often
    use this to update displays. So it is helpful to make sure
    we give at least some place that's located in a file.


self.proc = proc<EOL>self.core     = proc.core<EOL>self.debugger = proc.debugger<EOL>self.settings = self.debugger.settings<EOL>return<EOL>

proc contains the command processor object that this
        command is invoked through.  A debugger field gives access to
        the stack frame and I/O.


try:<EOL><INDENT>return(self.debugger.intf[-<NUM_LIT:1>].errmsg(msg))<EOL><DEDENT>except EOFError:<EOL><INDENT>pass<EOL><DEDENT>return None<EOL>

Convenience short-hand for self.debugger.intf.errmsg


try:<EOL><INDENT>return(self.debugger.intf[-<NUM_LIT:1>].msg(msg))<EOL><DEDENT>except EOFError:<EOL><INDENT>pass<EOL><DEDENT>return None<EOL>

Convenience short-hand for self.debugger.intf.msg


try:<EOL><INDENT>return(self.debugger.intf[-<NUM_LIT:1>].msg_nocr(msg))<EOL><DEDENT>except EOFError:<EOL><INDENT>pass<EOL><DEDENT>return None<EOL>

Convenience short-hand for self.debugger.intf.msg_nocr


raise NotImplementedError(NotImplementedMessage)<EOL>

The method that implements the debugger command.
        Help on the command comes from the docstring of this method.


self.debugger.core.stop()<EOL>self.debugger.core.execution_status = '<STR_LIT>'<EOL>self.proc.response['<STR_LIT>'] = '<STR_LIT>'<EOL>self.proc.response['<STR_LIT:name>']  = '<STR_LIT:status>'<EOL>self.proc.intf[-<NUM_LIT:1>].msg(self.proc.response)<EOL>raise Mexcept.DebuggerQuit<EOL>

quit command when there's just one thread.


self.msg("<STR_LIT>")<EOL>return False<EOL>

quit command when several threads are involved.


sys.excepthook = Mpost_mortem.post_mortem_excepthook<EOL>return<EOL>

Call debugger on an exeception that terminates a program


def run_eval(expression, debug_opts=None, start_opts=None, globals_=None,<EOL>locals_=None, tb_fn = None):

dbg = Mdebugger.Trepan(opts=debug_opts)<EOL>try:<EOL><INDENT>return dbg.run_eval(expression, start_opts=start_opts,<EOL>globals_=globals_, locals_=locals_)<EOL><DEDENT>except:<EOL><INDENT>dbg.core.trace_hook_suspend = True<EOL>if start_opts and '<STR_LIT>' in start_opts: tb_fn = start_opts['<STR_LIT>']<EOL>Mpost_mortem.uncaught_exception(dbg, tb_fn)<EOL><DEDENT>finally:<EOL><INDENT>dbg.core.trace_hook_suspend = False<EOL><DEDENT>return<EOL>

Evaluate the expression (given as a string) under debugger
    control starting with the statement subsequent to the place that
    this appears in your program.

    This is a wrapper to Debugger.run_eval(), so see that.

    When run_eval() returns, it returns the value of the expression.
    Otherwise this function is similar to run().


def run_call(func, debug_opts=None, start_opts=None, *args, **kwds):

dbg = Mdebugger.Trepan(opts=debug_opts)<EOL>try:<EOL><INDENT>return dbg.run_call(func, start_opts, *args, **kwds)<EOL><DEDENT>except:<EOL><INDENT>Mpost_mortem.uncaught_exception(dbg)<EOL>pass<EOL><DEDENT>return<EOL>

Call the function (a function or method object, not a string)
    with the given arguments starting with the statement subsequent to
    the place that this appears in your program.

    When run_call() returns, it returns whatever the function call
    returned.  The debugger prompt appears as soon as the function is
    entered.


def run_exec(statement, debug_opts=None, start_opts=None, globals_=None,<EOL>locals_=None):

dbg = Mdebugger.Trepan(opts=debug_opts)<EOL>try:<EOL><INDENT>return dbg.run_exec(statement, start_opts=start_opts,<EOL>globals_=globals_, locals_=locals_)<EOL><DEDENT>except:<EOL><INDENT>Mpost_mortem.uncaught_exception(dbg)<EOL>pass<EOL><DEDENT>return<EOL>

Execute the statement (given as a string) under debugger
    control starting with the statement subsequent to the place that
    this run_call appears in your program.

    This is a wrapper to Debugger.run_exec(), so see that.

    The debugger prompt appears before any code is executed;
    you can set breakpoints and type 'continue', or you can step
    through the statement using 'step' or 'next'

    The optional globals_ and locals_ arguments specify the environment
    in which the code is executed; by default the dictionary of the
    module __main__ is used.


def debug(dbg_opts=None, start_opts=None, post_mortem=True,<EOL>step_ignore=<NUM_LIT:1>, level=<NUM_LIT:0>):

if not isinstance(Mdebugger.debugger_obj, Mdebugger.Trepan):<EOL><INDENT>Mdebugger.debugger_obj = Mdebugger.Trepan(dbg_opts)<EOL>Mdebugger.debugger_obj.core.add_ignore(debug, stop)<EOL>pass<EOL><DEDENT>core = Mdebugger.debugger_obj.core<EOL>frame = sys._getframe(<NUM_LIT:0>+level)<EOL>core.set_next(frame)<EOL>if start_opts and '<STR_LIT>' in start_opts and start_opts['<STR_LIT>']:<EOL><INDENT>dbg_initfiles = start_opts['<STR_LIT>']<EOL>from trepan import options<EOL>options.add_startup_file(dbg_initfiles)<EOL>for init_cmdfile in dbg_initfiles:<EOL><INDENT>core.processor.queue_startfile(init_cmdfile)<EOL><DEDENT><DEDENT>if not core.is_started():<EOL><INDENT>core.start(start_opts)<EOL>pass<EOL><DEDENT>if post_mortem:<EOL><INDENT>debugger_on_post_mortem()<EOL>pass<EOL><DEDENT>if <NUM_LIT:0> == step_ignore:<EOL><INDENT>frame                   = sys._getframe(<NUM_LIT:1>+level)<EOL>core.stop_reason        = '<STR_LIT>'<EOL>old_trace_hook_suspend  = core.trace_hook_suspend<EOL>core.trace_hook_suspend = True<EOL>core.processor.event_processor(frame, '<STR_LIT>', None)<EOL>core.trace_hook_suspend = old_trace_hook_suspend<EOL><DEDENT>else:<EOL><INDENT>core.step_ignore = step_ignore-<NUM_LIT:1><EOL>pass<EOL><DEDENT>return<EOL>

Enter the debugger.

Parameters
----------

level : how many stack frames go back. Usually it will be
the default 0. But sometimes though there may be calls in setup to the debugger
that you may want to skip.

step_ignore : how many line events to ignore after the
debug() call. 0 means don't even wait for the debug() call to finish.

param dbg_opts : is an optional "options" dictionary that gets fed
trepan.Debugger(); `start_opts' are the optional "options"
dictionary that gets fed to trepan.Debugger.core.start().

Use like this:

.. code-block:: python

    ... # Possibly some Python code
    import trepan.api # Needed only once
    ... # Possibly some more Python code
    trepan.api.debug() # You can wrap inside conditional logic too
    pass  # Stop will be here.
    # Below is code you want to use the debugger to do things.
    ....  # more Python code
    # If you get to a place in the program where you aren't going
    # want to debug any more, but want to remove debugger trace overhead:
    trepan.api.stop()

Parameter "level" specifies how many stack frames go back. Usually it will be
the default 0. But sometimes though there may be calls in setup to the debugger
that you may want to skip.

Parameter "step_ignore" specifies how many line events to ignore after the
debug() call. 0 means don't even wait for the debug() call to finish.

In situations where you want an immediate stop in the "debug" call
rather than the statement following it ("pass" above), add parameter
step_ignore=0 to debug() like this::

    import trepan.api  # Needed only once
    # ... as before
    trepan.api.debug(step_ignore=0)
    # ... as before

Module variable _debugger_obj_ from module trepan.debugger is used as
the debugger instance variable; it can be subsequently used to change
settings or alter behavior. It should be of type Debugger (found in
module trepan). If not, it will get changed to that type::

   $ python
   >>> from trepan.debugger import debugger_obj
   >>> type(debugger_obj)
   <type 'NoneType'>
   >>> import trepan.api
   >>> trepan.api.debug()
   ...
   (Trepan) c
   >>> from trepan.debugger import debugger_obj
   >>> debugger_obj
   <trepan.debugger.Debugger instance at 0x7fbcacd514d0>
   >>>

If however you want your own separate debugger instance, you can
create it from the debugger _class Debugger()_ from module
trepan.debugger::

  $ python
  >>> from trepan.debugger import Debugger
  >>> dbgr = Debugger()  # Add options as desired
  >>> dbgr
  <trepan.debugger.Debugger instance at 0x2e25320>

`dbg_opts' is an optional "options" dictionary that gets fed
trepan.Debugger(); `start_opts' are the optional "options"
dictionary that gets fed to trepan.Debugger.core.start().


def is_ok_line_for_breakpoint(filename, lineno, errmsg_fn):

line = linecache.getline(filename, lineno)<EOL>if not line:<EOL><INDENT>errmsg_fn('<STR_LIT>')<EOL>return False<EOL><DEDENT>line = line.strip()<EOL>if (not line or (line[<NUM_LIT:0>] == '<STR_LIT:#>') or<EOL>(line[:<NUM_LIT:3>] == '<STR_LIT>') or line[:<NUM_LIT:3>] == "<STR_LIT>"):<EOL><INDENT>errmsg_fn('<STR_LIT>')<EOL>return False<EOL><DEDENT>return True<EOL>

Check whether specified line seems to be executable.

    Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank
    line or EOF). Warning: testing is not comprehensive.


basename = osp.basename(filename)<EOL>if '<STR_LIT:.>' in basename:<EOL><INDENT>pos = basename.rfind('<STR_LIT:.>')<EOL>return basename[:pos]<EOL><DEDENT>else:<EOL><INDENT>return basename<EOL><DEDENT>return None<EOL>

Given a file name, extract the most likely module name.


def search_file(filename, directories, cdir):

for trydir in directories:<EOL><INDENT>if trydir =='<STR_LIT>': trydir='<STR_LIT:.>'<EOL>elif trydir == '<STR_LIT>': trydir = cdir<EOL>tryfile = osp.realpath(osp.join(trydir, filename))<EOL>if osp.isfile(tryfile):<EOL><INDENT>return tryfile<EOL><DEDENT><DEDENT>return None<EOL>

Return a full pathname for filename if we can find one. path
    is a list of directories to prepend to filename. If no file is
    found we'll return None


if py_script.find(os.sep) != -<NUM_LIT:1>:<EOL><INDENT>return py_script<EOL><DEDENT>if dirnames is None:<EOL><INDENT>dirnames = os.environ['<STR_LIT>'].split(os.pathsep)<EOL><DEDENT>for dirname in dirnames:<EOL><INDENT>py_script_try = osp.join(dirname, py_script)<EOL>if osp.exists(py_script_try):<EOL><INDENT>return py_script_try<EOL><DEDENT><DEDENT>return py_script<EOL>

Do a shell-like path lookup for py_script and return the results.
    If we can't find anything return py_script


if '<STR_LIT>' != self.debugger.settings['<STR_LIT>']:<EOL><INDENT>message = colorize('<STR_LIT>', message)<EOL>pass<EOL><DEDENT>return(self.intf[-<NUM_LIT:1>].errmsg(message))<EOL>

Convenience short-hand for self.intf[-1].errmsg


return(self.intf[-<NUM_LIT:1>].msg(msg))<EOL>

Convenience short-hand for self.debugger.intf[-1].msg


return(self.intf[-<NUM_LIT:1>].msg_nocr(msg))<EOL>

Convenience short-hand for self.debugger.intf[-1].msg_nocr


from trepan.lib.format import rst_text<EOL>text = rst_text(text,<EOL>'<STR_LIT>' == self.debugger.settings['<STR_LIT>'],<EOL>self.debugger.settings['<STR_LIT:width>'])<EOL>return self.msg(text)<EOL>

Convert ReStructuredText and run through msg()


def grouper(iterable, n, fillvalue=None):

return list(zip_longest(*[iter(iterable)] * n, fillvalue=fillvalue))<EOL>

Group iterable by n elements.

    >>> for t in grouper('abcdefg', 3, fillvalue='x'):
    ...     print(''.join(t))
    abc
    def
    gxx


return [first_date + timedelta(days=n)<EOL>for n in range(<NUM_LIT:1> + (last_date - first_date).days)]<EOL>

Returns all dates from first to last included.


try:<EOL><INDENT>return datetime.date(int(s[:<NUM_LIT:4>]), int(s[<NUM_LIT:5>:<NUM_LIT:7>]), int(s[<NUM_LIT:8>:<NUM_LIT:10>]))<EOL><DEDENT>except ValueError:  <EOL><INDENT>return datetime.datetime.strptime(s, '<STR_LIT>').date()<EOL><DEDENT>


<EOL>self.fallback_on_wrong_date = fallback_on_wrong_date<EOL>self.fallback_on_missing_rate = fallback_on_missing_rate<EOL>self.ref_currency = ref_currency  <EOL>self.na_values = na_values        <EOL>self.verbose = verbose<EOL>self._rates = None<EOL>self.bounds = None<EOL>self.currencies = None<EOL>if currency_file is not None:<EOL><INDENT>self.load_file(currency_file)<EOL><DEDENT>

Instantiate a CurrencyConverter.

        :param str currency_file: Path to the source data. Can be a local path,
            or an URL starting with 'http://' or 'https://'. Defaults to the
            European Central Bank historical rates file included in the package.
        :param bool fallback_on_wrong_date: Set to False (default) to raise a
            RateNotFoundError when dates are requested outside the data's range.
            Set to True to extrapolate rates for dates outside the source data's
            range. The extrapolation is done by falling back to the first or
            last data point, for dates before and after the data's range,
            respectively.
        :param bool fallback_on_missing_rate: Set to True to linearly
            interpolate missing rates by their two closest valid rates. This
            only affects dates within the source data's range. Default False.
        :param str ref_currency: Three-letter currency code for the currency
            that the source data is oriented towards. This is EUR for the
            default European Central Bank data, and so the default is 'EUR'.
        :param iterable na_values: What to interpret as missing values in the
            source data.
        :param verbose: Set to True to print what is going on under the hood.


if currency_file.startswith(('<STR_LIT>', '<STR_LIT>')):<EOL><INDENT>content = urlopen(currency_file).read()<EOL><DEDENT>else:<EOL><INDENT>with open(currency_file, '<STR_LIT:rb>') as f:<EOL><INDENT>content = f.read()<EOL><DEDENT><DEDENT>if currency_file.endswith('<STR_LIT>'):<EOL><INDENT>self.load_lines(get_lines_from_zip(content))<EOL><DEDENT>else:<EOL><INDENT>self.load_lines(content.decode('<STR_LIT:utf-8>').splitlines())<EOL><DEDENT>

To be subclassed if alternate methods of loading data.


rates = self._rates[currency]<EOL>first_date, last_date = self.bounds[currency]<EOL>for date in list_dates_between(first_date, last_date):<EOL><INDENT>if date not in rates:<EOL><INDENT>rates[date] = None<EOL><DEDENT><DEDENT>if self.verbose:<EOL><INDENT>missing = len([r for r in itervalues(rates) if r is None])<EOL>if missing:<EOL><INDENT>print('<STR_LIT>'.format(<EOL>currency, missing, first_date, last_date,<EOL><NUM_LIT:1> + (last_date - first_date).days))<EOL><DEDENT><DEDENT>

Fill missing rates of a currency with the closest available ones.


rates = self._rates[currency]<EOL>tmp = defaultdict(lambda: [None, None])<EOL>for date in sorted(rates):<EOL><INDENT>rate = rates[date]<EOL>if rate is not None:<EOL><INDENT>closest_rate = rate<EOL>dist = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>dist += <NUM_LIT:1><EOL>tmp[date][<NUM_LIT:0>] = closest_rate, dist<EOL><DEDENT><DEDENT>for date in sorted(rates, reverse=True):<EOL><INDENT>rate = rates[date]<EOL>if rate is not None:<EOL><INDENT>closest_rate = rate<EOL>dist = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>dist += <NUM_LIT:1><EOL>tmp[date][<NUM_LIT:1>] = closest_rate, dist<EOL><DEDENT><DEDENT>for date in sorted(tmp):<EOL><INDENT>(r0, d0), (r1, d1) = tmp[date]<EOL>rates[date] = (r0 * d1 + r1 * d0) / (d0 + d1)<EOL>if self.verbose:<EOL><INDENT>print(('<STR_LIT>'<EOL>'<STR_LIT>').format(currency, date, r0, d0, r1, d1))<EOL><DEDENT><DEDENT>

Fill missing rates of a currency.

        This is done by linear interpolation of the two closest available rates.

        :param str currency: The currency to fill missing rates for.


if currency == self.ref_currency:<EOL><INDENT>return <NUM_LIT:1.0><EOL><DEDENT>if date not in self._rates[currency]:<EOL><INDENT>first_date, last_date = self.bounds[currency]<EOL>if not self.fallback_on_wrong_date:<EOL><INDENT>raise RateNotFoundError('<STR_LIT>'.format(<EOL>date, currency, first_date, last_date))<EOL><DEDENT>if date < first_date:<EOL><INDENT>fallback_date = first_date<EOL><DEDENT>elif date > last_date:<EOL><INDENT>fallback_date = last_date<EOL><DEDENT>else:<EOL><INDENT>raise AssertionError('<STR_LIT>')<EOL><DEDENT>if self.verbose:<EOL><INDENT>print(r'<STR_LIT>'.format(<EOL>date, currency, first_date, last_date, fallback_date))<EOL><DEDENT>date = fallback_date<EOL><DEDENT>rate = self._rates[currency][date]<EOL>if rate is None:<EOL><INDENT>raise RateNotFoundError('<STR_LIT>'.format(currency, date))<EOL><DEDENT>return rate<EOL>

Get a rate for a given currency and date.

        :type date: datetime.date

        >>> from datetime import date
        >>> c = CurrencyConverter()
        >>> c._get_rate('USD', date=date(2014, 3, 28))
        1.375...
        >>> c._get_rate('BGN', date=date(2010, 11, 21))
        Traceback (most recent call last):
        RateNotFoundError: BGN has no rate for 2010-11-21


def convert(self, amount, currency, new_currency='<STR_LIT>', date=None):

for c in currency, new_currency:<EOL><INDENT>if c not in self.currencies:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(c))<EOL><DEDENT><DEDENT>if date is None:<EOL><INDENT>date = self.bounds[currency].last_date<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>date = date.date()  <EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>r0 = self._get_rate(currency, date)<EOL>r1 = self._get_rate(new_currency, date)<EOL>return float(amount) / r0 * r1<EOL>

Convert amount from a currency to another one.

        :param float amount: The amount of `currency` to convert.
        :param str currency: The currency to convert from.
        :param str new_currency: The currency to convert to.
        :param datetime.date date: Use the conversion rate of this date. If this
            is not given, the most recent rate is used.

        :return: The value of `amount` in `new_currency`.
        :rtype: float

        >>> from datetime import date
        >>> c = CurrencyConverter()
        >>> c.convert(100, 'EUR', 'USD', date=date(2014, 3, 28))
        137.5...
        >>> c.convert(100, 'USD', date=date(2014, 3, 28))
        72.67...
        >>> c.convert(100, 'BGN', date=date(2010, 11, 21))
        Traceback (most recent call last):
        RateNotFoundError: BGN has no rate for 2010-11-21


def __init__(self, currency_file, **kwargs):

super(S3CurrencyConverter, self).__init__(currency_file, **kwargs)<EOL>


return PrintNode.parse(parser, token)<EOL>

A template tag which prints dumps the contents of objects.


text = [CONTEXT_TITLE]<EOL>for i, context_scope in enumerate(context):<EOL><INDENT>dump1 = linebreaksbr(pformat_django_context_html(context_scope))<EOL>dump2 = pformat_dict_summary_html(context_scope)<EOL>if len(context_scope) <= <NUM_LIT:3> and dump1.count('<STR_LIT>') > <NUM_LIT:20>:<EOL><INDENT>(dump1, dump2) = (dump2, dump1)<EOL><DEDENT>text.append(CONTEXT_BLOCK.format(<EOL>style=PRE_STYLE,<EOL>num=i,<EOL>dump1=dump1,<EOL>dump2=dump2<EOL>))<EOL><DEDENT>return u'<STR_LIT>'.join(text)<EOL>


text = []<EOL>for name, expr in self.variables:<EOL><INDENT>data = '<STR_LIT>'<EOL>try:<EOL><INDENT>if isinstance(expr.var, Variable):<EOL><INDENT>data = expr.var.resolve(context)<EOL><DEDENT>else:<EOL><INDENT>data = expr.resolve(context)  <EOL><DEDENT><DEDENT>except VariableDoesNotExist as e:<EOL><INDENT>keys = []<EOL>for scope in context:<EOL><INDENT>keys += scope.keys()<EOL><DEDENT>keys = sorted(set(keys))  <EOL>return ERROR_TYPE_BLOCK.format(style=PRE_ALERT_STYLE, error=escape(u"<STR_LIT>".format(expr, u'<STR_LIT:U+002CU+0020>'.join(keys))))<EOL><DEDENT>else:<EOL><INDENT>textdata = linebreaksbr(pformat_django_context_html(data))<EOL><DEDENT>if isinstance(data, SHORT_NAME_TYPES):<EOL><INDENT>text.append(BASIC_TYPE_BLOCK.format(style=PRE_STYLE, name=name, value=textdata))<EOL><DEDENT>else:<EOL><INDENT>text.append(OBJECT_TYPE_BLOCK.format(style=PRE_STYLE, name=name, type=data.__class__.__name__, value=textdata))<EOL><DEDENT><DEDENT>return u'<STR_LIT>'.join(text)<EOL>


sql = escape(sql)<EOL>sql = RE_SQL_NL.sub(u'<STR_LIT>', sql)<EOL>sql = RE_SQL.sub(u'<STR_LIT>', sql)<EOL>return sql<EOL>


if isinstance(object, QuerySet):<EOL><INDENT>text = '<STR_LIT>'<EOL>lineno = <NUM_LIT:0><EOL>for item in object.all()[:<NUM_LIT>]:<EOL><INDENT>lineno += <NUM_LIT:1><EOL>if lineno >= <NUM_LIT>:<EOL><INDENT>text += u'<STR_LIT>'<EOL>break<EOL><DEDENT>text += u'<STR_LIT>'.format(escape(repr(item)))<EOL><DEDENT>return text<EOL><DEDENT>elif isinstance(object, Manager):<EOL><INDENT>return mark_safe(u'<STR_LIT>')<EOL><DEDENT>elif isinstance(object, six.string_types):<EOL><INDENT>return escape(repr(object))<EOL><DEDENT>elif isinstance(object, Promise):<EOL><INDENT>return escape(_format_lazy(object))<EOL><DEDENT>elif isinstance(object, dict):<EOL><INDENT>return _format_dict(object)<EOL><DEDENT>elif isinstance(object, list):<EOL><INDENT>return _format_list(object)<EOL><DEDENT>elif hasattr(object, '<STR_LIT>'):<EOL><INDENT>return _format_object(object)<EOL><DEDENT>else:<EOL><INDENT>text = DebugPrettyPrinter(width=<NUM_LIT:200>).pformat(object)<EOL>return _style_text(text)<EOL><DEDENT>

Dump a variable to a HTML string with sensible output for template context fields.
It filters out all fields which are not usable in a template context.


if not dict:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>html = []<EOL>for key, value in sorted(six.iteritems(dict)):<EOL><INDENT>if not isinstance(value, DICT_EXPANDED_TYPES):<EOL><INDENT>value = '<STR_LIT>'<EOL><DEDENT>html.append(_format_dict_item(key, value))<EOL><DEDENT>return mark_safe(u'<STR_LIT>'.join(html))<EOL>


<EOL>text = escape(text)<EOL>text = text.replace('<STR_LIT>', "<STR_LIT>")<EOL>text = text.replace('<STR_LIT>', '<STR_LIT>')<EOL>text = text.replace('<STR_LIT>', '<STR_LIT>')<EOL>text = RE_PROXY.sub('<STR_LIT>', text)<EOL>text = RE_FUNCTION.sub('<STR_LIT>', text)<EOL>text = RE_GENERATOR.sub("<STR_LIT>", text)<EOL>text = RE_OBJECT_ADDRESS.sub('<STR_LIT>', text)<EOL>text = RE_MANAGER.sub('<STR_LIT>', text)<EOL>text = RE_CLASS_REPR.sub('<STR_LIT>', text)<EOL>text = RE_REQUEST_FIELDNAME.sub('<STR_LIT>', text)<EOL>text = RE_REQUEST_CLEANUP1.sub('<STR_LIT>', text)<EOL>text = RE_REQUEST_CLEANUP2.sub('<STR_LIT:)>', text)<EOL>return mark_safe(text)<EOL>

Apply some HTML highlighting to the contents.
This can't be done in the


attrs = iter(object.__dict__.items())<EOL>if object.__class__:<EOL><INDENT>attrs = chain(attrs, iter(object.__class__.__dict__.items()))<EOL><DEDENT>is_model = isinstance(object, Model)<EOL>is_form = isinstance(object, BaseForm)<EOL>attrs = dict(<EOL>(k, v)<EOL>for k, v in attrs<EOL>if not k.startswith('<STR_LIT:_>')<EOL>and not getattr(v, '<STR_LIT>', False)<EOL>and not (is_model and k in ('<STR_LIT>', '<STR_LIT>'))<EOL>and not (is_form and k in ('<STR_LIT:Meta>',))<EOL>)<EOL>for member in dir(object):<EOL><INDENT>try:<EOL><INDENT>if member.startswith('<STR_LIT:_>') or not hasattr(object, member):<EOL><INDENT>continue<EOL><DEDENT><DEDENT>except HANDLED_EXCEPTIONS as e:<EOL><INDENT>attrs[member] = _format_exception(e)<EOL>continue<EOL><DEDENT>value = getattr(object, member)<EOL>if callable(value) or member in attrs or getattr(value, '<STR_LIT>', False):<EOL><INDENT>continue<EOL><DEDENT>attrs[member] = value<EOL><DEDENT>for name, value in list(attrs.items()):  <EOL><INDENT>if isinstance(value, property):<EOL><INDENT>attrs[name] = _try_call(lambda: getattr(object, name))<EOL><DEDENT>elif isinstance(value, types.FunctionType):<EOL><INDENT>if PY3:<EOL><INDENT>spec = inspect.getfullargspec(value)<EOL><DEDENT>else:<EOL><INDENT>spec = inspect.getargspec(value)<EOL><DEDENT>if len(spec.args) == <NUM_LIT:1> or len(spec.args) == len(spec.defaults or ()) + <NUM_LIT:1>:<EOL><INDENT>if _is_unsafe_name(name):<EOL><INDENT>attrs[name] = LiteralStr('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>attrs[name] = _try_call(lambda: value(object))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>del attrs[name]<EOL><DEDENT><DEDENT>elif hasattr(value, '<STR_LIT>'):<EOL><INDENT>attrs[name] = value = _try_call(lambda: getattr(object, name), return_exceptions=True)<EOL>if isinstance(value, Manager):<EOL><INDENT>attrs[name] = LiteralStr('<STR_LIT>'.format(value.__class__.__name__))<EOL><DEDENT>elif isinstance(value, AttributeError):<EOL><INDENT>del attrs[name]  <EOL><DEDENT>elif isinstance(value, HANDLED_EXCEPTIONS):<EOL><INDENT>attrs[name] = _format_exception(value)<EOL><DEDENT><DEDENT><DEDENT>if getattr(object, '<STR_LIT>', None) is not object.__str__:<EOL><INDENT>attrs['<STR_LIT>'] = _try_call(lambda: smart_str(object))<EOL><DEDENT>elif getattr(object, '<STR_LIT>', None) is not object.__unicode__:<EOL><INDENT>attrs['<STR_LIT>'] = _try_call(lambda: smart_str(object))<EOL><DEDENT>if hasattr(object, '<STR_LIT>'):<EOL><INDENT>attrs['<STR_LIT>'] = LiteralStr('<STR_LIT>')<EOL><DEDENT>if hasattr(object, '<STR_LIT>'):<EOL><INDENT>attrs['<STR_LIT>'] = LiteralStr('<STR_LIT>')<EOL><DEDENT>if hasattr(object, '<STR_LIT>'):<EOL><INDENT>attrs['<STR_LIT>'] = LiteralStr('<STR_LIT>')<EOL><DEDENT>if hasattr(object, '<STR_LIT>'):<EOL><INDENT>attrs['<STR_LIT>'] = len(object)<EOL><DEDENT>if isinstance(object, BaseForm):<EOL><INDENT>for field_name in list(object.fields.keys()):<EOL><INDENT>attrs[field_name] = object[field_name]<EOL><DEDENT>del attrs['<STR_LIT>']<EOL><DEDENT>return _format_dict(attrs)<EOL>

# Instead of just printing <SomeType at 0xfoobar>, expand the fields.


args = value._proxy____args<EOL>kw = value._proxy____kw<EOL>if not kw and len(args) == <NUM_LIT:1> and isinstance(args[<NUM_LIT:0>], six.string_types):<EOL><INDENT>return LiteralStr(u'<STR_LIT>'.format(repr(value._proxy____args[<NUM_LIT:0>])))<EOL><DEDENT>return value<EOL>

Expand a _("TEST") call to something meaningful.


def _try_call(func, extra_exceptions=(), return_exceptions=False):

try:<EOL><INDENT>return func()<EOL><DEDENT>except HANDLED_EXCEPTIONS as e:<EOL><INDENT>if return_exceptions:<EOL><INDENT>return e<EOL><DEDENT>else:<EOL><INDENT>return _format_exception(e)<EOL><DEDENT><DEDENT>except extra_exceptions as e:<EOL><INDENT>if return_exceptions:<EOL><INDENT>return e<EOL><DEDENT>else:<EOL><INDENT>return _format_exception(e)<EOL><DEDENT><DEDENT>

Call a method, but
:param func:
:type func:
:param extra_exceptions:
:type extra_exceptions:
:return:
:rtype:


def format(self, object, context, maxlevels, level):

try:<EOL><INDENT>return PrettyPrinter.format(self, object, context, maxlevels, level)<EOL><DEDENT>except HANDLED_EXCEPTIONS as e:<EOL><INDENT>return _format_exception(e), True, False<EOL><DEDENT>

Format an item in the result.
Could be a dictionary key, value, etc..


def _format(self, object, stream, indent, allowance, context, level):

try:<EOL><INDENT>PrettyPrinter._format(self, object, stream, indent, allowance, context, level)<EOL><DEDENT>except Exception as e:<EOL><INDENT>stream.write(_format_exception(e))<EOL><DEDENT>


if not hasattr(response, '<STR_LIT>'):<EOL><INDENT>return None, None<EOL><DEDENT>template = response.template_name<EOL>if template is None:<EOL><INDENT>return None, None<EOL><DEDENT>if isinstance(template, (list, tuple)):<EOL><INDENT>if len(template) == <NUM_LIT:1>:<EOL><INDENT>return template[<NUM_LIT:0>], None<EOL><DEDENT>else:<EOL><INDENT>used_name = _get_used_template_name(template)<EOL>return used_name, template<EOL><DEDENT><DEDENT>elif isinstance(template, six.string_types):<EOL><INDENT>return template, None<EOL><DEDENT>else:<EOL><INDENT>filename = _get_template_filename(template)<EOL>template_name = '<STR_LIT>'.format(filename) if filename else '<STR_LIT>'<EOL>return template_name, None<EOL><DEDENT>

Get the template used in a TemplateResponse.
This returns a tuple of "active choice, all choices"


for template_name in template_name_list:<EOL><INDENT>try:<EOL><INDENT>get_template(template_name)<EOL>return template_name<EOL><DEDENT>except TemplateDoesNotExist:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>

Find which template of the template_names is selected by the Django loader.