~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Packman
  • Date: 2012-01-05 10:44:12 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6427.
  • Revision ID: martin.packman@canonical.com-20120105104412-z03fi9m43h946fvs
Merge bzr.dev to resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
import errno
18
20
import os
19
21
import re
947
949
    return os.fstat(f.fileno())[stat.ST_SIZE]
948
950
 
949
951
 
950
 
# Define rand_bytes based on platform.
951
 
try:
952
 
    # Python 2.4 and later have os.urandom,
953
 
    # but it doesn't work on some arches
954
 
    os.urandom(1)
955
 
    rand_bytes = os.urandom
956
 
except (NotImplementedError, AttributeError):
957
 
    # If python doesn't have os.urandom, or it doesn't work,
958
 
    # then try to first pull random data from /dev/urandom
 
952
# Alias os.urandom to support platforms (which?) without /dev/urandom and 
 
953
# override if it doesn't work. Avoid checking on windows where there is
 
954
# significant initialisation cost that can be avoided for some bzr calls.
 
955
 
 
956
rand_bytes = os.urandom
 
957
 
 
958
if rand_bytes.__module__ != "nt":
959
959
    try:
960
 
        rand_bytes = file('/dev/urandom', 'rb').read
961
 
    # Otherwise, use this hack as a last resort
962
 
    except (IOError, OSError):
 
960
        rand_bytes(1)
 
961
    except NotImplementedError:
963
962
        # not well seeded, but better than nothing
964
963
        def rand_bytes(n):
965
964
            import random
2042
2041
    behaves inconsistently on different platforms.
2043
2042
    """
2044
2043
    if sys.platform == "win32":
2045
 
        import win32utils
2046
2044
        return win32utils.get_host_name()
2047
2045
    else:
2048
2046
        import socket