/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Ā remote-transport

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Bazaar -- distributed version control
2
2
#
3
 
# Copyright (C) 2005 by Canonical Ltd
 
3
# Copyright (C) 2005 Canonical Ltd
4
4
#
5
5
# This program is free software; you can redistribute it and/or modify
6
6
# it under the terms of the GNU General Public License as published by
228
228
# choke on a Unicode string containing a relative path if
229
229
# os.getcwd() returns a non-sys.getdefaultencoding()-encoded
230
230
# string.
231
 
_fs_enc = sys.getfilesystemencoding()
 
231
_fs_enc = sys.getfilesystemencoding() or 'utf-8'
232
232
def _posix_abspath(path):
233
233
    # jam 20060426 rather than encoding to fsencoding
234
234
    # copy posixpath.abspath, but use os.getcwdu instead
1090
1090
    if _cached_user_encoding is None:
1091
1091
        _cached_user_encoding = 'ascii'
1092
1092
    return _cached_user_encoding
 
1093
 
 
1094
 
 
1095
def recv_all(socket, bytes):
 
1096
    """Receive an exact number of bytes.
 
1097
 
 
1098
    Regular Socket.recv() may return less than the requested number of bytes,
 
1099
    dependning on what's in the OS buffer.  MSG_WAITALL is not available
 
1100
    on all platforms, but this should work everywhere.  This will return
 
1101
    less than the requested amount if the remote end closes.
 
1102
 
 
1103
    This isn't optimized and is intended mostly for use in testing.
 
1104
    """
 
1105
    b = ''
 
1106
    while len(b) < bytes:
 
1107
        new = socket.recv(bytes - len(b))
 
1108
        if new == '':
 
1109
            break # eof
 
1110
        b += new
 
1111
    return b
 
1112
 
 
1113
def dereference_path(path):
 
1114
    """Determine the real path to a file.
 
1115
 
 
1116
    All parent elements are dereferenced.  But the file itself is not
 
1117
    dereferenced.
 
1118
    :param path: The original path.  May be absolute or relative.
 
1119
    :return: the real path *to* the file
 
1120
    """
 
1121
    parent, base = os.path.split(path)
 
1122
    # The pathjoin for '.' is a workaround for Python bug #1213894.
 
1123
    # (initial path components aren't dereferenced)
 
1124
    return pathjoin(realpath(pathjoin('.', parent)), base)