<s> import sys <EOL> __package__ = "<STR_LIT>" <EOL> __builtins__ = None <EOL> __doc__ = None <EOL> def fake ( ) : <EOL> return [ '<STR_LIT:all>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class TestClass ( object ) : <EOL> def __init__ ( self ) : <EOL> for n in fake ( ) : <EOL> setattr ( self , n , n ) <EOL> def __dir__ ( self ) : <EOL> return fake ( ) <EOL> class TestClass2 ( object ) : <EOL> def __init__ ( self ) : <EOL> self . dictAttr = False <EOL> self . attribute1 = None <EOL> self . other_attribute = False <EOL> def method1 ( self ) : <EOL> pass <EOL> dir ( sys . modules [ __name__ ] ) <EOL> dir ( TestClass ( ) ) <EOL> dir ( TestClass2 ( ) ) <EOL> dir ( str ( ) ) <EOL> dir ( list ( ) ) <EOL> dir ( { } ) <EOL> dir ( int ( ) ) <EOL> dir ( dir ) <EOL> dir ( fake ) <EOL> dir ( None ) <EOL> dir ( TestClass ) <EOL> dir ( TestClass2 ) <EOL> dir ( sys ) <EOL> dir ( dict ) <EOL> dir ( int ) <EOL> dir ( str ) <EOL> dir ( set ) <EOL> def test_in_dir ( names , obj ) : <EOL> r = dir ( obj ) <EOL> print [ n in r for n in names ] <EOL> test_in_dir ( fake ( ) , TestClass ( ) ) <EOL> test_in_dir ( [ '<STR_LIT>' , '<STR_LIT>' ] , TestClass2 ) <EOL> test_in_dir ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , TestClass2 ( ) ) <EOL> test_in_dir ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] + fake ( ) , TestClass ) <EOL> test_in_dir ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , TestClass2 ) <EOL> test_in_dir ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , TestClass2 ( ) ) <EOL> test_in_dir ( fake ( ) , TestClass ( ) ) <EOL> print len ( fake ( ) ) == len ( dir ( TestClass ( ) ) ) <EOL> for t in [ str , int , list , set , dict ] : <EOL> test_in_dir ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , t ) <EOL> class C1 ( object ) : <EOL> a = <NUM_LIT:1> <EOL> b = <NUM_LIT:2> <EOL> class C2 ( C1 ) : <EOL> b = <NUM_LIT:3> <EOL> c = <NUM_LIT:4> <EOL> print sorted ( [ s for s in dir ( C2 ) if s [ <NUM_LIT:0> ] != '<STR_LIT:_>' ] ) <EOL> c = C1 ( ) <EOL> c . d = <NUM_LIT:2> <EOL> d1 = c . __dict__ <EOL> d2 = d1 . copy ( ) <EOL> c . e = <NUM_LIT:3> <EOL> print sorted ( d1 . items ( ) ) <EOL> print sorted ( d2 . items ( ) ) <EOL> l = [ ] <EOL> for x in d1 : <EOL> l . append ( x ) <EOL> l . sort ( ) <EOL> print l <EOL> c = C1 ( ) <EOL> c . __dict__ . update ( dict ( a = <NUM_LIT:1> , b = <NUM_LIT:5> ) , d = <NUM_LIT:4> ) <EOL> print sorted ( c . __dict__ . items ( ) ) <EOL> class TestClass3 : <EOL> def __init__ ( self ) : <EOL> self . a = <NUM_LIT:1> <EOL> def foo ( self ) : <EOL> pass <EOL> def bar ( self ) : <EOL> pass <EOL> print sorted ( [ d for d in dir ( TestClass3 ) if not d . startswith ( '<STR_LIT:_>' ) ] ) <EOL> print sorted ( [ d for d in dir ( TestClass3 ( ) ) if not d . startswith ( '<STR_LIT:_>' ) ] ) <EOL> c = C1 ( ) <EOL> c . __dict__ . update ( [ ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:2> ) ] ) <EOL> print c . a , c . b <EOL> i = c . __dict__ . iteritems ( ) <EOL> l = [ ] <EOL> while True : <EOL> try : <EOL> l . append ( i . next ( ) ) <EOL> except StopIteration : <EOL> break <EOL> print sorted ( l ) <EOL> c = C1 ( ) <EOL> print sorted ( c . __dict__ . items ( ) ) <EOL> setattr ( c , u'<STR_LIT:a>' , <NUM_LIT:1> ) <EOL> print sorted ( c . __dict__ . items ( ) ) <EOL> c . __dict__ [ u'<STR_LIT:b>' ] = <NUM_LIT:2> <EOL> print sorted ( c . __dict__ . items ( ) ) <EOL> c . __dict__ . update ( { u'<STR_LIT:c>' : <NUM_LIT:3> } ) <EOL> print sorted ( c . __dict__ . items ( ) ) <EOL> try : <EOL> setattr ( c , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> assert <NUM_LIT:0> <EOL> except TypeError as e : <EOL> print e <EOL> print sorted ( c . __dict__ . items ( ) ) <EOL> c . __dict__ [ <NUM_LIT:5> ] = <NUM_LIT:2> <EOL> print sorted ( c . __dict__ . items ( ) ) </s>
