From 4090b201ac90940bc014cc3de6a0b621b5c94657 Mon Sep 17 00:00:00 2001 From: Geoff Boeing Date: Mon, 5 Feb 2024 15:43:32 -0800 Subject: [PATCH] rename settings module's default_accept_language, default_referer, and default_user_agent --- CHANGELOG.md | 5 +++-- osmnx/_http.py | 21 ++++++++++----------- osmnx/settings.py | 26 ++++++++++++++------------ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac4db845b..b27655f2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,15 +4,16 @@ - add type annotations to all public and private functions throughout package (#1107) - improve docstrings throughout package (#1116) +- improve logging and warnings throughout package (#1125) - remove functionality previously deprecated in v1 (#1113 #1122) - drop Python 3.8 support (#1106) - increase add_node_elevations_google default batch_size to 512 to match Google's limit (#1115) - make which_result function parameter consistently able to accept a list throughout package (#1113) - make utils_geo.bbox_from_point function return a tuple of floats for consistency with rest of package (#1113) -- improve logging and warnings throughout package (#1125) - fix bug in \_downloader.\_save_to_cache function usage (#1107) - fix bug in handling requests ConnectionError when querying Overpass status endpoint (#1113) -- minor fixes throughout to address inconsistencies revealed by type enforcement (#1107 #1114) +- fix minor bugs throughout to address inconsistencies revealed by type enforcement (#1107 #1114) +- rename settings module's default_accept_language, default_referer, and default_user_agent (#1129) - rename osm_xml module to \_osm_xml to make it private, as all its functions are private (#1113) - rename private \_downloader module to \_http (#1114) - remove unnecessary private \_api module (#1114) diff --git a/osmnx/_http.py b/osmnx/_http.py index 61f19ce26..a44f676dc 100644 --- a/osmnx/_http.py +++ b/osmnx/_http.py @@ -149,33 +149,32 @@ def _get_http_headers( user_agent: str | None = None, referer: str | None = None, accept_language: str | None = None ) -> dict[str, str]: """ - Update the default requests HTTP headers with OSMnx info. + Update the default requests HTTP headers with OSMnx information. Parameters ---------- user_agent - The user agent string. If None, use the OSMnx default. + The user agent. If None, use `settings.http_user_agent` value. referer - The referer string. If None, use the OSMnx default. + The referer. If None, use `settings.http_referer` value. accept_language - The accept language. Make it explicit for consistent Nominatim result - sorting. + The accept language. If None, use `settings.http_accept_language` + value. Returns ------- headers """ if user_agent is None: - user_agent = settings.default_user_agent + user_agent = settings.http_user_agent if referer is None: - referer = settings.default_referer + referer = settings.http_referer if accept_language is None: - accept_language = settings.default_accept_language + accept_language = settings.http_accept_language + info = {"User-Agent": user_agent, "referer": referer, "Accept-Language": accept_language} headers = dict(requests.utils.default_headers()) - headers.update( - {"User-Agent": user_agent, "referer": referer, "Accept-Language": accept_language} - ) + headers.update(info) return headers diff --git a/osmnx/settings.py b/osmnx/settings.py index 925df3bd2..92f9e8638 100644 --- a/osmnx/settings.py +++ b/osmnx/settings.py @@ -24,10 +24,8 @@ data_folder : str | Path Path to folder in which to save/load graph files by default. Default is `"./data"`. -default_accept_language : str - HTTP header accept-language. Default is `"en"`. default_access : str - Default filter for OSM "access" key. Default is `'["access"!~"private"]'`. + Filter for the OSM "access" key. Default is `'["access"!~"private"]'`. Note that also filtering out "access=no" ways prevents including transit-only bridges (e.g., Tilikum Crossing) from appearing in drivable road network (e.g., `'["access"!~"private|no"]'`). However, some drivable @@ -38,12 +36,6 @@ default_crs : str Default coordinate reference system to set when creating graphs. Default is `"epsg:4326"`. -default_referer : str - HTTP header referer. Default is - `"OSMnx Python package (https://github.com/gboeing/osmnx)"`. -default_user_agent : str - HTTP header user-agent. Default is - `"OSMnx Python package (https://github.com/gboeing/osmnx)"`. doh_url_template : str | None Endpoint to resolve DNS-over-HTTPS if local DNS resolution fails. Set to None to disable DoH, but see `downloader._config_dns` documentation for @@ -54,6 +46,16 @@ `"https://maps.googleapis.com/maps/api/elevation/json?locations={locations}&key={key}"` One example of an alternative equivalent would be Open Topo Data: `"https://api.opentopodata.org/v1/aster30m?locations={locations}&key={key}"` +http_accept_language : str + HTTP header accept-language. Default is `"en"`. Note that Nominatim's + default language is "en" and it can sort result importance scores + differently if a different language is specified. +http_referer : str + HTTP header referer. Default is + `"OSMnx Python package (https://github.com/gboeing/osmnx)"`. +http_user_agent : str + HTTP header user-agent. Default is + `"OSMnx Python package (https://github.com/gboeing/osmnx)"`. imgs_folder : str | Path Path to folder in which to save plotted images by default. Default is `"./images"`. @@ -146,15 +148,15 @@ cache_folder: str | Path = "./cache" cache_only_mode: bool = False data_folder: str | Path = "./data" -default_accept_language: str = "en" default_access: str = '["access"!~"private"]' default_crs: str = "epsg:4326" -default_referer: str = "OSMnx Python package (https://github.com/gboeing/osmnx)" -default_user_agent: str = "OSMnx Python package (https://github.com/gboeing/osmnx)" doh_url_template: str | None = "https://8.8.8.8/resolve?name={hostname}" elevation_url_template: str = ( "https://maps.googleapis.com/maps/api/elevation/json?locations={locations}&key={key}" ) +http_accept_language: str = "en" +http_referer: str = "OSMnx Python package (https://github.com/gboeing/osmnx)" +http_user_agent: str = "OSMnx Python package (https://github.com/gboeing/osmnx)" imgs_folder: str | Path = "./images" log_console: bool = False log_file: bool = False