opt
/
hc_python
/
lib
/
python3.12
/
site-packages
/
pre_commit
/
Go to Home Directory
+
Upload
Create File
root@0UT1S:~$
Execute
By Order of Mr.0UT1S
[DIR] ..
N/A
[DIR] __pycache__
N/A
[DIR] commands
N/A
[DIR] languages
N/A
[DIR] meta_hooks
N/A
[DIR] resources
N/A
__init__.py
0 bytes
Rename
Delete
__main__.py
127 bytes
Rename
Delete
all_languages.py
1.38 KB
Rename
Delete
clientlib.py
14.92 KB
Rename
Delete
color.py
3.14 KB
Rename
Delete
constants.py
282 bytes
Rename
Delete
envcontext.py
1.56 KB
Rename
Delete
error_handler.py
2.56 KB
Rename
Delete
errors.py
78 bytes
Rename
Delete
file_lock.py
2.29 KB
Rename
Delete
git.py
8.32 KB
Rename
Delete
hook.py
1.48 KB
Rename
Delete
lang_base.py
5.12 KB
Rename
Delete
logging_handler.py
1019 bytes
Rename
Delete
main.py
15.20 KB
Rename
Delete
output.py
911 bytes
Rename
Delete
parse_shebang.py
2.42 KB
Rename
Delete
prefix.py
495 bytes
Rename
Delete
repository.py
7.43 KB
Rename
Delete
staged_files_only.py
4.06 KB
Rename
Delete
store.py
9.17 KB
Rename
Delete
util.py
6.87 KB
Rename
Delete
xargs.py
5.41 KB
Rename
Delete
yaml.py
561 bytes
Rename
Delete
yaml_rewrite.py
1.31 KB
Rename
Delete
from __future__ import annotations import contextlib import errno import sys from collections.abc import Generator from typing import Callable if sys.platform == 'win32': # pragma: no cover (windows) import msvcrt # https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/locking # on windows we lock "regions" of files, we don't care about the actual # byte region so we'll just pick *some* number here. _region = 0xffff @contextlib.contextmanager def _locked( fileno: int, blocked_cb: Callable[[], None], ) -> Generator[None]: try: msvcrt.locking(fileno, msvcrt.LK_NBLCK, _region) except OSError: blocked_cb() while True: try: msvcrt.locking(fileno, msvcrt.LK_LOCK, _region) except OSError as e: # Locking violation. Returned when the _LK_LOCK or _LK_RLCK # flag is specified and the file cannot be locked after 10 # attempts. if e.errno != errno.EDEADLOCK: raise else: break try: yield finally: # From cursory testing, it seems to get unlocked when the file is # closed so this may not be necessary. # The documentation however states: # "Regions should be locked only briefly and should be unlocked # before closing a file or exiting the program." msvcrt.locking(fileno, msvcrt.LK_UNLCK, _region) else: # pragma: win32 no cover import fcntl @contextlib.contextmanager def _locked( fileno: int, blocked_cb: Callable[[], None], ) -> Generator[None]: try: fcntl.flock(fileno, fcntl.LOCK_EX | fcntl.LOCK_NB) except OSError: # pragma: no cover (tests are single-threaded) blocked_cb() fcntl.flock(fileno, fcntl.LOCK_EX) try: yield finally: fcntl.flock(fileno, fcntl.LOCK_UN) @contextlib.contextmanager def lock( path: str, blocked_cb: Callable[[], None], ) -> Generator[None]: with open(path, 'a+') as f: with _locked(f.fileno(), blocked_cb): yield
Save