diff --git a/recipes/al_monitor.recipe b/recipes/al_monitor.recipe
index 5842f5c73f..0067f9ed2f 100644
--- a/recipes/al_monitor.recipe
+++ b/recipes/al_monitor.recipe
@@ -162,7 +162,7 @@ class AlMonitor(BasicNewsRecipe):
def scrape_article_date(self, soup):
for span in soup.findAll('span'):
txt = self.text(span)
- rgx = re.compile('Posted ([a-zA-Z]+ \d\d?, \d\d\d\d).*')
+ rgx = re.compile(unicode(r'Posted ([a-zA-Z]+ \d\d?, \d\d\d\d).*'))
hit = rgx.match(txt)
if hit:
return self.date_from_string(txt)
diff --git a/recipes/appledaily_tw.recipe b/recipes/appledaily_tw.recipe
index 14e5be20a0..700ee4c7f1 100644
--- a/recipes/appledaily_tw.recipe
+++ b/recipes/appledaily_tw.recipe
@@ -106,5 +106,5 @@ class AppledailyTW(BasicNewsRecipe):
def preprocess_raw_html(self, raw_html, url):
raw_html = re.sub(unicode(r'', re.DOTALL), lambda match: ''), # fix malformed HTML with 2 body tags...
- (re.compile(u'(?:)?\(kliknij\,\ aby powiększyć\)(?:)?', re.IGNORECASE), lambda m: ''),
+ (re.compile(u'(?:)?\\(kliknij\\,\\ aby powiększyć\\)(?:)?', re.IGNORECASE), lambda m: ''),
(re.compile(unicode(r'(
\s*?
\s*?)+'), re.IGNORECASE), lambda m: '
')
]
remove_tags = [dict(attrs={'class':['infoParent', 'likeBar',
diff --git a/recipes/huffingtonpost.recipe b/recipes/huffingtonpost.recipe
index 82fcd3d2ba..d5e023c6db 100644
--- a/recipes/huffingtonpost.recipe
+++ b/recipes/huffingtonpost.recipe
@@ -62,7 +62,7 @@ class HuffingtonPostRecipe(BasicNewsRecipe):
remove_tags = []
remove_tags.append(dict(name='a', attrs={'href': re.compile(
- 'http://feedads\.g\.doubleclick.net.*')}))
+ 'http://feedads\\.g\\.doubleclick.net.*')}))
remove_tags.append(dict(name='div', attrs={'class': 'feedflare'}))
remove_tags.append(dict(name='a', attrs={'class': 'home_pixie'}))
remove_tags.append(dict(name='div', attrs={'id': [
diff --git a/recipes/lenta_ru.recipe b/recipes/lenta_ru.recipe
index 7a1a28652c..1e633b2c17 100644
--- a/recipes/lenta_ru.recipe
+++ b/recipes/lenta_ru.recipe
@@ -144,7 +144,7 @@ class LentaRURecipe(BasicNewsRecipe):
# Place article date after header
dates = soup.findAll(text=re.compile(
- '\d{2}\.\d{2}\.\d{4}, \d{2}:\d{2}:\d{2}'))
+ r'\d{2}\.\d{2}\.\d{4}, \d{2}:\d{2}:\d{2}'))
if dates:
for date in dates:
for string in date:
diff --git a/recipes/lwn_weekly.recipe b/recipes/lwn_weekly.recipe
index d2a9f11a9b..39da52ef98 100644
--- a/recipes/lwn_weekly.recipe
+++ b/recipes/lwn_weekly.recipe
@@ -121,7 +121,7 @@ class WeeklyLWN(BasicNewsRecipe):
if article_anchor:
article_url = article_anchor.get('href')
if not article_url:
- print('article_url is None for article_anchor "%s": "%s"' \
+ print('article_url is None for article_anchor "%s": "%s"'
% (str(article_anchor), article_title), file=sys.stderr)
continue
diff --git a/recipes/metro_news_nl.recipe b/recipes/metro_news_nl.recipe
index 8f2127130f..205f71c596 100644
--- a/recipes/metro_news_nl.recipe
+++ b/recipes/metro_news_nl.recipe
@@ -84,11 +84,11 @@ class AdvancedUserRecipe1306097511(BasicNewsRecipe):
remove_tags = [
dict(name=['iframe', 'script', 'noscript', 'style']),
dict(name='div', attrs={'class': ['fact-related-box', 'aside clearfix', 'aside clearfix middle-col-line', 'comments', 'share-tools', 'article-right-column', 'column-4-5', 'column-1-5', 'ad-msg', 'col-179 ', 'col-373 ', 'clear', 'ad', 'navigation', re.compile('share-tools(-top)?'), 'tools', 'metroCommentFormWrap', 'article-tools-below-title', 'related-links', 'padding-top-15', re.compile('^promo.*?$'), 'teaser-component', re.compile('fb(-comments|_iframe_widget)'), 'promos', 'header-links', 'promo-2']}), # noqa
- dict(id=['super-carousel', 'article-2', 'googleads', 'column-1-5-bottom', 'column-4-5', re.compile('^ad(\d+|adcomp.*?)?$'), 'adadcomp-4', 'margin-5', 'sidebar', re.compile('^article-\d'), 'comments', 'gallery-1', 'sharez_container', 'ts-container', 'topshares', 'ts-title']), # noqa
+ dict(id=['super-carousel', 'article-2', 'googleads', 'column-1-5-bottom', 'column-4-5', re.compile('^ad(\\d+|adcomp.*?)?$'), 'adadcomp-4', 'margin-5', 'sidebar', re.compile('^article-\\d'), 'comments', 'gallery-1', 'sharez_container', 'ts-container', 'topshares', 'ts-title']), # noqa
dict(name='a', attrs={'name': 'comments'}),
dict(name='img', attrs={'class': 'top-line',
'title': 'volledig scherm'}),
- dict(attrs={'style': re.compile('^(.*(display\s?:\s?none|img-mask|white)\s?;?.*)$'), 'title': 'volledig scherm'})]
+ dict(attrs={'style': re.compile('^(.*(display\\s?:\\s?none|img-mask|white)\\s?;?.*)$'), 'title': 'volledig scherm'})]
'''removed by before/after:
id:
@@ -223,7 +223,7 @@ class MerryProcess(BeautifulSoup):
return self.myKiller.safeRemovePart(souparray, True)
def removeEmptyTags(self, soup, run=0):
- emptymatches = re.compile('^[ \s\n\r\t ]*$')
+ emptymatches = re.compile('^[ \\s\n\r\t ]*$')
emptytags = soup.findAll(lambda tag: tag.find(True) is None and (
tag.string is None or tag.string.strip() == "" or tag.string.strip() == emptymatches) and not tag.isSelfClosing)
if emptytags and not (emptytags is None or emptytags == []):
diff --git a/recipes/observatorul_cultural.recipe b/recipes/observatorul_cultural.recipe
index 34b7ebe8f3..6f786b199e 100644
--- a/recipes/observatorul_cultural.recipe
+++ b/recipes/observatorul_cultural.recipe
@@ -29,7 +29,7 @@ class ObservatorulCultural(BasicNewsRecipe):
soup = self.index_to_soup(
'http://www.observatorcultural.ro/Arhiva*-archive.html')
issueTag = soup.find('a', href=re.compile(
- "observatorcultural.ro\/Numarul"))
+ "observatorcultural.ro\\/Numarul"))
issueURL = issueTag['href']
print(issueURL)
issueSoup = self.index_to_soup(issueURL)
diff --git a/src/calibre/customize/zipplugin.py b/src/calibre/customize/zipplugin.py
index 6028e5cb33..3c82c72640 100644
--- a/src/calibre/customize/zipplugin.py
+++ b/src/calibre/customize/zipplugin.py
@@ -83,6 +83,7 @@ def get_icons(zfp, name_or_list_of_names):
ians = ians.pop(names[0])
return ians
+
_translations_cache = {}
@@ -316,4 +317,3 @@ if __name__ == '__main__':
zf.write(os.path.join(x, y))
add_plugin(f.name)
print('Added plugin from', sys.argv[-1])
-
diff --git a/src/calibre/db/tests/profiling.py b/src/calibre/db/tests/profiling.py
index c8d77301a1..8e40524b48 100644
--- a/src/calibre/db/tests/profiling.py
+++ b/src/calibre/db/tests/profiling.py
@@ -40,5 +40,6 @@ def main():
show_stats(stats)
print('Stats saved to', stats)
+
if __name__ == '__main__':
main()
diff --git a/src/calibre/devices/cli.py b/src/calibre/devices/cli.py
index d9182d0c94..8dd8ca282b 100755
--- a/src/calibre/devices/cli.py
+++ b/src/calibre/devices/cli.py
@@ -221,7 +221,7 @@ def main():
try:
d.startup()
except:
- print ('Startup failed for device plugin: %s'%d)
+ print('Startup failed for device plugin: %s'%d)
if d.MANAGES_DEVICE_PRESENCE:
cd = d.detect_managed_devices(scanner.devices)
if cd is not None:
@@ -395,5 +395,6 @@ def main():
return 0
+
if __name__ == '__main__':
main()
diff --git a/src/calibre/devices/mtp/windows/remote.py b/src/calibre/devices/mtp/windows/remote.py
index 8974388164..fc0b78879c 100644
--- a/src/calibre/devices/mtp/windows/remote.py
+++ b/src/calibre/devices/mtp/windows/remote.py
@@ -93,8 +93,8 @@ def main():
finally:
dev.shutdown()
- print ('Device connection shutdown')
+ print('Device connection shutdown')
+
if __name__ == '__main__':
main()
-
diff --git a/src/calibre/devices/udisks.py b/src/calibre/devices/udisks.py
index 70d7bbbfac..70e924eac5 100644
--- a/src/calibre/devices/udisks.py
+++ b/src/calibre/devices/udisks.py
@@ -211,7 +211,6 @@ def test_udisks(ver=None):
print('Ejecting:')
u.eject(dev)
+
if __name__ == '__main__':
test_udisks()
-
-
diff --git a/src/calibre/devices/winusb.py b/src/calibre/devices/winusb.py
index ce8b239555..5b1a005328 100644
--- a/src/calibre/devices/winusb.py
+++ b/src/calibre/devices/winusb.py
@@ -53,6 +53,7 @@ class GUID(Structure):
''.join(["%02x" % d for d in self.data4[2:]]),
)
+
CONFIGRET = DWORD
DEVINST = DWORD
LPDWORD = POINTER(DWORD)
@@ -70,6 +71,8 @@ def CTL_CODE(DeviceType, Function, Method, Access):
def USB_CTL(id):
# CTL_CODE(FILE_DEVICE_USB, (id), METHOD_BUFFERED, FILE_ANY_ACCESS)
return CTL_CODE(0x22, id, 0, 0)
+
+
IOCTL_USB_GET_ROOT_HUB_NAME = USB_CTL(258)
IOCTL_USB_GET_NODE_INFORMATION = USB_CTL(258)
IOCTL_USB_GET_NODE_CONNECTION_INFORMATION = USB_CTL(259)
@@ -108,6 +111,7 @@ class SP_DEVINFO_DATA(Structure):
def __str__(self):
return "ClassGuid:%s DevInst:%s" % (self.ClassGuid, self.DevInst)
+
PSP_DEVINFO_DATA = POINTER(SP_DEVINFO_DATA)
@@ -122,6 +126,7 @@ class SP_DEVICE_INTERFACE_DATA(Structure):
def __str__(self):
return "InterfaceClassGuid:%s Flags:%s" % (self.InterfaceClassGuid, self.Flags)
+
ANYSIZE_ARRAY = 1
@@ -131,6 +136,7 @@ class SP_DEVICE_INTERFACE_DETAIL_DATA(Structure):
("DevicePath", c_wchar*ANYSIZE_ARRAY)
]
+
UCHAR = c_ubyte
@@ -216,6 +222,7 @@ class USB_DESCRIPTOR_REQUEST(Structure):
('Data', USB_STRING_DESCRIPTOR),
)
+
PUSB_DESCRIPTOR_REQUEST = POINTER(USB_DESCRIPTOR_REQUEST)
PSP_DEVICE_INTERFACE_DETAIL_DATA = POINTER(SP_DEVICE_INTERFACE_DETAIL_DATA)
PSP_DEVICE_INTERFACE_DATA = POINTER(SP_DEVICE_INTERFACE_DATA)
@@ -390,6 +397,7 @@ def config_err_check(result, func, args):
raise WindowsError(result, 'The cfgmgr32 function failed with err: %s' % CR_CODE_NAMES.get(result, result))
return args
+
GetLogicalDrives = cwrap('GetLogicalDrives', DWORD, errcheck=bool_err_check, lib=kernel32)
GetDriveType = cwrap('GetDriveTypeW', UINT, LPCWSTR, lib=kernel32)
GetVolumeNameForVolumeMountPoint = cwrap('GetVolumeNameForVolumeMountPointW', BOOL, LPCWSTR, LPWSTR, DWORD, errcheck=bool_err_check, lib=kernel32)
@@ -675,6 +683,7 @@ def get_volume_pathnames(volume_id, buf=None):
# def scan_usb_devices(): {{{
+
_USBDevice = namedtuple('USBDevice', 'vendor_id product_id bcd devid devinst')
@@ -1017,6 +1026,7 @@ def drives_for(vendor_id, product_id=None):
pprint(get_drive_letters_for_device(usbdev, debug=True))
print('USB info:', get_usb_info(usbdev, debug=True))
+
if __name__ == '__main__':
develop()
# }}}
diff --git a/src/calibre/ebooks/conversion/utils.py b/src/calibre/ebooks/conversion/utils.py
index 3e74f87e7e..886c9a97be 100644
--- a/src/calibre/ebooks/conversion/utils.py
+++ b/src/calibre/ebooks/conversion/utils.py
@@ -32,11 +32,11 @@ class HeuristicProcessor(object):
self.multi_blank = re.compile(r'(\s*]*>\s*
(\s*]*>\s*
\s*)*){2,}(?!\s*]*>\s*
(\s*]*>\s*
\s*)*){2,}', re.IGNORECASE)
self.line_open = "<(?Pp|div)[^>]*>\s*(<(?Pfont|span|[ibu])[^>]*>)?\s*(<(?Pfont|span|[ibu])[^>]*>)?\s*(<(?Pfont|span|[ibu])[^>]*>)?\s*" # noqa
- self.line_close = "((?P=inner3)>)?\s*((?P=inner2)>)?\s*((?P=inner1)>)?\s*(?P=outer)>"
+ self.line_close = "((?P=inner3)>)?\\s*((?P=inner2)>)?\\s*((?P=inner1)>)?\\s*(?P=outer)>"
self.single_blank = re.compile(r'(\s*<(p|div)[^>]*>\s*(p|div)>)', re.IGNORECASE)
self.scene_break_open = ''
- self.common_in_text_endings = u'[\"\'—’”,\.!\?\…\)„\w]'
- self.common_in_text_beginnings = u'[\w\'\"“‘‛]'
+ self.common_in_text_endings = u'[\"\'—’”,\\.!\\?\\…\\)„\\w]'
+ self.common_in_text_beginnings = u'[\\w\'\"“‘‛]'
def is_pdftohtml(self, src):
return '' in src[:1000]
@@ -54,10 +54,10 @@ class HeuristicProcessor(object):
" chapters. - " + unicode(chap))
return '
'+chap+'
\n'
else:
- delete_whitespace = re.compile('^\s*(?P.*?)\s*$')
+ delete_whitespace = re.compile('^\\s*(?P.*?)\\s*$')
delete_quotes = re.compile('\'\"')
- txt_chap = delete_quotes.sub('', delete_whitespace.sub('\g', html2text(chap)))
- txt_title = delete_quotes.sub('', delete_whitespace.sub('\g', html2text(title)))
+ txt_chap = delete_quotes.sub('', delete_whitespace.sub('\\g', html2text(chap)))
+ txt_title = delete_quotes.sub('', delete_whitespace.sub('\\g', html2text(title)))
self.html_preprocess_sections = self.html_preprocess_sections + 1
self.log.debug("marked " + unicode(self.html_preprocess_sections) +
" chapters & titles. - " + unicode(chap) + ", " + unicode(title))
@@ -216,24 +216,24 @@ class HeuristicProcessor(object):
title_line_open = "<(?Pp|div)[^>]*>\s*(<(?Pfont|span|[ibu])[^>]*>)?\s*(<(?Pfont|span|[ibu])[^>]*>)?\s*(<(?Pfont|span|[ibu])[^>]*>)?\s*" # noqa
chapter_header_open = r"(?P"
title_header_open = r"(?P"
- chapter_header_close = ")\s*"
+ chapter_header_close = ")\\s*"
title_header_close = ")"
chapter_line_close = self.line_close
- title_line_close = "((?P=inner6)>)?\s*((?P=inner5)>)?\s*((?P=inner4)>)?\s*(?P=outer2)>"
+ title_line_close = "((?P=inner6)>)?\\s*((?P=inner5)>)?\\s*((?P=inner4)>)?\\s*(?P=outer2)>"
is_pdftohtml = self.is_pdftohtml(html)
if is_pdftohtml:
- title_line_open = "<(?Pp)[^>]*>\s*"
- title_line_close = "\s*(?P=outer2)>"
+ title_line_open = "<(?Pp)[^>]*>\\s*"
+ title_line_close = "\\s*(?P=outer2)>"
if blanks_between_paragraphs:
- blank_lines = "(\s*]*>\s*
){0,2}\s*"
+ blank_lines = "(\\s*]*>\\s*
){0,2}\\s*"
else:
blank_lines = ""
opt_title_open = "("
opt_title_close = ")?"
- n_lookahead_open = "(?!\s*"
- n_lookahead_close = ")\s*"
+ n_lookahead_open = "(?!\\s*"
+ n_lookahead_close = ")\\s*"
default_title = r"(<[ibu][^>]*>)?\s{0,3}(?!Chapter)([\w\:\'’\"-]+\s{0,3}){1,5}?([ibu][^>]*>)?(?=<)"
simple_title = r"(<[ibu][^>]*>)?\s{0,3}(?!(Chapter|\s+<)).{0,65}?([ibu][^>]*>)?(?=<)"
@@ -358,12 +358,12 @@ class HeuristicProcessor(object):
# define the pieces of the regex
# (?(span|[iub])>)?\s*((p|div)>)?"
- blanklines = "\s*(?P<(p|span|div)[^>]*>\s*(<(p|span|div)[^>]*>\s*(span|p|div)>\s*)(span|p|div)>\s*){0,3}\s*"
- line_opening = "<(p|div)[^>]*>\s*(?P<(span|[iub])[^>]*>)?\s*"
+ line_ending = "\\s*(?P(span|[iub])>)?\\s*((p|div)>)?"
+ blanklines = "\\s*(?P<(p|span|div)[^>]*>\\s*(<(p|span|div)[^>]*>\\s*(span|p|div)>\\s*)(span|p|div)>\\s*){0,3}\\s*"
+ line_opening = "<(p|div)[^>]*>\\s*(?P<(span|[iub])[^>]*>)?\\s*"
txt_line_wrap = u"((\u0020|\u0009)*\n){1,4}"
if format == 'txt':
@@ -414,8 +414,8 @@ class HeuristicProcessor(object):
return html
def arrange_htm_line_endings(self, html):
- html = re.sub(r"\s*(?Pp|div)>", ""+"\g"+">\n", html)
- html = re.sub(r"\s*<(?Pp|div)(?P