Commit da42b987 authored by Dmitry Shelepnev's avatar Dmitry Shelepnev
Browse files

Fix Errors with FB2sax parser. Unify FB2 and FB2Sax working. Update tests in test_scan.py.

parent 2792ea25
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -113,9 +113,9 @@ class FB2Base(BookFile):

        def add_author_from_node(node):
            first_name = subnode_text(node, 'first-name')
            middle_name = subnode_text(node, 'middle-name')
            #middle_name = subnode_text(node, 'middle-name')
            last_name = subnode_text(node, 'last-name')
            self.__add_author__(' '.join([first_name, middle_name, last_name]), last_name)
            self.__add_author__(' '.join([first_name, last_name]), last_name)

        res = tree.xpath('/fb:FictionBook/fb:description/fb:title-info/fb:author', namespaces=self.__namespaces)
        if len(res) == 0:
+4 −5
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ class fb2parser:
          self.lang.tagopen(name)
          self.book_title.tagopen(name)
          self.annotation.tagopen(name)
          self.docdate.tagopen(name)
          self.docdate.tagopen(name,attrs)
          self.series.tagopen(name,attrs)
          if self.rc!=0:
             if self.cover_name.tagopen(name,attrs):
@@ -245,7 +245,6 @@ class fb2parser:
        except StopIteration:
            pass
        except Exception as err:
            print(err)
            self.parse_errormsg=err
            self.parse_error=1

@@ -262,7 +261,7 @@ class FB2sax(BookFile):
        self.file.seek(0, 0)
        self.fb2parser.parse(self.file)
        if self.fb2parser.parse_error != 0:
            raise FB2StructureException('FB2sax parse error')
            raise FB2StructureException('FB2sax parse error (%s)'%self.fb2parser.parse_errormsg)
        self.__detect_title()
        self.__detect_authors()
        self.__detect_tags()
@@ -293,8 +292,8 @@ class FB2sax(BookFile):
        return None

    def __detect_docdate(self):
        res = ''
        if len(self.fb2parser.docdate.getvalue()) > 0:
        res = self.fb2parser.docdate.getattr('value') or ''
        if len(res)==0 and len(self.fb2parser.docdate.getvalue()) > 0:
            res = self.fb2parser.docdate.getvalue()[0].strip();
        if len(res) > 0:
            self.__set_docdate__(res)
+1 −1
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ class opdsScanner:
                    for a in book_data.authors:
                        author_name = a.get('name','Unknown author').strip(strip_symbols)
                        # Если в имени автора нет запятой, то фамилию переносим из конца в начало
                        if author_name.find(',')>=0:
                        if author_name.find(',')<0:
                            author_names = author_name.split()
                            author_name = ' '.join([author_names[-1],' '.join(author_names[:-1])])
                        author=opdsdb.addauthor(author_name)
+480 KiB

File added.

No diff preview for this file type.

+530 KiB

File added.

No diff preview for this file type.

Loading