Dont import regex on calibre startup, since importing it seems to fail for unknown reasons on some linux installs

This commit is contained in:
Kovid Goyal 2016-07-27 13:05:46 +05:30
parent 554cdeb746
commit c572d2436e
2 changed files with 6 additions and 7 deletions

View File

@ -9,15 +9,15 @@ from collections import OrderedDict
import operator import operator
from cssutils.css import Property, CSSRule from cssutils.css import Property, CSSRule
import regex
from calibre import force_unicode from calibre import force_unicode
from calibre.ebooks import parse_css_length from calibre.ebooks import parse_css_length
from calibre.ebooks.oeb.normalize_css import normalizers, safe_parser from calibre.ebooks.oeb.normalize_css import normalizers, safe_parser
REGEX_FLAGS = regex.VERSION1 | regex.UNICODE | regex.IGNORECASE
def compile_pat(pat): def compile_pat(pat):
import regex
REGEX_FLAGS = regex.VERSION1 | regex.UNICODE | regex.IGNORECASE
return regex.compile(pat, flags=REGEX_FLAGS) return regex.compile(pat, flags=REGEX_FLAGS)
def all_properties(decl): def all_properties(decl):
@ -327,6 +327,7 @@ def export_rules(serialized_rules):
return '\n'.join(lines).encode('utf-8') return '\n'.join(lines).encode('utf-8')
def import_rules(raw_data): def import_rules(raw_data):
import regex
pat = regex.compile('\s*(\S+)\s*:\s*(.+)', flags=regex.VERSION1) pat = regex.compile('\s*(\S+)\s*:\s*(.+)', flags=regex.VERSION1)
current_rule = {} current_rule = {}

View File

@ -4,13 +4,11 @@
from __future__ import (unicode_literals, division, absolute_import, from __future__ import (unicode_literals, division, absolute_import,
print_function) print_function)
import regex
from collections import deque from collections import deque
REGEX_FLAGS = regex.VERSION1 | regex.WORD | regex.FULLCASE | regex.IGNORECASE | regex.UNICODE
def compile_pat(pat): 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) return regex.compile(pat, flags=REGEX_FLAGS)
def matcher(rule): def matcher(rule):
@ -57,7 +55,7 @@ def apply_rules(tag, rules):
break break
if ac == 'replace': if ac == 'replace':
if 'matches' in rule['match_type']: 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: else:
tag = rule['replace'] tag = rule['replace']
if ',' in tag: if ',' in tag: