nominatim-api 4.4.99.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nominatim_api/__init__.py +43 -0
- nominatim_api/config.py +378 -0
- nominatim_api/connection.py +149 -0
- nominatim_api/core.py +974 -0
- nominatim_api/errors.py +14 -0
- nominatim_api/localization.py +97 -0
- nominatim_api/logging.py +433 -0
- nominatim_api/lookup.py +250 -0
- nominatim_api/paths.py +15 -0
- nominatim_api/py.typed +0 -0
- nominatim_api/resources/settings/address-levels.json +226 -0
- nominatim_api/resources/settings/country-names/ad.yaml +158 -0
- nominatim_api/resources/settings/country-names/ae.yaml +122 -0
- nominatim_api/resources/settings/country-names/af.yaml +155 -0
- nominatim_api/resources/settings/country-names/ag.yaml +141 -0
- nominatim_api/resources/settings/country-names/ai.yaml +81 -0
- nominatim_api/resources/settings/country-names/al.yaml +166 -0
- nominatim_api/resources/settings/country-names/am.yaml +162 -0
- nominatim_api/resources/settings/country-names/ao.yaml +150 -0
- nominatim_api/resources/settings/country-names/ar.yaml +161 -0
- nominatim_api/resources/settings/country-names/at.yaml +155 -0
- nominatim_api/resources/settings/country-names/au.yaml +155 -0
- nominatim_api/resources/settings/country-names/az.yaml +161 -0
- nominatim_api/resources/settings/country-names/ba.yaml +155 -0
- nominatim_api/resources/settings/country-names/bb.yaml +125 -0
- nominatim_api/resources/settings/country-names/bd.yaml +40 -0
- nominatim_api/resources/settings/country-names/be.yaml +159 -0
- nominatim_api/resources/settings/country-names/bf.yaml +147 -0
- nominatim_api/resources/settings/country-names/bg.yaml +153 -0
- nominatim_api/resources/settings/country-names/bh.yaml +148 -0
- nominatim_api/resources/settings/country-names/bi.yaml +147 -0
- nominatim_api/resources/settings/country-names/bj.yaml +150 -0
- nominatim_api/resources/settings/country-names/bm.yaml +39 -0
- nominatim_api/resources/settings/country-names/bn.yaml +147 -0
- nominatim_api/resources/settings/country-names/bo.yaml +154 -0
- nominatim_api/resources/settings/country-names/br.yaml +163 -0
- nominatim_api/resources/settings/country-names/bs.yaml +140 -0
- nominatim_api/resources/settings/country-names/bt.yaml +150 -0
- nominatim_api/resources/settings/country-names/bw.yaml +151 -0
- nominatim_api/resources/settings/country-names/by.yaml +132 -0
- nominatim_api/resources/settings/country-names/bz.yaml +141 -0
- nominatim_api/resources/settings/country-names/ca.yaml +151 -0
- nominatim_api/resources/settings/country-names/cd.yaml +124 -0
- nominatim_api/resources/settings/country-names/cf.yaml +124 -0
- nominatim_api/resources/settings/country-names/cg.yaml +120 -0
- nominatim_api/resources/settings/country-names/ch.yaml +134 -0
- nominatim_api/resources/settings/country-names/ci.yaml +130 -0
- nominatim_api/resources/settings/country-names/ck.yaml +126 -0
- nominatim_api/resources/settings/country-names/cl.yaml +172 -0
- nominatim_api/resources/settings/country-names/cm.yaml +131 -0
- nominatim_api/resources/settings/country-names/cn.yaml +170 -0
- nominatim_api/resources/settings/country-names/co.yaml +130 -0
- nominatim_api/resources/settings/country-names/cr.yaml +132 -0
- nominatim_api/resources/settings/country-names/cu.yaml +127 -0
- nominatim_api/resources/settings/country-names/cv.yaml +52 -0
- nominatim_api/resources/settings/country-names/cy.yaml +128 -0
- nominatim_api/resources/settings/country-names/cz.yaml +152 -0
- nominatim_api/resources/settings/country-names/de.yaml +158 -0
- nominatim_api/resources/settings/country-names/dj.yaml +127 -0
- nominatim_api/resources/settings/country-names/dk.yaml +136 -0
- nominatim_api/resources/settings/country-names/dm.yaml +42 -0
- nominatim_api/resources/settings/country-names/do.yaml +115 -0
- nominatim_api/resources/settings/country-names/dz.yaml +159 -0
- nominatim_api/resources/settings/country-names/ec.yaml +122 -0
- nominatim_api/resources/settings/country-names/ee.yaml +136 -0
- nominatim_api/resources/settings/country-names/eg.yaml +161 -0
- nominatim_api/resources/settings/country-names/eh.yaml +17 -0
- nominatim_api/resources/settings/country-names/er.yaml +130 -0
- nominatim_api/resources/settings/country-names/es.yaml +148 -0
- nominatim_api/resources/settings/country-names/et.yaml +154 -0
- nominatim_api/resources/settings/country-names/fi.yaml +146 -0
- nominatim_api/resources/settings/country-names/fj.yaml +121 -0
- nominatim_api/resources/settings/country-names/fk.yaml +105 -0
- nominatim_api/resources/settings/country-names/fm.yaml +49 -0
- nominatim_api/resources/settings/country-names/fo.yaml +101 -0
- nominatim_api/resources/settings/country-names/fr.yaml +155 -0
- nominatim_api/resources/settings/country-names/ga.yaml +131 -0
- nominatim_api/resources/settings/country-names/gb.yaml +157 -0
- nominatim_api/resources/settings/country-names/gd.yaml +40 -0
- nominatim_api/resources/settings/country-names/ge.yaml +124 -0
- nominatim_api/resources/settings/country-names/gg.yaml +86 -0
- nominatim_api/resources/settings/country-names/gh.yaml +137 -0
- nominatim_api/resources/settings/country-names/gi.yaml +99 -0
- nominatim_api/resources/settings/country-names/gl.yaml +113 -0
- nominatim_api/resources/settings/country-names/gm.yaml +132 -0
- nominatim_api/resources/settings/country-names/gn.yaml +127 -0
- nominatim_api/resources/settings/country-names/gq.yaml +146 -0
- nominatim_api/resources/settings/country-names/gr.yaml +140 -0
- nominatim_api/resources/settings/country-names/gs.yaml +62 -0
- nominatim_api/resources/settings/country-names/gt.yaml +121 -0
- nominatim_api/resources/settings/country-names/gw.yaml +124 -0
- nominatim_api/resources/settings/country-names/gy.yaml +120 -0
- nominatim_api/resources/settings/country-names/hn.yaml +122 -0
- nominatim_api/resources/settings/country-names/hr.yaml +134 -0
- nominatim_api/resources/settings/country-names/ht.yaml +120 -0
- nominatim_api/resources/settings/country-names/hu.yaml +138 -0
- nominatim_api/resources/settings/country-names/id.yaml +140 -0
- nominatim_api/resources/settings/country-names/ie.yaml +146 -0
- nominatim_api/resources/settings/country-names/il.yaml +136 -0
- nominatim_api/resources/settings/country-names/im.yaml +88 -0
- nominatim_api/resources/settings/country-names/in.yaml +37 -0
- nominatim_api/resources/settings/country-names/io.yaml +98 -0
- nominatim_api/resources/settings/country-names/iq.yaml +129 -0
- nominatim_api/resources/settings/country-names/ir.yaml +135 -0
- nominatim_api/resources/settings/country-names/is.yaml +143 -0
- nominatim_api/resources/settings/country-names/it.yaml +148 -0
- nominatim_api/resources/settings/country-names/je.yaml +82 -0
- nominatim_api/resources/settings/country-names/jm.yaml +46 -0
- nominatim_api/resources/settings/country-names/jo.yaml +120 -0
- nominatim_api/resources/settings/country-names/jp.yaml +149 -0
- nominatim_api/resources/settings/country-names/ke.yaml +134 -0
- nominatim_api/resources/settings/country-names/kg.yaml +122 -0
- nominatim_api/resources/settings/country-names/kh.yaml +125 -0
- nominatim_api/resources/settings/country-names/ki.yaml +27 -0
- nominatim_api/resources/settings/country-names/km.yaml +56 -0
- nominatim_api/resources/settings/country-names/kn.yaml +49 -0
- nominatim_api/resources/settings/country-names/kp.yaml +141 -0
- nominatim_api/resources/settings/country-names/kr.yaml +137 -0
- nominatim_api/resources/settings/country-names/kw.yaml +120 -0
- nominatim_api/resources/settings/country-names/ky.yaml +101 -0
- nominatim_api/resources/settings/country-names/kz.yaml +133 -0
- nominatim_api/resources/settings/country-names/la.yaml +123 -0
- nominatim_api/resources/settings/country-names/lb.yaml +124 -0
- nominatim_api/resources/settings/country-names/lc.yaml +43 -0
- nominatim_api/resources/settings/country-names/li.yaml +46 -0
- nominatim_api/resources/settings/country-names/lk.yaml +126 -0
- nominatim_api/resources/settings/country-names/lr.yaml +124 -0
- nominatim_api/resources/settings/country-names/ls.yaml +125 -0
- nominatim_api/resources/settings/country-names/lt.yaml +147 -0
- nominatim_api/resources/settings/country-names/lu.yaml +129 -0
- nominatim_api/resources/settings/country-names/lv.yaml +152 -0
- nominatim_api/resources/settings/country-names/ly.yaml +135 -0
- nominatim_api/resources/settings/country-names/ma.yaml +128 -0
- nominatim_api/resources/settings/country-names/mc.yaml +142 -0
- nominatim_api/resources/settings/country-names/md.yaml +127 -0
- nominatim_api/resources/settings/country-names/me.yaml +126 -0
- nominatim_api/resources/settings/country-names/mg.yaml +136 -0
- nominatim_api/resources/settings/country-names/mh.yaml +51 -0
- nominatim_api/resources/settings/country-names/mk.yaml +145 -0
- nominatim_api/resources/settings/country-names/ml.yaml +128 -0
- nominatim_api/resources/settings/country-names/mm.yaml +128 -0
- nominatim_api/resources/settings/country-names/mn.yaml +131 -0
- nominatim_api/resources/settings/country-names/mr.yaml +129 -0
- nominatim_api/resources/settings/country-names/ms.yaml +80 -0
- nominatim_api/resources/settings/country-names/mt.yaml +79 -0
- nominatim_api/resources/settings/country-names/mu.yaml +100 -0
- nominatim_api/resources/settings/country-names/mv.yaml +102 -0
- nominatim_api/resources/settings/country-names/mw.yaml +125 -0
- nominatim_api/resources/settings/country-names/mx.yaml +136 -0
- nominatim_api/resources/settings/country-names/my.yaml +126 -0
- nominatim_api/resources/settings/country-names/mz.yaml +126 -0
- nominatim_api/resources/settings/country-names/na.yaml +129 -0
- nominatim_api/resources/settings/country-names/ne.yaml +125 -0
- nominatim_api/resources/settings/country-names/ng.yaml +135 -0
- nominatim_api/resources/settings/country-names/ni.yaml +119 -0
- nominatim_api/resources/settings/country-names/nl.yaml +140 -0
- nominatim_api/resources/settings/country-names/no.yaml +142 -0
- nominatim_api/resources/settings/country-names/np.yaml +29 -0
- nominatim_api/resources/settings/country-names/nr.yaml +43 -0
- nominatim_api/resources/settings/country-names/nu.yaml +48 -0
- nominatim_api/resources/settings/country-names/nz.yaml +126 -0
- nominatim_api/resources/settings/country-names/om.yaml +120 -0
- nominatim_api/resources/settings/country-names/pa.yaml +123 -0
- nominatim_api/resources/settings/country-names/pe.yaml +137 -0
- nominatim_api/resources/settings/country-names/pg.yaml +110 -0
- nominatim_api/resources/settings/country-names/ph.yaml +126 -0
- nominatim_api/resources/settings/country-names/pk.yaml +135 -0
- nominatim_api/resources/settings/country-names/pl.yaml +147 -0
- nominatim_api/resources/settings/country-names/pn.yaml +42 -0
- nominatim_api/resources/settings/country-names/ps.yaml +2 -0
- nominatim_api/resources/settings/country-names/pt.yaml +139 -0
- nominatim_api/resources/settings/country-names/pw.yaml +25 -0
- nominatim_api/resources/settings/country-names/py.yaml +118 -0
- nominatim_api/resources/settings/country-names/qa.yaml +120 -0
- nominatim_api/resources/settings/country-names/ro.yaml +133 -0
- nominatim_api/resources/settings/country-names/rs.yaml +135 -0
- nominatim_api/resources/settings/country-names/ru.yaml +168 -0
- nominatim_api/resources/settings/country-names/rw.yaml +128 -0
- nominatim_api/resources/settings/country-names/sa.yaml +128 -0
- nominatim_api/resources/settings/country-names/sb.yaml +108 -0
- nominatim_api/resources/settings/country-names/sc.yaml +119 -0
- nominatim_api/resources/settings/country-names/sd.yaml +137 -0
- nominatim_api/resources/settings/country-names/se.yaml +142 -0
- nominatim_api/resources/settings/country-names/sg.yaml +130 -0
- nominatim_api/resources/settings/country-names/sh.yaml +25 -0
- nominatim_api/resources/settings/country-names/si.yaml +129 -0
- nominatim_api/resources/settings/country-names/sk.yaml +128 -0
- nominatim_api/resources/settings/country-names/sl.yaml +124 -0
- nominatim_api/resources/settings/country-names/sm.yaml +40 -0
- nominatim_api/resources/settings/country-names/sn.yaml +130 -0
- nominatim_api/resources/settings/country-names/so.yaml +131 -0
- nominatim_api/resources/settings/country-names/sr.yaml +117 -0
- nominatim_api/resources/settings/country-names/ss.yaml +108 -0
- nominatim_api/resources/settings/country-names/st.yaml +48 -0
- nominatim_api/resources/settings/country-names/sv.yaml +119 -0
- nominatim_api/resources/settings/country-names/sy.yaml +129 -0
- nominatim_api/resources/settings/country-names/sz.yaml +140 -0
- nominatim_api/resources/settings/country-names/tc.yaml +68 -0
- nominatim_api/resources/settings/country-names/td.yaml +130 -0
- nominatim_api/resources/settings/country-names/tg.yaml +128 -0
- nominatim_api/resources/settings/country-names/th.yaml +131 -0
- nominatim_api/resources/settings/country-names/tj.yaml +122 -0
- nominatim_api/resources/settings/country-names/tk.yaml +69 -0
- nominatim_api/resources/settings/country-names/tl.yaml +49 -0
- nominatim_api/resources/settings/country-names/tm.yaml +121 -0
- nominatim_api/resources/settings/country-names/tn.yaml +129 -0
- nominatim_api/resources/settings/country-names/to.yaml +112 -0
- nominatim_api/resources/settings/country-names/tr.yaml +144 -0
- nominatim_api/resources/settings/country-names/tt.yaml +46 -0
- nominatim_api/resources/settings/country-names/tv.yaml +75 -0
- nominatim_api/resources/settings/country-names/tw.yaml +138 -0
- nominatim_api/resources/settings/country-names/tz.yaml +136 -0
- nominatim_api/resources/settings/country-names/ua.yaml +137 -0
- nominatim_api/resources/settings/country-names/ug.yaml +127 -0
- nominatim_api/resources/settings/country-names/us.yaml +166 -0
- nominatim_api/resources/settings/country-names/uy.yaml +143 -0
- nominatim_api/resources/settings/country-names/uz.yaml +121 -0
- nominatim_api/resources/settings/country-names/va.yaml +133 -0
- nominatim_api/resources/settings/country-names/vc.yaml +47 -0
- nominatim_api/resources/settings/country-names/ve.yaml +129 -0
- nominatim_api/resources/settings/country-names/vg.yaml +45 -0
- nominatim_api/resources/settings/country-names/vn.yaml +149 -0
- nominatim_api/resources/settings/country-names/vu.yaml +73 -0
- nominatim_api/resources/settings/country-names/ws.yaml +82 -0
- nominatim_api/resources/settings/country-names/xk.yaml +116 -0
- nominatim_api/resources/settings/country-names/ye.yaml +127 -0
- nominatim_api/resources/settings/country-names/za.yaml +149 -0
- nominatim_api/resources/settings/country-names/zm.yaml +125 -0
- nominatim_api/resources/settings/country-names/zw.yaml +131 -0
- nominatim_api/resources/settings/country_settings.yaml +1935 -0
- nominatim_api/resources/settings/env.defaults +239 -0
- nominatim_api/resources/settings/flex-base.lua +554 -0
- nominatim_api/resources/settings/icu-rules/extended-unicode-to-asccii.yaml +4941 -0
- nominatim_api/resources/settings/icu-rules/unicode-digits-to-decimal.yaml +24 -0
- nominatim_api/resources/settings/icu-rules/variants-bg.yaml +19 -0
- nominatim_api/resources/settings/icu-rules/variants-ca.yaml +90 -0
- nominatim_api/resources/settings/icu-rules/variants-cs.yaml +6 -0
- nominatim_api/resources/settings/icu-rules/variants-da.yaml +12 -0
- nominatim_api/resources/settings/icu-rules/variants-de.yaml +136 -0
- nominatim_api/resources/settings/icu-rules/variants-el.yaml +54 -0
- nominatim_api/resources/settings/icu-rules/variants-en.yaml +485 -0
- nominatim_api/resources/settings/icu-rules/variants-es.yaml +163 -0
- nominatim_api/resources/settings/icu-rules/variants-et.yaml +8 -0
- nominatim_api/resources/settings/icu-rules/variants-eu.yaml +6 -0
- nominatim_api/resources/settings/icu-rules/variants-fi.yaml +23 -0
- nominatim_api/resources/settings/icu-rules/variants-fr.yaml +297 -0
- nominatim_api/resources/settings/icu-rules/variants-gl.yaml +27 -0
- nominatim_api/resources/settings/icu-rules/variants-hu.yaml +4 -0
- nominatim_api/resources/settings/icu-rules/variants-it.yaml +77 -0
- nominatim_api/resources/settings/icu-rules/variants-ja.yaml +32 -0
- nominatim_api/resources/settings/icu-rules/variants-mg.yaml +12 -0
- nominatim_api/resources/settings/icu-rules/variants-ms.yaml +12 -0
- nominatim_api/resources/settings/icu-rules/variants-nl.yaml +53 -0
- nominatim_api/resources/settings/icu-rules/variants-no.yaml +11 -0
- nominatim_api/resources/settings/icu-rules/variants-pl.yaml +66 -0
- nominatim_api/resources/settings/icu-rules/variants-pt.yaml +196 -0
- nominatim_api/resources/settings/icu-rules/variants-ro.yaml +36 -0
- nominatim_api/resources/settings/icu-rules/variants-ru.yaml +14 -0
- nominatim_api/resources/settings/icu-rules/variants-sk.yaml +20 -0
- nominatim_api/resources/settings/icu-rules/variants-sl.yaml +35 -0
- nominatim_api/resources/settings/icu-rules/variants-sv.yaml +21 -0
- nominatim_api/resources/settings/icu-rules/variants-tr.yaml +14 -0
- nominatim_api/resources/settings/icu-rules/variants-uk.yaml +10 -0
- nominatim_api/resources/settings/icu-rules/variants-vi.yaml +48 -0
- nominatim_api/resources/settings/icu_tokenizer.yaml +211 -0
- nominatim_api/resources/settings/import-address.lua +74 -0
- nominatim_api/resources/settings/import-admin.lua +72 -0
- nominatim_api/resources/settings/import-extratags.lua +124 -0
- nominatim_api/resources/settings/import-full.lua +124 -0
- nominatim_api/resources/settings/import-photon.lua +120 -0
- nominatim_api/resources/settings/import-street.lua +74 -0
- nominatim_api/resources/settings/phrase-settings.json +25 -0
- nominatim_api/resources/settings/taginfo.lua +74 -0
- nominatim_api/result_formatting.py +56 -0
- nominatim_api/results.py +752 -0
- nominatim_api/reverse.py +603 -0
- nominatim_api/search/__init__.py +15 -0
- nominatim_api/search/db_search_builder.py +459 -0
- nominatim_api/search/db_search_fields.py +254 -0
- nominatim_api/search/db_search_lookups.py +114 -0
- nominatim_api/search/db_searches.py +874 -0
- nominatim_api/search/geocoder.py +274 -0
- nominatim_api/search/icu_tokenizer.py +314 -0
- nominatim_api/search/legacy_tokenizer.py +272 -0
- nominatim_api/search/query.py +297 -0
- nominatim_api/search/query_analyzer_factory.py +54 -0
- nominatim_api/search/token_assignment.py +422 -0
- nominatim_api/server/__init__.py +0 -0
- nominatim_api/server/falcon/__init__.py +0 -0
- nominatim_api/server/falcon/server.py +194 -0
- nominatim_api/server/starlette/__init__.py +0 -0
- nominatim_api/server/starlette/server.py +174 -0
- nominatim_api/sql/__init__.py +0 -0
- nominatim_api/sql/async_core_library.py +21 -0
- nominatim_api/sql/sqlalchemy_functions.py +221 -0
- nominatim_api/sql/sqlalchemy_schema.py +119 -0
- nominatim_api/sql/sqlalchemy_types/__init__.py +17 -0
- nominatim_api/sql/sqlalchemy_types/geometry.py +308 -0
- nominatim_api/sql/sqlalchemy_types/int_array.py +123 -0
- nominatim_api/sql/sqlalchemy_types/json.py +30 -0
- nominatim_api/sql/sqlalchemy_types/key_value.py +62 -0
- nominatim_api/sql/sqlite_functions.py +122 -0
- nominatim_api/status.py +51 -0
- nominatim_api/types.py +550 -0
- nominatim_api/typing.py +40 -0
- nominatim_api/utils/__init__.py +0 -0
- nominatim_api/utils/json_writer.py +149 -0
- nominatim_api/v1/__init__.py +21 -0
- nominatim_api/v1/classtypes.py +201 -0
- nominatim_api/v1/format.py +259 -0
- nominatim_api/v1/format_json.py +275 -0
- nominatim_api/v1/format_xml.py +126 -0
- nominatim_api/v1/helpers.py +201 -0
- nominatim_api/v1/server_glue.py +577 -0
- nominatim_api/version.py +11 -0
- nominatim_api-4.4.99.dev1.dist-info/METADATA +58 -0
- nominatim_api-4.4.99.dev1.dist-info/RECORD +318 -0
- nominatim_api-4.4.99.dev1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Nominatim. (https://nominatim.org)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (C) 2024 by the Nominatim developer community.
|
|
6
|
+
# For a full list of authors see the git log.
|
|
7
|
+
"""
|
|
8
|
+
The public interface of the Nominatim library.
|
|
9
|
+
|
|
10
|
+
Classes and functions defined in this file are considered stable. Always
|
|
11
|
+
import from this file, not from the source files directly.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
# See also https://github.com/PyCQA/pylint/issues/6006
|
|
15
|
+
# pylint: disable=useless-import-alias
|
|
16
|
+
|
|
17
|
+
from .errors import (UsageError as UsageError)
|
|
18
|
+
from .config import (Configuration as Configuration)
|
|
19
|
+
|
|
20
|
+
from .core import (NominatimAPI as NominatimAPI,
|
|
21
|
+
NominatimAPIAsync as NominatimAPIAsync)
|
|
22
|
+
from .connection import (SearchConnection as SearchConnection)
|
|
23
|
+
from .status import (StatusResult as StatusResult)
|
|
24
|
+
from .types import (PlaceID as PlaceID,
|
|
25
|
+
OsmID as OsmID,
|
|
26
|
+
PlaceRef as PlaceRef,
|
|
27
|
+
Point as Point,
|
|
28
|
+
Bbox as Bbox,
|
|
29
|
+
GeometryFormat as GeometryFormat,
|
|
30
|
+
DataLayer as DataLayer)
|
|
31
|
+
from .results import (SourceTable as SourceTable,
|
|
32
|
+
AddressLine as AddressLine,
|
|
33
|
+
AddressLines as AddressLines,
|
|
34
|
+
WordInfo as WordInfo,
|
|
35
|
+
WordInfos as WordInfos,
|
|
36
|
+
DetailedResult as DetailedResult,
|
|
37
|
+
ReverseResult as ReverseResult,
|
|
38
|
+
ReverseResults as ReverseResults,
|
|
39
|
+
SearchResult as SearchResult,
|
|
40
|
+
SearchResults as SearchResults)
|
|
41
|
+
from .localization import (Locales as Locales)
|
|
42
|
+
|
|
43
|
+
from .version import NOMINATIM_API_VERSION as __version__
|
nominatim_api/config.py
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Nominatim. (https://nominatim.org)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (C) 2024 by the Nominatim developer community.
|
|
6
|
+
# For a full list of authors see the git log.
|
|
7
|
+
"""
|
|
8
|
+
Nominatim configuration accessor.
|
|
9
|
+
"""
|
|
10
|
+
from typing import Dict, Any, List, Mapping, Optional
|
|
11
|
+
import importlib.util
|
|
12
|
+
import logging
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
import json
|
|
17
|
+
import yaml
|
|
18
|
+
|
|
19
|
+
from dotenv import dotenv_values
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
from psycopg2.extensions import parse_dsn
|
|
23
|
+
except ModuleNotFoundError:
|
|
24
|
+
from psycopg.conninfo import conninfo_to_dict as parse_dsn # type: ignore[assignment]
|
|
25
|
+
|
|
26
|
+
from .typing import StrPath
|
|
27
|
+
from .errors import UsageError
|
|
28
|
+
from . import paths
|
|
29
|
+
|
|
30
|
+
LOG = logging.getLogger()
|
|
31
|
+
CONFIG_CACHE : Dict[str, Any] = {}
|
|
32
|
+
|
|
33
|
+
def flatten_config_list(content: Any, section: str = '') -> List[Any]:
|
|
34
|
+
""" Flatten YAML configuration lists that contain include sections
|
|
35
|
+
which are lists themselves.
|
|
36
|
+
"""
|
|
37
|
+
if not content:
|
|
38
|
+
return []
|
|
39
|
+
|
|
40
|
+
if not isinstance(content, list):
|
|
41
|
+
raise UsageError(f"List expected in section '{section}'.")
|
|
42
|
+
|
|
43
|
+
output = []
|
|
44
|
+
for ele in content:
|
|
45
|
+
if isinstance(ele, list):
|
|
46
|
+
output.extend(flatten_config_list(ele, section))
|
|
47
|
+
else:
|
|
48
|
+
output.append(ele)
|
|
49
|
+
|
|
50
|
+
return output
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class Configuration:
|
|
54
|
+
""" This class wraps access to the configuration settings
|
|
55
|
+
for the Nominatim instance in use.
|
|
56
|
+
|
|
57
|
+
All Nominatim configuration options are prefixed with 'NOMINATIM_' to
|
|
58
|
+
avoid conflicts with other environment variables. All settings can
|
|
59
|
+
be accessed as properties of the class under the same name as the
|
|
60
|
+
setting but with the `NOMINATIM_` prefix removed. In addition, there
|
|
61
|
+
are accessor functions that convert the setting values to types
|
|
62
|
+
other than string.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
def __init__(self, project_dir: Optional[Path],
|
|
66
|
+
environ: Optional[Mapping[str, str]] = None) -> None:
|
|
67
|
+
self.environ = environ or os.environ
|
|
68
|
+
self.project_dir = project_dir
|
|
69
|
+
self.config_dir = paths.CONFIG_DIR
|
|
70
|
+
self._config = dotenv_values(str(self.config_dir / 'env.defaults'))
|
|
71
|
+
if self.project_dir is not None and (self.project_dir / '.env').is_file():
|
|
72
|
+
self.project_dir = self.project_dir.resolve()
|
|
73
|
+
self._config.update(dotenv_values(str(self.project_dir / '.env')))
|
|
74
|
+
|
|
75
|
+
class _LibDirs:
|
|
76
|
+
module: Path
|
|
77
|
+
osm2pgsql: Path
|
|
78
|
+
php = paths.PHPLIB_DIR
|
|
79
|
+
sql = paths.SQLLIB_DIR
|
|
80
|
+
data = paths.DATA_DIR
|
|
81
|
+
|
|
82
|
+
self.lib_dir = _LibDirs()
|
|
83
|
+
self._private_plugins: Dict[str, object] = {}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def set_libdirs(self, **kwargs: StrPath) -> None:
|
|
87
|
+
""" Set paths to library functions and data.
|
|
88
|
+
"""
|
|
89
|
+
for key, value in kwargs.items():
|
|
90
|
+
setattr(self.lib_dir, key, None if value is None else Path(value))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def __getattr__(self, name: str) -> str:
|
|
94
|
+
name = 'NOMINATIM_' + name
|
|
95
|
+
|
|
96
|
+
if name in self.environ:
|
|
97
|
+
return self.environ[name]
|
|
98
|
+
|
|
99
|
+
return self._config[name] or ''
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def get_bool(self, name: str) -> bool:
|
|
103
|
+
""" Return the given configuration parameter as a boolean.
|
|
104
|
+
|
|
105
|
+
Parameters:
|
|
106
|
+
name: Name of the configuration parameter with the NOMINATIM_
|
|
107
|
+
prefix removed.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
`True` for values of '1', 'yes' and 'true', `False` otherwise.
|
|
111
|
+
"""
|
|
112
|
+
return getattr(self, name).lower() in ('1', 'yes', 'true')
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def get_int(self, name: str) -> int:
|
|
116
|
+
""" Return the given configuration parameter as an int.
|
|
117
|
+
|
|
118
|
+
Parameters:
|
|
119
|
+
name: Name of the configuration parameter with the NOMINATIM_
|
|
120
|
+
prefix removed.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
The configuration value converted to int.
|
|
124
|
+
|
|
125
|
+
Raises:
|
|
126
|
+
ValueError: when the value is not a number.
|
|
127
|
+
"""
|
|
128
|
+
try:
|
|
129
|
+
return int(getattr(self, name))
|
|
130
|
+
except ValueError as exp:
|
|
131
|
+
LOG.fatal("Invalid setting NOMINATIM_%s. Needs to be a number.", name)
|
|
132
|
+
raise UsageError("Configuration error.") from exp
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def get_str_list(self, name: str) -> Optional[List[str]]:
|
|
136
|
+
""" Return the given configuration parameter as a list of strings.
|
|
137
|
+
The values are assumed to be given as a comma-sparated list and
|
|
138
|
+
will be stripped before returning them.
|
|
139
|
+
|
|
140
|
+
Parameters:
|
|
141
|
+
name: Name of the configuration parameter with the NOMINATIM_
|
|
142
|
+
prefix removed.
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
(List[str]): The comma-split parameter as a list. The
|
|
146
|
+
elements are stripped of leading and final spaces before
|
|
147
|
+
being returned.
|
|
148
|
+
(None): The configuration parameter was unset or empty.
|
|
149
|
+
"""
|
|
150
|
+
raw = getattr(self, name)
|
|
151
|
+
|
|
152
|
+
return [v.strip() for v in raw.split(',')] if raw else None
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def get_path(self, name: str) -> Optional[Path]:
|
|
156
|
+
""" Return the given configuration parameter as a Path.
|
|
157
|
+
|
|
158
|
+
Parameters:
|
|
159
|
+
name: Name of the configuration parameter with the NOMINATIM_
|
|
160
|
+
prefix removed.
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
(Path): A Path object of the parameter value.
|
|
164
|
+
If a relative path is configured, then the function converts this
|
|
165
|
+
into an absolute path with the project directory as root path.
|
|
166
|
+
(None): The configuration parameter was unset or empty.
|
|
167
|
+
"""
|
|
168
|
+
value = getattr(self, name)
|
|
169
|
+
if not value:
|
|
170
|
+
return None
|
|
171
|
+
|
|
172
|
+
cfgpath = Path(value)
|
|
173
|
+
|
|
174
|
+
if not cfgpath.is_absolute():
|
|
175
|
+
assert self.project_dir is not None
|
|
176
|
+
cfgpath = self.project_dir / cfgpath
|
|
177
|
+
|
|
178
|
+
return cfgpath.resolve()
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def get_libpq_dsn(self) -> str:
|
|
182
|
+
""" Get configured database DSN converted into the key/value format
|
|
183
|
+
understood by libpq and psycopg.
|
|
184
|
+
"""
|
|
185
|
+
dsn = self.DATABASE_DSN
|
|
186
|
+
|
|
187
|
+
def quote_param(param: str) -> str:
|
|
188
|
+
key, val = param.split('=')
|
|
189
|
+
val = val.replace('\\', '\\\\').replace("'", "\\'")
|
|
190
|
+
if ' ' in val:
|
|
191
|
+
val = "'" + val + "'"
|
|
192
|
+
return key + '=' + val
|
|
193
|
+
|
|
194
|
+
if dsn.startswith('pgsql:'):
|
|
195
|
+
# Old PHP DSN format. Convert before returning.
|
|
196
|
+
return ' '.join([quote_param(p) for p in dsn[6:].split(';')])
|
|
197
|
+
|
|
198
|
+
return dsn
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def get_database_params(self) -> Mapping[str, str]:
|
|
202
|
+
""" Get the configured parameters for the database connection
|
|
203
|
+
as a mapping.
|
|
204
|
+
"""
|
|
205
|
+
dsn = self.DATABASE_DSN
|
|
206
|
+
|
|
207
|
+
if dsn.startswith('pgsql:'):
|
|
208
|
+
return dict((p.split('=', 1) for p in dsn[6:].split(';')))
|
|
209
|
+
|
|
210
|
+
return parse_dsn(dsn)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def get_import_style_file(self) -> Path:
|
|
214
|
+
""" Return the import style file as a path object. Translates the
|
|
215
|
+
name of the standard styles automatically into a file in the
|
|
216
|
+
config style.
|
|
217
|
+
"""
|
|
218
|
+
style = getattr(self, 'IMPORT_STYLE')
|
|
219
|
+
|
|
220
|
+
if style in ('admin', 'street', 'address', 'full', 'extratags'):
|
|
221
|
+
return self.config_dir / f'import-{style}.lua'
|
|
222
|
+
|
|
223
|
+
return self.find_config_file('', 'IMPORT_STYLE')
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def get_os_env(self) -> Dict[str, str]:
|
|
227
|
+
""" Return a copy of the OS environment with the Nominatim configuration
|
|
228
|
+
merged in.
|
|
229
|
+
"""
|
|
230
|
+
env = {k: v for k, v in self._config.items() if v is not None}
|
|
231
|
+
env.update(self.environ)
|
|
232
|
+
|
|
233
|
+
return env
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def load_sub_configuration(self, filename: StrPath,
|
|
237
|
+
config: Optional[str] = None) -> Any:
|
|
238
|
+
""" Load additional configuration from a file. `filename` is the name
|
|
239
|
+
of the configuration file. The file is first searched in the
|
|
240
|
+
project directory and then in the global settings directory.
|
|
241
|
+
|
|
242
|
+
If `config` is set, then the name of the configuration file can
|
|
243
|
+
be additionally given through a .env configuration option. When
|
|
244
|
+
the option is set, then the file will be exclusively loaded as set:
|
|
245
|
+
if the name is an absolute path, the file name is taken as is,
|
|
246
|
+
if the name is relative, it is taken to be relative to the
|
|
247
|
+
project directory.
|
|
248
|
+
|
|
249
|
+
The format of the file is determined from the filename suffix.
|
|
250
|
+
Currently only files with extension '.yaml' are supported.
|
|
251
|
+
|
|
252
|
+
YAML files support a special '!include' construct. When the
|
|
253
|
+
directive is given, the value is taken to be a filename, the file
|
|
254
|
+
is loaded using this function and added at the position in the
|
|
255
|
+
configuration tree.
|
|
256
|
+
"""
|
|
257
|
+
configfile = self.find_config_file(filename, config)
|
|
258
|
+
|
|
259
|
+
if str(configfile) in CONFIG_CACHE:
|
|
260
|
+
return CONFIG_CACHE[str(configfile)]
|
|
261
|
+
|
|
262
|
+
if configfile.suffix in ('.yaml', '.yml'):
|
|
263
|
+
result = self._load_from_yaml(configfile)
|
|
264
|
+
elif configfile.suffix == '.json':
|
|
265
|
+
with configfile.open('r', encoding='utf-8') as cfg:
|
|
266
|
+
result = json.load(cfg)
|
|
267
|
+
else:
|
|
268
|
+
raise UsageError(f"Config file '{configfile}' has unknown format.")
|
|
269
|
+
|
|
270
|
+
CONFIG_CACHE[str(configfile)] = result
|
|
271
|
+
return result
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def load_plugin_module(self, module_name: str, internal_path: str) -> Any:
|
|
275
|
+
""" Load a Python module as a plugin.
|
|
276
|
+
|
|
277
|
+
The module_name may have three variants:
|
|
278
|
+
|
|
279
|
+
* A name without any '.' is assumed to be an internal module
|
|
280
|
+
and will be searched relative to `internal_path`.
|
|
281
|
+
* If the name ends in `.py`, module_name is assumed to be a
|
|
282
|
+
file name relative to the project directory.
|
|
283
|
+
* Any other name is assumed to be an absolute module name.
|
|
284
|
+
|
|
285
|
+
In either of the variants the module name must start with a letter.
|
|
286
|
+
"""
|
|
287
|
+
if not module_name or not module_name[0].isidentifier():
|
|
288
|
+
raise UsageError(f'Invalid module name {module_name}')
|
|
289
|
+
|
|
290
|
+
if '.' not in module_name:
|
|
291
|
+
module_name = module_name.replace('-', '_')
|
|
292
|
+
full_module = f'{internal_path}.{module_name}'
|
|
293
|
+
return sys.modules.get(full_module) or importlib.import_module(full_module)
|
|
294
|
+
|
|
295
|
+
if module_name.endswith('.py'):
|
|
296
|
+
if self.project_dir is None or not (self.project_dir / module_name).exists():
|
|
297
|
+
raise UsageError(f"Cannot find module '{module_name}' in project directory.")
|
|
298
|
+
|
|
299
|
+
if module_name in self._private_plugins:
|
|
300
|
+
return self._private_plugins[module_name]
|
|
301
|
+
|
|
302
|
+
file_path = str(self.project_dir / module_name)
|
|
303
|
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
|
304
|
+
if spec:
|
|
305
|
+
module = importlib.util.module_from_spec(spec)
|
|
306
|
+
# Do not add to global modules because there is no standard
|
|
307
|
+
# module name that Python can resolve.
|
|
308
|
+
self._private_plugins[module_name] = module
|
|
309
|
+
assert spec.loader is not None
|
|
310
|
+
spec.loader.exec_module(module)
|
|
311
|
+
|
|
312
|
+
return module
|
|
313
|
+
|
|
314
|
+
return sys.modules.get(module_name) or importlib.import_module(module_name)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def find_config_file(self, filename: StrPath,
|
|
318
|
+
config: Optional[str] = None) -> Path:
|
|
319
|
+
""" Resolve the location of a configuration file given a filename and
|
|
320
|
+
an optional configuration option with the file name.
|
|
321
|
+
Raises a UsageError when the file cannot be found or is not
|
|
322
|
+
a regular file.
|
|
323
|
+
"""
|
|
324
|
+
if config is not None:
|
|
325
|
+
cfg_value = getattr(self, config)
|
|
326
|
+
if cfg_value:
|
|
327
|
+
cfg_filename = Path(cfg_value)
|
|
328
|
+
|
|
329
|
+
if cfg_filename.is_absolute():
|
|
330
|
+
cfg_filename = cfg_filename.resolve()
|
|
331
|
+
|
|
332
|
+
if not cfg_filename.is_file():
|
|
333
|
+
LOG.fatal("Cannot find config file '%s'.", cfg_filename)
|
|
334
|
+
raise UsageError("Config file not found.")
|
|
335
|
+
|
|
336
|
+
return cfg_filename
|
|
337
|
+
|
|
338
|
+
filename = cfg_filename
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
search_paths = [self.project_dir, self.config_dir]
|
|
342
|
+
for path in search_paths:
|
|
343
|
+
if path is not None and (path / filename).is_file():
|
|
344
|
+
return path / filename
|
|
345
|
+
|
|
346
|
+
LOG.fatal("Configuration file '%s' not found.\nDirectories searched: %s",
|
|
347
|
+
filename, search_paths)
|
|
348
|
+
raise UsageError("Config file not found.")
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def _load_from_yaml(self, cfgfile: Path) -> Any:
|
|
352
|
+
""" Load a YAML configuration file. This installs a special handler that
|
|
353
|
+
allows to include other YAML files using the '!include' operator.
|
|
354
|
+
"""
|
|
355
|
+
yaml.add_constructor('!include', self._yaml_include_representer,
|
|
356
|
+
Loader=yaml.SafeLoader)
|
|
357
|
+
return yaml.safe_load(cfgfile.read_text(encoding='utf-8'))
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def _yaml_include_representer(self, loader: Any, node: yaml.Node) -> Any:
|
|
361
|
+
""" Handler for the '!include' operator in YAML files.
|
|
362
|
+
|
|
363
|
+
When the filename is relative, then the file is first searched in the
|
|
364
|
+
project directory and then in the global settings directory.
|
|
365
|
+
"""
|
|
366
|
+
fname = loader.construct_scalar(node)
|
|
367
|
+
|
|
368
|
+
if Path(fname).is_absolute():
|
|
369
|
+
configfile = Path(fname)
|
|
370
|
+
else:
|
|
371
|
+
configfile = self.find_config_file(loader.construct_scalar(node))
|
|
372
|
+
|
|
373
|
+
if configfile.suffix != '.yaml':
|
|
374
|
+
LOG.fatal("Format error while reading '%s': only YAML format supported.",
|
|
375
|
+
configfile)
|
|
376
|
+
raise UsageError("Cannot handle config file format.")
|
|
377
|
+
|
|
378
|
+
return yaml.safe_load(configfile.read_text(encoding='utf-8'))
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Nominatim. (https://nominatim.org)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (C) 2024 by the Nominatim developer community.
|
|
6
|
+
# For a full list of authors see the git log.
|
|
7
|
+
"""
|
|
8
|
+
Extended SQLAlchemy connection class that also includes access to the schema.
|
|
9
|
+
"""
|
|
10
|
+
from typing import cast, Any, Mapping, Sequence, Union, Dict, Optional, Set, \
|
|
11
|
+
Awaitable, Callable, TypeVar
|
|
12
|
+
import asyncio
|
|
13
|
+
|
|
14
|
+
import sqlalchemy as sa
|
|
15
|
+
from sqlalchemy.ext.asyncio import AsyncConnection
|
|
16
|
+
|
|
17
|
+
from .typing import SaFromClause
|
|
18
|
+
from .sql.sqlalchemy_schema import SearchTables
|
|
19
|
+
from .sql.sqlalchemy_types import Geometry
|
|
20
|
+
from .logging import log
|
|
21
|
+
|
|
22
|
+
T = TypeVar('T')
|
|
23
|
+
|
|
24
|
+
class SearchConnection:
|
|
25
|
+
""" An extended SQLAlchemy connection class, that also contains
|
|
26
|
+
the table definitions. The underlying asynchronous SQLAlchemy
|
|
27
|
+
connection can be accessed with the 'connection' property.
|
|
28
|
+
The 't' property is the collection of Nominatim tables.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self, conn: AsyncConnection,
|
|
32
|
+
tables: SearchTables,
|
|
33
|
+
properties: Dict[str, Any]) -> None:
|
|
34
|
+
self.connection = conn
|
|
35
|
+
self.t = tables # pylint: disable=invalid-name
|
|
36
|
+
self._property_cache = properties
|
|
37
|
+
self._classtables: Optional[Set[str]] = None
|
|
38
|
+
self.query_timeout: Optional[int] = None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def set_query_timeout(self, timeout: Optional[int]) -> None:
|
|
42
|
+
""" Set the timeout after which a query over this connection
|
|
43
|
+
is cancelled.
|
|
44
|
+
"""
|
|
45
|
+
self.query_timeout = timeout
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def scalar(self, sql: sa.sql.base.Executable,
|
|
49
|
+
params: Union[Mapping[str, Any], None] = None
|
|
50
|
+
) -> Any:
|
|
51
|
+
""" Execute a 'scalar()' query on the connection.
|
|
52
|
+
"""
|
|
53
|
+
log().sql(self.connection, sql, params)
|
|
54
|
+
return await asyncio.wait_for(self.connection.scalar(sql, params), self.query_timeout)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
async def execute(self, sql: 'sa.Executable',
|
|
58
|
+
params: Union[Mapping[str, Any], Sequence[Mapping[str, Any]], None] = None
|
|
59
|
+
) -> 'sa.Result[Any]':
|
|
60
|
+
""" Execute a 'execute()' query on the connection.
|
|
61
|
+
"""
|
|
62
|
+
log().sql(self.connection, sql, params)
|
|
63
|
+
return await asyncio.wait_for(self.connection.execute(sql, params), self.query_timeout)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
async def get_property(self, name: str, cached: bool = True) -> str:
|
|
67
|
+
""" Get a property from Nominatim's property table.
|
|
68
|
+
|
|
69
|
+
Property values are normally cached so that they are only
|
|
70
|
+
retrieved from the database when they are queried for the
|
|
71
|
+
first time with this function. Set 'cached' to False to force
|
|
72
|
+
reading the property from the database.
|
|
73
|
+
|
|
74
|
+
Raises a ValueError if the property does not exist.
|
|
75
|
+
"""
|
|
76
|
+
lookup_name = f'DBPROP:{name}'
|
|
77
|
+
|
|
78
|
+
if cached and lookup_name in self._property_cache:
|
|
79
|
+
return cast(str, self._property_cache[lookup_name])
|
|
80
|
+
|
|
81
|
+
sql = sa.select(self.t.properties.c.value)\
|
|
82
|
+
.where(self.t.properties.c.property == name)
|
|
83
|
+
value = await self.connection.scalar(sql)
|
|
84
|
+
|
|
85
|
+
if value is None:
|
|
86
|
+
raise ValueError(f"Property '{name}' not found in database.")
|
|
87
|
+
|
|
88
|
+
self._property_cache[lookup_name] = cast(str, value)
|
|
89
|
+
|
|
90
|
+
return cast(str, value)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
async def get_db_property(self, name: str) -> Any:
|
|
94
|
+
""" Get a setting from the database. At the moment, only
|
|
95
|
+
'server_version', the version of the database software, can
|
|
96
|
+
be retrieved with this function.
|
|
97
|
+
|
|
98
|
+
Raises a ValueError if the property does not exist.
|
|
99
|
+
"""
|
|
100
|
+
if name != 'server_version':
|
|
101
|
+
raise ValueError(f"DB setting '{name}' not found in database.")
|
|
102
|
+
|
|
103
|
+
return self._property_cache['DB:server_version']
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
async def get_cached_value(self, group: str, name: str,
|
|
107
|
+
factory: Callable[[], Awaitable[T]]) -> T:
|
|
108
|
+
""" Access the cache for this Nominatim instance.
|
|
109
|
+
Each cache value needs to belong to a group and have a name.
|
|
110
|
+
This function is for internal API use only.
|
|
111
|
+
|
|
112
|
+
`factory` is an async callback function that produces
|
|
113
|
+
the value if it is not already cached.
|
|
114
|
+
|
|
115
|
+
Returns the cached value or the result of factory (also caching
|
|
116
|
+
the result).
|
|
117
|
+
"""
|
|
118
|
+
full_name = f'{group}:{name}'
|
|
119
|
+
|
|
120
|
+
if full_name in self._property_cache:
|
|
121
|
+
return cast(T, self._property_cache[full_name])
|
|
122
|
+
|
|
123
|
+
value = await factory()
|
|
124
|
+
self._property_cache[full_name] = value
|
|
125
|
+
|
|
126
|
+
return value
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
async def get_class_table(self, cls: str, typ: str) -> Optional[SaFromClause]:
|
|
130
|
+
""" Lookup up if there is a classtype table for the given category
|
|
131
|
+
and return a SQLAlchemy table for it, if it exists.
|
|
132
|
+
"""
|
|
133
|
+
if self._classtables is None:
|
|
134
|
+
res = await self.execute(sa.text("""SELECT tablename FROM pg_tables
|
|
135
|
+
WHERE tablename LIKE 'place_classtype_%'
|
|
136
|
+
"""))
|
|
137
|
+
self._classtables = {r[0] for r in res}
|
|
138
|
+
|
|
139
|
+
tablename = f"place_classtype_{cls}_{typ}"
|
|
140
|
+
|
|
141
|
+
if tablename not in self._classtables:
|
|
142
|
+
return None
|
|
143
|
+
|
|
144
|
+
if tablename in self.t.meta.tables:
|
|
145
|
+
return self.t.meta.tables[tablename]
|
|
146
|
+
|
|
147
|
+
return sa.Table(tablename, self.t.meta,
|
|
148
|
+
sa.Column('place_id', sa.BigInteger),
|
|
149
|
+
sa.Column('centroid', Geometry))
|