/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Bazaar -- distributed version control
2
 
#
3
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
4
2
#
5
3
# This program is free software; you can redistribute it and/or modify
6
4
# it under the terms of the GNU General Public License as published by
228
226
# choke on a Unicode string containing a relative path if
229
227
# os.getcwd() returns a non-sys.getdefaultencoding()-encoded
230
228
# string.
231
 
_fs_enc = sys.getfilesystemencoding()
 
229
_fs_enc = sys.getfilesystemencoding() or 'utf-8'
232
230
def _posix_abspath(path):
233
231
    # jam 20060426 rather than encoding to fsencoding
234
232
    # copy posixpath.abspath, but use os.getcwdu instead
334
332
        """Error handler for shutil.rmtree function [for win32]
335
333
        Helps to remove files and dirs marked as read-only.
336
334
        """
337
 
        type_, value = excinfo[:2]
 
335
        exception = excinfo[1]
338
336
        if function in (os.remove, os.rmdir) \
339
 
            and type_ == OSError \
340
 
            and value.errno == errno.EACCES:
 
337
            and isinstance(exception, OSError) \
 
338
            and exception.errno == errno.EACCES:
341
339
            make_writable(path)
342
340
            function(path)
343
341
        else:
374
372
            mutter('encoding stdout as sys.stdin encoding %r', output_encoding)
375
373
    else:
376
374
        mutter('encoding stdout as sys.stdout encoding %r', output_encoding)
 
375
    if output_encoding == 'cp0':
 
376
        # invalid encoding (cp0 means 'no codepage' on Windows)
 
377
        output_encoding = bzrlib.user_encoding
 
378
        mutter('cp0 is invalid encoding.'
 
379
               ' encoding stdout as bzrlib.user_encoding %r', output_encoding)
377
380
    return output_encoding
378
381
 
379
382
 
1087
1090
                         "  Continuing with ascii encoding.\n"
1088
1091
                         % (e, os.environ.get('LANG')))
1089
1092
 
1090
 
    if _cached_user_encoding is None:
 
1093
    # Windows returns 'cp0' to indicate there is no code page. So we'll just
 
1094
    # treat that as ASCII, and not support printing unicode characters to the
 
1095
    # console.
 
1096
    if _cached_user_encoding in (None, 'cp0'):
1091
1097
        _cached_user_encoding = 'ascii'
1092
1098
    return _cached_user_encoding
 
1099
 
 
1100
 
 
1101
def recv_all(socket, bytes):
 
1102
    """Receive an exact number of bytes.
 
1103
 
 
1104
    Regular Socket.recv() may return less than the requested number of bytes,
 
1105
    dependning on what's in the OS buffer.  MSG_WAITALL is not available
 
1106
    on all platforms, but this should work everywhere.  This will return
 
1107
    less than the requested amount if the remote end closes.
 
1108
 
 
1109
    This isn't optimized and is intended mostly for use in testing.
 
1110
    """
 
1111
    b = ''
 
1112
    while len(b) < bytes:
 
1113
        new = socket.recv(bytes - len(b))
 
1114
        if new == '':
 
1115
            break # eof
 
1116
        b += new
 
1117
    return b
 
1118
 
 
1119
def dereference_path(path):
 
1120
    """Determine the real path to a file.
 
1121
 
 
1122
    All parent elements are dereferenced.  But the file itself is not
 
1123
    dereferenced.
 
1124
    :param path: The original path.  May be absolute or relative.
 
1125
    :return: the real path *to* the file
 
1126
    """
 
1127
    parent, base = os.path.split(path)
 
1128
    # The pathjoin for '.' is a workaround for Python bug #1213894.
 
1129
    # (initial path components aren't dereferenced)
 
1130
    return pathjoin(realpath(pathjoin('.', parent)), base)