mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-02 14:45:48 +01:00
Moved replace_entities to utils.entities.
This commit is contained in:
@@ -29,11 +29,6 @@ class CurrentDir(object):
|
|||||||
_ent_pat = re.compile(r'&(\S+?);')
|
_ent_pat = re.compile(r'&(\S+?);')
|
||||||
|
|
||||||
|
|
||||||
def replace_entities(raw, encoding='cp1252'):
|
|
||||||
return _ent_pat.sub(partial(entities.entity_to_unicode, encoding=encoding),
|
|
||||||
raw)
|
|
||||||
|
|
||||||
|
|
||||||
def xml_replace_entities(raw, encoding='cp1252'):
|
def xml_replace_entities(raw, encoding='cp1252'):
|
||||||
return _ent_pat.sub(partial(entities.xml_entity_to_unicode,
|
return _ent_pat.sub(partial(entities.xml_entity_to_unicode,
|
||||||
encoding=encoding), raw)
|
encoding=encoding), raw)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import sys
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
from ebook_converter.ebooks.chardet import detect_xml_encoding
|
from ebook_converter.ebooks.chardet import detect_xml_encoding
|
||||||
from ebook_converter import replace_entities
|
from ebook_converter.utils import entities
|
||||||
|
|
||||||
|
|
||||||
class Link(object):
|
class Link(object):
|
||||||
@@ -154,7 +154,7 @@ class HTMLFile(object):
|
|||||||
url = match.group(i)
|
url = match.group(i)
|
||||||
if url:
|
if url:
|
||||||
break
|
break
|
||||||
url = replace_entities(url)
|
url = entities.replace_entities(url)
|
||||||
try:
|
try:
|
||||||
link = self.resolve(url)
|
link = self.resolve(url)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from lxml.etree import Comment
|
|||||||
from ebook_converter.ebooks.metadata import string_to_authors, authors_to_string
|
from ebook_converter.ebooks.metadata import string_to_authors, authors_to_string
|
||||||
from ebook_converter.ebooks.metadata.book.base import Metadata
|
from ebook_converter.ebooks.metadata.book.base import Metadata
|
||||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||||
from ebook_converter import replace_entities
|
from ebook_converter.utils import entities
|
||||||
from ebook_converter.utils.date import parse_date, is_date_undefined
|
from ebook_converter.utils.date import parse_date, is_date_undefined
|
||||||
|
|
||||||
|
|
||||||
@@ -73,7 +73,8 @@ def handle_comment(data, comment_tags):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
if field:
|
if field:
|
||||||
comment_tags[field].append(replace_entities(match.group('content')))
|
comment_tags[field].append(
|
||||||
|
entities.replace_entities(match.group('content')))
|
||||||
|
|
||||||
|
|
||||||
def parse_metadata(src):
|
def parse_metadata(src):
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import struct, re, os
|
import struct, re, os
|
||||||
|
|
||||||
from ebook_converter import replace_entities
|
|
||||||
from ebook_converter.utils.date import parse_date
|
from ebook_converter.utils.date import parse_date
|
||||||
from ebook_converter.ebooks.mobi import MobiError
|
from ebook_converter.ebooks.mobi import MobiError
|
||||||
from ebook_converter.ebooks.metadata import MetaInformation, check_isbn
|
from ebook_converter.ebooks.metadata import MetaInformation, check_isbn
|
||||||
from ebook_converter.ebooks.mobi.langcodes import main_language, sub_language, mobi2iana
|
from ebook_converter.ebooks.mobi.langcodes import main_language, sub_language, mobi2iana
|
||||||
from ebook_converter.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
from ebook_converter.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
||||||
from ebook_converter.utils.localization import canonicalize_lang
|
|
||||||
from ebook_converter.utils.config_base import tweaks
|
from ebook_converter.utils.config_base import tweaks
|
||||||
|
from ebook_converter.utils import entities
|
||||||
|
from ebook_converter.utils.localization import canonicalize_lang
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@@ -106,7 +106,8 @@ class EXTHHeader(object): # {{{
|
|||||||
# else:
|
# else:
|
||||||
# print 'unknown record', idx, repr(content)
|
# print 'unknown record', idx, repr(content)
|
||||||
if title:
|
if title:
|
||||||
self.mi.title = replace_entities(clean_xml_chars(clean_ascii_chars(title)))
|
title = clean_xml_chars(clean_ascii_chars(title))
|
||||||
|
self.mi.title = entities.replace_entities(title)
|
||||||
|
|
||||||
def process_metadata(self, idx, content, codec):
|
def process_metadata(self, idx, content, codec):
|
||||||
if idx == 100:
|
if idx == 100:
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from ebook_converter import replace_entities
|
|
||||||
from ebook_converter.ebooks.metadata.toc import TOC
|
from ebook_converter.ebooks.metadata.toc import TOC
|
||||||
from ebook_converter.ebooks.mobi.reader.headers import NULL_INDEX
|
from ebook_converter.ebooks.mobi.reader.headers import NULL_INDEX
|
||||||
from ebook_converter.ebooks.mobi.reader.index import read_index
|
from ebook_converter.ebooks.mobi.reader.index import read_index
|
||||||
|
from ebook_converter.utils import entities
|
||||||
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
tag_fieldname_map = {
|
tag_fieldname_map = {
|
||||||
1: ['pos',0],
|
1: ['pos',0],
|
||||||
2: ['len',0],
|
2: ['len',0],
|
||||||
@@ -87,7 +83,8 @@ def build_toc(index_entries):
|
|||||||
for item in level_map[lvl]:
|
for item in level_map[lvl]:
|
||||||
parent = num_map[item['parent']]
|
parent = num_map[item['parent']]
|
||||||
child = parent.add_item(item['href'], item['idtag'],
|
child = parent.add_item(item['href'], item['idtag'],
|
||||||
replace_entities(item['text'], encoding=None))
|
entities.replace_entities(item['text'],
|
||||||
|
encoding=None))
|
||||||
num_map[item['num']] = child
|
num_map[item['num']] = child
|
||||||
|
|
||||||
# Set play orders in depth first order
|
# Set play orders in depth first order
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
|
||||||
from ebook_converter import replace_entities
|
from ebook_converter.utils import entities
|
||||||
|
|
||||||
|
|
||||||
def _upper(string):
|
def _upper(string):
|
||||||
@@ -185,7 +185,7 @@ def parse_css(data, fname='<string>', is_declaration=False, decode=None, log_lev
|
|||||||
|
|
||||||
|
|
||||||
def handle_entities(text, func):
|
def handle_entities(text, func):
|
||||||
return func(replace_entities(text))
|
return func(entities.replace_entities(text))
|
||||||
|
|
||||||
|
|
||||||
def apply_func_to_match_groups(match, func=_upper,
|
def apply_func_to_match_groups(match, func=_upper,
|
||||||
|
|||||||
Reference in New Issue
Block a user