From c33799f69e7eb42cb0ab4735c7e878d74faca16a Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 19 Apr 2025 05:28:42 +0200 Subject: webmap-import: Break down into separate modules. --- common.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'common.py') diff --git a/common.py b/common.py index 0bece11..eab9dd5 100644 --- a/common.py +++ b/common.py @@ -164,6 +164,16 @@ def format_time(ts : float, precision : int = 3) -> str: h, m = divmod(m, 60) return f'{h:02d}:{m:02d}:{s:0{w}.{precision}f}' +def escape_identifier(identifier : str) -> str: + """Escape the given identifier, cf. + swig/python/gdal-utils/osgeo_utils/samples/validate_gpkg.py:_esc_id().""" + + if identifier is None or '\x00' in identifier: + raise RuntimeError(f'Invalid identifier "{identifier}"') + + # SQL:1999 delimited identifier + return '"' + identifier.replace('"', '""') + '"' + ###### # The function definitions below are taken from cpython's source code -- cgit v1.2.3