Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Catch possible malformed XML
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:6dede47dbda4f35a12da11409f56e71ccd5688ff
User & Date: brandon 2018-10-13 16:38:06
Context
2018-10-13
17:14
Fix extraction of PNG cover files from blorbs check-in: 0c718f8c4f user: brandon tags: trunk
16:38
Catch possible malformed XML check-in: 6dede47dbd user: brandon tags: trunk
2018-10-09
19:37
Move error checking to pyifbabel tool check-in: 7cc6c3a772 user: brandon tags: trunk
Changes

Changes to treatyofbabel/__init__.py.

141
142
143
144
145
146
147

148


149

150
151
152
153
154
155
156
157
158

    """
    try:
        xml_doc = xml.dom.minidom.parse(story_file)
    except:
        story_data = _get_story_data(story_file)
        if blorb.claim_story_file(story_data):

            return blorb.get_story_file_ifid(story_data)


        else:

            handler = deduce_handler(story_file, story_data)
            return [handler.get_story_file_ifid(story_data)]
    else:
        if not ifiction.is_ifiction(xml_doc):
            return None
        ifids = []
        stories = ifiction.get_all_stories(xml_doc)
        for story in stories:
            ifids.append(ifiction.get_identification(story)["ifid"])







>
|
>
>
|
>
|
|







141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

    """
    try:
        xml_doc = xml.dom.minidom.parse(story_file)
    except:
        story_data = _get_story_data(story_file)
        if blorb.claim_story_file(story_data):
            try:
                ifids = blorb.get_story_file_ifid(story_data)
            except:
                return [blorb._get_embedded_ifid(story_data)]
            else:
                return ifids
        handler = deduce_handler(story_file, story_data)
        return [handler.get_story_file_ifid(story_data)]
    else:
        if not ifiction.is_ifiction(xml_doc):
            return None
        ifids = []
        stories = ifiction.get_all_stories(xml_doc)
        for story in stories:
            ifids.append(ifiction.get_identification(story)["ifid"])

Changes to treatyofbabel/ifiction.py.

26
27
28
29
30
31
32

33
34
35
36
37
38
39
...
189
190
191
192
193
194
195

196


197
198
199
200
201
202
203
very well change following an impending switch in the underlying
Python XML parsing library.

"""


import xml.dom.minidom


from babelerrors import IFictionError


BIBLIO_ATTR = ['title', 'author', 'language', 'headline',
               'firstpublished', 'genre', 'group', 'description',
               'series', 'seriesnumber', 'forgiveness']
................................................................................
    Returns:
        An xml.dom.minidom DOM object

    """
    clean_ifiction = munge_html(ifiction)
    clean_ifiction = clean_ifiction.replace('\n', '')
    clean_ifiction = clean_ifiction.replace('\t', '')

    doc = xml.dom.minidom.parseString(clean_ifiction)


    if not is_ifiction(doc):
        raise IFictionError("Document not IFiction")
    return doc


def add_comment(ifiction_dom, comment):
    """Add a comment to an IFiction DOM.







>







 







>
|
>
>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
very well change following an impending switch in the underlying
Python XML parsing library.

"""


import xml.dom.minidom
from xml.parsers.expat import ExpatError

from babelerrors import IFictionError


BIBLIO_ATTR = ['title', 'author', 'language', 'headline',
               'firstpublished', 'genre', 'group', 'description',
               'series', 'seriesnumber', 'forgiveness']
................................................................................
    Returns:
        An xml.dom.minidom DOM object

    """
    clean_ifiction = munge_html(ifiction)
    clean_ifiction = clean_ifiction.replace('\n', '')
    clean_ifiction = clean_ifiction.replace('\t', '')
    try:
        doc = xml.dom.minidom.parseString(clean_ifiction)
    except ExpatError:
        raise IFictionError("Malformed XML document")
    if not is_ifiction(doc):
        raise IFictionError("Document not IFiction")
    return doc


def add_comment(ifiction_dom, comment):
    """Add a comment to an IFiction DOM.