diff --git a/src/calibre/devices/prs500/cli/main.py b/src/calibre/devices/prs500/cli/main.py index 6d568b01a2..f122f6332e 100755 --- a/src/calibre/devices/prs500/cli/main.py +++ b/src/calibre/devices/prs500/cli/main.py @@ -282,7 +282,7 @@ def main(): outfile = os.path.join(outfile, path[path.rfind("/")+1:]) try: outfile = open(outfile, "wb") - except IOError, e: + except IOError as e: print >> sys.stderr, e parser.print_help() return 1 @@ -291,13 +291,13 @@ def main(): elif args[1].startswith("prs500:"): try: infile = open(args[0], "rb") - except IOError, e: + except IOError as e: print >> sys.stderr, e parser.print_help() return 1 try: dev.put_file(infile, args[1][7:]) - except PathError, err: + except PathError as err: if options.force and 'exists' in str(err): dev.del_file(err.path, False) dev.put_file(infile, args[1][7:]) @@ -355,7 +355,7 @@ def main(): return 1 except DeviceLocked: print >> sys.stderr, "The device is locked. Use the --unlock option" - except (ArgumentError, DeviceError), e: + except (ArgumentError, DeviceError) as e: print >>sys.stderr, e return 1 return 0 diff --git a/src/calibre/devices/prs500/driver.py b/src/calibre/devices/prs500/driver.py index 65ecc98a81..aaba094fb3 100644 --- a/src/calibre/devices/prs500/driver.py +++ b/src/calibre/devices/prs500/driver.py @@ -177,7 +177,7 @@ class PRS500(DeviceConfig, DevicePlugin): dev.send_validated_command(BeginEndSession(end=True)) dev.in_session = False raise - except USBError, err: + except USBError as err: if "No such device" in str(err): raise DeviceError() 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_write_max_packet_size = wed.MaxPacketSize self.handle.claim_interface(self.INTERFACE_ID) - except USBError, err: + except USBError as err: raise DeviceBusy(str(err)) # Large timeout as device may still be initializing res = self.send_validated_command(GetUSBProtocolVersion(), timeout=20000) @@ -303,7 +303,7 @@ class PRS500(DeviceConfig, DevicePlugin): try: self.handle.reset() self.handle.release_interface(self.INTERFACE_ID) - except Exception, err: + except Exception as err: print >> sys.stderr, err self.handle, self.device = None, None self.in_session = False @@ -509,7 +509,7 @@ class PRS500(DeviceConfig, DevicePlugin): outfile.write("".join(map(chr, packets[0][16:]))) for i in range(1, len(packets)): outfile.write("".join(map(chr, packets[i]))) - except IOError, err: + except IOError as err: self.send_validated_command(FileClose(_id)) raise ArgumentError("File get operation failed. " + \ "Could not write to local location: " + str(err)) @@ -656,7 +656,7 @@ class PRS500(DeviceConfig, DevicePlugin): dest = None try: 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): return (False, None) else: raise diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 91bb6d7416..c46e9539c9 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -128,7 +128,7 @@ class Device(DeviceConfig, DevicePlugin): try: sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \ win32file.GetDiskFreeSpace(prefix) - except Exception, err: + except Exception as err: if getattr(err, 'args', [None])[0] == 21: # Disk not ready time.sleep(3) sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters = \ @@ -771,7 +771,7 @@ class Device(DeviceConfig, DevicePlugin): for d in drives: try: eject(d) - except Exception, e: + except Exception as e: print 'Udisks eject call for:', d, 'failed:' print '\t', e failures = True diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py index c5bac936b5..7776be5e28 100644 --- a/src/calibre/ebooks/__init__.py +++ b/src/calibre/ebooks/__init__.py @@ -57,7 +57,7 @@ class HTMLRenderer(object): buf.open(QBuffer.WriteOnly) image.save(buf, 'JPEG') self.data = str(ba.data()) - except Exception, e: + except Exception as e: self.exception = e self.traceback = traceback.format_exc() finally: diff --git a/src/calibre/ebooks/epub/fix/container.py b/src/calibre/ebooks/epub/fix/container.py index 539d886312..1669290a7b 100644 --- a/src/calibre/ebooks/epub/fix/container.py +++ b/src/calibre/ebooks/epub/fix/container.py @@ -151,7 +151,7 @@ class Container(object): if name in self.mime_map: try: raw = self._parse(raw, self.mime_map[name]) - except XMLSyntaxError, err: + except XMLSyntaxError as err: raise ParseError(name, unicode(err)) self.cache[name] = raw return raw diff --git a/src/calibre/ebooks/epub/fix/main.py b/src/calibre/ebooks/epub/fix/main.py index fbfe80551d..e4c1a60a77 100644 --- a/src/calibre/ebooks/epub/fix/main.py +++ b/src/calibre/ebooks/epub/fix/main.py @@ -54,7 +54,7 @@ def main(args=sys.argv): epub = os.path.abspath(args[1]) try: run(epub, opts, default_log) - except ParseError, err: + except ParseError as err: default_log.error(unicode(err)) raise SystemExit(1) diff --git a/src/calibre/ebooks/html/input.py b/src/calibre/ebooks/html/input.py index 1599d3c896..dd0a247a67 100644 --- a/src/calibre/ebooks/html/input.py +++ b/src/calibre/ebooks/html/input.py @@ -110,7 +110,7 @@ class HTMLFile(object): try: with open(self.path, 'rb') as f: 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)) if level == 0: 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) nl.append(nf) flat.append(nf) - except IgnoreFile, err: + except IgnoreFile as err: rejects.append(link) if not err.doesnt_exist or verbose > 1: print repr(err) diff --git a/src/calibre/ebooks/lrf/html/convert_from.py b/src/calibre/ebooks/lrf/html/convert_from.py index 3be8f85e45..4ee1538e3f 100644 --- a/src/calibre/ebooks/lrf/html/convert_from.py +++ b/src/calibre/ebooks/lrf/html/convert_from.py @@ -332,7 +332,7 @@ class HTMLConverter(object): soup = BeautifulSoup(raw, convertEntities=BeautifulSoup.XHTML_ENTITIES, markupMassage=nmassage) - except ConversionError, err: + except ConversionError as err: if 'Failed to coerce to unicode' in str(err): raw = unicode(raw, 'utf8', 'replace') soup = BeautifulSoup(raw, @@ -935,7 +935,7 @@ class HTMLConverter(object): try: im = PILImage.open(path) - except IOError, err: + except IOError as err: self.log.warning('Unable to process image: %s\n%s'%( original_path, err)) return encoding = detect_encoding(im) @@ -953,7 +953,7 @@ class HTMLConverter(object): pt.close() self.scaled_images[path] = pt 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)) if width == None or height == None: @@ -1013,7 +1013,7 @@ class HTMLConverter(object): if not self.images.has_key(path): try: self.images[path] = ImageStream(path, encoding=encoding) - except LrsError, err: + except LrsError as err: self.log.warning(_('Could not process image: %s\n%s')%( original_path, err)) return @@ -1768,7 +1768,7 @@ class HTMLConverter(object): tag_css = self.tag_css(tag)[0] # Table should not inherit CSS try: 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.exception('') self.log.debug(_('Bad table:\n%s')%unicode(tag)[:300]) @@ -1858,7 +1858,7 @@ def process_file(path, options, logger): tf.close() tim.save(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) options.cover = None else: diff --git a/src/calibre/ebooks/metadata/amazon.py b/src/calibre/ebooks/metadata/amazon.py index 8e4dd1dd27..4100439feb 100644 --- a/src/calibre/ebooks/metadata/amazon.py +++ b/src/calibre/ebooks/metadata/amazon.py @@ -108,7 +108,7 @@ def _get_cover_url(br, asin): q = 'http://amzn.com/'+asin try: raw = br.open_novisit(q).read() - except Exception, e: + except Exception as e: if callable(getattr(e, 'getcode', None)) and \ e.getcode() == 404: return None @@ -139,7 +139,7 @@ def get_metadata(br, asin, mi): q = 'http://amzn.com/'+asin try: raw = br.open_novisit(q).read() - except Exception, e: + except Exception as e: if callable(getattr(e, 'getcode', None)) and \ e.getcode() == 404: return False diff --git a/src/calibre/ebooks/metadata/amazonfr.py b/src/calibre/ebooks/metadata/amazonfr.py index 156fff3d75..248c8d9ed0 100644 --- a/src/calibre/ebooks/metadata/amazonfr.py +++ b/src/calibre/ebooks/metadata/amazonfr.py @@ -33,7 +33,7 @@ class AmazonFr(MetadataSource): try: self.results = search(self.title, self.book_author, self.publisher, self.isbn, max_results=10, verbose=self.verbose, lang='fr') - except Exception, e: + except Exception as e: self.exception = e self.tb = traceback.format_exc() @@ -50,7 +50,7 @@ class AmazonEs(MetadataSource): try: self.results = search(self.title, self.book_author, self.publisher, self.isbn, max_results=10, verbose=self.verbose, lang='es') - except Exception, e: + except Exception as e: self.exception = e self.tb = traceback.format_exc() @@ -67,7 +67,7 @@ class AmazonEn(MetadataSource): try: self.results = search(self.title, self.book_author, self.publisher, self.isbn, max_results=10, verbose=self.verbose, lang='en') - except Exception, e: + except Exception as e: self.exception = e self.tb = traceback.format_exc() @@ -84,7 +84,7 @@ class AmazonDe(MetadataSource): try: self.results = search(self.title, self.book_author, self.publisher, self.isbn, max_results=10, verbose=self.verbose, lang='de') - except Exception, e: + except Exception as e: self.exception = e self.tb = traceback.format_exc() @@ -103,7 +103,7 @@ class Amazon(MetadataSource): try: self.results = search(self.title, self.book_author, self.publisher, self.isbn, max_results=10, verbose=self.verbose, lang='all') - except Exception, e: + except Exception as e: self.exception = e self.tb = traceback.format_exc() @@ -193,7 +193,7 @@ class Query(object): try: raw = browser.open_novisit(self.urldata, timeout=timeout).read() - except Exception, e: + except Exception as e: report(verbose) if callable(getattr(e, 'getcode', None)) and \ e.getcode() == 404: @@ -226,7 +226,7 @@ class Query(object): try: urldata = self.urldata + '&page=' + str(i) raw = browser.open_novisit(urldata, timeout=timeout).read() - except Exception, e: + except Exception as e: continue if '
There was an error reading from file:
") + _file + "
'+_('The template %s is invalid:')%tmpl + \
'
'+unicode(err), show=True)
diff --git a/src/calibre/gui2/dialogs/check_library.py b/src/calibre/gui2/dialogs/check_library.py
index 560090d2b3..95f99d4034 100644
--- a/src/calibre/gui2/dialogs/check_library.py
+++ b/src/calibre/gui2/dialogs/check_library.py
@@ -68,7 +68,7 @@ class DBCheck(QDialog): # {{{
self.start_load()
return
QTimer.singleShot(0, self.do_one_dump)
- except Exception, e:
+ except Exception as e:
import traceback
self.error = (as_unicode(e), traceback.format_exc())
self.reject()
@@ -90,7 +90,7 @@ class DBCheck(QDialog): # {{{
self.conn.commit()
QTimer.singleShot(0, self.do_one_load)
- except Exception, e:
+ except Exception as e:
import traceback
self.error = (as_unicode(e), traceback.format_exc())
self.reject()
@@ -111,7 +111,7 @@ class DBCheck(QDialog): # {{{
self.pb.setValue(self.pb.value() + 1)
self.count -= 1
QTimer.singleShot(0, self.do_one_load)
- except Exception, e:
+ except Exception as e:
import traceback
self.error = (as_unicode(e), traceback.format_exc())
self.reject()
diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py
index 4a9a320561..0683f2cb91 100644
--- a/src/calibre/gui2/dialogs/metadata_bulk.py
+++ b/src/calibre/gui2/dialogs/metadata_bulk.py
@@ -120,7 +120,7 @@ class MyBlockingBusy(QDialog): # {{{
self.msg.setText(self.msg_text.format(self.phases[self.current_phase],
percent))
self.do_one(id)
- except Exception, err:
+ except Exception as err:
import traceback
try:
err = unicode(err)
diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py
index 9efe7f7160..f6b7b94453 100644
--- a/src/calibre/gui2/dialogs/metadata_single.py
+++ b/src/calibre/gui2/dialogs/metadata_single.py
@@ -76,7 +76,7 @@ class CoverFetcher(Thread): # {{{
self.cover_data, self.errors = download_cover(mi,
timeout=self.timeout)
- except Exception, e:
+ except Exception as e:
self.exception = e
self.traceback = traceback.format_exc()
print self.traceback
@@ -183,7 +183,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
try:
cf = open(_file, "rb")
cover = cf.read()
- except IOError, e:
+ except IOError as e:
d = error_dialog(self, _('Error reading file'),
_("
There was an error reading from file:
") + _file + "
Could not create recipe. Error:
%s')%str(err)).exec_()
return
@@ -246,7 +246,7 @@ class %(classname)s(%(base_class)s):
src = unicode(self.source_code.toPlainText())
try:
title = compile_recipe(src).title
- except Exception, err:
+ except Exception as err:
error_dialog(self, _('Invalid input'),
_('
Could not create recipe. Error:
%s')%str(err)).exec_()
return
@@ -333,7 +333,7 @@ class %(classname)s(%(base_class)s):
try:
profile = open(file, 'rb').read().decode('utf-8')
title = compile_recipe(profile).title
- except Exception, err:
+ except Exception as err:
error_dialog(self, _('Invalid input'),
_('
Could not create recipe. Error:
%s')%str(err)).exec_()
return
diff --git a/src/calibre/gui2/dnd.py b/src/calibre/gui2/dnd.py
index 928de72578..1f9dbdfa34 100644
--- a/src/calibre/gui2/dnd.py
+++ b/src/calibre/gui2/dnd.py
@@ -35,7 +35,7 @@ class Worker(Thread): # {{{
try:
br = browser()
br.retrieve(self.url, self.fpath, self.callback)
- except Exception, e:
+ except Exception as e:
self.err = as_unicode(e)
import traceback
self.tb = traceback.format_exc()
diff --git a/src/calibre/gui2/email.py b/src/calibre/gui2/email.py
index c84b3180f7..81c1d9c255 100644
--- a/src/calibre/gui2/email.py
+++ b/src/calibre/gui2/email.py
@@ -116,7 +116,7 @@ class Emailer(Thread): # {{{
try:
self.sendmail(job)
break
- except Exception, e:
+ except Exception as e:
if not self._run:
return
import traceback
diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py
index 3a090f8102..0f74500099 100644
--- a/src/calibre/gui2/library/delegates.py
+++ b/src/calibre/gui2/library/delegates.py
@@ -398,7 +398,7 @@ class CcTemplateDelegate(QStyledItemDelegate): # {{{
val = unicode(editor.textbox.toPlainText())
try:
validation_formatter.validate(val)
- except Exception, err:
+ except Exception as err:
error_dialog(self.parent(), _('Invalid template'),
'
'+_('The template %s is invalid:')%val + \
'
'+str(err), show=True)
diff --git a/src/calibre/gui2/lrf_renderer/main.py b/src/calibre/gui2/lrf_renderer/main.py
index 2acfd3c9a7..e68e04adcf 100644
--- a/src/calibre/gui2/lrf_renderer/main.py
+++ b/src/calibre/gui2/lrf_renderer/main.py
@@ -35,7 +35,7 @@ class RenderWorker(QThread):
self.stream = None
if self.aborted:
self.lrf = None
- except Exception, err:
+ except Exception as err:
self.lrf, self.stream = None, None
self.exception = err
self.formatted_traceback = traceback.format_exc()
diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py
index 976b679726..c67ec8c2b4 100644
--- a/src/calibre/gui2/main.py
+++ b/src/calibre/gui2/main.py
@@ -399,7 +399,7 @@ def main(args=sys.argv):
if __name__ == '__main__':
try:
sys.exit(main())
- except Exception, err:
+ except Exception as err:
if not iswindows: raise
tb = traceback.format_exc()
from PyQt4.QtGui import QErrorMessage
diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py
index d5a8de7b67..635a037482 100644
--- a/src/calibre/gui2/metadata/basic_widgets.py
+++ b/src/calibre/gui2/metadata/basic_widgets.py
@@ -656,7 +656,7 @@ class Cover(ImageView): # {{{
try:
cf = open(_file, "rb")
cover = cf.read()
- except IOError, e:
+ except IOError as e:
d = error_dialog(self, _('Error reading file'),
_("
There was an error reading from file:
")
+ _file + "
'+_('The template %s is invalid:')%s + \
'
'+str(err), show=True)
diff --git a/src/calibre/gui2/preferences/save_template.py b/src/calibre/gui2/preferences/save_template.py
index 4c00a14c0f..96ca8c8945 100644
--- a/src/calibre/gui2/preferences/save_template.py
+++ b/src/calibre/gui2/preferences/save_template.py
@@ -57,7 +57,7 @@ class SaveTemplate(QWidget, Ui_Form):
return question_dialog(self, _('Constant template'),
_('The template contains no {fields}, so all '
'books will have the same name. Is this OK?'))
- except Exception, err:
+ except Exception as err:
error_dialog(self, _('Invalid template'),
'
'+_('The template %s is invalid:')%tmpl + \
'
'+str(err), show=True)
diff --git a/src/calibre/gui2/viewer/dictionary.py b/src/calibre/gui2/viewer/dictionary.py
index dad8d1821c..d5dd4d0a86 100644
--- a/src/calibre/gui2/viewer/dictionary.py
+++ b/src/calibre/gui2/viewer/dictionary.py
@@ -36,7 +36,7 @@ class Lookup(QThread):
def run(self):
try:
self.define()
- except Exception, e:
+ except Exception as e:
import traceback
self.exception = e
self.traceback = traceback.format_exc()
diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py
index c570a6e159..ea0509b51a 100644
--- a/src/calibre/gui2/widgets.py
+++ b/src/calibre/gui2/widgets.py
@@ -97,7 +97,7 @@ class FilenamePattern(QWidget, Ui_Form):
def do_test(self):
try:
pat = self.pattern()
- except Exception, err:
+ except Exception as err:
error_dialog(self, _('Invalid regular expression'),
_('Invalid regular expression: %s')%err).exec_()
return
diff --git a/src/calibre/gui2/wizard/__init__.py b/src/calibre/gui2/wizard/__init__.py
index c629b10b5d..a32347dc72 100644
--- a/src/calibre/gui2/wizard/__init__.py
+++ b/src/calibre/gui2/wizard/__init__.py
@@ -565,7 +565,7 @@ def move_library(oldloc, newloc, parent, callback_on_complete):
# Try to load existing library at new location
try:
LibraryDatabase2(newloc)
- except Exception, err:
+ except Exception as err:
det = traceback.format_exc()
error_dialog(parent, _('Invalid database'),
_('
An invalid library already exists at ' @@ -577,7 +577,7 @@ def move_library(oldloc, newloc, parent, callback_on_complete): else: callback(newloc) return - except Exception, err: + except Exception as err: det = traceback.format_exc() error_dialog(parent, _('Could not move library'), unicode(err), det, show=True) diff --git a/src/calibre/library/server/base.py b/src/calibre/library/server/base.py index 83d395dec5..dba6abbfa5 100644 --- a/src/calibre/library/server/base.py +++ b/src/calibre/library/server/base.py @@ -222,7 +222,7 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache, # cherrypy.engine.signal_handler.subscribe() cherrypy.engine.block() - except Exception, e: + except Exception as e: self.exception = e finally: self.is_running = False diff --git a/src/calibre/library/server/content.py b/src/calibre/library/server/content.py index 11ea2b951e..919f5a7969 100644 --- a/src/calibre/library/server/content.py +++ b/src/calibre/library/server/content.py @@ -169,7 +169,7 @@ class ContentServer(object): return cover return save_cover_data_to(img, 'img.jpg', return_data=True, resize_to=(width, height)) - except Exception, err: + except Exception as err: import traceback cherrypy.log.error('Failed to generate cover:') cherrypy.log.error(traceback.print_exc()) diff --git a/src/calibre/library/server/main.py b/src/calibre/library/server/main.py index e4de710c6a..3a6f918022 100644 --- a/src/calibre/library/server/main.py +++ b/src/calibre/library/server/main.py @@ -69,7 +69,7 @@ def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): if pid > 0: # exit first parent sys.exit(0) - except OSError, e: + except OSError as e: print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror) sys.exit(1) @@ -84,7 +84,7 @@ def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): if pid > 0: # exit from second parent sys.exit(0) - except OSError, e: + except OSError as e: print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror) sys.exit(1) diff --git a/src/calibre/library/sqlite.py b/src/calibre/library/sqlite.py index 2075ab5880..511106fe7b 100644 --- a/src/calibre/library/sqlite.py +++ b/src/calibre/library/sqlite.py @@ -193,7 +193,7 @@ def load_c_extensions(conn, debug=DEBUG): conn.load_extension(ext_path) conn.enable_load_extension(False) return True - except Exception, e: + except Exception as e: if debug: print 'Failed to load high performance sqlite C extension' print e @@ -247,14 +247,14 @@ class DBThread(Thread): if func == 'dump': try: ok, res = True, tuple(self.conn.iterdump()) - except Exception, err: + except Exception as err: ok, res = False, (err, traceback.format_exc()) elif func == 'create_dynamic_filter': try: f = DynamicFilter(args[0]) self.conn.create_function(args[0], 1, f) ok, res = True, f - except Exception, err: + except Exception as err: ok, res = False, (err, traceback.format_exc()) else: bfunc = getattr(self.conn, func) @@ -263,7 +263,7 @@ class DBThread(Thread): try: ok, res = True, bfunc(*args, **kwargs) break - except OperationalError, err: + except OperationalError as err: # Retry if unable to open db file e = str(err) if 'unable to open' not in e or i == 2: @@ -273,10 +273,10 @@ class DBThread(Thread): reprlib.repr(kwargs)) raise time.sleep(0.5) - except Exception, err: + except Exception as err: ok, res = False, (err, traceback.format_exc()) self.results.put((ok, res)) - except Exception, err: + except Exception as err: self.unhandled_error = (err, traceback.format_exc()) class DatabaseException(Exception): diff --git a/src/calibre/linux.py b/src/calibre/linux.py index 96f0fbd92d..dfab13e3b8 100644 --- a/src/calibre/linux.py +++ b/src/calibre/linux.py @@ -59,7 +59,7 @@ for x in {manifest!r}: shutil.rmtree(x) else: os.unlink(x) - except Exception, e: + except Exception as e: print 'Failed to delete', x print '\t', e @@ -285,7 +285,7 @@ class PostInstall: complete -o nospace -C calibre-complete ebook-convert ''')) - except TypeError, err: + except TypeError as err: if 'resolve_entities' in str(err): print 'You need python-lxml >= 2.0.5 for calibre' sys.exit(1) diff --git a/src/calibre/utils/Zeroconf.py b/src/calibre/utils/Zeroconf.py index f4a7119d16..fbb9b4e71f 100755 --- a/src/calibre/utils/Zeroconf.py +++ b/src/calibre/utils/Zeroconf.py @@ -863,7 +863,7 @@ class Engine(threading.Thread): for socket in rr: try: self.readers[socket].handle_read() - except NonLocalNameException, err: + except NonLocalNameException as err: print err except UnicodeDecodeError: if DEBUG: diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index 740e67bee8..2e40275beb 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -316,7 +316,7 @@ class TemplateFormatter(string.Formatter): self.locals = {} try: ans = self.vformat(fmt, [], kwargs).strip() - except Exception, e: + except Exception as e: if DEBUG: traceback.print_exc() ans = error_value + ' ' + e.message diff --git a/src/calibre/utils/lock.py b/src/calibre/utils/lock.py index 5098c78f90..0b66be963b 100644 --- a/src/calibre/utils/lock.py +++ b/src/calibre/utils/lock.py @@ -32,7 +32,7 @@ class WindowsExclFile(object): None, #No template file ) break - except pywintypes.error, err: + except pywintypes.error as err: if getattr(err, 'args', [-1])[0] in (0x20, 0x21): time.sleep(1) continue diff --git a/src/calibre/utils/pdftk.py b/src/calibre/utils/pdftk.py index 1263b60306..f4fcb8a2e3 100644 --- a/src/calibre/utils/pdftk.py +++ b/src/calibre/utils/pdftk.py @@ -56,7 +56,7 @@ def set_metadata(stream, mi): try: p.wait() break - except OSError, e: + except OSError as e: if e.errno == errno.EINTR: continue else: diff --git a/src/calibre/utils/smtp.py b/src/calibre/utils/smtp.py index 744021f911..81936a8f71 100644 --- a/src/calibre/utils/smtp.py +++ b/src/calibre/utils/smtp.py @@ -76,7 +76,7 @@ def sendmail_direct(from_, to, msg, timeout, localhost, verbose, s.connect(host, 25) s.sendmail(from_, [to], msg) return s.quit() - except Exception, e: + except Exception as e: last_error, last_traceback = e, traceback.format_exc() if last_error is not None: print last_traceback