def remove_html_markup_traced(s):
    sys.settrace(traceit)
    ret = remove_html_markup(s)
    sys.settrace(None)
    return ret
        return self._traceit

    def __enter__(self):
        """Called at begin of `with` block. Turn tracing on."""
        self.original_trace_function = sys.gettrace()
        sys.settrace(self._traceit)
        return self

    def __exit__(self, tp, value, traceback):
        """Called at begin of `with` block. Turn tracing off."""
        sys.settrace(self.original_trace_function)


if __name__ == "__main__":
    with Tracer():
        remove_html_markup("abc")

# ## Accessing Source Code

if __name__ == "__main__":
    print('\n## Accessing Source Code')

import inspect


class Tracer(Tracer):
    def traceit(self, frame, event, arg):
        if event == 'line':
            module = inspect.getmodule(frame.f_code)
            if module is None:
                source = inspect.getsource(frame.f_code)
def some_extreme_function(s):
    ...  # Long-running function
    remove_html_markup(s)
Example #4
0
if __name__ == "__main__":
    print('\n## Some Examples')

# ### Removing HTML Markup

if __name__ == "__main__":
    print('\n### Removing HTML Markup')

if __package__ is None or __package__ == "":
    from Intro_Debugging import remove_html_markup
else:
    from .Intro_Debugging import remove_html_markup

if __name__ == "__main__":
    with InvariantAnnotator() as annotator:
        remove_html_markup("<foo>bar</foo>")
        remove_html_markup("bar")
        remove_html_markup('"bar"')

if __name__ == "__main__":
    print_content(annotator.functions_with_invariants(), '.py')

# ### A Recursive Function

if __name__ == "__main__":
    print('\n### A Recursive Function')


def list_length(elems):
    if elems == []:
        length = 0