home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnb101.zip / Lib / site-packages / Fnorb / orb / uuid.py < prev   
Text File  |  1999-06-28  |  2KB  |  72 lines

  1. #!/usr/bin/env python
  2. #############################################################################
  3. # Copyright (C) DSTC Pty Ltd (ACN 052 372 577) 1997, 1998, 1999
  4. # Unpublished work.  All Rights Reserved.
  5. #
  6. # The software contained on this media is the property of the
  7. # DSTC Pty Ltd.  Use of this software is strictly in accordance
  8. # with the license agreement in the accompanying LICENSE.DOC file.
  9. # If your distribution of this software does not contain a
  10. # LICENSE.DOC file then you have no rights to use this software
  11. # in any manner and should contact DSTC at the address below
  12. # to determine an appropriate licensing arrangement.
  13. #      DSTC Pty Ltd
  14. #      Level 7, GP South
  15. #      Staff House Road
  16. #      University of Queensland
  17. #      St Lucia, 4072
  18. #      Australia
  19. #      Tel: +61 7 3365 4310
  20. #      Fax: +61 7 3365 4311
  21. #      Email: enquiries@dstc.edu.au
  22. # This software is being provided "AS IS" without warranty of
  23. # any kind.  In no event shall DSTC Pty Ltd be liable for
  24. # damage of any kind arising out of or in connection with
  25. # the use or performance of this software.
  26. #
  27. # Project:  Hector
  28. # File:     $Source: /units/arch/src/Fnorb/orb/RCS/uuid.py,v $
  29. #
  30. #############################################################################
  31. """
  32. unique ID string generator
  33.  
  34. used to provide unique ids.  will eventually be replaced by a UUID
  35. module, but i'm too lazy to implement that at this moment.
  36.  
  37. """
  38. #############################################################################
  39.  
  40. from   time   import time
  41. from   random import randint
  42.  
  43.  
  44. #############################################################################
  45.  
  46. def id():
  47.     """Generate a unique ID string."""
  48.  
  49.     t = long((time() % 1.0) * 1.0e8)
  50.     return "%08X-%04X" % (t, randint(0, 0xffff))
  51.  
  52.  
  53. def uuid():
  54.     """Generate an IETF RFC-xxxx UUID (one day)."""
  55.  
  56.     #fixme: needs a portable way to find the ethernet address ...
  57.     t = long((time() % 1.0) * 1.0e8)
  58.     l = (randint(0, 0xffff) << 16) | randint(0, 0xffff)
  59.     return "%08X-%04X-%04X-%04X-%08X" % \
  60.        (t, randint(0,0xffff), randint(0,0xffff), randint(0,0xffff), l)
  61.  
  62.  
  63. #############################################################################
  64.  
  65. if __name__ == "__main__":
  66.     print uuid()
  67.  
  68.  
  69. #############################################################################
  70.