<s> from IPython . core . magic import ( Magics , magics_class , <EOL> cell_magic , needs_local_scope ) <EOL> import IPython . display <EOL> try : <EOL> from io import StringIO <EOL> except ImportError : <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> import sys <EOL> valid_choices = [ x [ <NUM_LIT:8> : ] for x in dir ( IPython . display ) if '<STR_LIT>' == x [ : <NUM_LIT:8> ] ] <EOL> @ magics_class <EOL> class OutputMagics ( Magics ) : <EOL> @ needs_local_scope <EOL> @ cell_magic <EOL> def to ( self , line , cell , local_ns = None ) : <EOL> choice = line . strip ( ) <EOL> assert choice in valid_choices , "<STR_LIT>" + str ( valid_choices ) <EOL> display_fn = getattr ( IPython . display , "<STR_LIT>" + choice ) <EOL> "<STR_LIT>" <EOL> with StringIO ( ) as out : <EOL> old_out = sys . stdout <EOL> try : <EOL> sys . stdout = out <EOL> exec ( cell , self . shell . user_ns , local_ns ) <EOL> out . seek ( <NUM_LIT:0> ) <EOL> display_fn ( out . getvalue ( ) , raw = True ) <EOL> finally : <EOL> sys . stdout = old_out </s>
