From c572d2436eedea6260b5a1b2b23f2a11589b6809 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 27 Jul 2016 13:05:46 +0530 Subject: [PATCH] Dont import regex on calibre startup, since importing it seems to fail for unknown reasons on some linux installs --- src/calibre/ebooks/css_transform_rules.py | 5 +++-- src/calibre/ebooks/metadata/tag_mapper.py | 8 +++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/calibre/ebooks/css_transform_rules.py b/src/calibre/ebooks/css_transform_rules.py index 34f9c4f8b4..e1c3c12077 100644 --- a/src/calibre/ebooks/css_transform_rules.py +++ b/src/calibre/ebooks/css_transform_rules.py @@ -9,15 +9,15 @@ from collections import OrderedDict import operator from cssutils.css import Property, CSSRule -import regex from calibre import force_unicode from calibre.ebooks import parse_css_length from calibre.ebooks.oeb.normalize_css import normalizers, safe_parser -REGEX_FLAGS = regex.VERSION1 | regex.UNICODE | regex.IGNORECASE def compile_pat(pat): + import regex + REGEX_FLAGS = regex.VERSION1 | regex.UNICODE | regex.IGNORECASE return regex.compile(pat, flags=REGEX_FLAGS) def all_properties(decl): @@ -327,6 +327,7 @@ def export_rules(serialized_rules): return '\n'.join(lines).encode('utf-8') def import_rules(raw_data): + import regex pat = regex.compile('\s*(\S+)\s*:\s*(.+)', flags=regex.VERSION1) current_rule = {} diff --git a/src/calibre/ebooks/metadata/tag_mapper.py b/src/calibre/ebooks/metadata/tag_mapper.py index 0d5355bb52..068ab7ae0d 100644 --- a/src/calibre/ebooks/metadata/tag_mapper.py +++ b/src/calibre/ebooks/metadata/tag_mapper.py @@ -4,13 +4,11 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) -import regex from collections import deque -REGEX_FLAGS = regex.VERSION1 | regex.WORD | regex.FULLCASE | regex.IGNORECASE | regex.UNICODE - - def compile_pat(pat): + import regex + REGEX_FLAGS = regex.VERSION1 | regex.WORD | regex.FULLCASE | regex.IGNORECASE | regex.UNICODE return regex.compile(pat, flags=REGEX_FLAGS) def matcher(rule): @@ -57,7 +55,7 @@ def apply_rules(tag, rules): break if ac == 'replace': if 'matches' in rule['match_type']: - tag = regex.sub(rule['query'], rule['replace'], tag, flags=REGEX_FLAGS) + tag = compile_pat(rule['query']).sub(rule['replace'], tag) else: tag = rule['replace'] if ',' in tag: