2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 00:31:55 +00:00

catch nonUTF8 survex files, DataIssues url editor

This commit is contained in:
Philip Sargent 2022-07-15 14:09:32 +03:00
parent 5582d545a1
commit 86a18c3ebc
2 changed files with 21 additions and 5 deletions

View File

@ -119,9 +119,14 @@ class SvxForm(forms.Form):
print(">>> >>> WARNING - svx file not found, showing TEMPLATE SVX",fname, flush=True) print(">>> >>> WARNING - svx file not found, showing TEMPLATE SVX",fname, flush=True)
self.template = True self.template = True
return survextemplatefile return survextemplatefile
fin = open(fname, "r",encoding='utf8',newline='') try:
svxtext = fin.read() fin = open(fname, "r",encoding='utf8',newline='')
fin.close() svxtext = fin.read()
fin.close()
except:
fin = open(fname, "r",encoding='iso-8859-1',newline='')
svxtext = fin.read()
fin.close()
return svxtext return svxtext
def DiffCode(self, rcode): def DiffCode(self, rcode):

View File

@ -1140,7 +1140,18 @@ class LoadingSurvex():
return return
self.svxfileslist.append(path) self.svxfileslist.append(path)
svxlines = fin.read().splitlines() try:
svxlines = fin.read().splitlines()
except UnicodeDecodeError:
# some bugger put an umlaut in a non-UTF survex file ?!
message = f" ! ERROR *include file '{path}' in '{survexblock}' has UnicodeDecodeError"
print(message)
print(message,file=sys.stderr)
offendingfile = "/survexfile/" + path + ".svx"
DataIssue.objects.create(parser='survex', message=message, url=offendingfile)
return # skip this survex file and all things *included in it
for svxline in svxlines: for svxline in svxlines:
self.lineno += 1 self.lineno += 1
thissvxline += 1 thissvxline += 1
@ -1153,7 +1164,7 @@ class LoadingSurvex():
print(message) print(message)
print(message,file=sys.stderr) print(message,file=sys.stderr)
DataIssue.objects.create(parser='survex', message=message) DataIssue.objects.create(parser='survex', message=message)
return # skip this survex file return # skip this survex file and all things *included in it
includestmt =self.rx_include.match(svxline) includestmt =self.rx_include.match(svxline)
if not includestmt: if not includestmt: