27
26
lazy_import(globals(), """
28
27
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,
44
from tempfile import (
49
37
from bzrlib import (
304
292
running python.exe under cmd.exe return capital C:\\
305
293
running win32 python inside a cygwin shell returns lowercase c:\\
307
drive, path = _nt_splitdrive(path)
295
drive, path = ntpath.splitdrive(path)
308
296
return drive.upper() + path
311
299
def _win32_abspath(path):
312
# Real _nt_abspath doesn't have a problem with a unicode cwd
313
return _win32_fixdrive(_nt_abspath(unicode(path)).replace('\\', '/'))
300
# Real ntpath.abspath doesn't have a problem with a unicode cwd
301
return _win32_fixdrive(ntpath.abspath(unicode(path)).replace('\\', '/'))
316
304
def _win98_abspath(path):
327
315
# /path => C:/path
328
316
path = unicode(path)
329
317
# check for absolute path
330
drive = _nt_splitdrive(path)[0]
318
drive = ntpath.splitdrive(path)[0]
331
319
if drive == '' and path[:2] not in('//','\\\\'):
332
320
cwd = os.getcwdu()
333
321
# we cannot simply os.path.join cwd and path
334
322
# because os.path.join('C:','/path') produce '/path'
335
323
# and this is incorrect
336
324
if path[:1] in ('/','\\'):
337
cwd = _nt_splitdrive(cwd)[0]
325
cwd = ntpath.splitdrive(cwd)[0]
339
327
path = cwd + '\\' + path
340
return _win32_fixdrive(_nt_normpath(path).replace('\\', '/'))
328
return _win32_fixdrive(ntpath.normpath(path).replace('\\', '/'))
343
331
def _win32_realpath(path):
344
# Real _nt_realpath doesn't have a problem with a unicode cwd
345
return _win32_fixdrive(_nt_realpath(unicode(path)).replace('\\', '/'))
332
# Real ntpath.realpath doesn't have a problem with a unicode cwd
333
return _win32_fixdrive(ntpath.realpath(unicode(path)).replace('\\', '/'))
348
336
def _win32_pathjoin(*args):
349
return _nt_join(*args).replace('\\', '/')
337
return ntpath.join(*args).replace('\\', '/')
352
340
def _win32_normpath(path):
353
return _win32_fixdrive(_nt_normpath(unicode(path)).replace('\\', '/'))
341
return _win32_fixdrive(ntpath.normpath(unicode(path)).replace('\\', '/'))
356
344
def _win32_getcwd():
395
383
basename = os.path.basename
396
384
split = os.path.split
397
385
splitext = os.path.splitext
398
# These were already imported into local scope
399
# mkdtemp = tempfile.mkdtemp
400
# rmtree = shutil.rmtree
386
mkdtemp = tempfile.mkdtemp
387
rmtree = shutil.rmtree
402
389
MIN_ABS_PATHLENGTH = 1
511
498
"""True if f is a regular file."""
513
return S_ISREG(os.lstat(f)[ST_MODE])
500
return stat.S_ISREG(os.lstat(f)[stat.ST_MODE])
518
505
"""True if f is a symlink."""
520
return S_ISLNK(os.lstat(f)[ST_MODE])
507
return stat.S_ISLNK(os.lstat(f)[stat.ST_MODE])
2043
2030
sent_total += sent
2044
2031
report_activity(sent, 'write')
2033
# socket.create_connection() is not available before python2.6, so we provide
2034
# it for earlier versions
2035
if getattr(socket, 'create_connection', None) is not None:
2036
connect_socket = socket.create_connection
2038
# We don't use nor handle the timeout though
2039
def connect_socket(address, timeout=None):
2040
err = socket.error('getaddrinfo returns an empty list')
2041
for res in socket.getaddrinfo(host, port):
2042
af, socktype, proto, canonname, sa = res
2045
sock = socket.socket(af, socktype, proto)
2049
except socket.error, err:
2050
# 'err' is now the most recent error
2051
if sock is not None:
2047
2056
def dereference_path(path):
2048
2057
"""Determine the real path to a file.