<s> from dill . source import getsource , getname , _wrap , likely_import <EOL> from dill . source import getimportable <EOL> import sys <EOL> PY3 = sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> <EOL> f = lambda x : x ** <NUM_LIT:2> <EOL> def g ( x ) : return f ( x ) - x <EOL> def h ( x ) : <EOL> def g ( x ) : return x <EOL> return g ( x ) - x <EOL> class Foo ( object ) : <EOL> def bar ( self , x ) : <EOL> return x * x + x <EOL> _foo = Foo ( ) <EOL> def add ( x , y ) : <EOL> return x + y <EOL> squared = lambda x : x ** <NUM_LIT:2> <EOL> class Bar : <EOL> pass <EOL> _bar = Bar ( ) <EOL> assert getsource ( f ) == '<STR_LIT>' <EOL> assert getsource ( g ) == '<STR_LIT>' <EOL> assert getsource ( h ) == '<STR_LIT>' <EOL> assert getname ( f ) == '<STR_LIT:f>' <EOL> assert getname ( g ) == '<STR_LIT:g>' <EOL> assert getname ( h ) == '<STR_LIT:h>' <EOL> assert _wrap ( f ) ( <NUM_LIT:4> ) == <NUM_LIT:16> <EOL> assert _wrap ( g ) ( <NUM_LIT:4> ) == <NUM_LIT:12> <EOL> assert _wrap ( h ) ( <NUM_LIT:4> ) == <NUM_LIT:0> <EOL> assert getname ( Foo ) == '<STR_LIT>' <EOL> assert getname ( Bar ) == '<STR_LIT>' <EOL> assert getsource ( Bar ) == '<STR_LIT>' <EOL> assert getsource ( Foo ) == '<STR_LIT>' <EOL> assert likely_import ( likely_import ) == '<STR_LIT>' <EOL> if PY3 : builtin = '<STR_LIT>' <EOL> else : builtin = '<STR_LIT>' <EOL> assert likely_import ( pow ) == '<STR_LIT>' <EOL> assert likely_import ( <NUM_LIT:100> ) == '<STR_LIT>' <EOL> assert likely_import ( True ) == '<STR_LIT>' <EOL> assert likely_import ( pow , explicit = True ) == '<STR_LIT>' % builtin <EOL> assert likely_import ( <NUM_LIT:100> , explicit = True ) == '<STR_LIT>' <EOL> assert likely_import ( True , explicit = True ) == '<STR_LIT>' if PY3 else '<STR_LIT>' % builtin <EOL> assert likely_import ( None ) == '<STR_LIT>' <EOL> assert likely_import ( None , explicit = True ) == '<STR_LIT>' <EOL> from math import sin <EOL> assert likely_import ( sin ) == '<STR_LIT>' <EOL> assert likely_import ( add ) == '<STR_LIT>' % __name__ <EOL> assert likely_import ( squared ) == '<STR_LIT>' % __name__ <EOL> try : <EOL> from StringIO import StringIO <EOL> x = "<STR_LIT>" <EOL> y = x <EOL> except ImportError : <EOL> from io import BytesIO as StringIO <EOL> x = "<STR_LIT>" <EOL> y = "<STR_LIT>" <EOL> s = StringIO ( ) <EOL> assert likely_import ( StringIO ) == x <EOL> assert likely_import ( s ) == y <EOL> assert likely_import ( Foo ) == '<STR_LIT>' % __name__ <EOL> assert likely_import ( _foo ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( add ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( squared ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( Foo ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( Foo . bar ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( _foo . bar ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( None ) == '<STR_LIT>' <EOL> assert getimportable ( <NUM_LIT:100> ) == '<STR_LIT>' <EOL> assert getimportable ( add , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( squared , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( None , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( Bar , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( Foo , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( Foo . bar , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( Foo . bar , byname = True ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( Foo . bar , alias = '<STR_LIT>' , byname = True ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( Foo , alias = '<STR_LIT>' , byname = True ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( squared , alias = '<STR_LIT>' , byname = True ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( squared , alias = '<STR_LIT>' , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( add , alias = '<STR_LIT>' , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( None , alias = '<STR_LIT>' , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( <NUM_LIT:100> , alias = '<STR_LIT>' , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( add , explicit = True ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( squared , explicit = True ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( Foo , explicit = True ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( Foo . bar , explicit = True ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( _foo . bar , explicit = True ) == '<STR_LIT>' % __name__ <EOL> assert getimportable ( None , explicit = True ) == '<STR_LIT>' <EOL> assert getimportable ( <NUM_LIT:100> , explicit = True ) == '<STR_LIT>' <EOL> try : <EOL> from numpy import array <EOL> x = array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> assert getimportable ( x ) == '<STR_LIT>' <EOL> assert getimportable ( array ) == '<STR_LIT>' <EOL> assert getimportable ( x , byname = False ) == '<STR_LIT>' <EOL> assert getimportable ( array , byname = False ) == '<STR_LIT>' <EOL> except ImportError : pass <EOL> assert getimportable ( _foo , byname = False ) . startswith ( "<STR_LIT>" ) </s>
