362
362
def _mac_getcwd():
363
return unicodedata.normalize('NFKC', os.getcwdu())
363
return unicodedata.normalize('NFC', os.getcwdu())
366
366
# Default is to just use the python builtins, but these can be rebound on
670
670
tt = time.localtime(t)
671
671
offset = local_time_offset(t)
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"
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.
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.
1021
1020
So return the normalized path, and a flag indicating if the file
1022
1021
can be accessed by that path.
1025
return unicodedata.normalize('NFKC', unicode(path)), True
1024
return unicodedata.normalize('NFC', unicode(path)), True
1028
1027
def _inaccessible_normalized_filename(path):
1029
1028
__doc__ = _accessible_normalized_filename.__doc__
1031
normalized = unicodedata.normalize('NFKC', unicode(path))
1030
normalized = unicodedata.normalize('NFC', unicode(path))
1032
1031
return normalized, normalized == path
1409
def send_all(socket, bytes):
1410
"""Send all bytes on a socket.
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.
1416
for pos in xrange(0, len(bytes), chunk_size):
1417
socket.sendall(bytes[pos:pos+chunk_size])
1409
1420
def dereference_path(path):
1410
1421
"""Determine the real path to a file.
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"
1439
def resource_string(package, resource_name):
1440
"""Load a resource from a package and return it as a string.
1442
Note: Only packages that start with bzrlib are currently supported.
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
1447
http://peak.telecommunity.com/DevCenter/PkgResources#basic-resource-access.
1448
If and when pkg_resources becomes a standard library, this routine
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)
1458
raise errors.BzrError('resource package %s not in bzrlib' % package)
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()