/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 from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Bazaar -- distributed version control
2
 
#
3
 
# Copyright (C) 2005 by 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
1090
1088
    if _cached_user_encoding is None:
1091
1089
        _cached_user_encoding = 'ascii'
1092
1090
    return _cached_user_encoding
 
1091
 
 
1092
 
 
1093
def recv_all(socket, bytes):
 
1094
    """Receive an exact number of bytes.
 
1095
 
 
1096
    Regular Socket.recv() may return less than the requested number of bytes,
 
1097
    dependning on what's in the OS buffer.  MSG_WAITALL is not available
 
1098
    on all platforms, but this should work everywhere.  This will return
 
1099
    less than the requested amount if the remote end closes.
 
1100
 
 
1101
    This isn't optimized and is intended mostly for use in testing.
 
1102
    """
 
1103
    b = ''
 
1104
    while len(b) < bytes:
 
1105
        new = socket.recv(bytes - len(b))
 
1106
        if new == '':
 
1107
            break # eof
 
1108
        b += new
 
1109
    return b
 
1110
 
 
1111
def dereference_path(path):
 
1112
    """Determine the real path to a file.
 
1113
 
 
1114
    All parent elements are dereferenced.  But the file itself is not
 
1115
    dereferenced.
 
1116
    :param path: The original path.  May be absolute or relative.
 
1117
    :return: the real path *to* the file
 
1118
    """
 
1119
    parent, base = os.path.split(path)
 
1120
    # The pathjoin for '.' is a workaround for Python bug #1213894.
 
1121
    # (initial path components aren't dereferenced)
 
1122
    return pathjoin(realpath(pathjoin('.', parent)), base)