~ubuntu-branches/debian/sid/calibre/sid

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/oeb/polish/check/parsing.py

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-02-27 07:48:06 UTC
  • mto: This revision was merged to the branch mainline in revision 74.
  • Revision ID: package-import@ubuntu.com-20140227074806-64wdebb3ptosxhhx
Tags: upstream-1.25.0+dfsg
ImportĀ upstreamĀ versionĀ 1.25.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
class NamedEntities(BaseError):
52
52
 
53
53
    level = WARN
54
 
    INDIVIDUAL_FIX = _('Replace all named entities with their character equivalents in this file')
 
54
    INDIVIDUAL_FIX = _('Replace all named entities with their character equivalents in this book')
55
55
    HELP = _('Named entities are often only incompletely supported by various book reading software.'
56
56
             ' Therefore, it is best to not use them, replacing them with the actual characters they'
57
57
             ' represent. This can be done automatically.')
60
60
        BaseError.__init__(self, _('Named entities present'), name)
61
61
 
62
62
    def __call__(self, container):
63
 
        raw = container.raw_data(self.name)
64
 
        nraw = replace_pat.sub(lambda m:html5_entities[m.group(1)], raw)
65
 
        with container.open(self.name, 'wb') as f:
66
 
            f.write(nraw.encode('utf-8'))
67
 
        return True
 
63
        changed = False
 
64
        from calibre.ebooks.oeb.polish.check.main import XML_TYPES
 
65
        check_types = XML_TYPES | OEB_DOCS
 
66
        for name, mt in container.mime_map.iteritems():
 
67
            if mt in check_types:
 
68
                raw = container.raw_data(name)
 
69
                nraw = replace_pat.sub(lambda m:html5_entities[m.group(1)], raw)
 
70
                if raw != nraw:
 
71
                    changed = True
 
72
                    with container.open(name, 'wb') as f:
 
73
                        f.write(nraw.encode('utf-8'))
 
74
        return changed
68
75
 
69
76
class EscapedName(BaseError):
70
77
 
202
209
    except Exception as err:
203
210
        return errors + [errcls(err.message, name)]
204
211
 
205
 
    if mt in OEB_DOCS and root.nsmap.get(root.prefix, None) != XHTML_NS:
206
 
        errors.append(BadNamespace(name, root.nsmap.get(root.prefix, None)))
 
212
    if mt in OEB_DOCS:
 
213
        if root.nsmap.get(root.prefix, None) != XHTML_NS:
 
214
            errors.append(BadNamespace(name, root.nsmap.get(root.prefix, None)))
207
215
 
208
216
    return errors
209
217