diff options
author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
---|---|---|
committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/asyncpg/compat.py | |
parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
download | gn-ai-master.tar.gz |
Diffstat (limited to '.venv/lib/python3.12/site-packages/asyncpg/compat.py')
-rw-r--r-- | .venv/lib/python3.12/site-packages/asyncpg/compat.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/asyncpg/compat.py b/.venv/lib/python3.12/site-packages/asyncpg/compat.py new file mode 100644 index 00000000..3eec9eb7 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/asyncpg/compat.py @@ -0,0 +1,61 @@ +# Copyright (C) 2016-present the asyncpg authors and contributors +# <see AUTHORS file> +# +# This module is part of asyncpg and is released under +# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0 + + +import pathlib +import platform +import typing +import sys + + +SYSTEM = platform.uname().system + + +if SYSTEM == 'Windows': + import ctypes.wintypes + + CSIDL_APPDATA = 0x001a + + def get_pg_home_directory() -> typing.Optional[pathlib.Path]: + # We cannot simply use expanduser() as that returns the user's + # home directory, whereas Postgres stores its config in + # %AppData% on Windows. + buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH) + r = ctypes.windll.shell32.SHGetFolderPathW(0, CSIDL_APPDATA, 0, 0, buf) + if r: + return None + else: + return pathlib.Path(buf.value) / 'postgresql' + +else: + def get_pg_home_directory() -> typing.Optional[pathlib.Path]: + try: + return pathlib.Path.home() + except (RuntimeError, KeyError): + return None + + +async def wait_closed(stream): + # Not all asyncio versions have StreamWriter.wait_closed(). + if hasattr(stream, 'wait_closed'): + try: + await stream.wait_closed() + except ConnectionResetError: + # On Windows wait_closed() sometimes propagates + # ConnectionResetError which is totally unnecessary. + pass + + +if sys.version_info < (3, 12): + from ._asyncio_compat import wait_for as wait_for # noqa: F401 +else: + from asyncio import wait_for as wait_for # noqa: F401 + + +if sys.version_info < (3, 11): + from ._asyncio_compat import timeout_ctx as timeout # noqa: F401 +else: + from asyncio import timeout as timeout # noqa: F401 |