Support loading docs in utf-8 from pg version 10

This commit is contained in:
Magnus Hagander
2016-11-16 13:00:50 +01:00
parent c5d162dee7
commit ab0ee30881

View File

@ -29,7 +29,17 @@ def load_doc_file(filename, f):
indent='auto',
)
contents = unicode(f.read(),'latin1')
# Postgres 10 started using xml toolchain and now produces docmentation in utf8. So we need
# to figure out which version it is.
rawcontents = f.read()
if rawcontents.startswith('<?xml version="1.0" encoding="UTF-8"'):
# Version 10, use utf8
encoding = 'utf-8'
else:
encoding = 'latin1'
contents = unicode(rawcontents, encoding)
tm = re_titlematch.search(contents)
if tm:
title = tm.group(1)