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

« back to all changes in this revision

Viewing changes to src/calibre/library/catalogs/epub_mobi_builder.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:
3
3
__license__ = 'GPL v3'
4
4
__copyright__ = '2010, Greg Riker'
5
5
 
6
 
import datetime, htmlentitydefs, os, platform, re, shutil, time, unicodedata, zlib
 
6
import datetime, os, platform, re, shutil, time, unicodedata, zlib
7
7
from copy import deepcopy
8
8
from xml.sax.saxutils import escape
9
9
 
10
10
from calibre import (prepare_string_for_xml, strftime, force_unicode,
11
 
        isbytestring)
 
11
        isbytestring, replace_entities)
12
12
from calibre.constants import isosx, cache_dir
13
13
from calibre.customize.conversion import DummyReporter
14
14
from calibre.customize.ui import output_profiles
432
432
        Return:
433
433
         s (str): converted string
434
434
        """
435
 
        matches = re.findall("&#\d+;", s)
436
 
        if len(matches) > 0:
437
 
            hits = set(matches)
438
 
            for hit in hits:
439
 
                name = hit[2:-1]
440
 
                try:
441
 
                    entnum = int(name)
442
 
                    s = s.replace(hit, unichr(entnum))
443
 
                except ValueError:
444
 
                    pass
445
 
 
446
 
        matches = re.findall("&\w+;", s)
447
 
        hits = set(matches)
448
 
        amp = "&"
449
 
        if amp in hits:
450
 
            hits.remove(amp)
451
 
        for hit in hits:
452
 
            name = hit[1:-1]
453
 
            if htmlentitydefs.name2codepoint in name:
454
 
                    s = s.replace(hit, unichr(htmlentitydefs.name2codepoint[name]))
455
 
        s = s.replace(amp, "&")
456
 
        return s
 
435
        return replace_entities(s)
457
436
 
458
437
    def copy_catalog_resources(self):
459
438
        """ Copy resources from calibre source to self.catalog_path.
1233
1212
        else:
1234
1213
            # Validate custom field is usable as a genre source
1235
1214
            field_md = self.db.metadata_for_field(self.opts.genre_source_field)
1236
 
            if not field_md['datatype'] in ['enumeration', 'text']:
 
1215
            if field_md is None or not field_md['datatype'] in ['enumeration', 'text']:
1237
1216
                all_custom_fields = self.db.custom_field_keys()
1238
1217
                eligible_custom_fields = []
1239
1218
                for cf in all_custom_fields:
4743
4722
        Return:
4744
4723
         (list): filtered data_set
4745
4724
        """
4746
 
 
4747
4725
        filtered_data_set = []
4748
4726
        exclusion_pairs = []
4749
4727
        exclusion_set = []
4794
4772
                                filtered_data_set.remove(record)
4795
4773
                            break
4796
4774
                        else:
4797
 
                            filtered_data_set.append(record)
 
4775
                            if record not in filtered_data_set:
 
4776
                                filtered_data_set.append(record)
4798
4777
                    else:
4799
4778
                        if (record not in filtered_data_set and
4800
4779
                            record not in exclusion_set):