mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
use raw strings where possible to avoid escaping
This commit is contained in:
parent
975b9ac168
commit
cdc2e21a77
@ -242,7 +242,7 @@ class BIBTEX(CatalogPlugin):
|
||||
# define a function to replace the template entry by its value
|
||||
def tpl_replace(objtplname) :
|
||||
|
||||
tpl_field = re.sub('[\\{\\}]', '', objtplname.group())
|
||||
tpl_field = re.sub(r'[\{\}]', '', objtplname.group())
|
||||
|
||||
if tpl_field in TEMPLATE_ALLOWED_FIELDS :
|
||||
if tpl_field in ['pubdate', 'timestamp'] :
|
||||
@ -259,14 +259,14 @@ class BIBTEX(CatalogPlugin):
|
||||
|
||||
if len(template_citation) >0 :
|
||||
tpl_citation = bibtexclass.utf8ToBibtex(
|
||||
bibtexclass.ValidateCitationKey(re.sub('\\{[^{}]*\\}',
|
||||
bibtexclass.ValidateCitationKey(re.sub(r'\{[^{}]*\}',
|
||||
tpl_replace, template_citation)))
|
||||
|
||||
if len(tpl_citation) >0 :
|
||||
return tpl_citation
|
||||
|
||||
if len(entry["isbn"]) > 0 :
|
||||
template_citation = '%s' % re.sub('[\\D]','', entry["isbn"])
|
||||
template_citation = '%s' % re.sub(r'[\D]','', entry["isbn"])
|
||||
|
||||
else :
|
||||
template_citation = '%s' % unicode_type(entry["id"])
|
||||
|
@ -156,9 +156,9 @@ class CSV_XML(CatalogPlugin):
|
||||
|
||||
# Convert HTML to markdown text
|
||||
if isinstance(item, unicode_type):
|
||||
opening_tag = re.search('<(\\w+)(\x20|>)', item)
|
||||
opening_tag = re.search(r'<(\w+)( |>)', item)
|
||||
if opening_tag:
|
||||
closing_tag = re.search('<\\/%s>$' % opening_tag.group(1), item)
|
||||
closing_tag = re.search(r'<\/%s>$' % opening_tag.group(1), item)
|
||||
if closing_tag:
|
||||
item = html2text(item)
|
||||
|
||||
|
@ -1228,11 +1228,11 @@ class CatalogBuilder(object):
|
||||
clipped to max_len
|
||||
"""
|
||||
|
||||
normalized = massaged = re.sub('\\s', '', ascii_text(tag).lower())
|
||||
if re.search('\\W', normalized):
|
||||
normalized = massaged = re.sub(r'\s', '', ascii_text(tag).lower())
|
||||
if re.search(r'\W', normalized):
|
||||
normalized = ''
|
||||
for c in massaged:
|
||||
if re.search('\\W', c):
|
||||
if re.search(r'\W', c):
|
||||
normalized += self.generate_unicode_name(c)
|
||||
else:
|
||||
normalized += c
|
||||
@ -1395,7 +1395,7 @@ class CatalogBuilder(object):
|
||||
Return:
|
||||
(str): asciized version of author
|
||||
"""
|
||||
return re.sub("\\W", "", ascii_text(author))
|
||||
return re.sub(r"\W", "", ascii_text(author))
|
||||
|
||||
def generate_format_args(self, book):
|
||||
""" Generate the format args for template substitution.
|
||||
@ -4228,9 +4228,9 @@ class CatalogBuilder(object):
|
||||
|
||||
# Generate a legal XHTML id/href string
|
||||
if self.letter_or_symbol(series) == self.SYMBOLS:
|
||||
return "symbol_%s_series" % re.sub('\\W', '', series).lower()
|
||||
return "symbol_%s_series" % re.sub(r'\W', '', series).lower()
|
||||
else:
|
||||
return "%s_series" % re.sub('\\W', '', ascii_text(series)).lower()
|
||||
return "%s_series" % re.sub(r'\W', '', ascii_text(series)).lower()
|
||||
|
||||
def generate_short_description(self, description, dest=None):
|
||||
""" Generate a truncated version of the supplied string.
|
||||
@ -4311,7 +4311,7 @@ class CatalogBuilder(object):
|
||||
else:
|
||||
if re.match('[0-9]+', word[0]):
|
||||
word = word.replace(',', '')
|
||||
suffix = re.search('[\\D]', word)
|
||||
suffix = re.search(r'[\D]', word)
|
||||
if suffix:
|
||||
word = '%10.0f%s' % (float(word[:suffix.start()]), word[suffix.start():])
|
||||
else:
|
||||
@ -4327,7 +4327,7 @@ class CatalogBuilder(object):
|
||||
else:
|
||||
if re.search('[0-9]+', word[0]):
|
||||
word = word.replace(',', '')
|
||||
suffix = re.search('[\\D]', word)
|
||||
suffix = re.search(r'[\D]', word)
|
||||
if suffix:
|
||||
word = '%10.0f%s' % (float(word[:suffix.start()]), word[suffix.start():])
|
||||
else:
|
||||
|
@ -90,8 +90,8 @@ class NumberToText(object): # {{{
|
||||
# Special case ordinals
|
||||
if re.search('[st|nd|rd|th]',self.number):
|
||||
self.number = re.sub(',','',self.number)
|
||||
ordinal_suffix = re.search('[\\D]', self.number)
|
||||
ordinal_number = re.sub('\\D','',re.sub(',','',self.number))
|
||||
ordinal_suffix = re.search(r'[\D]', self.number)
|
||||
ordinal_number = re.sub(r'\D','',re.sub(',','',self.number))
|
||||
if self.verbose:
|
||||
self.log("Ordinal: %s" % ordinal_number)
|
||||
self.number_as_float = ordinal_number
|
||||
@ -155,8 +155,8 @@ class NumberToText(object): # {{{
|
||||
if self.verbose:
|
||||
self.log("Hybrid: %s" % self.number)
|
||||
# Split the token into number/text
|
||||
number_position = re.search('\\d',self.number).start()
|
||||
text_position = re.search('\\D',self.number).start()
|
||||
number_position = re.search(r'\d',self.number).start()
|
||||
text_position = re.search(r'\D',self.number).start()
|
||||
if number_position < text_position:
|
||||
number = self.number[:text_position]
|
||||
text = self.number[text_position:]
|
||||
|
@ -60,7 +60,7 @@ def _connect(path):
|
||||
conn = sqlite.connect(path, factory=Connection, detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES)
|
||||
conn.row_factory = lambda cursor, row : list(row)
|
||||
conn.create_aggregate('concat', 1, Concatenate)
|
||||
title_pat = re.compile('^(A|The|An)\\s+', re.IGNORECASE)
|
||||
title_pat = re.compile(r'^(A|The|An)\s+', re.IGNORECASE)
|
||||
|
||||
def title_sort(title):
|
||||
match = title_pat.search(title)
|
||||
|
Loading…
x
Reference in New Issue
Block a user