From ee407ca871debaa2bcbc8f6e00c947630e5ecd37 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Fri, 23 Feb 2007 06:03:02 +0000 Subject: [PATCH] * src/GrampsDbUtils/_GedcomParser.py: fix a few bugs svn: r8216 --- ChangeLog | 1 + src/GrampsDbUtils/_GedcomParse.py | 24 ++++++++++++------------ src/GrampsDbUtils/_GedcomTokens.py | 2 +- src/GrampsDbUtils/_ReadGedcom.py | 4 ++++ src/docgen/ODFDoc.py | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index a827d311b..532918a08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ 2007-02-22 Don Allingham + * src/GrampsDbUtils/_GedcomParser.py: fix a few bugs * src/DataViews/_PedigreeView.py: remove redundant call * src/PageView.py: remove redundant call * src/ViewManager.py: pylint fixes diff --git a/src/GrampsDbUtils/_GedcomParse.py b/src/GrampsDbUtils/_GedcomParse.py index e0d3f3c4a..e740100ad 100644 --- a/src/GrampsDbUtils/_GedcomParse.py +++ b/src/GrampsDbUtils/_GedcomParse.py @@ -278,10 +278,13 @@ class StageOne: for line in self.ifile: self.lcnt +=1 data = line.split(None,2) + [''] - (level, key, value) = data[:3] - value = value.strip() - level = int(level) - key = key.strip() + try: + (level, key, value) = data[:3] + value = value.strip() + level = int(level) + key = key.strip() + except: + raise Errors.GedcomError("Corrupted file at line %d" % self.lcnt) if level == 0: if value == "FAM": @@ -2905,12 +2908,12 @@ class GedcomParser(UpdateCallback): """ state.location = RelLib.Location() state.location.set_street(line.data) - state.note = None + state.note = [] self.parse_level(state, self.parse_loc_tbl, self.func_undefined) location = state.location - note = state.note + note_list = state.note place_handle = state.event.get_place_handle() if place_handle: @@ -2929,7 +2932,7 @@ class GedcomParser(UpdateCallback): place_handle = place.handle place.set_main_location(location) - if note: + for note in note_list: place.add_note(note) state.event.set_place_handle(place_handle) @@ -3250,9 +3253,7 @@ class GedcomParser(UpdateCallback): """ date, text = self.parse_source_data(state.level+1) if date: - import DateHandler - date_obj = DateHandler.parser.parse(date) - state.src_ref.set_date_object(date_obj) + state.src_ref.set_date_object(date) state.src_ref.set_text(text) def func_srcref_obje(self, line, state): @@ -3869,8 +3870,7 @@ class GedcomParser(UpdateCallback): """ if not state.location: state.location = RelLib.Location() - self.parse_note(line, state.location, state.level+1) - + self.parse_note(line, state.note, state.level+1) def map_ancestry_com(self, original_gid): """ diff --git a/src/GrampsDbUtils/_GedcomTokens.py b/src/GrampsDbUtils/_GedcomTokens.py index 3e8be799d..836b01bf8 100644 --- a/src/GrampsDbUtils/_GedcomTokens.py +++ b/src/GrampsDbUtils/_GedcomTokens.py @@ -231,5 +231,5 @@ tokens = { "_PRIM" : TOKEN_IGNORE,"_SSHOW" : TOKEN_IGNORE, "_PAREN" : TOKEN_IGNORE,"BLOB" : TOKEN_BLOB, "CONL" : TOKEN_CONL, "RESN" : TOKEN_RESN, - "_MEDI" : TOKEN_MEDI, + "_MEDI" : TOKEN_MEDI, "_MASTER" : TOKEN_IGNORE, } diff --git a/src/GrampsDbUtils/_ReadGedcom.py b/src/GrampsDbUtils/_ReadGedcom.py index 6fda54796..d2b767ab7 100644 --- a/src/GrampsDbUtils/_ReadGedcom.py +++ b/src/GrampsDbUtils/_ReadGedcom.py @@ -80,6 +80,10 @@ def import2(database, filename, callback, code_set, use_trans): except IOError, msg: ErrorDialog(_("%s could not be opened\n") % filename, str(msg)) return + except Errors.GedcomError, msg: + ErrorDialog(_("Invalid GEDCOM file"), + _("%s could not be imported") % filename + "\n" + str(msg)) + return if database.get_number_of_people() == 0: diff --git a/src/docgen/ODFDoc.py b/src/docgen/ODFDoc.py index 565605ce7..048f7596b 100644 --- a/src/docgen/ODFDoc.py +++ b/src/docgen/ODFDoc.py @@ -1113,7 +1113,7 @@ class ODFDoc(BaseDoc.BaseDoc): self.cntnt.write('' % para_name) text = text.replace('\t','') text = text.replace('\n','') - self.cntnt.write(text) + self.cntnt.write(escape(text)) self.cntnt.write('') self.cntnt.write('\n') self.cntnt.write('\n')