~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Pool
  • Date: 2005-05-10 08:22:18 UTC
  • Revision ID: mbp@sourcefrog.net-20050510082218-cb22b6d981315883
- cope on platforms with no urandom feature
  including win32 python2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# along with this program; if not, write to the Free Software
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
 
import os, types, re, time, errno
 
19
import os, types, re, time, errno, sys
20
20
from stat import S_ISREG, S_ISDIR, S_ISLNK, ST_MODE, ST_SIZE
21
21
 
22
22
from errors import bailout, BzrError
285
285
 
286
286
if hasattr(os, 'urandom'): # python 2.4 and later
287
287
    rand_bytes = os.urandom
 
288
elif sys.platform == 'linux2':
 
289
    rand_bytes = file('/dev/urandom', 'rb').read
288
290
else:
289
 
    # FIXME: No good on non-Linux
290
 
    _rand_file = file('/dev/urandom', 'rb')
291
 
    rand_bytes = _rand_file.read
 
291
    # not well seeded, but better than nothing
 
292
    def rand_bytes(n):
 
293
        import random
 
294
        s = ''
 
295
        while n:
 
296
            s += chr(random.randint(0, 255))
 
297
            n -= 1
 
298
        return s
292
299
 
293
300
 
294
301
## TODO: We could later have path objects that remember their list