File: utils_.py

package info (click to toggle)
python-passlib 1.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,184 kB
  • sloc: python: 26,132; makefile: 7
file content (21 lines) | stat: -rw-r--r-- 506 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import contextlib
import os
import warnings
from collections.abc import Iterator
from os import PathLike


def backdate_file_mtime(path: PathLike, offset: int = 10) -> None:
    atime = os.path.getatime(path)
    mtime = os.path.getmtime(path) - offset
    os.utime(path, (atime, mtime))


WARN_SETTINGS_ARG = "passing settings to.*is deprecated"


@contextlib.contextmanager
def no_warnings() -> Iterator[None]:
    with warnings.catch_warnings(record=True) as result:
        yield
    assert not result