Module Expr Str ClassDef bases body FunctionDef arguments args NameParam defaults body Import alias Assign AttributeStore NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Assign AttributeStore AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Return Str decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Slice Num decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Import alias Assign AttributeStore AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr If CompareIs NameLoad NameLoad body Print Str Return NameLoad decorator_list decorator_list
N/A N/A 
A "mirroring" ``stdout`` context.

While active, the context manager reverses text output to
``stdout``::

# BEGIN MIRROR_DEMO_1

    >>> from mirror import LookingGlass
    >>> with LookingGlass() as what:  # <1>
    ...      print('Alice, Kitty and Snowdrop')  # <2>
    ...      print(what)
    ...
    pordwonS dna yttiK ,ecilA  # <3>
    YKCOWREBBAJ
    >>> what  # <4>
    'JABBERWOCKY'
    >>> print('Back to normal.')  # <5>
    Back to normal.

# END MIRROR_DEMO_1


This exposes the context manager operation::

# BEGIN MIRROR_DEMO_2

    >>> from mirror import LookingGlass
    >>> manager = LookingGlass()  # <1>
    >>> manager
    <mirror.LookingGlass object at 0x2a578ac>
    >>> monster = manager.__enter__()  # <2>
    >>> monster == 'JABBERWOCKY'  # <3>
    eurT
    >>> monster
    'YKCOWREBBAJ'
    >>> manager
    >ca875a2x0 ta tcejbo ssalGgnikooL.rorrim<
    >>> manager.__exit__(None, None, None)  # <4>
    >>> monster
    'JABBERWOCKY'

# END MIRROR_DEMO_2

The context manager can handle and "swallow" exceptions.

# BEGIN MIRROR_DEMO_3

    >>> from mirror import LookingGlass
    >>> with LookingGlass():
    ...      print('Humpty Dumpty')
    ...      x = 1/0  # <1>
    ...      print('END')  # <2>
    ...
    ytpmuD ytpmuH
    Please DO NOT divide by zero!
    >>> with LookingGlass():
    ...      print('Humpty Dumpty')
    ...      x = no_such_name  # <1>
    ...      print('END')  # <2>
    ...
    Traceback (most recent call last):
      ...
    NameError: name 'no_such_name' is not defined

# END MIRROR_DEMO_3

 LookingGlass N/A N/A __enter__ N/A N/A self N/A N/A N/A sys N/A N/A self original_write N/A N/A sys stdout write N/A N/A N/A sys stdout write N/A self reverse_write N/A JABBERWOCKY N/A reverse_write N/A N/A self text N/A N/A N/A N/A N/A self original_write N/A text N/A -1 N/A __exit__ N/A N/A self exc_type exc_value traceback N/A N/A N/A sys N/A N/A N/A sys stdout write N/A self original_write N/A N/A exc_type ZeroDivisionError N/A N/A Please DO NOT divide by zero! N/A True N/A N/A