home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Languages / python / PyObjC-0.47-MIHS / pyobjc-0.47-src / Demo / ObjC / StructUser / StructUser.py < prev   
Encoding:
Python Source  |  1996-11-13  |  2.0 KB  |  77 lines

  1. #!/usr/local/bin/python
  2. #
  3. # Copyright (c) 1996 by Lele Gaifax.  All Rights Reserved
  4. #
  5. # This file is part of the PyObjC package.
  6. #
  7. # $RCSfile: StructUser.py,v $
  8. # $Revision: 1.1.1.2 $
  9. # $Date: 1996/11/14 01:49:58 $
  10. #
  11. # Created Mon Sep  9 18:34:01 1996.
  12. #
  13.  
  14. import ObjC
  15.  
  16. NXBundle = ObjC.lookup_class ('NXBundle')
  17.  
  18. su_bundle = NXBundle.alloc().initForDirectory__ ('StructUser.bundle')
  19. StructUser = su_bundle.principalClass()
  20.  
  21. if StructUser:
  22.     print "Building a StructUser with a default contents..."
  23.     me = StructUser.me()
  24.     me.show()
  25.  
  26.     print
  27.     print "Fetching the passwd entry of user #4..."
  28.     uucp = StructUser.alloc().initWithUserId__ (4)
  29.     uucp.show()
  30.     print "... and getting its value via the appropriate method..."
  31.     try:
  32.     print uucp.pwdEntry()
  33.     except ObjC.error, m:
  34.     print m, "... Sorry!"
  35.  
  36.     print
  37.     print "Building a custom User Entry..."
  38.     other = StructUser.alloc()
  39.     other.initWithPasswd__ (('other', 'ThisIsThePassword', 104, 401, 10, 'Comments?', '', '/usr/local/spool/uucppublic', '/usr/local/lib/uucp/uucico'))
  40.     other.show()
  41.     print "... and getting its value via the appropriate method..."
  42.     try:
  43.     print other.pwdEntry()
  44.     except ObjC.error, m:
  45.     print m, "... Sorry!"
  46.  
  47.     # This does not work yet.
  48.     print
  49.     print "Trying float/double handling code..."
  50.     #entry = other.pwdEntry()
  51.     #uid = entry[2]
  52.     uid = 4
  53.     #print entry, uid
  54.     okresult = uid * 3.14159
  55.     result = uucp.multiplyUserIdBy__ (3.14159)
  56.     print result
  57.     if round (result, 5) != round (okresult, 5):
  58.     print "as expected, it does not work yet: should be", okresult
  59.     else:
  60.     print "Great!! it works!"
  61.  
  62.     print
  63.     print "Building a custom User Entry with wrong data..."
  64.     other = StructUser.alloc()
  65.     try:
  66.     other.initWithPasswd__ (('other', 'ThisIsThePassword', 401, 10, 'Comments?', '', '/usr/local/spool/uucppublic', '/usr/local/lib/uucp/uucico'))
  67.     other.show()
  68.     except ObjC.error, m:
  69.     print "Correctly, the module generated an exception:", m
  70.     else:
  71.     print "Wrong behaviour!"
  72.     # end try
  73.  
  74. # end if
  75.  
  76.  
  77.