home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Lib / test / test_new.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  2.2 KB  |  64 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. verbose
  5. print 'new.module()'
  6. m = new.module('Spam')
  7. if verbose:
  8.     print m
  9.  
  10. m.Eggs = Eggs
  11. sys.modules['Spam'] = m
  12. import Spam
  13.  
  14. def get_more_yolks(self):
  15.     return self.yolks + 3
  16.  
  17. print 'new.classobj()'
  18. C = new.classobj('Spam', (Spam.Eggs,), {
  19.     'get_more_yolks': get_more_yolks })
  20. if verbose:
  21.     print C
  22.  
  23. print 'new.instance()'
  24. c = new.instance(C, {
  25.     'yolks': 3 })
  26. if verbose:
  27.     print c
  28.  
  29.  
  30. def break_yolks(self):
  31.     self.yolks = self.yolks - 2
  32.  
  33. print 'new.instancemethod()'
  34. im = new.instancemethod(break_yolks, c, C)
  35. if verbose:
  36.     print im
  37.  
  38. if c.get_yolks() != 3 and c.get_more_yolks() != 6:
  39.     print 'Broken call of hand-crafted class instance'
  40.  
  41. im()
  42. if c.get_yolks() != 1 and c.get_more_yolks() != 4:
  43.     print 'Broken call of hand-crafted instance method'
  44.  
  45. codestr = '\na = 1\nb = 2\nc = a + b\n'
  46. ccode = compile(codestr, '<string>', 'exec')
  47. g = {
  48.     'c': 0,
  49.     '__builtins__': __builtins__ }
  50. print 'new.function()'
  51. func = new.function(ccode, g)
  52. if verbose:
  53.     print func
  54.  
  55. func()
  56. if g['c'] != 3:
  57.     print 'Could not create a proper function object'
  58.  
  59. print 'new.code()'
  60. d = new.code(3, 3, 3, 3, codestr, (), (), (), '<string>', '<name>', 1, '')
  61. if verbose:
  62.     print d
  63.  
  64.