Skip to content

Commit 9d1a38d

Browse files
add datetime representer and allow unicode characters (#2191)
1 parent 936190d commit 9d1a38d

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

pygeoapi/util.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,26 @@ def path_representer(dumper, data):
202202

203203
yaml.add_multi_representer(pathlib.PurePath, path_representer)
204204

205+
def datetime_representer(dumper, data: datetime):
206+
if data.tzinfo is None:
207+
data = data.replace(tzinfo=timezone.utc)
208+
else:
209+
data = data.astimezone(timezone.utc)
210+
value = data.strftime("%Y-%m-%dT%H:%M:%SZ")
211+
212+
# timestamp in a specified format, without string quotes
213+
return dumper.represent_scalar(u'tag:yaml.org,2002:timestamp', value)
214+
215+
yaml.add_representer(datetime, datetime_representer)
216+
205217
lock = FileLock(f'{destfile}.lock')
206218

207219
with lock:
208220
LOGGER.debug('Dumping YAML document')
209221
with open(destfile, 'wb') as fh:
210-
yaml.dump(dict_, fh, sort_keys=False, encoding='utf8', indent=4,
211-
default_flow_style=False)
222+
yaml.dump(dict_, fh, sort_keys=False, encoding='utf8',
223+
indent=4, default_flow_style=False,
224+
allow_unicode=True)
212225

213226
return True
214227

tests/data/mysql_data.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- A test database for the mysql provider; a simple geospatial app
1+
-- A test database for the mysql provider; a simple geospatial app
22

33
-- Create the database
44
DROP DATABASE IF EXISTS test_geo_app;

0 commit comments

Comments
 (0)