~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Pool
  • Date: 2006-02-17 20:34:30 UTC
  • mto: This revision was merged to the branch mainline in revision 1569.
  • Revision ID: mbp@sourcefrog.net-20060217203430-d15f555c71a6c0cd
New utility routine rand_chars

Show diffs side-by-side

added added

removed removed

Lines of Context:
441
441
    """Return size of given open file."""
442
442
    return os.fstat(f.fileno())[ST_SIZE]
443
443
 
 
444
 
444
445
# Define rand_bytes based on platform.
445
446
try:
446
447
    # Python 2.4 and later have os.urandom,
463
464
                n -= 1
464
465
            return s
465
466
 
 
467
 
 
468
ALNUM = '0123456789abcdefghijklmnopqrstuvwxyz'
 
469
def rand_chars(num):
 
470
    """Return a random string of num alphanumeric characters
 
471
    
 
472
    The result only contains lowercase chars because it may be used on 
 
473
    case-insensitive filesystems.
 
474
    """
 
475
    s = ''
 
476
    for raw_byte in rand_bytes(num):
 
477
        s += ALNUM[ord(raw_byte) % 36]
 
478
    return s
 
479
 
 
480
 
466
481
## TODO: We could later have path objects that remember their list
467
482
## decomposition (might be too tricksy though.)
468
483