2 # Ron Murawski <ron@horizonchess.com>
\r
4 from builtins import OSError as error
\r
5 from io import TextIOWrapper as _TextIOWrapper
\r
6 from posix import stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078
\r
9 Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr,
\r
10 Optional, Generic, Set, Callable, Text, Sequence, IO, NamedTuple, NoReturn, TypeVar
\r
12 from . import path as path
\r
16 # ----- os variables -----
\r
18 if sys.version_info >= (3, 2):
\r
19 supports_bytes_environ: bool
\r
21 if sys.version_info >= (3, 3):
\r
22 supports_dir_fd: Set[Callable[..., Any]]
\r
23 supports_fd: Set[Callable[..., Any]]
\r
24 supports_effective_ids: Set[Callable[..., Any]]
\r
25 supports_follow_symlinks: Set[Callable[..., Any]]
\r
38 O_DSYNC: int # Unix only
\r
39 O_RSYNC: int # Unix only
\r
40 O_SYNC: int # Unix only
\r
41 O_NDELAY: int # Unix only
\r
42 O_NONBLOCK: int # Unix only
\r
43 O_NOCTTY: int # Unix only
\r
44 O_SHLOCK: int # Unix only
\r
45 O_EXLOCK: int # Unix only
\r
46 O_BINARY: int # Windows only
\r
47 O_NOINHERIT: int # Windows only
\r
48 O_SHORT_LIVED: int # Windows only
\r
49 O_TEMPORARY: int # Windows only
\r
50 O_RANDOM: int # Windows only
\r
51 O_SEQUENTIAL: int # Windows only
\r
52 O_TEXT: int # Windows only
\r
53 O_ASYNC: int # Gnu extension if in C library
\r
54 O_DIRECT: int # Gnu extension if in C library
\r
55 O_DIRECTORY: int # Gnu extension if in C library
\r
56 O_NOFOLLOW: int # Gnu extension if in C library
\r
57 O_NOATIME: int # Gnu extension if in C library
\r
58 O_LARGEFILE: int # Gnu extension if in C library
\r
76 class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
\r
77 def copy(self) -> Dict[AnyStr, AnyStr]: ...
\r
78 def __delitem__(self, key: AnyStr) -> None: ...
\r
79 def __getitem__(self, key: AnyStr) -> AnyStr: ...
\r
80 def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ...
\r
81 def __iter__(self) -> Iterator[AnyStr]: ...
\r
82 def __len__(self) -> int: ...
\r
84 environ: _Environ[str]
\r
85 if sys.version_info >= (3, 2):
\r
86 environb: _Environ[bytes]
\r
88 confstr_names: Dict[str, int] # Unix only
\r
89 pathconf_names: Dict[str, int] # Unix only
\r
90 sysconf_names: Dict[str, int] # Unix only
\r
92 EX_OK: int # Unix only
\r
93 EX_USAGE: int # Unix only
\r
94 EX_DATAERR: int # Unix only
\r
95 EX_NOINPUT: int # Unix only
\r
96 EX_NOUSER: int # Unix only
\r
97 EX_NOHOST: int # Unix only
\r
98 EX_UNAVAILABLE: int # Unix only
\r
99 EX_SOFTWARE: int # Unix only
\r
100 EX_OSERR: int # Unix only
\r
101 EX_OSFILE: int # Unix only
\r
102 EX_CANTCREAT: int # Unix only
\r
103 EX_IOERR: int # Unix only
\r
104 EX_TEMPFAIL: int # Unix only
\r
105 EX_PROTOCOL: int # Unix only
\r
106 EX_NOPERM: int # Unix only
\r
107 EX_CONFIG: int # Unix only
\r
108 EX_NOTFOUND: int # Unix only
\r
113 if sys.platform == 'win32':
\r
114 P_DETACH: int # Windows only
\r
115 P_OVERLAY: int # Windows only
\r
117 # wait()/waitpid() options
\r
118 WNOHANG: int # Unix only
\r
119 WCONTINUED: int # some Unix systems
\r
120 WUNTRACED: int # Unix only
\r
122 TMP_MAX: int # Undocumented, but used by tempfile
\r
124 # ----- os classes (structures) -----
\r
125 if sys.version_info >= (3, 6):
\r
126 from builtins import _PathLike as PathLike # See comment in builtins
\r
128 _PathType = path._PathType
\r
130 _StatVFS = NamedTuple('_StatVFS', [('f_bsize', int), ('f_frsize', int), ('f_blocks', int),
\r
131 ('f_bfree', int), ('f_bavail', int), ('f_files', int),
\r
132 ('f_ffree', int), ('f_favail', int), ('f_flag', int),
\r
133 ('f_namemax', int)])
\r
135 def ctermid() -> str: ... # Unix only
\r
136 def getegid() -> int: ... # Unix only
\r
137 def geteuid() -> int: ... # Unix only
\r
138 def getgid() -> int: ... # Unix only
\r
139 def getgroups() -> List[int]: ... # Unix only, behaves differently on Mac
\r
140 def initgroups(username: str, gid: int) -> None: ... # Unix only
\r
141 def getlogin() -> str: ...
\r
142 def getpgid(pid: int) -> int: ... # Unix only
\r
143 def getpgrp() -> int: ... # Unix only
\r
144 def getpid() -> int: ...
\r
145 def getppid() -> int: ...
\r
146 def getresuid() -> Tuple[int, int, int]: ... # Unix only
\r
147 def getresgid() -> Tuple[int, int, int]: ... # Unix only
\r
148 def getuid() -> int: ... # Unix only
\r
149 def setegid(egid: int) -> None: ... # Unix only
\r
150 def seteuid(euid: int) -> None: ... # Unix only
\r
151 def setgid(gid: int) -> None: ... # Unix only
\r
152 def setgroups(groups: Sequence[int]) -> None: ... # Unix only
\r
153 def setpgrp() -> None: ... # Unix only
\r
154 def setpgid(pid: int, pgrp: int) -> None: ... # Unix only
\r
155 def setregid(rgid: int, egid: int) -> None: ... # Unix only
\r
156 def setresgid(rgid: int, egid: int, sgid: int) -> None: ... # Unix only
\r
157 def setresuid(ruid: int, euid: int, suid: int) -> None: ... # Unix only
\r
158 def setreuid(ruid: int, euid: int) -> None: ... # Unix only
\r
159 def getsid(pid: int) -> int: ... # Unix only
\r
160 def setsid() -> None: ... # Unix only
\r
161 def setuid(uid: int) -> None: ... # Unix only
\r
162 def strerror(code: int) -> str: ...
\r
163 def umask(mask: int) -> int: ...
\r
164 def uname() -> Tuple[str, str, str, str, str]: ... # Unix only
\r
167 def getenv(key: Text) -> Optional[str]: ...
\r
169 def getenv(key: Text, default: _T) -> Union[str, _T]: ...
\r
170 def putenv(key: Union[bytes, Text], value: Union[bytes, Text]) -> None: ...
\r
171 def unsetenv(key: Union[bytes, Text]) -> None: ...
\r
173 def fdopen(fd: int, *args, **kwargs) -> IO[Any]: ...
\r
174 def close(fd: int) -> None: ...
\r
175 def closerange(fd_low: int, fd_high: int) -> None: ...
\r
176 def dup(fd: int) -> int: ...
\r
177 def dup2(fd: int, fd2: int) -> None: ...
\r
178 def fchmod(fd: int, mode: int) -> None: ... # Unix only
\r
179 def fchown(fd: int, uid: int, gid: int) -> None: ... # Unix only
\r
180 def fdatasync(fd: int) -> None: ... # Unix only, not Mac
\r
181 def fpathconf(fd: int, name: Union[str, int]) -> int: ... # Unix only
\r
182 def fstat(fd: int) -> Any: ...
\r
183 def fstatvfs(fd: int) -> _StatVFS: ... # Unix only
\r
184 def fsync(fd: int) -> None: ...
\r
185 def ftruncate(fd: int, length: int) -> None: ... # Unix only
\r
186 def isatty(fd: int) -> bool: ... # Unix only
\r
187 def lseek(fd: int, pos: int, how: int) -> int: ...
\r
188 def open(file: _PathType, flags: int, mode: int = ...) -> int: ...
\r
189 def openpty() -> Tuple[int, int]: ... # some flavors of Unix
\r
190 def pipe() -> Tuple[int, int]: ...
\r
191 def read(fd: int, n: int) -> bytes: ...
\r
192 def tcgetpgrp(fd: int) -> int: ... # Unix only
\r
193 def tcsetpgrp(fd: int, pg: int) -> None: ... # Unix only
\r
194 def ttyname(fd: int) -> str: ... # Unix only
\r
195 def write(fd: int, string: bytes) -> int: ...
\r
196 def access(path: _PathType, mode: int) -> bool: ...
\r
197 def chdir(path: _PathType) -> None: ...
\r
198 def fchdir(fd: int) -> None: ...
\r
199 def getcwd() -> str: ...
\r
200 def getcwdu() -> unicode: ...
\r
201 def chflags(path: _PathType, flags: int) -> None: ... # Unix only
\r
202 def chroot(path: _PathType) -> None: ... # Unix only
\r
203 def chmod(path: _PathType, mode: int) -> None: ...
\r
204 def chown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only
\r
205 def lchflags(path: _PathType, flags: int) -> None: ... # Unix only
\r
206 def lchmod(path: _PathType, mode: int) -> None: ... # Unix only
\r
207 def lchown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only
\r
208 def link(src: _PathType, link_name: _PathType) -> None: ...
\r
209 def listdir(path: AnyStr) -> List[AnyStr]: ...
\r
210 def lstat(path: _PathType) -> Any: ...
\r
211 def mkfifo(path: _PathType, mode: int = ...) -> None: ... # Unix only
\r
212 def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ...
\r
213 def major(device: int) -> int: ...
\r
214 def minor(device: int) -> int: ...
\r
215 def makedev(major: int, minor: int) -> int: ...
\r
216 def mkdir(path: _PathType, mode: int = ...) -> None: ...
\r
217 def makedirs(path: _PathType, mode: int = ...) -> None: ...
\r
218 def pathconf(path: _PathType, name: Union[str, int]) -> int: ... # Unix only
\r
219 def readlink(path: AnyStr) -> AnyStr: ...
\r
220 def remove(path: _PathType) -> None: ...
\r
221 def removedirs(path: _PathType) -> None: ...
\r
222 def rename(src: _PathType, dst: _PathType) -> None: ...
\r
223 def renames(old: _PathType, new: _PathType) -> None: ...
\r
224 def rmdir(path: _PathType) -> None: ...
\r
225 def stat(path: _PathType) -> Any: ...
\r
227 def stat_float_times() -> bool: ...
\r
229 def stat_float_times(newvalue: bool) -> None: ...
\r
230 def statvfs(path: _PathType) -> _StatVFS: ... # Unix only
\r
231 def symlink(source: _PathType, link_name: _PathType) -> None: ...
\r
232 def unlink(path: _PathType) -> None: ...
\r
233 # TODO: add ns, dir_fd, follow_symlinks argument
\r
234 if sys.version_info >= (3, 0):
\r
235 def utime(path: _PathType, times: Optional[Tuple[float, float]] = ...) -> None: ...
\r
237 def utime(path: _PathType, times: Optional[Tuple[float, float]]) -> None: ...
\r
239 if sys.version_info >= (3, 6):
\r
240 def walk(top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ...,
\r
241 onerror: Optional[Callable[[OSError], Any]] = ...,
\r
242 followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
\r
243 List[AnyStr]]]: ...
\r
245 def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[Callable[[OSError], Any]] = ...,
\r
246 followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
\r
247 List[AnyStr]]]: ...
\r
249 def abort() -> NoReturn: ...
\r
250 # These are defined as execl(file, *args) but the first *arg is mandatory.
\r
251 def execl(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
\r
252 def execlp(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
\r
254 # These are: execle(file, *args, env) but env is pulled from the last element of the args.
\r
255 def execle(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ...
\r
256 def execlpe(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ...
\r
258 # The docs say `args: tuple or list of strings`
\r
259 # The implementation enforces tuple or list so we can't use Sequence.
\r
260 _ExecVArgs = Union[Tuple[Union[bytes, Text], ...], List[bytes], List[Text], List[Union[bytes, Text]]]
\r
261 def execv(path: _PathType, args: _ExecVArgs) -> NoReturn: ...
\r
262 def execve(path: _PathType, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ...
\r
263 def execvp(file: _PathType, args: _ExecVArgs) -> NoReturn: ...
\r
264 def execvpe(file: _PathType, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ...
\r
266 def _exit(n: int) -> NoReturn: ...
\r
267 def fork() -> int: ... # Unix only
\r
268 def forkpty() -> Tuple[int, int]: ... # some flavors of Unix
\r
269 def kill(pid: int, sig: int) -> None: ...
\r
270 def killpg(pgid: int, sig: int) -> None: ... # Unix only
\r
271 def nice(increment: int) -> int: ... # Unix only
\r
272 def plock(op: int) -> None: ... # Unix only ???op is int?
\r
274 if sys.version_info >= (3, 0):
\r
275 class popen(_TextIOWrapper):
\r
276 # TODO 'b' modes or bytes command not accepted?
\r
277 def __init__(self, command: str, mode: str = ...,
\r
278 bufsize: int = ...) -> None: ...
\r
279 def close(self) -> Any: ... # may return int
\r
281 def popen(command: str, *args, **kwargs) -> IO[Any]: ...
\r
282 def popen2(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ...
\r
283 def popen3(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any], IO[Any]]: ...
\r
284 def popen4(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ...
\r
286 def spawnl(mode: int, path: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ...
\r
287 def spawnle(mode: int, path: _PathType, arg0: Union[bytes, Text],
\r
288 *args: Any) -> int: ... # Imprecise sig
\r
289 def spawnlp(mode: int, file: _PathType, arg0: Union[bytes, Text],
\r
290 *args: Union[bytes, Text]) -> int: ... # Unix only TODO
\r
291 def spawnlpe(mode: int, file: _PathType, arg0: Union[bytes, Text], *args: Any) -> int:
\r
292 ... # Imprecise signature; Unix only TODO
\r
293 def spawnv(mode: int, path: _PathType, args: List[Union[bytes, Text]]) -> int: ...
\r
294 def spawnve(mode: int, path: _PathType, args: List[Union[bytes, Text]],
\r
295 env: Mapping[str, str]) -> int: ...
\r
296 def spawnvp(mode: int, file: _PathType, args: List[Union[bytes, Text]]) -> int: ... # Unix only
\r
297 def spawnvpe(mode: int, file: _PathType, args: List[Union[bytes, Text]],
\r
298 env: Mapping[str, str]) -> int:
\r
300 def startfile(path: _PathType, operation: Optional[str] = ...) -> None: ... # Windows only
\r
301 def system(command: _PathType) -> int: ...
\r
302 def times() -> Tuple[float, float, float, float, float]: ...
\r
303 def wait() -> Tuple[int, int]: ... # Unix only
\r
304 def waitpid(pid: int, options: int) -> Tuple[int, int]: ...
\r
305 def wait3(options: int) -> Tuple[int, int, Any]: ... # Unix only
\r
306 def wait4(pid: int, options: int) -> Tuple[int, int, Any]: ... # Unix only
\r
307 def WCOREDUMP(status: int) -> bool: ... # Unix only
\r
308 def WIFCONTINUED(status: int) -> bool: ... # Unix only
\r
309 def WIFSTOPPED(status: int) -> bool: ... # Unix only
\r
310 def WIFSIGNALED(status: int) -> bool: ... # Unix only
\r
311 def WIFEXITED(status: int) -> bool: ... # Unix only
\r
312 def WEXITSTATUS(status: int) -> int: ... # Unix only
\r
313 def WSTOPSIG(status: int) -> int: ... # Unix only
\r
314 def WTERMSIG(status: int) -> int: ... # Unix only
\r
315 def confstr(name: Union[str, int]) -> Optional[str]: ... # Unix only
\r
316 def getloadavg() -> Tuple[float, float, float]: ... # Unix only
\r
317 def sysconf(name: Union[str, int]) -> int: ... # Unix only
\r
318 def urandom(n: int) -> bytes: ...
\r
320 if sys.version_info >= (3, 0):
\r
321 def sched_getaffinity(id: int) -> Set[int]: ...
\r
322 if sys.version_info >= (3, 3):
\r
325 def waitid(idtype: int, id: int, options: int) -> waitresult: ...
\r
327 if sys.version_info < (3, 0):
\r
328 def tmpfile() -> IO[Any]: ...
\r
329 def tmpnam() -> str: ...
\r
330 def tempnam(dir: str = ..., prefix: str = ...) -> str: ...
\r
336 if sys.version_info >= (3, 3):
\r
337 def sync() -> None: ... # Unix only
\r
339 def truncate(path: Union[_PathType, int], length: int) -> None: ... # Unix only up to version 3.4
\r
341 def fwalk(top: AnyStr = ..., topdown: bool = ...,
\r
342 onerror: Callable = ..., *, follow_symlinks: bool = ...,
\r
343 dir_fd: int = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
\r
344 List[AnyStr], int]]: ... # Unix only
\r
346 terminal_size = NamedTuple('terminal_size', [('columns', int), ('lines', int)])
\r
347 def get_terminal_size(fd: int = ...) -> terminal_size: ...
\r
349 if sys.version_info >= (3, 4):
\r
350 def cpu_count() -> Optional[int]: ...
\r