mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Change except clauses to use the cleaner as keyword
This commit is contained in:
parent
5be578a9fd
commit
2c782a4938
@ -282,7 +282,7 @@ def main():
|
|||||||
outfile = os.path.join(outfile, path[path.rfind("/")+1:])
|
outfile = os.path.join(outfile, path[path.rfind("/")+1:])
|
||||||
try:
|
try:
|
||||||
outfile = open(outfile, "wb")
|
outfile = open(outfile, "wb")
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >> sys.stderr, e
|
print >> sys.stderr, e
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
return 1
|
return 1
|
||||||
@ -291,13 +291,13 @@ def main():
|
|||||||
elif args[1].startswith("prs500:"):
|
elif args[1].startswith("prs500:"):
|
||||||
try:
|
try:
|
||||||
infile = open(args[0], "rb")
|
infile = open(args[0], "rb")
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >> sys.stderr, e
|
print >> sys.stderr, e
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
return 1
|
return 1
|
||||||
try:
|
try:
|
||||||
dev.put_file(infile, args[1][7:])
|
dev.put_file(infile, args[1][7:])
|
||||||
except PathError, err:
|
except PathError as err:
|
||||||
if options.force and 'exists' in str(err):
|
if options.force and 'exists' in str(err):
|
||||||
dev.del_file(err.path, False)
|
dev.del_file(err.path, False)
|
||||||
dev.put_file(infile, args[1][7:])
|
dev.put_file(infile, args[1][7:])
|
||||||
@ -355,7 +355,7 @@ def main():
|
|||||||
return 1
|
return 1
|
||||||
except DeviceLocked:
|
except DeviceLocked:
|
||||||
print >> sys.stderr, "The device is locked. Use the --unlock option"
|
print >> sys.stderr, "The device is locked. Use the --unlock option"
|
||||||
except (ArgumentError, DeviceError), e:
|
except (ArgumentError, DeviceError) as e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
@ -177,7 +177,7 @@ class PRS500(DeviceConfig, DevicePlugin):
|
|||||||
dev.send_validated_command(BeginEndSession(end=True))
|
dev.send_validated_command(BeginEndSession(end=True))
|
||||||
dev.in_session = False
|
dev.in_session = False
|
||||||
raise
|
raise
|
||||||
except USBError, err:
|
except USBError as err:
|
||||||
if "No such device" in str(err):
|
if "No such device" in str(err):
|
||||||
raise DeviceError()
|
raise DeviceError()
|
||||||
elif "Connection timed out" in str(err):
|
elif "Connection timed out" in str(err):
|
||||||
@ -272,7 +272,7 @@ class PRS500(DeviceConfig, DevicePlugin):
|
|||||||
self.bulk_read_max_packet_size = red.MaxPacketSize
|
self.bulk_read_max_packet_size = red.MaxPacketSize
|
||||||
self.bulk_write_max_packet_size = wed.MaxPacketSize
|
self.bulk_write_max_packet_size = wed.MaxPacketSize
|
||||||
self.handle.claim_interface(self.INTERFACE_ID)
|
self.handle.claim_interface(self.INTERFACE_ID)
|
||||||
except USBError, err:
|
except USBError as err:
|
||||||
raise DeviceBusy(str(err))
|
raise DeviceBusy(str(err))
|
||||||
# Large timeout as device may still be initializing
|
# Large timeout as device may still be initializing
|
||||||
res = self.send_validated_command(GetUSBProtocolVersion(), timeout=20000)
|
res = self.send_validated_command(GetUSBProtocolVersion(), timeout=20000)
|
||||||
@ -303,7 +303,7 @@ class PRS500(DeviceConfig, DevicePlugin):
|
|||||||
try:
|
try:
|
||||||
self.handle.reset()
|
self.handle.reset()
|
||||||
self.handle.release_interface(self.INTERFACE_ID)
|
self.handle.release_interface(self.INTERFACE_ID)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
print >> sys.stderr, err
|
print >> sys.stderr, err
|
||||||
self.handle, self.device = None, None
|
self.handle, self.device = None, None
|
||||||
self.in_session = False
|
self.in_session = False
|
||||||
@ -509,7 +509,7 @@ class PRS500(DeviceConfig, DevicePlugin):
|
|||||||
outfile.write("".join(map(chr, packets[0][16:])))
|
outfile.write("".join(map(chr, packets[0][16:])))
|
||||||
for i in range(1, len(packets)):
|
for i in range(1, len(packets)):
|
||||||
outfile.write("".join(map(chr, packets[i])))
|
outfile.write("".join(map(chr, packets[i])))
|
||||||
except IOError, err:
|
except IOError as err:
|
||||||
self.send_validated_command(FileClose(_id))
|
self.send_validated_command(FileClose(_id))
|
||||||
raise ArgumentError("File get operation failed. " + \
|
raise ArgumentError("File get operation failed. " + \
|
||||||
"Could not write to local location: " + str(err))
|
"Could not write to local location: " + str(err))
|
||||||
@ -656,7 +656,7 @@ class PRS500(DeviceConfig, DevicePlugin):
|
|||||||
dest = None
|
dest = None
|
||||||
try:
|
try:
|
||||||
dest = self.path_properties(path, end_session=False)
|
dest = self.path_properties(path, end_session=False)
|
||||||
except PathError, err:
|
except PathError as err:
|
||||||
if "does not exist" in str(err) or "not mounted" in str(err):
|
if "does not exist" in str(err) or "not mounted" in str(err):
|
||||||
return (False, None)
|
return (False, None)
|
||||||
else: raise
|
else: raise
|
||||||
|
@ -128,7 +128,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
try:
|
try:
|
||||||
sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \
|
sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \
|
||||||
win32file.GetDiskFreeSpace(prefix)
|
win32file.GetDiskFreeSpace(prefix)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
if getattr(err, 'args', [None])[0] == 21: # Disk not ready
|
if getattr(err, 'args', [None])[0] == 21: # Disk not ready
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \
|
sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \
|
||||||
@ -771,7 +771,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
for d in drives:
|
for d in drives:
|
||||||
try:
|
try:
|
||||||
eject(d)
|
eject(d)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print 'Udisks eject call for:', d, 'failed:'
|
print 'Udisks eject call for:', d, 'failed:'
|
||||||
print '\t', e
|
print '\t', e
|
||||||
failures = True
|
failures = True
|
||||||
|
@ -57,7 +57,7 @@ class HTMLRenderer(object):
|
|||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QBuffer.WriteOnly)
|
||||||
image.save(buf, 'JPEG')
|
image.save(buf, 'JPEG')
|
||||||
self.data = str(ba.data())
|
self.data = str(ba.data())
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.traceback = traceback.format_exc()
|
self.traceback = traceback.format_exc()
|
||||||
finally:
|
finally:
|
||||||
|
@ -151,7 +151,7 @@ class Container(object):
|
|||||||
if name in self.mime_map:
|
if name in self.mime_map:
|
||||||
try:
|
try:
|
||||||
raw = self._parse(raw, self.mime_map[name])
|
raw = self._parse(raw, self.mime_map[name])
|
||||||
except XMLSyntaxError, err:
|
except XMLSyntaxError as err:
|
||||||
raise ParseError(name, unicode(err))
|
raise ParseError(name, unicode(err))
|
||||||
self.cache[name] = raw
|
self.cache[name] = raw
|
||||||
return raw
|
return raw
|
||||||
|
@ -54,7 +54,7 @@ def main(args=sys.argv):
|
|||||||
epub = os.path.abspath(args[1])
|
epub = os.path.abspath(args[1])
|
||||||
try:
|
try:
|
||||||
run(epub, opts, default_log)
|
run(epub, opts, default_log)
|
||||||
except ParseError, err:
|
except ParseError as err:
|
||||||
default_log.error(unicode(err))
|
default_log.error(unicode(err))
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class HTMLFile(object):
|
|||||||
try:
|
try:
|
||||||
with open(self.path, 'rb') as f:
|
with open(self.path, 'rb') as f:
|
||||||
src = f.read()
|
src = f.read()
|
||||||
except IOError, err:
|
except IOError as err:
|
||||||
msg = 'Could not read from file: %s with error: %s'%(self.path, as_unicode(err))
|
msg = 'Could not read from file: %s with error: %s'%(self.path, as_unicode(err))
|
||||||
if level == 0:
|
if level == 0:
|
||||||
raise IOError(msg)
|
raise IOError(msg)
|
||||||
@ -202,7 +202,7 @@ def traverse(path_to_html_file, max_levels=sys.maxint, verbose=0, encoding=None)
|
|||||||
raise IgnoreFile('%s is a binary file'%nf.path, -1)
|
raise IgnoreFile('%s is a binary file'%nf.path, -1)
|
||||||
nl.append(nf)
|
nl.append(nf)
|
||||||
flat.append(nf)
|
flat.append(nf)
|
||||||
except IgnoreFile, err:
|
except IgnoreFile as err:
|
||||||
rejects.append(link)
|
rejects.append(link)
|
||||||
if not err.doesnt_exist or verbose > 1:
|
if not err.doesnt_exist or verbose > 1:
|
||||||
print repr(err)
|
print repr(err)
|
||||||
|
@ -332,7 +332,7 @@ class HTMLConverter(object):
|
|||||||
soup = BeautifulSoup(raw,
|
soup = BeautifulSoup(raw,
|
||||||
convertEntities=BeautifulSoup.XHTML_ENTITIES,
|
convertEntities=BeautifulSoup.XHTML_ENTITIES,
|
||||||
markupMassage=nmassage)
|
markupMassage=nmassage)
|
||||||
except ConversionError, err:
|
except ConversionError as err:
|
||||||
if 'Failed to coerce to unicode' in str(err):
|
if 'Failed to coerce to unicode' in str(err):
|
||||||
raw = unicode(raw, 'utf8', 'replace')
|
raw = unicode(raw, 'utf8', 'replace')
|
||||||
soup = BeautifulSoup(raw,
|
soup = BeautifulSoup(raw,
|
||||||
@ -935,7 +935,7 @@ class HTMLConverter(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
im = PILImage.open(path)
|
im = PILImage.open(path)
|
||||||
except IOError, err:
|
except IOError as err:
|
||||||
self.log.warning('Unable to process image: %s\n%s'%( original_path, err))
|
self.log.warning('Unable to process image: %s\n%s'%( original_path, err))
|
||||||
return
|
return
|
||||||
encoding = detect_encoding(im)
|
encoding = detect_encoding(im)
|
||||||
@ -953,7 +953,7 @@ class HTMLConverter(object):
|
|||||||
pt.close()
|
pt.close()
|
||||||
self.scaled_images[path] = pt
|
self.scaled_images[path] = pt
|
||||||
return pt.name
|
return pt.name
|
||||||
except (IOError, SystemError), err: # PIL chokes on interlaced PNG images as well a some GIF images
|
except (IOError, SystemError) as err: # PIL chokes on interlaced PNG images as well a some GIF images
|
||||||
self.log.warning(_('Unable to process image %s. Error: %s')%(path, err))
|
self.log.warning(_('Unable to process image %s. Error: %s')%(path, err))
|
||||||
|
|
||||||
if width == None or height == None:
|
if width == None or height == None:
|
||||||
@ -1013,7 +1013,7 @@ class HTMLConverter(object):
|
|||||||
if not self.images.has_key(path):
|
if not self.images.has_key(path):
|
||||||
try:
|
try:
|
||||||
self.images[path] = ImageStream(path, encoding=encoding)
|
self.images[path] = ImageStream(path, encoding=encoding)
|
||||||
except LrsError, err:
|
except LrsError as err:
|
||||||
self.log.warning(_('Could not process image: %s\n%s')%(
|
self.log.warning(_('Could not process image: %s\n%s')%(
|
||||||
original_path, err))
|
original_path, err))
|
||||||
return
|
return
|
||||||
@ -1768,7 +1768,7 @@ class HTMLConverter(object):
|
|||||||
tag_css = self.tag_css(tag)[0] # Table should not inherit CSS
|
tag_css = self.tag_css(tag)[0] # Table should not inherit CSS
|
||||||
try:
|
try:
|
||||||
self.process_table(tag, tag_css)
|
self.process_table(tag, tag_css)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
self.log.warning(_('An error occurred while processing a table: %s. Ignoring table markup.')%repr(err))
|
self.log.warning(_('An error occurred while processing a table: %s. Ignoring table markup.')%repr(err))
|
||||||
self.log.exception('')
|
self.log.exception('')
|
||||||
self.log.debug(_('Bad table:\n%s')%unicode(tag)[:300])
|
self.log.debug(_('Bad table:\n%s')%unicode(tag)[:300])
|
||||||
@ -1858,7 +1858,7 @@ def process_file(path, options, logger):
|
|||||||
tf.close()
|
tf.close()
|
||||||
tim.save(tf.name)
|
tim.save(tf.name)
|
||||||
tpath = tf.name
|
tpath = tf.name
|
||||||
except IOError, err: # PIL sometimes fails, for example on interlaced PNG files
|
except IOError as err: # PIL sometimes fails, for example on interlaced PNG files
|
||||||
logger.warn(_('Could not read cover image: %s'), err)
|
logger.warn(_('Could not read cover image: %s'), err)
|
||||||
options.cover = None
|
options.cover = None
|
||||||
else:
|
else:
|
||||||
|
@ -108,7 +108,7 @@ def _get_cover_url(br, asin):
|
|||||||
q = 'http://amzn.com/'+asin
|
q = 'http://amzn.com/'+asin
|
||||||
try:
|
try:
|
||||||
raw = br.open_novisit(q).read()
|
raw = br.open_novisit(q).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
return None
|
return None
|
||||||
@ -139,7 +139,7 @@ def get_metadata(br, asin, mi):
|
|||||||
q = 'http://amzn.com/'+asin
|
q = 'http://amzn.com/'+asin
|
||||||
try:
|
try:
|
||||||
raw = br.open_novisit(q).read()
|
raw = br.open_novisit(q).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
return False
|
return False
|
||||||
|
@ -33,7 +33,7 @@ class AmazonFr(MetadataSource):
|
|||||||
try:
|
try:
|
||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10, verbose=self.verbose, lang='fr')
|
self.isbn, max_results=10, verbose=self.verbose, lang='fr')
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class AmazonEs(MetadataSource):
|
|||||||
try:
|
try:
|
||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10, verbose=self.verbose, lang='es')
|
self.isbn, max_results=10, verbose=self.verbose, lang='es')
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ class AmazonEn(MetadataSource):
|
|||||||
try:
|
try:
|
||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10, verbose=self.verbose, lang='en')
|
self.isbn, max_results=10, verbose=self.verbose, lang='en')
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ class AmazonDe(MetadataSource):
|
|||||||
try:
|
try:
|
||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10, verbose=self.verbose, lang='de')
|
self.isbn, max_results=10, verbose=self.verbose, lang='de')
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ class Amazon(MetadataSource):
|
|||||||
try:
|
try:
|
||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10, verbose=self.verbose, lang='all')
|
self.isbn, max_results=10, verbose=self.verbose, lang='all')
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ class Query(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
raw = browser.open_novisit(self.urldata, timeout=timeout).read()
|
raw = browser.open_novisit(self.urldata, timeout=timeout).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
report(verbose)
|
report(verbose)
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
@ -226,7 +226,7 @@ class Query(object):
|
|||||||
try:
|
try:
|
||||||
urldata = self.urldata + '&page=' + str(i)
|
urldata = self.urldata + '&page=' + str(i)
|
||||||
raw = browser.open_novisit(urldata, timeout=timeout).read()
|
raw = browser.open_novisit(urldata, timeout=timeout).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
continue
|
continue
|
||||||
if '<title>404 - ' in raw:
|
if '<title>404 - ' in raw:
|
||||||
continue
|
continue
|
||||||
@ -413,7 +413,7 @@ class ResultList(list):
|
|||||||
def get_individual_metadata(self, browser, linkdata, verbose):
|
def get_individual_metadata(self, browser, linkdata, verbose):
|
||||||
try:
|
try:
|
||||||
raw = browser.open_novisit(linkdata).read()
|
raw = browser.open_novisit(linkdata).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
report(verbose)
|
report(verbose)
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
@ -445,7 +445,7 @@ class ResultList(list):
|
|||||||
# self.clean_entry(entry, invalid_id=inv_ids)
|
# self.clean_entry(entry, invalid_id=inv_ids)
|
||||||
title = self.get_title(entry)
|
title = self.get_title(entry)
|
||||||
authors = self.get_authors(entry)
|
authors = self.get_authors(entry)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Failed to get all details for an entry'
|
print 'Failed to get all details for an entry'
|
||||||
print e
|
print e
|
||||||
|
@ -91,7 +91,7 @@ class OpenLibraryCovers(CoverDownload): # {{{
|
|||||||
br.open_novisit(HeadRequest(self.OPENLIBRARY%mi.isbn), timeout=timeout)
|
br.open_novisit(HeadRequest(self.OPENLIBRARY%mi.isbn), timeout=timeout)
|
||||||
self.debug('cover for', mi.isbn, 'found')
|
self.debug('cover for', mi.isbn, 'found')
|
||||||
ans.set()
|
ans.set()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if callable(getattr(e, 'getcode', None)) and e.getcode() == 302:
|
if callable(getattr(e, 'getcode', None)) and e.getcode() == 302:
|
||||||
self.debug('cover for', mi.isbn, 'found')
|
self.debug('cover for', mi.isbn, 'found')
|
||||||
ans.set()
|
ans.set()
|
||||||
@ -106,7 +106,7 @@ class OpenLibraryCovers(CoverDownload): # {{{
|
|||||||
try:
|
try:
|
||||||
ans = br.open(self.OPENLIBRARY%mi.isbn, timeout=timeout).read()
|
ans = br.open(self.OPENLIBRARY%mi.isbn, timeout=timeout).read()
|
||||||
result_queue.put((True, ans, 'jpg', self.name))
|
result_queue.put((True, ans, 'jpg', self.name))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if callable(getattr(e, 'getcode', None)) and e.getcode() == 404:
|
if callable(getattr(e, 'getcode', None)) and e.getcode() == 404:
|
||||||
result_queue.put((False, _('ISBN: %s not found')%mi.isbn, '', self.name))
|
result_queue.put((False, _('ISBN: %s not found')%mi.isbn, '', self.name))
|
||||||
else:
|
else:
|
||||||
@ -131,7 +131,7 @@ class AmazonCovers(CoverDownload): # {{{
|
|||||||
get_cover_url(mi.isbn, br)
|
get_cover_url(mi.isbn, br)
|
||||||
self.debug('cover for', mi.isbn, 'found')
|
self.debug('cover for', mi.isbn, 'found')
|
||||||
ans.set()
|
ans.set()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.debug(e)
|
self.debug(e)
|
||||||
|
|
||||||
def get_covers(self, mi, result_queue, abort, timeout=5.):
|
def get_covers(self, mi, result_queue, abort, timeout=5.):
|
||||||
@ -145,7 +145,7 @@ class AmazonCovers(CoverDownload): # {{{
|
|||||||
raise ValueError('No cover found for ISBN: %s'%mi.isbn)
|
raise ValueError('No cover found for ISBN: %s'%mi.isbn)
|
||||||
cover_data = br.open_novisit(url).read()
|
cover_data = br.open_novisit(url).read()
|
||||||
result_queue.put((True, cover_data, 'jpg', self.name))
|
result_queue.put((True, cover_data, 'jpg', self.name))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
result_queue.put((False, self.exception_to_string(e),
|
result_queue.put((False, self.exception_to_string(e),
|
||||||
traceback.format_exc(), self.name))
|
traceback.format_exc(), self.name))
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ class DoubanCovers(CoverDownload): # {{{
|
|||||||
try:
|
try:
|
||||||
url = self.DOUBAN_ISBN_URL + isbn + "?apikey=" + self.CALIBRE_DOUBAN_API_KEY
|
url = self.DOUBAN_ISBN_URL + isbn + "?apikey=" + self.CALIBRE_DOUBAN_API_KEY
|
||||||
src = br.open(url, timeout=timeout).read()
|
src = br.open(url, timeout=timeout).read()
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
if isinstance(getattr(err, 'args', [None])[0], socket.timeout):
|
if isinstance(getattr(err, 'args', [None])[0], socket.timeout):
|
||||||
err = Exception(_('Douban.com API timed out. Try again later.'))
|
err = Exception(_('Douban.com API timed out. Try again later.'))
|
||||||
raise err
|
raise err
|
||||||
@ -248,7 +248,7 @@ class DoubanCovers(CoverDownload): # {{{
|
|||||||
if self.get_cover_url(mi.isbn, br, timeout=timeout) != None:
|
if self.get_cover_url(mi.isbn, br, timeout=timeout) != None:
|
||||||
self.debug('cover for', mi.isbn, 'found')
|
self.debug('cover for', mi.isbn, 'found')
|
||||||
ans.set()
|
ans.set()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.debug(e)
|
self.debug(e)
|
||||||
|
|
||||||
def get_covers(self, mi, result_queue, abort, timeout=5.):
|
def get_covers(self, mi, result_queue, abort, timeout=5.):
|
||||||
@ -259,7 +259,7 @@ class DoubanCovers(CoverDownload): # {{{
|
|||||||
url = self.get_cover_url(mi.isbn, br, timeout=timeout)
|
url = self.get_cover_url(mi.isbn, br, timeout=timeout)
|
||||||
cover_data = br.open_novisit(url).read()
|
cover_data = br.open_novisit(url).read()
|
||||||
result_queue.put((True, cover_data, 'jpg', self.name))
|
result_queue.put((True, cover_data, 'jpg', self.name))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
result_queue.put((False, self.exception_to_string(e),
|
result_queue.put((False, self.exception_to_string(e),
|
||||||
traceback.format_exc(), self.name))
|
traceback.format_exc(), self.name))
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -49,7 +49,7 @@ class DoubanBooks(MetadataSource):
|
|||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10,
|
self.isbn, max_results=10,
|
||||||
verbose=self.verbose)
|
verbose=self.verbose)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ class ResultList(list):
|
|||||||
raw = browser.open(id_url).read()
|
raw = browser.open(id_url).read()
|
||||||
feed = etree.fromstring(raw)
|
feed = etree.fromstring(raw)
|
||||||
x = entry(feed)[0]
|
x = entry(feed)[0]
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Failed to get all details for an entry'
|
print 'Failed to get all details for an entry'
|
||||||
print e
|
print e
|
||||||
@ -212,7 +212,7 @@ def search(title=None, author=None, publisher=None, isbn=None,
|
|||||||
api_key = CALIBRE_DOUBAN_API_KEY
|
api_key = CALIBRE_DOUBAN_API_KEY
|
||||||
|
|
||||||
while start > 0 and len(entries) <= max_results:
|
while start > 0 and len(entries) <= max_results:
|
||||||
new, start = Query(title=title, author=author, publisher=publisher,
|
new, start = Query(title=title, author=author, publisher=publisher,
|
||||||
isbn=isbn, max_results=max_results, start_index=start, api_key=api_key)(br, verbose)
|
isbn=isbn, max_results=max_results, start_index=start, api_key=api_key)(br, verbose)
|
||||||
if not new:
|
if not new:
|
||||||
break
|
break
|
||||||
|
@ -93,7 +93,7 @@ class MetadataSource(Plugin): # {{{
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
mi.comments = None
|
mi.comments = None
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ class GoogleBooks(MetadataSource): # {{{
|
|||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10,
|
self.isbn, max_results=10,
|
||||||
verbose=self.verbose)
|
verbose=self.verbose)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ class ISBNDB(MetadataSource): # {{{
|
|||||||
try:
|
try:
|
||||||
opts, args = option_parser().parse_args(args)
|
opts, args = option_parser().parse_args(args)
|
||||||
self.results = create_books(opts, args)
|
self.results = create_books(opts, args)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ class Amazon(MetadataSource): # {{{
|
|||||||
try:
|
try:
|
||||||
self.results = get_social_metadata(self.title, self.book_author,
|
self.results = get_social_metadata(self.title, self.book_author,
|
||||||
self.publisher, self.isbn)
|
self.publisher, self.isbn)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ class KentDistrictLibrary(MetadataSource): # {{{
|
|||||||
from calibre.ebooks.metadata.kdl import get_series
|
from calibre.ebooks.metadata.kdl import get_series
|
||||||
try:
|
try:
|
||||||
self.results = get_series(self.title, self.book_author)
|
self.results = get_series(self.title, self.book_author)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
self.exception = e
|
self.exception = e
|
||||||
|
@ -30,7 +30,7 @@ class Fictionwise(MetadataSource): # {{{
|
|||||||
try:
|
try:
|
||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10, verbose=self.verbose)
|
self.isbn, max_results=10, verbose=self.verbose)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ class Query(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
raw = browser.open_novisit(self.BASE_URL, self.urldata, timeout=timeout).read()
|
raw = browser.open_novisit(self.BASE_URL, self.urldata, timeout=timeout).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
report(verbose)
|
report(verbose)
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
@ -276,7 +276,7 @@ class ResultList(list):
|
|||||||
def get_individual_metadata(self, browser, linkdata, verbose):
|
def get_individual_metadata(self, browser, linkdata, verbose):
|
||||||
try:
|
try:
|
||||||
raw = browser.open_novisit(self.BASE_URL + linkdata).read()
|
raw = browser.open_novisit(self.BASE_URL + linkdata).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
report(verbose)
|
report(verbose)
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
@ -311,7 +311,7 @@ class ResultList(list):
|
|||||||
#maybe strenghten the search
|
#maybe strenghten the search
|
||||||
ratings = self.get_rating(entry.xpath("./p/table")[1], verbose)
|
ratings = self.get_rating(entry.xpath("./p/table")[1], verbose)
|
||||||
authors = self.get_authors(entry)
|
authors = self.get_authors(entry)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if verbose:
|
if verbose:
|
||||||
print _('Failed to get all details for an entry')
|
print _('Failed to get all details for an entry')
|
||||||
print e
|
print e
|
||||||
@ -328,7 +328,7 @@ class ResultList(list):
|
|||||||
#maybe strenghten the search
|
#maybe strenghten the search
|
||||||
ratings = self.get_rating(entry.xpath("./p/table")[1], verbose)
|
ratings = self.get_rating(entry.xpath("./p/table")[1], verbose)
|
||||||
authors = self.get_authors(entry)
|
authors = self.get_authors(entry)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if verbose:
|
if verbose:
|
||||||
print _('Failed to get all details for an entry')
|
print _('Failed to get all details for an entry')
|
||||||
print e
|
print e
|
||||||
|
@ -176,7 +176,7 @@ class ResultList(list):
|
|||||||
raw = browser.open(id_url).read()
|
raw = browser.open(id_url).read()
|
||||||
feed = etree.fromstring(raw)
|
feed = etree.fromstring(raw)
|
||||||
x = entry(feed)[0]
|
x = entry(feed)[0]
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Failed to get all details for an entry'
|
print 'Failed to get all details for an entry'
|
||||||
print e
|
print e
|
||||||
|
@ -38,7 +38,7 @@ def get_metadata(stream):
|
|||||||
mi.author = author
|
mi.author = author
|
||||||
if category:
|
if category:
|
||||||
mi.category = category
|
mi.category = category
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
msg = u'Couldn\'t read metadata from imp: %s with error %s'%(mi.title, unicode(err))
|
msg = u'Couldn\'t read metadata from imp: %s with error %s'%(mi.title, unicode(err))
|
||||||
print >>sys.stderr, msg.encode('utf8')
|
print >>sys.stderr, msg.encode('utf8')
|
||||||
return mi
|
return mi
|
||||||
|
@ -25,7 +25,7 @@ def fetch_metadata(url, max=3, timeout=5.):
|
|||||||
while len(books) < total_results and max > 0:
|
while len(books) < total_results and max > 0:
|
||||||
try:
|
try:
|
||||||
raw = br.open(url, timeout=timeout).read()
|
raw = br.open(url, timeout=timeout).read()
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
raise ISBNDBError('Could not fetch ISBNDB metadata. Error: '+str(err))
|
raise ISBNDBError('Could not fetch ISBNDB metadata. Error: '+str(err))
|
||||||
soup = BeautifulStoneSoup(raw,
|
soup = BeautifulStoneSoup(raw,
|
||||||
convertEntities=BeautifulStoneSoup.XML_ENTITIES)
|
convertEntities=BeautifulStoneSoup.XML_ENTITIES)
|
||||||
|
@ -43,7 +43,7 @@ def get_series(title, authors, timeout=60):
|
|||||||
br = browser()
|
br = browser()
|
||||||
try:
|
try:
|
||||||
raw = br.open_novisit(url, timeout=timeout).read()
|
raw = br.open_novisit(url, timeout=timeout).read()
|
||||||
except URLError, e:
|
except URLError as e:
|
||||||
if isinstance(e.reason, socket.timeout):
|
if isinstance(e.reason, socket.timeout):
|
||||||
raise Exception('KDL Server busy, try again later')
|
raise Exception('KDL Server busy, try again later')
|
||||||
raise
|
raise
|
||||||
|
@ -45,7 +45,7 @@ def check_for_cover(isbn, timeout=5.):
|
|||||||
try:
|
try:
|
||||||
br.open_novisit(HeadRequest(OPENLIBRARY%isbn), timeout=timeout)
|
br.open_novisit(HeadRequest(OPENLIBRARY%isbn), timeout=timeout)
|
||||||
return True
|
return True
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if callable(getattr(e, 'getcode', None)) and e.getcode() == 302:
|
if callable(getattr(e, 'getcode', None)) and e.getcode() == 302:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -32,7 +32,7 @@ class NiceBooks(MetadataSource):
|
|||||||
try:
|
try:
|
||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10, verbose=self.verbose)
|
self.isbn, max_results=10, verbose=self.verbose)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ class NiceBooksCovers(CoverDownload):
|
|||||||
if Covers(mi.isbn)(entry).check_cover():
|
if Covers(mi.isbn)(entry).check_cover():
|
||||||
self.debug('cover for', mi.isbn, 'found')
|
self.debug('cover for', mi.isbn, 'found')
|
||||||
ans.set()
|
ans.set()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.debug(e)
|
self.debug(e)
|
||||||
|
|
||||||
def get_covers(self, mi, result_queue, abort, timeout=5.):
|
def get_covers(self, mi, result_queue, abort, timeout=5.):
|
||||||
@ -67,7 +67,7 @@ class NiceBooksCovers(CoverDownload):
|
|||||||
if not ext:
|
if not ext:
|
||||||
ext = 'jpg'
|
ext = 'jpg'
|
||||||
result_queue.put((True, cover_data, ext, self.name))
|
result_queue.put((True, cover_data, ext, self.name))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
result_queue.put((False, self.exception_to_string(e),
|
result_queue.put((False, self.exception_to_string(e),
|
||||||
traceback.format_exc(), self.name))
|
traceback.format_exc(), self.name))
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ class Query(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
raw = browser.open_novisit(self.BASE_URL+self.urldata, timeout=timeout).read()
|
raw = browser.open_novisit(self.BASE_URL+self.urldata, timeout=timeout).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
report(verbose)
|
report(verbose)
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
@ -144,7 +144,7 @@ class Query(object):
|
|||||||
try:
|
try:
|
||||||
urldata = self.urldata + '&p=' + str(i)
|
urldata = self.urldata + '&p=' + str(i)
|
||||||
raw = browser.open_novisit(self.BASE_URL+urldata, timeout=timeout).read()
|
raw = browser.open_novisit(self.BASE_URL+urldata, timeout=timeout).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
continue
|
continue
|
||||||
if '<title>404 - ' in raw:
|
if '<title>404 - ' in raw:
|
||||||
continue
|
continue
|
||||||
@ -233,7 +233,7 @@ class ResultList(list):
|
|||||||
def get_individual_metadata(self, browser, linkdata, verbose):
|
def get_individual_metadata(self, browser, linkdata, verbose):
|
||||||
try:
|
try:
|
||||||
raw = browser.open_novisit(self.BASE_URL + linkdata).read()
|
raw = browser.open_novisit(self.BASE_URL + linkdata).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
report(verbose)
|
report(verbose)
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
@ -266,7 +266,7 @@ class ResultList(list):
|
|||||||
entry = entry.find("div[@id='book-info']")
|
entry = entry.find("div[@id='book-info']")
|
||||||
title = self.get_title(entry)
|
title = self.get_title(entry)
|
||||||
authors = self.get_authors(entry)
|
authors = self.get_authors(entry)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Failed to get all details for an entry'
|
print 'Failed to get all details for an entry'
|
||||||
print e
|
print e
|
||||||
@ -280,7 +280,7 @@ class ResultList(list):
|
|||||||
entry = entry.find("div[@id='book-info']")
|
entry = entry.find("div[@id='book-info']")
|
||||||
title = self.get_title(entry)
|
title = self.get_title(entry)
|
||||||
authors = self.get_authors(entry)
|
authors = self.get_authors(entry)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Failed to get all details for an entry'
|
print 'Failed to get all details for an entry'
|
||||||
print e
|
print e
|
||||||
@ -315,7 +315,7 @@ class Covers(object):
|
|||||||
cover, ext = browser.open_novisit(self.urlimg, timeout=timeout).read(), \
|
cover, ext = browser.open_novisit(self.urlimg, timeout=timeout).read(), \
|
||||||
self.urlimg.rpartition('.')[-1]
|
self.urlimg.rpartition('.')[-1]
|
||||||
return cover, ext if ext else 'jpg'
|
return cover, ext if ext else 'jpg'
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
if isinstance(getattr(err, 'args', [None])[0], socket.timeout):
|
if isinstance(getattr(err, 'args', [None])[0], socket.timeout):
|
||||||
raise NiceBooksError(_('Nicebooks timed out. Try again later.'))
|
raise NiceBooksError(_('Nicebooks timed out. Try again later.'))
|
||||||
if not len(self.urlimg):
|
if not len(self.urlimg):
|
||||||
|
@ -43,7 +43,7 @@ def get_metadata(stream):
|
|||||||
elif key.strip() == 'AUTHOR':
|
elif key.strip() == 'AUTHOR':
|
||||||
mi.author = value
|
mi.author = value
|
||||||
mi.authors = string_to_authors(value)
|
mi.authors = string_to_authors(value)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
msg = u'Couldn\'t read metadata from rb: %s with error %s'%(mi.title, unicode(err))
|
msg = u'Couldn\'t read metadata from rb: %s with error %s'%(mi.title, unicode(err))
|
||||||
print >>sys.stderr, msg.encode('utf8')
|
print >>sys.stderr, msg.encode('utf8')
|
||||||
raise
|
raise
|
||||||
|
@ -46,7 +46,7 @@ class Worker(Thread): # {{{
|
|||||||
def get_details(self):
|
def get_details(self):
|
||||||
try:
|
try:
|
||||||
raw = self.browser.open_novisit(self.url, timeout=self.timeout).read().strip()
|
raw = self.browser.open_novisit(self.url, timeout=self.timeout).read().strip()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
self.log.error('URL malformed: %r'%self.url)
|
self.log.error('URL malformed: %r'%self.url)
|
||||||
@ -359,7 +359,7 @@ class Amazon(Source):
|
|||||||
br = self.browser
|
br = self.browser
|
||||||
try:
|
try:
|
||||||
raw = br.open_novisit(query, timeout=timeout).read().strip()
|
raw = br.open_novisit(query, timeout=timeout).read().strip()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
log.error('Query malformed: %r'%query)
|
log.error('Query malformed: %r'%query)
|
||||||
|
@ -213,7 +213,7 @@ class GoogleBooks(Source):
|
|||||||
br = self.browser
|
br = self.browser
|
||||||
try:
|
try:
|
||||||
raw = br.open_novisit(query, timeout=timeout).read()
|
raw = br.open_novisit(query, timeout=timeout).read()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
log.exception('Failed to make identify query: %r'%query)
|
log.exception('Failed to make identify query: %r'%query)
|
||||||
return as_unicode(e)
|
return as_unicode(e)
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ class GoogleBooks(Source):
|
|||||||
feed = etree.fromstring(xml_to_unicode(clean_ascii_chars(raw),
|
feed = etree.fromstring(xml_to_unicode(clean_ascii_chars(raw),
|
||||||
strip_encoding_pats=True)[0], parser=parser)
|
strip_encoding_pats=True)[0], parser=parser)
|
||||||
entries = entry(feed)
|
entries = entry(feed)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
log.exception('Failed to parse identify results')
|
log.exception('Failed to parse identify results')
|
||||||
return as_unicode(e)
|
return as_unicode(e)
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ class TOC(list):
|
|||||||
if path and os.access(path, os.R_OK):
|
if path and os.access(path, os.R_OK):
|
||||||
try:
|
try:
|
||||||
self.read_ncx_toc(path)
|
self.read_ncx_toc(path)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
print 'WARNING: Invalid NCX file:', err
|
print 'WARNING: Invalid NCX file:', err
|
||||||
return
|
return
|
||||||
cwd = os.path.abspath(self.base_path)
|
cwd = os.path.abspath(self.base_path)
|
||||||
|
@ -884,13 +884,13 @@ class Manifest(object):
|
|||||||
def first_pass(data):
|
def first_pass(data):
|
||||||
try:
|
try:
|
||||||
data = etree.fromstring(data, parser=parser)
|
data = etree.fromstring(data, parser=parser)
|
||||||
except etree.XMLSyntaxError, err:
|
except etree.XMLSyntaxError as err:
|
||||||
self.oeb.log.exception('Initial parse failed:')
|
self.oeb.log.exception('Initial parse failed:')
|
||||||
repl = lambda m: ENTITYDEFS.get(m.group(1), m.group(0))
|
repl = lambda m: ENTITYDEFS.get(m.group(1), m.group(0))
|
||||||
data = ENTITY_RE.sub(repl, data)
|
data = ENTITY_RE.sub(repl, data)
|
||||||
try:
|
try:
|
||||||
data = etree.fromstring(data, parser=parser)
|
data = etree.fromstring(data, parser=parser)
|
||||||
except etree.XMLSyntaxError, err:
|
except etree.XMLSyntaxError as err:
|
||||||
self.oeb.logger.warn('Parsing file %r as HTML' % self.href)
|
self.oeb.logger.warn('Parsing file %r as HTML' % self.href)
|
||||||
if err.args and err.args[0].startswith('Excessive depth'):
|
if err.args and err.args[0].startswith('Excessive depth'):
|
||||||
from lxml.html import soupparser
|
from lxml.html import soupparser
|
||||||
|
@ -103,7 +103,7 @@ def main(args=sys.argv, name=''):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
decrypt(args[0], opts.output, args[1])
|
decrypt(args[0], opts.output, args[1])
|
||||||
except DecryptionError, e:
|
except DecryptionError as e:
|
||||||
print e.value
|
print e.value
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ def pdftohtml(output_dir, pdf_path, no_images):
|
|||||||
try:
|
try:
|
||||||
p = popen(cmd, stderr=logf._fd, stdout=logf._fd,
|
p = popen(cmd, stderr=logf._fd, stdout=logf._fd,
|
||||||
stdin=subprocess.PIPE)
|
stdin=subprocess.PIPE)
|
||||||
except OSError, err:
|
except OSError as err:
|
||||||
if err.errno == 2:
|
if err.errno == 2:
|
||||||
raise ConversionError(_('Could not find pdftohtml, check it is in your PATH'))
|
raise ConversionError(_('Could not find pdftohtml, check it is in your PATH'))
|
||||||
else:
|
else:
|
||||||
@ -60,7 +60,7 @@ def pdftohtml(output_dir, pdf_path, no_images):
|
|||||||
try:
|
try:
|
||||||
ret = p.wait()
|
ret = p.wait()
|
||||||
break
|
break
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if e.errno == errno.EINTR:
|
if e.errno == errno.EINTR:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
@ -268,7 +268,7 @@ class RTFInput(InputFormatPlugin):
|
|||||||
self.log('Converting RTF to XML...')
|
self.log('Converting RTF to XML...')
|
||||||
try:
|
try:
|
||||||
xml = self.generate_xml(stream.name)
|
xml = self.generate_xml(stream.name)
|
||||||
except RtfInvalidCodeException, e:
|
except RtfInvalidCodeException as e:
|
||||||
raise ValueError(_('This RTF file has a feature calibre does not '
|
raise ValueError(_('This RTF file has a feature calibre does not '
|
||||||
'support. Convert it to HTML first and then try it.\n%s')%e)
|
'support. Convert it to HTML first and then try it.\n%s')%e)
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class SNBFile:
|
|||||||
uncompressedData += bzdc.decompress(data)
|
uncompressedData += bzdc.decompress(data)
|
||||||
else:
|
else:
|
||||||
uncompressedData += data
|
uncompressedData += data
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
if len(uncompressedData) != self.plainStreamSizeUncompressed:
|
if len(uncompressedData) != self.plainStreamSizeUncompressed:
|
||||||
raise Exception()
|
raise Exception()
|
||||||
|
@ -32,7 +32,7 @@ class Worker(Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
self.doit()
|
self.doit()
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
import traceback
|
import traceback
|
||||||
try:
|
try:
|
||||||
err = unicode(err)
|
err = unicode(err)
|
||||||
|
@ -78,7 +78,7 @@ class RecursiveFind(QThread): # {{{
|
|||||||
if isinstance(root, unicode):
|
if isinstance(root, unicode):
|
||||||
root = root.encode(filesystem_encoding)
|
root = root.encode(filesystem_encoding)
|
||||||
self.walk(root)
|
self.walk(root)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
|
@ -192,7 +192,7 @@ class MetadataWidget(Widget, Ui_Form):
|
|||||||
try:
|
try:
|
||||||
cf = open(_file, "rb")
|
cf = open(_file, "rb")
|
||||||
cover = cf.read()
|
cover = cf.read()
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
d = error_dialog(self.parent(), _('Error reading file'),
|
d = error_dialog(self.parent(), _('Error reading file'),
|
||||||
_("<p>There was an error reading from file: <br /><b>") + _file + "</b></p><br />"+str(e))
|
_("<p>There was an error reading from file: <br /><b>") + _file + "</b></p><br />"+str(e))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
@ -69,7 +69,7 @@ class SearchAndReplaceWidget(Widget, Ui_Form):
|
|||||||
try:
|
try:
|
||||||
pat = unicode(x.regex)
|
pat = unicode(x.regex)
|
||||||
re.compile(pat)
|
re.compile(pat)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
error_dialog(self, _('Invalid regular expression'),
|
error_dialog(self, _('Invalid regular expression'),
|
||||||
_('Invalid regular expression: %s')%err, show=True)
|
_('Invalid regular expression: %s')%err, show=True)
|
||||||
return False
|
return False
|
||||||
|
@ -64,7 +64,7 @@ class DeviceJob(BaseJob): # {{{
|
|||||||
self.result = self.func(*self.args, **self.kwargs)
|
self.result = self.func(*self.args, **self.kwargs)
|
||||||
if self._aborted:
|
if self._aborted:
|
||||||
return
|
return
|
||||||
except (Exception, SystemExit), err:
|
except (Exception, SystemExit) as err:
|
||||||
if self._aborted:
|
if self._aborted:
|
||||||
return
|
return
|
||||||
self.failed = True
|
self.failed = True
|
||||||
@ -162,7 +162,7 @@ class DeviceManager(Thread): # {{{
|
|||||||
dev.reset(detected_device=detected_device,
|
dev.reset(detected_device=detected_device,
|
||||||
report_progress=self.report_progress)
|
report_progress=self.report_progress)
|
||||||
dev.open(self.current_library_uuid)
|
dev.open(self.current_library_uuid)
|
||||||
except OpenFeedback, e:
|
except OpenFeedback as e:
|
||||||
if dev not in self.ejected_devices:
|
if dev not in self.ejected_devices:
|
||||||
self.open_feedback_msg(dev.get_gui_name(), e.feedback_msg)
|
self.open_feedback_msg(dev.get_gui_name(), e.feedback_msg)
|
||||||
self.ejected_devices.add(dev)
|
self.ejected_devices.add(dev)
|
||||||
|
@ -133,7 +133,7 @@ class ConfigWidget(QWidget, Ui_ConfigWidget):
|
|||||||
try:
|
try:
|
||||||
validation_formatter.validate(tmpl)
|
validation_formatter.validate(tmpl)
|
||||||
return True
|
return True
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
error_dialog(self, _('Invalid template'),
|
error_dialog(self, _('Invalid template'),
|
||||||
'<p>'+_('The template %s is invalid:')%tmpl + \
|
'<p>'+_('The template %s is invalid:')%tmpl + \
|
||||||
'<br>'+unicode(err), show=True)
|
'<br>'+unicode(err), show=True)
|
||||||
|
@ -68,7 +68,7 @@ class DBCheck(QDialog): # {{{
|
|||||||
self.start_load()
|
self.start_load()
|
||||||
return
|
return
|
||||||
QTimer.singleShot(0, self.do_one_dump)
|
QTimer.singleShot(0, self.do_one_dump)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
self.error = (as_unicode(e), traceback.format_exc())
|
self.error = (as_unicode(e), traceback.format_exc())
|
||||||
self.reject()
|
self.reject()
|
||||||
@ -90,7 +90,7 @@ class DBCheck(QDialog): # {{{
|
|||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
QTimer.singleShot(0, self.do_one_load)
|
QTimer.singleShot(0, self.do_one_load)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
self.error = (as_unicode(e), traceback.format_exc())
|
self.error = (as_unicode(e), traceback.format_exc())
|
||||||
self.reject()
|
self.reject()
|
||||||
@ -111,7 +111,7 @@ class DBCheck(QDialog): # {{{
|
|||||||
self.pb.setValue(self.pb.value() + 1)
|
self.pb.setValue(self.pb.value() + 1)
|
||||||
self.count -= 1
|
self.count -= 1
|
||||||
QTimer.singleShot(0, self.do_one_load)
|
QTimer.singleShot(0, self.do_one_load)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
self.error = (as_unicode(e), traceback.format_exc())
|
self.error = (as_unicode(e), traceback.format_exc())
|
||||||
self.reject()
|
self.reject()
|
||||||
|
@ -120,7 +120,7 @@ class MyBlockingBusy(QDialog): # {{{
|
|||||||
self.msg.setText(self.msg_text.format(self.phases[self.current_phase],
|
self.msg.setText(self.msg_text.format(self.phases[self.current_phase],
|
||||||
percent))
|
percent))
|
||||||
self.do_one(id)
|
self.do_one(id)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
import traceback
|
import traceback
|
||||||
try:
|
try:
|
||||||
err = unicode(err)
|
err = unicode(err)
|
||||||
|
@ -76,7 +76,7 @@ class CoverFetcher(Thread): # {{{
|
|||||||
|
|
||||||
self.cover_data, self.errors = download_cover(mi,
|
self.cover_data, self.errors = download_cover(mi,
|
||||||
timeout=self.timeout)
|
timeout=self.timeout)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.traceback = traceback.format_exc()
|
self.traceback = traceback.format_exc()
|
||||||
print self.traceback
|
print self.traceback
|
||||||
@ -183,7 +183,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
try:
|
try:
|
||||||
cf = open(_file, "rb")
|
cf = open(_file, "rb")
|
||||||
cover = cf.read()
|
cover = cf.read()
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
d = error_dialog(self, _('Error reading file'),
|
d = error_dialog(self, _('Error reading file'),
|
||||||
_("<p>There was an error reading from file: <br /><b>") + _file + "</b></p><br />"+str(e))
|
_("<p>There was an error reading from file: <br /><b>") + _file + "</b></p><br />"+str(e))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
@ -237,7 +237,7 @@ class %(classname)s(%(base_class)s):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
compile_recipe(src)
|
compile_recipe(src)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
error_dialog(self, _('Invalid input'),
|
error_dialog(self, _('Invalid input'),
|
||||||
_('<p>Could not create recipe. Error:<br>%s')%str(err)).exec_()
|
_('<p>Could not create recipe. Error:<br>%s')%str(err)).exec_()
|
||||||
return
|
return
|
||||||
@ -246,7 +246,7 @@ class %(classname)s(%(base_class)s):
|
|||||||
src = unicode(self.source_code.toPlainText())
|
src = unicode(self.source_code.toPlainText())
|
||||||
try:
|
try:
|
||||||
title = compile_recipe(src).title
|
title = compile_recipe(src).title
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
error_dialog(self, _('Invalid input'),
|
error_dialog(self, _('Invalid input'),
|
||||||
_('<p>Could not create recipe. Error:<br>%s')%str(err)).exec_()
|
_('<p>Could not create recipe. Error:<br>%s')%str(err)).exec_()
|
||||||
return
|
return
|
||||||
@ -333,7 +333,7 @@ class %(classname)s(%(base_class)s):
|
|||||||
try:
|
try:
|
||||||
profile = open(file, 'rb').read().decode('utf-8')
|
profile = open(file, 'rb').read().decode('utf-8')
|
||||||
title = compile_recipe(profile).title
|
title = compile_recipe(profile).title
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
error_dialog(self, _('Invalid input'),
|
error_dialog(self, _('Invalid input'),
|
||||||
_('<p>Could not create recipe. Error:<br>%s')%str(err)).exec_()
|
_('<p>Could not create recipe. Error:<br>%s')%str(err)).exec_()
|
||||||
return
|
return
|
||||||
|
@ -35,7 +35,7 @@ class Worker(Thread): # {{{
|
|||||||
try:
|
try:
|
||||||
br = browser()
|
br = browser()
|
||||||
br.retrieve(self.url, self.fpath, self.callback)
|
br.retrieve(self.url, self.fpath, self.callback)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.err = as_unicode(e)
|
self.err = as_unicode(e)
|
||||||
import traceback
|
import traceback
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
@ -116,7 +116,7 @@ class Emailer(Thread): # {{{
|
|||||||
try:
|
try:
|
||||||
self.sendmail(job)
|
self.sendmail(job)
|
||||||
break
|
break
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if not self._run:
|
if not self._run:
|
||||||
return
|
return
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -398,7 +398,7 @@ class CcTemplateDelegate(QStyledItemDelegate): # {{{
|
|||||||
val = unicode(editor.textbox.toPlainText())
|
val = unicode(editor.textbox.toPlainText())
|
||||||
try:
|
try:
|
||||||
validation_formatter.validate(val)
|
validation_formatter.validate(val)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
error_dialog(self.parent(), _('Invalid template'),
|
error_dialog(self.parent(), _('Invalid template'),
|
||||||
'<p>'+_('The template %s is invalid:')%val + \
|
'<p>'+_('The template %s is invalid:')%val + \
|
||||||
'<br>'+str(err), show=True)
|
'<br>'+str(err), show=True)
|
||||||
|
@ -35,7 +35,7 @@ class RenderWorker(QThread):
|
|||||||
self.stream = None
|
self.stream = None
|
||||||
if self.aborted:
|
if self.aborted:
|
||||||
self.lrf = None
|
self.lrf = None
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
self.lrf, self.stream = None, None
|
self.lrf, self.stream = None, None
|
||||||
self.exception = err
|
self.exception = err
|
||||||
self.formatted_traceback = traceback.format_exc()
|
self.formatted_traceback = traceback.format_exc()
|
||||||
|
@ -399,7 +399,7 @@ def main(args=sys.argv):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
if not iswindows: raise
|
if not iswindows: raise
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
from PyQt4.QtGui import QErrorMessage
|
from PyQt4.QtGui import QErrorMessage
|
||||||
|
@ -656,7 +656,7 @@ class Cover(ImageView): # {{{
|
|||||||
try:
|
try:
|
||||||
cf = open(_file, "rb")
|
cf = open(_file, "rb")
|
||||||
cover = cf.read()
|
cover = cf.read()
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
d = error_dialog(self, _('Error reading file'),
|
d = error_dialog(self, _('Error reading file'),
|
||||||
_("<p>There was an error reading from file: <br /><b>")
|
_("<p>There was an error reading from file: <br /><b>")
|
||||||
+ _file + "</b></p><br />"+str(e))
|
+ _file + "</b></p><br />"+str(e))
|
||||||
|
@ -88,7 +88,7 @@ class DownloadMetadata(Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
self._run()
|
self._run()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ class MetadataSingleDialogBase(ResizableDialog):
|
|||||||
return False
|
return False
|
||||||
self.books_to_refresh |= getattr(widget, 'books_to_refresh',
|
self.books_to_refresh |= getattr(widget, 'books_to_refresh',
|
||||||
set([]))
|
set([]))
|
||||||
except IOError, err:
|
except IOError as err:
|
||||||
if err.errno == 13: # Permission denied
|
if err.errno == 13: # Permission denied
|
||||||
import traceback
|
import traceback
|
||||||
fname = err.filename if err.filename else 'file'
|
fname = err.filename if err.filename else 'file'
|
||||||
|
@ -34,7 +34,7 @@ class DBUSNotifier(Notifier):
|
|||||||
import dbus
|
import dbus
|
||||||
self.dbus = dbus
|
self.dbus = dbus
|
||||||
self._notify = dbus.Interface(dbus.SessionBus().get_object(server, path), interface)
|
self._notify = dbus.Interface(dbus.SessionBus().get_object(server, path), interface)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
self.ok = False
|
self.ok = False
|
||||||
self.err = str(err)
|
self.err = str(err)
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
if d != 0:
|
if d != 0:
|
||||||
try:
|
try:
|
||||||
validation_formatter.validate(s)
|
validation_formatter.validate(s)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
error_dialog(self, _('Invalid template'),
|
error_dialog(self, _('Invalid template'),
|
||||||
'<p>'+_('The template %s is invalid:')%s + \
|
'<p>'+_('The template %s is invalid:')%s + \
|
||||||
'<br>'+str(err), show=True)
|
'<br>'+str(err), show=True)
|
||||||
|
@ -57,7 +57,7 @@ class SaveTemplate(QWidget, Ui_Form):
|
|||||||
return question_dialog(self, _('Constant template'),
|
return question_dialog(self, _('Constant template'),
|
||||||
_('The template contains no {fields}, so all '
|
_('The template contains no {fields}, so all '
|
||||||
'books will have the same name. Is this OK?'))
|
'books will have the same name. Is this OK?'))
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
error_dialog(self, _('Invalid template'),
|
error_dialog(self, _('Invalid template'),
|
||||||
'<p>'+_('The template %s is invalid:')%tmpl + \
|
'<p>'+_('The template %s is invalid:')%tmpl + \
|
||||||
'<br>'+str(err), show=True)
|
'<br>'+str(err), show=True)
|
||||||
|
@ -36,7 +36,7 @@ class Lookup(QThread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
self.define()
|
self.define()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.traceback = traceback.format_exc()
|
self.traceback = traceback.format_exc()
|
||||||
|
@ -97,7 +97,7 @@ class FilenamePattern(QWidget, Ui_Form):
|
|||||||
def do_test(self):
|
def do_test(self):
|
||||||
try:
|
try:
|
||||||
pat = self.pattern()
|
pat = self.pattern()
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
error_dialog(self, _('Invalid regular expression'),
|
error_dialog(self, _('Invalid regular expression'),
|
||||||
_('Invalid regular expression: %s')%err).exec_()
|
_('Invalid regular expression: %s')%err).exec_()
|
||||||
return
|
return
|
||||||
|
@ -565,7 +565,7 @@ def move_library(oldloc, newloc, parent, callback_on_complete):
|
|||||||
# Try to load existing library at new location
|
# Try to load existing library at new location
|
||||||
try:
|
try:
|
||||||
LibraryDatabase2(newloc)
|
LibraryDatabase2(newloc)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
det = traceback.format_exc()
|
det = traceback.format_exc()
|
||||||
error_dialog(parent, _('Invalid database'),
|
error_dialog(parent, _('Invalid database'),
|
||||||
_('<p>An invalid library already exists at '
|
_('<p>An invalid library already exists at '
|
||||||
@ -577,7 +577,7 @@ def move_library(oldloc, newloc, parent, callback_on_complete):
|
|||||||
else:
|
else:
|
||||||
callback(newloc)
|
callback(newloc)
|
||||||
return
|
return
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
det = traceback.format_exc()
|
det = traceback.format_exc()
|
||||||
error_dialog(parent, _('Could not move library'),
|
error_dialog(parent, _('Could not move library'),
|
||||||
unicode(err), det, show=True)
|
unicode(err), det, show=True)
|
||||||
|
@ -222,7 +222,7 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
|
|||||||
# cherrypy.engine.signal_handler.subscribe()
|
# cherrypy.engine.signal_handler.subscribe()
|
||||||
|
|
||||||
cherrypy.engine.block()
|
cherrypy.engine.block()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
finally:
|
finally:
|
||||||
self.is_running = False
|
self.is_running = False
|
||||||
|
@ -169,7 +169,7 @@ class ContentServer(object):
|
|||||||
return cover
|
return cover
|
||||||
return save_cover_data_to(img, 'img.jpg', return_data=True,
|
return save_cover_data_to(img, 'img.jpg', return_data=True,
|
||||||
resize_to=(width, height))
|
resize_to=(width, height))
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
import traceback
|
import traceback
|
||||||
cherrypy.log.error('Failed to generate cover:')
|
cherrypy.log.error('Failed to generate cover:')
|
||||||
cherrypy.log.error(traceback.print_exc())
|
cherrypy.log.error(traceback.print_exc())
|
||||||
|
@ -69,7 +69,7 @@ def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
|
|||||||
if pid > 0:
|
if pid > 0:
|
||||||
# exit first parent
|
# exit first parent
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
|
print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
|
|||||||
if pid > 0:
|
if pid > 0:
|
||||||
# exit from second parent
|
# exit from second parent
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
|
print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ def load_c_extensions(conn, debug=DEBUG):
|
|||||||
conn.load_extension(ext_path)
|
conn.load_extension(ext_path)
|
||||||
conn.enable_load_extension(False)
|
conn.enable_load_extension(False)
|
||||||
return True
|
return True
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if debug:
|
if debug:
|
||||||
print 'Failed to load high performance sqlite C extension'
|
print 'Failed to load high performance sqlite C extension'
|
||||||
print e
|
print e
|
||||||
@ -247,14 +247,14 @@ class DBThread(Thread):
|
|||||||
if func == 'dump':
|
if func == 'dump':
|
||||||
try:
|
try:
|
||||||
ok, res = True, tuple(self.conn.iterdump())
|
ok, res = True, tuple(self.conn.iterdump())
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
ok, res = False, (err, traceback.format_exc())
|
ok, res = False, (err, traceback.format_exc())
|
||||||
elif func == 'create_dynamic_filter':
|
elif func == 'create_dynamic_filter':
|
||||||
try:
|
try:
|
||||||
f = DynamicFilter(args[0])
|
f = DynamicFilter(args[0])
|
||||||
self.conn.create_function(args[0], 1, f)
|
self.conn.create_function(args[0], 1, f)
|
||||||
ok, res = True, f
|
ok, res = True, f
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
ok, res = False, (err, traceback.format_exc())
|
ok, res = False, (err, traceback.format_exc())
|
||||||
else:
|
else:
|
||||||
bfunc = getattr(self.conn, func)
|
bfunc = getattr(self.conn, func)
|
||||||
@ -263,7 +263,7 @@ class DBThread(Thread):
|
|||||||
try:
|
try:
|
||||||
ok, res = True, bfunc(*args, **kwargs)
|
ok, res = True, bfunc(*args, **kwargs)
|
||||||
break
|
break
|
||||||
except OperationalError, err:
|
except OperationalError as err:
|
||||||
# Retry if unable to open db file
|
# Retry if unable to open db file
|
||||||
e = str(err)
|
e = str(err)
|
||||||
if 'unable to open' not in e or i == 2:
|
if 'unable to open' not in e or i == 2:
|
||||||
@ -273,10 +273,10 @@ class DBThread(Thread):
|
|||||||
reprlib.repr(kwargs))
|
reprlib.repr(kwargs))
|
||||||
raise
|
raise
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
ok, res = False, (err, traceback.format_exc())
|
ok, res = False, (err, traceback.format_exc())
|
||||||
self.results.put((ok, res))
|
self.results.put((ok, res))
|
||||||
except Exception, err:
|
except Exception as err:
|
||||||
self.unhandled_error = (err, traceback.format_exc())
|
self.unhandled_error = (err, traceback.format_exc())
|
||||||
|
|
||||||
class DatabaseException(Exception):
|
class DatabaseException(Exception):
|
||||||
|
@ -59,7 +59,7 @@ for x in {manifest!r}:
|
|||||||
shutil.rmtree(x)
|
shutil.rmtree(x)
|
||||||
else:
|
else:
|
||||||
os.unlink(x)
|
os.unlink(x)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print 'Failed to delete', x
|
print 'Failed to delete', x
|
||||||
print '\t', e
|
print '\t', e
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ class PostInstall:
|
|||||||
|
|
||||||
complete -o nospace -C calibre-complete ebook-convert
|
complete -o nospace -C calibre-complete ebook-convert
|
||||||
'''))
|
'''))
|
||||||
except TypeError, err:
|
except TypeError as err:
|
||||||
if 'resolve_entities' in str(err):
|
if 'resolve_entities' in str(err):
|
||||||
print 'You need python-lxml >= 2.0.5 for calibre'
|
print 'You need python-lxml >= 2.0.5 for calibre'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -863,7 +863,7 @@ class Engine(threading.Thread):
|
|||||||
for socket in rr:
|
for socket in rr:
|
||||||
try:
|
try:
|
||||||
self.readers[socket].handle_read()
|
self.readers[socket].handle_read()
|
||||||
except NonLocalNameException, err:
|
except NonLocalNameException as err:
|
||||||
print err
|
print err
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
@ -316,7 +316,7 @@ class TemplateFormatter(string.Formatter):
|
|||||||
self.locals = {}
|
self.locals = {}
|
||||||
try:
|
try:
|
||||||
ans = self.vformat(fmt, [], kwargs).strip()
|
ans = self.vformat(fmt, [], kwargs).strip()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
ans = error_value + ' ' + e.message
|
ans = error_value + ' ' + e.message
|
||||||
|
@ -32,7 +32,7 @@ class WindowsExclFile(object):
|
|||||||
None, #No template file
|
None, #No template file
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
except pywintypes.error, err:
|
except pywintypes.error as err:
|
||||||
if getattr(err, 'args', [-1])[0] in (0x20, 0x21):
|
if getattr(err, 'args', [-1])[0] in (0x20, 0x21):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
continue
|
continue
|
||||||
|
@ -56,7 +56,7 @@ def set_metadata(stream, mi):
|
|||||||
try:
|
try:
|
||||||
p.wait()
|
p.wait()
|
||||||
break
|
break
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if e.errno == errno.EINTR:
|
if e.errno == errno.EINTR:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
@ -76,7 +76,7 @@ def sendmail_direct(from_, to, msg, timeout, localhost, verbose,
|
|||||||
s.connect(host, 25)
|
s.connect(host, 25)
|
||||||
s.sendmail(from_, [to], msg)
|
s.sendmail(from_, [to], msg)
|
||||||
return s.quit()
|
return s.quit()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
last_error, last_traceback = e, traceback.format_exc()
|
last_error, last_traceback = e, traceback.format_exc()
|
||||||
if last_error is not None:
|
if last_error is not None:
|
||||||
print last_traceback
|
print last_traceback
|
||||||
|
Loading…
x
Reference in New Issue
Block a user