/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

  • Committer: Robert Collins
  • Date: 2008-02-06 04:06:42 UTC
  • mfrom: (3216 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3217.
  • Revision ID: robertc@robertcollins.net-20080206040642-2efx3l4iv5f95lxp
Merge up with bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
from bzrlib import symbol_versioning
58
58
from bzrlib.symbol_versioning import (
59
59
    deprecated_function,
60
 
    zero_ninetythree,
 
60
    one_zero,
61
61
    )
62
62
from bzrlib.trace import mutter
63
63
 
360
360
 
361
361
 
362
362
def _mac_getcwd():
363
 
    return unicodedata.normalize('NFKC', os.getcwdu())
 
363
    return unicodedata.normalize('NFC', os.getcwdu())
364
364
 
365
365
 
366
366
# Default is to just use the python builtins, but these can be rebound on
468
468
        return pathjoin(F(p), e)
469
469
 
470
470
 
471
 
@deprecated_function(zero_ninetythree)
 
471
@deprecated_function(one_zero)
472
472
def backup_file(fn):
473
473
    """Copy a file to a backup.
474
474
 
670
670
        tt = time.localtime(t)
671
671
        offset = local_time_offset(t)
672
672
    else:
673
 
        raise errors.BzrError("unsupported timezone format %r" % timezone,
674
 
                              ['options are "utc", "original", "local"'])
 
673
        raise errors.UnsupportedTimezoneFormat(timezone)
675
674
    if date_fmt is None:
676
675
        date_fmt = "%a %Y-%m-%d %H:%M:%S"
677
676
    if show_offset:
1015
1014
    On platforms where the system does not normalize filenames 
1016
1015
    (Windows, Linux), you have to access a file by its exact path.
1017
1016
 
1018
 
    Internally, bzr only supports NFC/NFKC normalization, since that is 
 
1017
    Internally, bzr only supports NFC normalization, since that is 
1019
1018
    the standard for XML documents.
1020
1019
 
1021
1020
    So return the normalized path, and a flag indicating if the file
1022
1021
    can be accessed by that path.
1023
1022
    """
1024
1023
 
1025
 
    return unicodedata.normalize('NFKC', unicode(path)), True
 
1024
    return unicodedata.normalize('NFC', unicode(path)), True
1026
1025
 
1027
1026
 
1028
1027
def _inaccessible_normalized_filename(path):
1029
1028
    __doc__ = _accessible_normalized_filename.__doc__
1030
1029
 
1031
 
    normalized = unicodedata.normalize('NFKC', unicode(path))
 
1030
    normalized = unicodedata.normalize('NFC', unicode(path))
1032
1031
    return normalized, normalized == path
1033
1032
 
1034
1033
 
1406
1405
        b += new
1407
1406
    return b
1408
1407
 
 
1408
 
 
1409
def send_all(socket, bytes):
 
1410
    """Send all bytes on a socket.
 
1411
 
 
1412
    Regular socket.sendall() can give socket error 10053 on Windows.  This
 
1413
    implementation sends no more than 64k at a time, which avoids this problem.
 
1414
    """
 
1415
    chunk_size = 2**16
 
1416
    for pos in xrange(0, len(bytes), chunk_size):
 
1417
        socket.sendall(bytes[pos:pos+chunk_size])
 
1418
 
 
1419
 
1409
1420
def dereference_path(path):
1410
1421
    """Determine the real path to a file.
1411
1422
 
1423
1434
def supports_mapi():
1424
1435
    """Return True if we can use MAPI to launch a mail client."""
1425
1436
    return sys.platform == "win32"
 
1437
 
 
1438
 
 
1439
def resource_string(package, resource_name):
 
1440
    """Load a resource from a package and return it as a string.
 
1441
 
 
1442
    Note: Only packages that start with bzrlib are currently supported.
 
1443
 
 
1444
    This is designed to be a lightweight implementation of resource
 
1445
    loading in a way which is API compatible with the same API from
 
1446
    pkg_resources. See
 
1447
    http://peak.telecommunity.com/DevCenter/PkgResources#basic-resource-access.
 
1448
    If and when pkg_resources becomes a standard library, this routine
 
1449
    can delegate to it.
 
1450
    """
 
1451
    # Check package name is within bzrlib
 
1452
    if package == "bzrlib":
 
1453
        resource_relpath = resource_name
 
1454
    elif package.startswith("bzrlib."):
 
1455
        package = package[len("bzrlib."):].replace('.', os.sep)
 
1456
        resource_relpath = pathjoin(package, resource_name)
 
1457
    else:
 
1458
        raise errors.BzrError('resource package %s not in bzrlib' % package)
 
1459
 
 
1460
    # Map the resource to a file and read its contents
 
1461
    base = dirname(bzrlib.__file__)
 
1462
    if getattr(sys, 'frozen', None):    # bzr.exe
 
1463
        base = abspath(pathjoin(base, '..', '..'))
 
1464
    filename = pathjoin(base, resource_relpath)
 
1465
    return open(filename, 'rU').read()