26
27
lazy_import(globals(), """
27
28
from datetime import datetime
30
from ntpath import (abspath as _nt_abspath,
32
normpath as _nt_normpath,
33
realpath as _nt_realpath,
34
splitdrive as _nt_splitdrive,
31
# We need to import both shutil and rmtree as we export the later on posix
32
# and need the former on windows
34
from shutil import rmtree
37
# We need to import both tempfile and mkdtemp as we export the later on posix
38
# and need the former on windows
40
from tempfile import mkdtemp
44
from tempfile import (
43
49
from bzrlib import (
298
304
running python.exe under cmd.exe return capital C:\\
299
305
running win32 python inside a cygwin shell returns lowercase c:\\
301
drive, path = ntpath.splitdrive(path)
307
drive, path = _nt_splitdrive(path)
302
308
return drive.upper() + path
305
311
def _win32_abspath(path):
306
# Real ntpath.abspath doesn't have a problem with a unicode cwd
307
return _win32_fixdrive(ntpath.abspath(unicode(path)).replace('\\', '/'))
312
# Real _nt_abspath doesn't have a problem with a unicode cwd
313
return _win32_fixdrive(_nt_abspath(unicode(path)).replace('\\', '/'))
310
316
def _win98_abspath(path):
321
327
# /path => C:/path
322
328
path = unicode(path)
323
329
# check for absolute path
324
drive = ntpath.splitdrive(path)[0]
330
drive = _nt_splitdrive(path)[0]
325
331
if drive == '' and path[:2] not in('//','\\\\'):
326
332
cwd = os.getcwdu()
327
333
# we cannot simply os.path.join cwd and path
328
334
# because os.path.join('C:','/path') produce '/path'
329
335
# and this is incorrect
330
336
if path[:1] in ('/','\\'):
331
cwd = ntpath.splitdrive(cwd)[0]
337
cwd = _nt_splitdrive(cwd)[0]
333
339
path = cwd + '\\' + path
334
return _win32_fixdrive(ntpath.normpath(path).replace('\\', '/'))
340
return _win32_fixdrive(_nt_normpath(path).replace('\\', '/'))
337
343
def _win32_realpath(path):
338
# Real ntpath.realpath doesn't have a problem with a unicode cwd
339
return _win32_fixdrive(ntpath.realpath(unicode(path)).replace('\\', '/'))
344
# Real _nt_realpath doesn't have a problem with a unicode cwd
345
return _win32_fixdrive(_nt_realpath(unicode(path)).replace('\\', '/'))
342
348
def _win32_pathjoin(*args):
343
return ntpath.join(*args).replace('\\', '/')
349
return _nt_join(*args).replace('\\', '/')
346
352
def _win32_normpath(path):
347
return _win32_fixdrive(ntpath.normpath(unicode(path)).replace('\\', '/'))
353
return _win32_fixdrive(_nt_normpath(unicode(path)).replace('\\', '/'))
350
356
def _win32_getcwd():
389
395
basename = os.path.basename
390
396
split = os.path.split
391
397
splitext = os.path.splitext
392
# These were already lazily imported into local scope
398
# These were already imported into local scope
393
399
# mkdtemp = tempfile.mkdtemp
394
400
# rmtree = shutil.rmtree
512
518
"""True if f is a regular file."""
514
return stat.S_ISREG(os.lstat(f)[stat.ST_MODE])
520
return S_ISREG(os.lstat(f)[ST_MODE])
519
525
"""True if f is a symlink."""
521
return stat.S_ISLNK(os.lstat(f)[stat.ST_MODE])
527
return S_ISLNK(os.lstat(f)[ST_MODE])
2065
2071
report_activity(sent, 'write')
2068
def connect_socket(address):
2069
# Slight variation of the socket.create_connection() function (provided by
2070
# python-2.6) that can fail if getaddrinfo returns an empty list. We also
2071
# provide it for previous python versions. Also, we don't use the timeout
2072
# parameter (provided by the python implementation) so we don't implement
2074
err = socket.error('getaddrinfo returns an empty list')
2075
host, port = address
2076
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
2077
af, socktype, proto, canonname, sa = res
2080
sock = socket.socket(af, socktype, proto)
2084
except socket.error, err:
2085
# 'err' is now the most recent error
2086
if sock is not None:
2091
2074
def dereference_path(path):
2092
2075
"""Determine the real path to a file.
2189
@deprecated_function(deprecated_in((2, 2, 0)))
2190
2172
def re_compile_checked(re_string, flags=0, where=""):
2191
2173
"""Return a compiled re, or raise a sensible error.
2202
2184
re_obj = re.compile(re_string, flags)
2203
2185
re_obj.search("")
2205
except errors.InvalidPattern, e:
2207
2189
where = ' in ' + where
2208
2190
# despite the name 'error' is a type
2209
raise errors.BzrCommandError('Invalid regular expression%s: %s'
2191
raise errors.BzrCommandError('Invalid regular expression%s: %r: %s'
2192
% (where, re_string, e))
2213
2195
if sys.platform == "win32":