This commit is contained in:
@@ -4,26 +4,22 @@
|
||||
# This module is part of asyncpg and is released under
|
||||
# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import enum
|
||||
import pathlib
|
||||
import platform
|
||||
import typing
|
||||
import sys
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
import asyncio
|
||||
|
||||
SYSTEM: typing.Final = platform.uname().system
|
||||
SYSTEM = platform.uname().system
|
||||
|
||||
|
||||
if sys.platform == 'win32':
|
||||
if SYSTEM == 'Windows':
|
||||
import ctypes.wintypes
|
||||
|
||||
CSIDL_APPDATA: typing.Final = 0x001a
|
||||
CSIDL_APPDATA = 0x001a
|
||||
|
||||
def get_pg_home_directory() -> pathlib.Path | None:
|
||||
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.
|
||||
@@ -35,14 +31,14 @@ if sys.platform == 'win32':
|
||||
return pathlib.Path(buf.value) / 'postgresql'
|
||||
|
||||
else:
|
||||
def get_pg_home_directory() -> pathlib.Path | None:
|
||||
def get_pg_home_directory() -> typing.Optional[pathlib.Path]:
|
||||
try:
|
||||
return pathlib.Path.home()
|
||||
except (RuntimeError, KeyError):
|
||||
return None
|
||||
|
||||
|
||||
async def wait_closed(stream: asyncio.StreamWriter) -> None:
|
||||
async def wait_closed(stream):
|
||||
# Not all asyncio versions have StreamWriter.wait_closed().
|
||||
if hasattr(stream, 'wait_closed'):
|
||||
try:
|
||||
@@ -53,13 +49,6 @@ async def wait_closed(stream: asyncio.StreamWriter) -> None:
|
||||
pass
|
||||
|
||||
|
||||
if sys.version_info < (3, 12):
|
||||
def markcoroutinefunction(c): # type: ignore
|
||||
pass
|
||||
else:
|
||||
from inspect import markcoroutinefunction # noqa: F401
|
||||
|
||||
|
||||
if sys.version_info < (3, 12):
|
||||
from ._asyncio_compat import wait_for as wait_for # noqa: F401
|
||||
else:
|
||||
@@ -70,19 +59,3 @@ 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
|
||||
|
||||
if sys.version_info < (3, 9):
|
||||
from typing import ( # noqa: F401
|
||||
Awaitable as Awaitable,
|
||||
)
|
||||
else:
|
||||
from collections.abc import ( # noqa: F401
|
||||
Awaitable as Awaitable,
|
||||
)
|
||||
|
||||
if sys.version_info < (3, 11):
|
||||
class StrEnum(str, enum.Enum):
|
||||
__str__ = str.__str__
|
||||
__repr__ = enum.Enum.__repr__
|
||||
else:
|
||||
from enum import StrEnum as StrEnum # noqa: F401
|
||||
|
||||
Reference in New Issue
Block a user