X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/6e89310a9285f1ad15d8002bf68f578eada367a0..8b41b80bff156c2b9cdebfa2b0fba75421fb228a:/src/nominatim_api/core.py diff --git a/src/nominatim_api/core.py b/src/nominatim_api/core.py index 6f91e7a8..6c4c37d7 100644 --- a/src/nominatim_api/core.py +++ b/src/nominatim_api/core.py @@ -7,7 +7,7 @@ """ Implementation of classes for API access via libraries. """ -from typing import Mapping, Optional, Any, AsyncIterator, Dict, Sequence, List, Tuple +from typing import Mapping, Optional, Any, AsyncIterator, Dict, Sequence, List, Tuple, cast import asyncio import sys import contextlib @@ -16,10 +16,10 @@ from pathlib import Path import sqlalchemy as sa import sqlalchemy.ext.asyncio as sa_asyncio -from nominatim_core.errors import UsageError -from nominatim_core.db.sqlalchemy_schema import SearchTables -from nominatim_core.db.async_core_library import PGCORE_LIB, PGCORE_ERROR -from nominatim_core.config import Configuration +from .errors import UsageError +from .sql.sqlalchemy_schema import SearchTables +from .sql.async_core_library import PGCORE_LIB, PGCORE_ERROR +from .config import Configuration from .sql import sqlite_functions, sqlalchemy_functions #pylint: disable=unused-import from .connection import SearchConnection from .status import get_status, StatusResult @@ -107,16 +107,16 @@ class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes raise UsageError(f"SQlite database '{params.get('dbname')}' does not exist.") else: dsn = self.config.get_database_params() - query = {k: v for k, v in dsn.items() + query = {k: str(v) for k, v in dsn.items() if k not in ('user', 'password', 'dbname', 'host', 'port')} dburl = sa.engine.URL.create( f'postgresql+{PGCORE_LIB}', - database=dsn.get('dbname'), - username=dsn.get('user'), - password=dsn.get('password'), - host=dsn.get('host'), - port=int(dsn['port']) if 'port' in dsn else None, + database=cast(str, dsn.get('dbname')), + username=cast(str, dsn.get('user')), + password=cast(str, dsn.get('password')), + host=cast(str, dsn.get('host')), + port=int(cast(str, dsn['port'])) if 'port' in dsn else None, query=query) engine = sa_asyncio.create_async_engine(dburl, **extra_args) @@ -382,7 +382,7 @@ class NominatimAPI: @property def config(self) -> Configuration: - """ Provide read-only access to the [configuration](#Configuration) + """ Provide read-only access to the [configuration](Configuration.md) used by the API. """ return self._async_api.config