##// END OF EJS Templates
bundlerepo: fix string interpolation...
bundlerepo: fix string interpolation Matt Harbison is saying we cannot `%s` a type into a byte string and that seems reasonable.

File last commit:

r50713:3fd5824f default
r51096:149f09ff default
Show More
windows.py
764 lines | 23.1 KiB | text/x-python | PythonLexer
Martin Geisler
put license and copyright info into comment blocks
r8226 # windows.py - Windows utility function implementations for Mercurial
#
Raphaël Gomès
contributor: change mentions of mpm to olivia...
r47575 # Copyright 2005-2009 Olivia Mackall <olivia@selenic.com> and others
Martin Geisler
put license and copyright info into comment blocks
r8226 #
# This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Sune Foldager
posixfile: remove posixfile_nt and fix import bug in windows.py...
r8421
Gregory Szorc
windows: use absolute_import
r27360 import errno
Augie Fackler
windows: if username(uid=None) is loaded, just use getpass...
r44356 import getpass
Matt Harbison
typing: add a missing suppression directive for `msvcrt`
r50214 import msvcrt # pytype: disable=import-error
Gregory Szorc
windows: use absolute_import
r27360 import os
import re
import stat
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 import string
Gregory Szorc
windows: use absolute_import
r27360 import sys
Matt Harbison
typing: attempt to remove @overloads in the platform module for stdlib methods...
r50713 import typing
Matt Harbison
windows: drop some py2 compatibility code...
r50213 import winreg # pytype: disable=import-error
Gregory Szorc
windows: use absolute_import
r27360
Matt Harbison
pytype: stop excluding mercurial/ui.py...
r50688 from typing import (
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 AnyStr,
Matt Harbison
pytype: stop excluding mercurial/ui.py...
r50688 BinaryIO,
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 Iterable,
Iterator,
List,
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 Mapping,
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 NoReturn,
Optional,
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 Pattern,
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 Sequence,
Matt Harbison
typing: attempt to remove @overloads in the platform module for stdlib methods...
r50713 Tuple,
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 Union,
Matt Harbison
pytype: stop excluding mercurial/ui.py...
r50688 )
Gregory Szorc
windows: use absolute_import
r27360 from .i18n import _
Gregory Szorc
py3: manually import getattr where it is needed...
r43359 from .pycompat import getattr
Gregory Szorc
windows: use absolute_import
r27360 from . import (
encoding,
Augie Fackler
ssh: ban any username@host or host that starts with - (SEC)...
r33724 error,
Yuya Nishihara
osutil: switch to policy importer...
r32367 policy,
Pulkit Goyal
py3: replace os.pathsep with pycompat.ospathsep...
r30612 pycompat,
Matt Harbison
pytype: stop excluding mercurial/ui.py...
r50688 typelib,
Matt Harbison
windows: correct the import of win32...
r27436 win32,
Gregory Szorc
windows: use absolute_import
r27360 )
Pulkit Goyal
py3: conditionalize _winreg import...
r29760
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 osutil = policy.importmod('osutil')
Yuya Nishihara
osutil: switch to policy importer...
r32367
Matt Harbison
util: add a function to show the mount point of the filesystem...
r35531 getfsmountpoint = win32.getvolumename
Matt Harbison
win32: implement util.getfstype()...
r35528 getfstype = win32.getfstype
Matt Mackall
windows: fix pyflakes warning on unused imports...
r15016 getuser = win32.getuser
hidewindow = win32.hidewindow
makedir = win32.makedir
nlinks = win32.nlinks
oslink = win32.oslink
samedevice = win32.samedevice
samefile = win32.samefile
setsignalhandler = win32.setsignalhandler
spawndetached = win32.spawndetached
Bryan O'Sullivan
util: implement a faster os.path.split for posix systems...
r17560 split = os.path.split
Matt Mackall
windows: fix pyflakes warning on unused imports...
r15016 testpid = win32.testpid
unlink = win32.unlink
Adrian Buehlmann
windows: eliminate win32 wildcard import
r14985
Matt Harbison
typing: attempt to remove @overloads in the platform module for stdlib methods...
r50713 if typing.TYPE_CHECKING:
# Replace the various overloads that come along with aliasing stdlib methods
# with the narrow definition that we care about in the type checking phase
# only. This ensures that both Windows and POSIX see only the definition
# that is actually available.
#
# Note that if we check pycompat.TYPE_CHECKING here, it is always False, and
# the methods aren't replaced.
def split(p: bytes) -> Tuple[bytes, bytes]:
raise NotImplementedError
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 umask: int = 0o022
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class mixedfilemodewrapper:
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375 """Wraps a file handle when it is opened in read/write mode.
fopen() and fdopen() on Windows have a specific-to-Windows requirement
that files opened with mode r+, w+, or a+ make a call to a file positioning
function when switching between reads and writes. Without this extra call,
Python will raise a not very intuitive "IOError: [Errno 0] Error."
This class wraps posixfile instances when the file is opened in read/write
mode and automatically adds checks or inserts appropriate file positioning
calls when necessary.
"""
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375 OPNONE = 0
OPREAD = 1
OPWRITE = 2
def __init__(self, fp):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 object.__setattr__(self, '_fp', fp)
object.__setattr__(self, '_lastop', 0)
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375
Matt Harbison
windows: add context manager support to mixedfilemodewrapper...
r31891 def __enter__(self):
Matt Harbison
windows: ensure mixedfilemodewrapper fd doesn't escape by entering context mgr...
r40974 self._fp.__enter__()
return self
Matt Harbison
windows: add context manager support to mixedfilemodewrapper...
r31891
def __exit__(self, exc_type, exc_val, exc_tb):
self._fp.__exit__(exc_type, exc_val, exc_tb)
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375 def __getattr__(self, name):
return getattr(self._fp, name)
def __setattr__(self, name, value):
return self._fp.__setattr__(name, value)
def _noopseek(self):
self._fp.seek(0, os.SEEK_CUR)
def seek(self, *args, **kwargs):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 object.__setattr__(self, '_lastop', self.OPNONE)
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375 return self._fp.seek(*args, **kwargs)
def write(self, d):
if self._lastop == self.OPREAD:
self._noopseek()
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 object.__setattr__(self, '_lastop', self.OPWRITE)
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375 return self._fp.write(d)
def writelines(self, *args, **kwargs):
if self._lastop == self.OPREAD:
self._noopeseek()
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 object.__setattr__(self, '_lastop', self.OPWRITE)
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375 return self._fp.writelines(*args, **kwargs)
def read(self, *args, **kwargs):
if self._lastop == self.OPWRITE:
self._noopseek()
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 object.__setattr__(self, '_lastop', self.OPREAD)
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375 return self._fp.read(*args, **kwargs)
def readline(self, *args, **kwargs):
if self._lastop == self.OPWRITE:
self._noopseek()
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 object.__setattr__(self, '_lastop', self.OPREAD)
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375 return self._fp.readline(*args, **kwargs)
def readlines(self, *args, **kwargs):
if self._lastop == self.OPWRITE:
self._noopseek()
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 object.__setattr__(self, '_lastop', self.OPREAD)
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375 return self._fp.readlines(*args, **kwargs)
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class fdproxy:
Matt Harbison
py3: proxy posixfile objects to re-add a useful 'name' attribute on Windows...
r39845 """Wraps osutil.posixfile() to override the name attribute to reflect the
underlying file name.
"""
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
py3: proxy posixfile objects to re-add a useful 'name' attribute on Windows...
r39845 def __init__(self, name, fp):
self.name = name
self._fp = fp
def __enter__(self):
Matt Harbison
py3: ensure the proxied Windows fd doesn't escape by entering context manager...
r40973 self._fp.__enter__()
# Return this wrapper for the context manager so that the name is
# still available.
return self
Matt Harbison
py3: proxy posixfile objects to re-add a useful 'name' attribute on Windows...
r39845
def __exit__(self, exc_type, exc_value, traceback):
self._fp.__exit__(exc_type, exc_value, traceback)
def __iter__(self):
return iter(self._fp)
def __getattr__(self, name):
return getattr(self._fp, name)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 def posixfile(name, mode=b'r', buffering=-1):
Adrian Buehlmann
windows: adjust doc string and comments of posixfile()...
r24069 '''Open a file with even more POSIX-like semantics'''
Sune Foldager
posixfile: remove posixfile_nt and fix import bug in windows.py...
r8421 try:
Augie Fackler
formatting: blacken the codebase...
r43346 fp = osutil.posixfile(name, mode, buffering) # may raise WindowsError
Matt Harbison
windows: seek to the end of posixfile when opening in append mode...
r24051
Matt Harbison
py3: proxy posixfile objects to re-add a useful 'name' attribute on Windows...
r39845 # PyFile_FromFd() ignores the name, and seems to report fp.name as the
# underlying file descriptor.
Gregory Szorc
windows: remove conditional for Python 3...
r49753 fp = fdproxy(name, fp)
Matt Harbison
py3: proxy posixfile objects to re-add a useful 'name' attribute on Windows...
r39845
Matt Harbison
windows: seek to the end of posixfile when opening in append mode...
r24051 # The position when opening in append mode is implementation defined, so
# make it consistent with other platforms, which position at EOF.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'a' in mode:
Adrian Buehlmann
windows: use os.SEEK_END
r25462 fp.seek(0, os.SEEK_END)
Matt Harbison
windows: seek to the end of posixfile when opening in append mode...
r24051
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'+' in mode:
Gregory Szorc
windows: insert file positioning call between reads and writes...
r26375 return mixedfilemodewrapper(fp)
Matt Harbison
windows: seek to the end of posixfile when opening in append mode...
r24051 return fp
Matt Harbison
typing: suppress an name-error warning in `mercurial/windows.py`...
r48822 except WindowsError as err: # pytype: disable=name-error
Adrian Buehlmann
windows: adjust doc string and comments of posixfile()...
r24069 # convert to a friendlier exception
Augie Fackler
formatting: blacken the codebase...
r43346 raise IOError(
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 err.errno, '%s: %s' % (encoding.strfromlocal(name), err.strerror)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Yuya Nishihara
osutil: proxy through util (and platform) modules (API)...
r32203 # may be wrapped by win32mbcs extension
listdir = osutil.listdir
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def get_password() -> bytes:
Matt Harbison
util: avoid echoing the password to the console on Windows py3 (issue6446)...
r47949 """Prompt for password with echo off, using Windows getch().
This shouldn't be called directly- use ``ui.getpass()`` instead, which
checks if the session is interactive first.
"""
Matt Harbison
windows: avoid a bytes vs unicode crash reading passwords on py2...
r48593 pw = u""
Matt Harbison
util: avoid echoing the password to the console on Windows py3 (issue6446)...
r47949 while True:
Matt Harbison
typing: disable warnings for a couple of Windows specific attributes...
r48217 c = msvcrt.getwch() # pytype: disable=module-attr
Matt Harbison
windows: avoid a bytes vs unicode crash reading passwords on py2...
r48593 if c == u'\r' or c == u'\n':
Matt Harbison
util: avoid echoing the password to the console on Windows py3 (issue6446)...
r47949 break
Matt Harbison
windows: avoid a bytes vs unicode crash reading passwords on py2...
r48593 if c == u'\003':
Matt Harbison
util: avoid echoing the password to the console on Windows py3 (issue6446)...
r47949 raise KeyboardInterrupt
Matt Harbison
windows: avoid a bytes vs unicode crash reading passwords on py2...
r48593 if c == u'\b':
Matt Harbison
util: avoid echoing the password to the console on Windows py3 (issue6446)...
r47949 pw = pw[:-1]
else:
pw = pw + c
Matt Harbison
windows: avoid a bytes vs unicode crash reading passwords on py2...
r48593 msvcrt.putwch(u'\r') # pytype: disable=module-attr
msvcrt.putwch(u'\n') # pytype: disable=module-attr
return encoding.unitolocal(pw)
Matt Harbison
util: avoid echoing the password to the console on Windows py3 (issue6446)...
r47949
Matt Harbison
pytype: stop excluding mercurial/ui.py...
r50688 class winstdout(typelib.BinaryIO_Proxy):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Some files on Windows misbehave.
Manuel Jacob
windows: augment docstring of `winstdout` class
r45705
When writing to a broken pipe, EINVAL instead of EPIPE may be raised.
When writing too many bytes to a console at the same, a "Not enough space"
error may happen. Python 3 already works around that.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Matt Harbison
pytype: stop excluding mercurial/ui.py...
r50688 def __init__(self, fp: BinaryIO):
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 self.fp = fp
def __getattr__(self, key):
return getattr(self.fp, key)
def close(self):
try:
self.fp.close()
Idan Kamara
eliminate various naked except clauses
r14004 except IOError:
pass
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
def write(self, s):
try:
Gregory Szorc
windows: remove write throttling support...
r49754 return self.fp.write(s)
Gregory Szorc
global: mass rewrite to use modern exception syntax...
r25660 except IOError as inst:
Sune Foldager
windows: fix incorrect detection of broken pipe when writing to pager...
r38575 if inst.errno != 0 and not win32.lasterrorwaspipeerror(inst):
Matt Mackall
many, many trivial check-code fixups
r10282 raise
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 self.close()
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 raise IOError(errno.EPIPE, 'Broken pipe')
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
def flush(self):
try:
return self.fp.flush()
Gregory Szorc
global: mass rewrite to use modern exception syntax...
r25660 except IOError as inst:
Sune Foldager
windows: fix incorrect detection of broken pipe when writing to pager...
r38575 if not win32.lasterrorwaspipeerror(inst):
Matt Mackall
many, many trivial check-code fixups
r10282 raise
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 raise IOError(errno.EPIPE, 'Broken pipe')
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def openhardlinks() -> bool:
Matt Harbison
windows: drop detection of Windows 95/98/ME...
r44374 return True
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def parsepatchoutput(output_line: bytes) -> bytes:
timeless
Generally replace "file name" with "filename" in help and comments.
r8761 """parses the output produced by patch and returns the filename"""
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 pf = output_line[14:]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if pf[0] == b'`':
Augie Fackler
formatting: blacken the codebase...
r43346 pf = pf[1:-1] # Remove the quotes
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 return pf
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def sshargs(
sshcmd: bytes, host: bytes, user: Optional[bytes], port: Optional[bytes]
) -> bytes:
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 '''Build argument list for ssh or Plink'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 pflag = b'plink' in sshcmd.lower() and b'-P' or b'-p'
args = user and (b"%s@%s" % (user, host)) or host
if args.startswith(b'-') or args.startswith(b'/'):
Augie Fackler
ssh: ban any username@host or host that starts with - (SEC)...
r33724 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'illegal ssh hostname or username starting with - or /: %s')
Augie Fackler
formatting: blacken the codebase...
r43346 % args
)
Jun Wu
ssh: quote parameters using shellquote (SEC)...
r33732 args = shellquote(args)
if port:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 args = b'%s %s %s' % (pflag, shellquote(port), args)
Jun Wu
ssh: quote parameters using shellquote (SEC)...
r33732 return args
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def setflags(f: bytes, l: bool, x: bool) -> None:
Adrian Buehlmann
util: move copymode into posix.py and windows.py...
r15011 pass
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def copymode(
src: bytes,
dst: bytes,
mode: Optional[bytes] = None,
enforcewritable: bool = False,
) -> None:
pass
def checkexec(path: bytes) -> bool:
Adrian Buehlmann
util: move checkexec() to posix.py and return False on Windows
r13879 return False
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def checklink(path: bytes) -> bool:
Adrian Buehlmann
util: move checklink() to posix.py and return False on Windows...
r13890 return False
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def setbinary(fd) -> None:
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 # When run without console, pipes may expose invalid
# fileno(), usually set to -1.
Augie Fackler
windows: use getattr instead of hasattr
r14969 fno = getattr(fd, 'fileno', None)
if fno is not None and fno() >= 0:
Matt Harbison
windows: suppress pytype warnings for Windows imports and functions...
r44207 msvcrt.setmode(fno(), os.O_BINARY) # pytype: disable=module-attr
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def pconvert(path: bytes) -> bytes:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return path.replace(pycompat.ossep, b'/')
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def localpath(path: bytes) -> bytes:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return path.replace(b'/', b'\\')
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 def normpath(path: bytes) -> bytes:
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 return pconvert(os.path.normpath(path))
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def normcase(path: bytes) -> bytes:
Augie Fackler
formatting: blacken the codebase...
r43346 return encoding.upper(path) # NTFS compares via upper()
Matt Mackall
dirstate: fix case-folding identity for traditional Unix...
r15488
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 DRIVE_RE_B: Pattern[bytes] = re.compile(b'^[a-z]:')
DRIVE_RE_S: Pattern[str] = re.compile('^[a-z]:')
windows: introduce a `util.abspath` to replace os.path.abspath...
r48422
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 # TODO: why is this accepting str?
def abspath(path: AnyStr) -> AnyStr:
windows: introduce a `util.abspath` to replace os.path.abspath...
r48422 abs_path = os.path.abspath(path) # re-exports
# Python on Windows is inconsistent regarding the capitalization of drive
# letter and this cause issue with various path comparison along the way.
# So we normalize the drive later to upper case here.
#
# See https://bugs.python.org/issue40368 for and example of this hell.
if isinstance(abs_path, bytes):
if DRIVE_RE_B.match(abs_path):
abs_path = abs_path[0:1].upper() + abs_path[1:]
elif DRIVE_RE_S.match(abs_path):
abs_path = abs_path[0:1].upper() + abs_path[1:]
return abs_path
Siddharth Agarwal
windows: define normcase spec and fallback...
r24598 # see posix.py for definitions
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 normcasespec: int = encoding.normcasespecs.upper
Siddharth Agarwal
windows: define normcase spec and fallback...
r24598 normcasefallback = encoding.upperfallback
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 def samestat(s1: os.stat_result, s2: os.stat_result) -> bool:
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 return False
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 def shelltocmdexe(path: bytes, env: Mapping[bytes, bytes]) -> bytes:
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 r"""Convert shell variables in the form $var and ${var} inside ``path``
to %var% form. Existing Windows style variables are left unchanged.
The variables are limited to the given environment. Unknown variables are
left unchanged.
>>> e = {b'var1': b'v1', b'var2': b'v2', b'var3': b'v3'}
>>> # Only valid values are expanded
>>> shelltocmdexe(b'cmd $var1 ${var2} %var3% $missing ${missing} %missing%',
... e)
'cmd %var1% %var2% %var3% $missing ${missing} %missing%'
>>> # Single quote prevents expansion, as does \$ escaping
>>> shelltocmdexe(b"cmd '$var1 ${var2} %var3%' \$var1 \${var2} \\", e)
Matt Harbison
windows: replace single quote with double quote when translating to cmd.exe...
r38747 'cmd "$var1 ${var2} %var3%" $var1 ${var2} \\'
Matt Harbison
windows: don't consider '$$' to be an escaped '$' when translating to cmd.exe...
r38646 >>> # $$ is not special. %% is not special either, but can be the end and
>>> # start of consecutive variables
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 >>> shelltocmdexe(b"cmd $$ %% %var1%%var2%", e)
Matt Harbison
windows: don't consider '$$' to be an escaped '$' when translating to cmd.exe...
r38646 'cmd $$ %% %var1%%var2%'
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 >>> # No double substitution
>>> shelltocmdexe(b"$var1 %var1%", {b'var1': b'%var2%', b'var2': b'boom'})
'%var1% %var1%'
Matt Harbison
windows: expand '~/' and '~\' to %USERPROFILE% when translating to cmd.exe...
r38748 >>> # Tilde expansion
>>> shelltocmdexe(b"~/dir ~\dir2 ~tmpfile \~/", {})
'%USERPROFILE%/dir %USERPROFILE%\\dir2 ~tmpfile ~/'
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 """
Matt Harbison
windows: expand '~/' and '~\' to %USERPROFILE% when translating to cmd.exe...
r38748 if not any(c in path for c in b"$'~"):
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 return path
varchars = pycompat.sysbytes(string.ascii_letters + string.digits) + b'_-'
res = b''
index = 0
pathlen = len(path)
while index < pathlen:
Augie Fackler
formatting: blacken the codebase...
r43346 c = path[index : index + 1]
if c == b'\'': # no expansion within single quotes
path = path[index + 1 :]
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 pathlen = len(path)
try:
index = path.index(b'\'')
Matt Harbison
windows: replace single quote with double quote when translating to cmd.exe...
r38747 res += b'"' + path[:index] + b'"'
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 except ValueError:
res += c + path
index = pathlen - 1
elif c == b'%': # variable
Augie Fackler
formatting: blacken the codebase...
r43346 path = path[index + 1 :]
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 pathlen = len(path)
try:
index = path.index(b'%')
except ValueError:
res += b'%' + path
index = pathlen - 1
else:
var = path[:index]
res += b'%' + var + b'%'
Matt Harbison
windows: don't consider '$$' to be an escaped '$' when translating to cmd.exe...
r38646 elif c == b'$': # variable
Augie Fackler
formatting: blacken the codebase...
r43346 if path[index + 1 : index + 2] == b'{':
path = path[index + 2 :]
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 pathlen = len(path)
try:
index = path.index(b'}')
var = path[:index]
# See below for why empty variables are handled specially
Matt Harbison
py3: byteify windows.shelltocmdexe()...
r39946 if env.get(var, b'') != b'':
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 res += b'%' + var + b'%'
else:
res += b'${' + var + b'}'
except ValueError:
res += b'${' + path
index = pathlen - 1
else:
var = b''
index += 1
Augie Fackler
formatting: blacken the codebase...
r43346 c = path[index : index + 1]
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 while c != b'' and c in varchars:
var += c
index += 1
Augie Fackler
formatting: blacken the codebase...
r43346 c = path[index : index + 1]
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 # Some variables (like HG_OLDNODE) may be defined, but have an
# empty value. Those need to be skipped because when spawning
# cmd.exe to run the hook, it doesn't replace %VAR% for an empty
# VAR, and that really confuses things like revset expressions.
# OTOH, if it's left in Unix format and the hook runs sh.exe, it
# will substitute to an empty string, and everything is happy.
Matt Harbison
py3: byteify windows.shelltocmdexe()...
r39946 if env.get(var, b'') != b'':
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 res += b'%' + var + b'%'
else:
res += b'$' + var
Matt Harbison
py3: byteify windows.shelltocmdexe()...
r39946 if c != b'':
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 index -= 1
Augie Fackler
formatting: blacken the codebase...
r43346 elif (
c == b'~'
and index + 1 < pathlen
and path[index + 1 : index + 2] in (b'\\', b'/')
):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 res += b"%USERPROFILE%"
Augie Fackler
formatting: blacken the codebase...
r43346 elif (
c == b'\\'
and index + 1 < pathlen
and path[index + 1 : index + 2] in (b'$', b'~')
):
Matt Harbison
windows: expand '~/' and '~\' to %USERPROFILE% when translating to cmd.exe...
r38748 # Skip '\', but only if it is escaping $ or ~
Augie Fackler
formatting: blacken the codebase...
r43346 res += path[index + 1 : index + 2]
Matt Harbison
windows: add a method to convert Unix style command lines to Windows style...
r38502 index += 1
else:
res += c
index += 1
return res
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 # A sequence of backslashes is special iff it precedes a double quote:
# - if there's an even number of backslashes, the double quote is not
# quoted (i.e. it ends the quoted region)
# - if there's an odd number of backslashes, the double quote is quoted
# - in both cases, every pair of backslashes is unquoted into a single
# backslash
# (See http://msdn2.microsoft.com/en-us/library/a1y7w461.aspx )
# So, to quote a string, we must surround it in double quotes, double
timeless@mozdev.org
spelling: precede
r17505 # the number of backslashes that precede double quotes and add another
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 # backslash before every double quote (being careful with the double
# quote we've appended to the end)
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 _quotere: Optional[Pattern[bytes]] = None
FUJIWARA Katsunori
windows: quote the specified string only when it has to be quoted...
r23682 _needsshellquote = None
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def shellquote(s: bytes) -> bytes:
Matt Harbison
windows: add doctest for shellquote()...
r24908 r"""
Yuya Nishihara
doctest: bulk-replace string literals with b'' for Python 3...
r34133 >>> shellquote(br'C:\Users\xyz')
Matt Harbison
windows: add doctest for shellquote()...
r24908 '"C:\\Users\\xyz"'
Yuya Nishihara
doctest: bulk-replace string literals with b'' for Python 3...
r34133 >>> shellquote(br'C:\Users\xyz/mixed')
Matt Harbison
windows: add doctest for shellquote()...
r24908 '"C:\\Users\\xyz/mixed"'
>>> # Would be safe not to quote too, since it is all double backslashes
Yuya Nishihara
doctest: bulk-replace string literals with b'' for Python 3...
r34133 >>> shellquote(br'C:\\Users\\xyz')
Matt Harbison
windows: add doctest for shellquote()...
r24908 '"C:\\\\Users\\\\xyz"'
>>> # But this must be quoted
Yuya Nishihara
doctest: bulk-replace string literals with b'' for Python 3...
r34133 >>> shellquote(br'C:\\Users\\xyz/abc')
Matt Harbison
windows: add doctest for shellquote()...
r24908 '"C:\\\\Users\\\\xyz/abc"'
"""
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 global _quotere
if _quotere is None:
Matt Harbison
py3: fix str vs bytes in enough places to run `hg version` on Windows...
r39680 _quotere = re.compile(br'(\\*)("|\\$)')
FUJIWARA Katsunori
windows: quote the specified string only when it has to be quoted...
r23682 global _needsshellquote
if _needsshellquote is None:
Matt Harbison
windows: make shellquote() quote any path containing '\' (issue4629)...
r24885 # ":" is also treated as "safe character", because it is used as a part
# of path name on Windows. "\" is also part of a path name, but isn't
# safe because shlex.split() (kind of) treats it as an escape char and
# drops it. It will leave the next character, even if it is another
# "\".
Matt Harbison
py3: fix str vs bytes in enough places to run `hg version` on Windows...
r39680 _needsshellquote = re.compile(br'[^a-zA-Z0-9._:/-]').search
Yuya Nishihara
shellquote: fix missing quotes for empty string...
r24108 if s and not _needsshellquote(s) and not _quotere.search(s):
FUJIWARA Katsunori
windows: quote the specified string only when it has to be quoted...
r23682 # "s" shouldn't have to be quoted
return s
Matt Harbison
py3: fix str vs bytes in enough places to run `hg version` on Windows...
r39680 return b'"%s"' % _quotere.sub(br'\1\1\\\2', s)
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 def _unquote(s: bytes) -> bytes:
Yuya Nishihara
util: factor out shellsplit() function...
r36433 if s.startswith(b'"') and s.endswith(b'"'):
return s[1:-1]
return s
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def shellsplit(s: bytes) -> List[bytes]:
Yuya Nishihara
util: factor out shellsplit() function...
r36433 """Parse a command string in cmd.exe way (best-effort)"""
return pycompat.maplist(_unquote, pycompat.shlexsplit(s, posix=False))
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 # if you change this stub into a real check, please try to implement the
# username and groupname functions above, too.
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def isowner(st: os.stat_result) -> bool:
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 return True
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def findexe(command: bytes) -> Optional[bytes]:
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Find executable for command searching like cmd.exe does.
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 If command is a basename then PATH is searched for command.
PATH isn't searched if command is an absolute or relative path.
An extension from PATHEXT is found and added if not present.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 If command isn't found None is returned."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 pathext = encoding.environ.get(b'PATHEXT', b'.COM;.EXE;.BAT;.CMD')
Pulkit Goyal
py3: replace os.pathsep with pycompat.ospathsep...
r30612 pathexts = [ext for ext in pathext.lower().split(pycompat.ospathsep)]
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 if os.path.splitext(command)[1].lower() in pathexts:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 pathexts = [b'']
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def findexisting(pathcommand: bytes) -> Optional[bytes]:
Matt Harbison
cleanup: fix docstring formatting...
r44226 """Will append extension (if needed) and return existing file"""
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 for ext in pathexts:
executable = pathcommand + ext
if os.path.exists(executable):
return executable
return None
Pulkit Goyal
py3: replace os.sep with pycompat.ossep (part 3 of 4)
r30615 if pycompat.ossep in command:
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 return findexisting(command)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for path in encoding.environ.get(b'PATH', b'').split(pycompat.ospathsep):
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 executable = findexisting(os.path.join(path, command))
if executable is not None:
return executable
Steve Borho
windows: expand environment vars in find_exe...
r10156 return findexisting(os.path.expanduser(os.path.expandvars(command)))
Matt Mackall
util: split out posix, windows, and win32 modules
r7890
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
cleanup: use set literals...
r32291 _wantedkinds = {stat.S_IFREG, stat.S_IFLNK}
Bryan O'Sullivan
dirstate: move file type filtering to its source...
r18017
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def statfiles(files: Sequence[bytes]) -> Iterator[Optional[os.stat_result]]:
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Stat each file in files. Yield each stat, or None if a file
Bryan O'Sullivan
dirstate: move file type filtering to its source...
r18017 does not exist or has a type we don't care about.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 Cluster and cache stat per directory to minimize number of OS stat calls."""
Augie Fackler
formatting: blacken the codebase...
r43346 dircache = {} # dirname -> filename -> status | None if file does not exist
Bryan O'Sullivan
dirstate: move file type filtering to its source...
r18017 getkind = stat.S_IFMT
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 for nf in files:
Augie Fackler
formatting: blacken the codebase...
r43346 nf = normcase(nf)
Shun-ichi GOTO
Use os.path.split() for MBCS with win32mbcs extension.
r9099 dir, base = os.path.split(nf)
if not dir:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 dir = b'.'
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 cache = dircache.get(dir, None)
if cache is None:
try:
Augie Fackler
cleanup: run pyupgrade on our source tree to clean up varying things...
r44937 dmap = {
normcase(n): s
for n, k, s in listdir(dir, True)
if getkind(s.st_mode) in _wantedkinds
}
Manuel Jacob
py3: catch specific OSError subclasses instead of checking errno...
r50206 except (FileNotFoundError, NotADirectoryError):
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 dmap = {}
cache = dircache.setdefault(dir, dmap)
yield cache.get(base, None)
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def username(uid: Optional[int] = None) -> Optional[bytes]:
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 """Return the name of the user with the given uid.
If uid is None, return the name of the current user."""
Augie Fackler
windows: if username(uid=None) is loaded, just use getpass...
r44356 if not uid:
Matt Harbison
windows: gracefully handle when the username cannot be determined...
r50414 try:
return pycompat.fsencode(getpass.getuser())
except ModuleNotFoundError:
# getpass.getuser() checks for a few environment variables first,
# but if those aren't set, imports pwd and calls getpwuid(), none of
# which exists on Windows.
pass
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 return None
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def groupname(gid: Optional[int] = None) -> Optional[bytes]:
Matt Mackall
util: split out posix, windows, and win32 modules
r7890 """Return the name of the group with the given gid.
If gid is None, return the name of the current group."""
return None
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 def readlink(pathname: bytes) -> bytes:
Matt Harbison
windows: degrade to py2 behavior when reading a non-symlink as a symlink...
r48680 path = pycompat.fsdecode(pathname)
try:
link = os.readlink(path)
except ValueError as e:
# On py2, os.readlink() raises an AttributeError since it is
# unsupported. On py3, reading a non-link raises a ValueError. Simply
# treat this as the error the locking code has been expecting up to now
# until an effort can be made to enable symlink support on Windows.
raise AttributeError(e)
return pycompat.fsencode(link)
Matt Harbison
py3: convert os.readlink() path to native strings on Windows...
r39940
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 def removedirs(name: bytes) -> None:
Henrik Stuart
windows: avoid deleting non-empty reparse points...
r8364 """special version of os.removedirs that does not remove symlinked
directories or junction points if they actually contain files"""
Yuya Nishihara
osutil: proxy through util (and platform) modules (API)...
r32203 if listdir(name):
Henrik Stuart
windows: avoid deleting non-empty reparse points...
r8364 return
os.rmdir(name)
head, tail = os.path.split(name)
if not tail:
head, tail = os.path.split(head)
while head and tail:
try:
Yuya Nishihara
osutil: proxy through util (and platform) modules (API)...
r32203 if listdir(head):
Henrik Stuart
windows: avoid deleting non-empty reparse points...
r8364 return
os.rmdir(head)
Idan Kamara
eliminate various naked except clauses
r14004 except (ValueError, OSError):
Henrik Stuart
windows: avoid deleting non-empty reparse points...
r8364 break
head, tail = os.path.split(head)
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 def rename(src: bytes, dst: bytes) -> None:
Adrian Buehlmann
util: move rename into posix.py and windows.py
r9549 '''atomically rename file src to dst, replacing dst if it exists'''
try:
os.rename(src, dst)
Manuel Jacob
py3: catch FileExistsError instead of checking errno == EEXIST
r50200 except FileExistsError:
Adrian Buehlmann
reintroduces util.unlink, for POSIX and Windows....
r13280 unlink(dst)
Adrian Buehlmann
util: move rename into posix.py and windows.py
r9549 os.rename(src, dst)
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 def gethgcmd() -> List[bytes]:
Matt Harbison
py3: resolve Unicode issues around `hg serve` on Windows...
r39755 return [encoding.strtolocal(arg) for arg in [sys.executable] + sys.argv[:1]]
Patrick Mezard
Find right hg command for detached process...
r10239
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def groupmembers(name: bytes) -> List[bytes]:
Patrick Mezard
acl: grp module is not available on windows
r11138 # Don't support groups on Windows for now
Brodie Rao
cleanup: "raise SomeException()" -> "raise SomeException"
r16687 raise KeyError
Patrick Mezard
acl: grp module is not available on windows
r11138
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def isexec(f: bytes) -> bool:
Adrian Buehlmann
util: eliminate wildcard imports
r14926 return False
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class cachestat:
Matt Harbison
typing: add type hints to the platform `cachestat` classes
r50710 def __init__(self, path: bytes) -> None:
Idan Kamara
posix, windows: introduce cachestat...
r14927 pass
Matt Harbison
typing: add type hints to the platform `cachestat` classes
r50710 def cacheable(self) -> bool:
Idan Kamara
posix, windows: introduce cachestat...
r14927 return False
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def lookupreg(
key: bytes,
valname: Optional[bytes] = None,
scope: Optional[Union[int, Iterable[int]]] = None,
) -> Optional[bytes]:
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Look up a key/value name in the Windows registry.
Adrian Buehlmann
win32: move lookupreg() to windows.py...
r16807
valname: value name. If unspecified, the default value for the key
is used.
scope: optionally specify scope for registry lookup, this can be
a sequence of scopes to look up in order. Default (CURRENT_USER,
LOCAL_MACHINE).
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
Adrian Buehlmann
win32: move lookupreg() to windows.py...
r16807 if scope is None:
Matt Harbison
pytype: disable a few errors about Windows specific module attributes...
r49843 # pytype: disable=module-attr
Pulkit Goyal
py3: conditionalize _winreg import...
r29760 scope = (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE)
Matt Harbison
pytype: disable a few errors about Windows specific module attributes...
r49843 # pytype: enable=module-attr
Adrian Buehlmann
win32: move lookupreg() to windows.py...
r16807 elif not isinstance(scope, (list, tuple)):
scope = (scope,)
for s in scope:
try:
Matt Harbison
pytype: disable a few errors about Windows specific module attributes...
r49843 # pytype: disable=module-attr
Matt Harbison
windows: open registry keys using unicode names...
r39679 with winreg.OpenKey(s, encoding.strfromlocal(key)) as hkey:
Matt Harbison
pytype: disable a few errors about Windows specific module attributes...
r49843 # pytype: enable=module-attr
Matt Harbison
windows: prevent bytes from being passed to registry APIs...
r50212 name = None
if valname is not None:
name = encoding.strfromlocal(valname)
Matt Harbison
pytype: disable a few errors about Windows specific module attributes...
r49843 # pytype: disable=module-attr
Matt Harbison
py3: use str to query registry values on Windows...
r40302 val = winreg.QueryValueEx(hkey, name)[0]
Matt Harbison
pytype: disable a few errors about Windows specific module attributes...
r49843 # pytype: enable=module-attr
Matt Harbison
windows: open registry keys using unicode names...
r39679 # never let a Unicode string escape into the wild
return encoding.unitolocal(val)
Adrian Buehlmann
win32: move lookupreg() to windows.py...
r16807 except EnvironmentError:
pass
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 expandglobs: bool = True
Bryan O'Sullivan
util: add functions to check symlink/exec bits...
r18868
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def statislink(st: Optional[os.stat_result]) -> bool:
Bryan O'Sullivan
util: add functions to check symlink/exec bits...
r18868 '''check whether a stat result is a symlink'''
return False
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def statisexec(st: Optional[os.stat_result]) -> bool:
Bryan O'Sullivan
util: add functions to check symlink/exec bits...
r18868 '''check whether a stat result is an executable file'''
return False
Gregory Szorc
platform: implement readpipe()...
r22245
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add trivial type hints to rest of the windows platform module...
r50712 def poll(fds) -> List:
Pierre-Yves David
util: add a simple poll utility...
r25420 # see posix.py for description
raise NotImplementedError()
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def readpipe(pipe) -> bytes:
Gregory Szorc
platform: implement readpipe()...
r22245 """Read all available data from a pipe."""
chunks = []
while True:
Matt Harbison
windows: allow readpipe() to actually read data out of the pipe...
r24653 size = win32.peekpipe(pipe)
Gregory Szorc
platform: implement readpipe()...
r22245 if not size:
break
s = pipe.read(size)
if not s:
break
chunks.append(s)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''.join(chunks)
Yuya Nishihara
chgserver: extract utility to bind unix domain socket to long path...
r29530
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Harbison
typing: add type hints to the common posix/windows platform functions...
r50707 def bindunixsocket(sock, path: bytes) -> NoReturn:
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 raise NotImplementedError('unsupported platform')