237
# This may throw an exception, in which case success will
239
rename_func(old, new)
238
# This may throw an exception, in which case success will
240
rename_func(old, new)
242
except (IOError, OSError), e:
243
# source and target may be aliases of each other (e.g. on a
244
# case-insensitive filesystem), so we may have accidentally renamed
245
# source by when we tried to rename target
246
if not (file_existed and e.errno in (None, errno.ENOENT)):
243
250
# If the file used to exist, rename it back into place
355
362
def _mac_getcwd():
356
return unicodedata.normalize('NFKC', os.getcwdu())
363
return unicodedata.normalize('NFC', os.getcwdu())
359
366
# Default is to just use the python builtins, but these can be rebound on
663
670
tt = time.localtime(t)
664
671
offset = local_time_offset(t)
666
raise errors.BzrError("unsupported timezone format %r" % timezone,
667
['options are "utc", "original", "local"'])
673
raise errors.UnsupportedTimezoneFormat(timezone)
668
674
if date_fmt is None:
669
675
date_fmt = "%a %Y-%m-%d %H:%M:%S"
1008
1014
On platforms where the system does not normalize filenames
1009
1015
(Windows, Linux), you have to access a file by its exact path.
1011
Internally, bzr only supports NFC/NFKC normalization, since that is
1017
Internally, bzr only supports NFC normalization, since that is
1012
1018
the standard for XML documents.
1014
1020
So return the normalized path, and a flag indicating if the file
1015
1021
can be accessed by that path.
1018
return unicodedata.normalize('NFKC', unicode(path)), True
1024
return unicodedata.normalize('NFC', unicode(path)), True
1021
1027
def _inaccessible_normalized_filename(path):
1022
1028
__doc__ = _accessible_normalized_filename.__doc__
1024
normalized = unicodedata.normalize('NFKC', unicode(path))
1030
normalized = unicodedata.normalize('NFC', unicode(path))
1025
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])
1402
1420
def dereference_path(path):
1403
1421
"""Determine the real path to a file.
1416
1434
def supports_mapi():
1417
1435
"""Return True if we can use MAPI to launch a mail client."""
1418
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()