diff --git a/calibre-plugin/common_utils.py b/calibre-plugin/common_utils.py index d4570530..101816fc 100644 --- a/calibre-plugin/common_utils.py +++ b/calibre-plugin/common_utils.py @@ -2,6 +2,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) +import six __license__ = 'GPL v3' __copyright__ = '2011, Grant Drake , 2018, Jim Miller' @@ -367,7 +368,7 @@ class KeyValueComboBox(QComboBox): def populate_combo(self, selected_key): self.clear() selected_idx = idx = -1 - for key, value in self.values.iteritems(): + for key, value in six.iteritems(self.values): idx = idx + 1 self.addItem(value) if key == selected_key: @@ -375,7 +376,7 @@ class KeyValueComboBox(QComboBox): self.setCurrentIndex(selected_idx) def selected_key(self): - for key, value in self.values.iteritems(): + for key, value in six.iteritems(self.values): if value == unicode(self.currentText()).strip(): return key @@ -533,7 +534,7 @@ class PrefsViewerDialog(SizePersistedDialog): def _populate_settings(self): self.keys_list.clear() ns_prefix = self._get_ns_prefix() - keys = sorted([k[len(ns_prefix):] for k in self.db.prefs.iterkeys() + keys = sorted([k[len(ns_prefix):] for k in six.iterkeys(self.db.prefs) if k.startswith(ns_prefix)]) for key in keys: self.keys_list.addItem(key) @@ -596,7 +597,7 @@ class PrefsViewerDialog(SizePersistedDialog): if not confirm(message, self.namespace+'_clear_settings', self): return ns_prefix = self._get_ns_prefix() - keys = [k for k in self.db.prefs.iterkeys() if k.startswith(ns_prefix)] + keys = [k for k in six.iterkeys(self.db.prefs) if k.startswith(ns_prefix)] for k in keys: del self.db.prefs[k] self._populate_settings() diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py index 73fc8868..1532d10c 100644 --- a/calibre-plugin/config.py +++ b/calibre-plugin/config.py @@ -2,6 +2,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) +import six __license__ = 'GPL v3' __copyright__ = '2019, Jim Miller' @@ -190,7 +191,7 @@ class RejectURLList: self._save_list(listcache) def add_text(self,rejecttext,addreasontext): - self.add(self._read_list_from_text(rejecttext,addreasontext).values()) + self.add(list(self._read_list_from_text(rejecttext,addreasontext).values())) def add(self,rejectlist,clear=False): with self.sync_lock: @@ -203,7 +204,7 @@ class RejectURLList: self._save_list(listcache) def get_list(self): - return self._get_listcache().values() + return list(self._get_listcache().values()) def get_reject_reasons(self): return self.prefs['rejectreasons'].splitlines() @@ -329,7 +330,7 @@ class ConfigWidget(QWidget): prefs['plugin_gen_cover'] = self.calibrecover_tab.plugin_gen_cover.isChecked() prefs['gcnewonly'] = self.calibrecover_tab.gcnewonly.isChecked() gc_site_settings = {} - for (site,combo) in self.calibrecover_tab.gc_dropdowns.iteritems(): + for (site,combo) in six.iteritems(self.calibrecover_tab.gc_dropdowns): val = unicode(convert_qvariant(combo.itemData(combo.currentIndex()))) if val != 'none': gc_site_settings[site] = val @@ -357,7 +358,7 @@ class ConfigWidget(QWidget): # Standard Columns tab colsnewonly = {} - for (col,checkbox) in self.std_columns_tab.stdcol_newonlycheck.iteritems(): + for (col,checkbox) in six.iteritems(self.std_columns_tab.stdcol_newonlycheck): colsnewonly[col] = checkbox.isChecked() prefs['std_cols_newonly'] = colsnewonly @@ -383,7 +384,7 @@ class ConfigWidget(QWidget): # cust cols tab colsmap = {} - for (col,combo) in self.cust_columns_tab.custcol_dropdowns.iteritems(): + for (col,combo) in six.iteritems(self.cust_columns_tab.custcol_dropdowns): val = unicode(convert_qvariant(combo.itemData(combo.currentIndex()))) if val != 'none': colsmap[col] = val @@ -391,7 +392,7 @@ class ConfigWidget(QWidget): prefs['custom_cols'] = colsmap colsnewonly = {} - for (col,checkbox) in self.cust_columns_tab.custcol_newonlycheck.iteritems(): + for (col,checkbox) in six.iteritems(self.cust_columns_tab.custcol_newonlycheck): colsnewonly[col] = checkbox.isChecked() prefs['custom_cols_newonly'] = colsnewonly @@ -818,7 +819,7 @@ class PersonalIniTab(QWidget): def show_defaults(self): IniTextDialog(self, - get_resources('plugin-defaults.ini'), + get_resources('plugin-defaults.ini').decode('utf-8'), icon=self.windowIcon(), title=_('Plugin Defaults'), label=_("Plugin Defaults (%s) (Read-Only)")%'plugin-defaults.ini', @@ -852,11 +853,11 @@ class PersonalIniTab(QWidget): def show_showcalcols(self): lines=[]#[('calibre_std_user_categories',_('User Categories'))] - for k,f in field_metadata.iteritems(): + for k,f in six.iteritems(field_metadata): if f['name'] and k not in STD_COLS_SKIP: # only if it has a human readable name. lines.append(('calibre_std_'+k,f['name'])) - for k, column in self.plugin_action.gui.library_view.model().custom_columns.iteritems(): + for k, column in six.iteritems(self.plugin_action.gui.library_view.model().custom_columns): if k != prefs['savemetacol']: # custom always have name. lines.append(('calibre_cust_'+k[1:],column['name'])) @@ -1354,7 +1355,7 @@ class CustomColumnsTab(QWidget): self.sl = QVBoxLayout() scrollcontent.setLayout(self.sl) - for key, column in custom_columns.iteritems(): + for key, column in six.iteritems(custom_columns): if column['datatype'] in permitted_values: # print("\n============== %s ===========\n"%key) @@ -1407,7 +1408,7 @@ class CustomColumnsTab(QWidget): self.errorcol = QComboBox(self) self.errorcol.setToolTip(tooltip) self.errorcol.addItem('','none') - for key, column in custom_columns.iteritems(): + for key, column in six.iteritems(custom_columns): if column['datatype'] in ('text','comments'): self.errorcol.addItem(column['name'],key) self.errorcol.setCurrentIndex(self.errorcol.findData(prefs['errorcol'])) @@ -1431,7 +1432,7 @@ class CustomColumnsTab(QWidget): self.savemetacol = QComboBox(self) self.savemetacol.setToolTip(tooltip) self.savemetacol.addItem('','') - for key, column in custom_columns.iteritems(): + for key, column in six.iteritems(custom_columns): if column['datatype'] in ('comments'): self.savemetacol.addItem(column['name'],key) self.savemetacol.setCurrentIndex(self.savemetacol.findData(prefs['savemetacol'])) @@ -1451,7 +1452,7 @@ class CustomColumnsTab(QWidget): self.lastcheckedcol = QComboBox(self) self.lastcheckedcol.setToolTip(tooltip) self.lastcheckedcol.addItem('','none') - for key, column in custom_columns.iteritems(): + for key, column in six.iteritems(custom_columns): if column['datatype'] == 'datetime': self.lastcheckedcol.addItem(column['name'],key) self.lastcheckedcol.setCurrentIndex(self.lastcheckedcol.findData(prefs['lastcheckedcol'])) @@ -1494,7 +1495,7 @@ class StandardColumnsTab(QWidget): self.stdcol_newonlycheck = {} rows=[] - for key, column in columns.iteritems(): + for key, column in six.iteritems(columns): row = [] rows.append(row) label = QLabel(column) diff --git a/calibre-plugin/fff_plugin.py b/calibre-plugin/fff_plugin.py index f502b3e5..73df0808 100644 --- a/calibre-plugin/fff_plugin.py +++ b/calibre-plugin/fff_plugin.py @@ -2,6 +2,8 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) +import six +from six.moves import range __license__ = 'GPL v3' __copyright__ = '2019, Jim Miller' @@ -32,7 +34,6 @@ from io import BytesIO from functools import partial from datetime import datetime, time, date from string import Template -import urllib import email import traceback @@ -237,7 +238,7 @@ class FanFicFarePlugin(InterfaceAction): for f in filelist.splitlines(): #print("filename:%s"%f) if f.endswith(".eml"): - fhandle = urllib.urlopen(f) + fhandle = six.moves.urllib.request.urlopen(f) msg = email.message_from_file(fhandle) if msg.is_multipart(): for part in msg.walk(): @@ -1443,7 +1444,7 @@ class FanFicFarePlugin(InterfaceAction): #logger.debug("%s(%s): %s"%(label,key,value)) # custom columns - for k, column in self.gui.library_view.model().custom_columns.iteritems(): + for k, column in six.iteritems(self.gui.library_view.model().custom_columns): if k != prefs['savemetacol']: key='calibre_cust_'+k[1:] label=column['name'] @@ -2027,7 +2028,7 @@ class FanFicFarePlugin(InterfaceAction): # implement 'newonly' flags here by setting to the current # value again. if not book['added']: - for (col,newonly) in prefs['std_cols_newonly'].iteritems(): + for (col,newonly) in six.iteritems(prefs['std_cols_newonly']): if newonly: if col == "identifiers": mi.set_identifiers(oldmi.get_identifiers()) @@ -2070,7 +2071,7 @@ class FanFicFarePlugin(InterfaceAction): self.set_custom(db, book_id, 'lastcheckedcol', book['timestamp'], label=label, commit=True) #print("prefs['custom_cols'] %s"%prefs['custom_cols']) - for col, meta in prefs['custom_cols'].iteritems(): + for col, meta in six.iteritems(prefs['custom_cols']): #print("setting %s to %s"%(col,meta)) if col not in custom_columns: logger.debug("%s not an existing column, skipping."%col) @@ -2305,7 +2306,7 @@ class FanFicFarePlugin(InterfaceAction): #print("cover_path:%s"%cover_path) opts = ALL_OPTS.copy() opts.update(data) - O = namedtuple('Options', ' '.join(ALL_OPTS.iterkeys())) + O = namedtuple('Options', ' '.join(six.iterkeys(ALL_OPTS))) opts = O(**opts) log = Log(level=Log.DEBUG) @@ -2626,7 +2627,7 @@ class FanFicFarePlugin(InterfaceAction): book['all_metadata']['dateUpdated'] = b['all_metadata']['dateUpdated'] # copy list all_metadata - for (k,v) in b['all_metadata'].iteritems(): + for (k,v) in six.iteritems(b['all_metadata']): #print("merge_meta_books v:%s k:%s"%(v,k)) if k in ('numChapters','numWords'): if k in b['all_metadata'] and b['all_metadata'][k]: diff --git a/calibre-plugin/jobs.py b/calibre-plugin/jobs.py index 5dab4413..1d25b161 100644 --- a/calibre-plugin/jobs.py +++ b/calibre-plugin/jobs.py @@ -2,6 +2,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) +import six __license__ = 'GPL v3' __copyright__ = '2018, Jim Miller, 2011, Grant Drake ' @@ -323,7 +324,7 @@ def do_download_for_worker(book,options,merge,notification=lambda x,y:x): data = {'smarten_punctuation':True} opts = ALL_OPTS.copy() opts.update(data) - O = namedtuple('Options', ' '.join(ALL_OPTS.iterkeys())) + O = namedtuple('Options', ' '.join(six.iterkeys(ALL_OPTS))) opts = O(**opts) log = Log(level=Log.DEBUG) @@ -356,7 +357,7 @@ def inject_cal_cols(book,story,configuration): if 'calibre_columns' in book: injectini = ['[injected]'] extra_valid = [] - for k, v in book['calibre_columns'].iteritems(): + for k, v in six.iteritems(book['calibre_columns']): story.setMetadata(k,v['val']) injectini.append('%s_label:%s'%(k,v['label'])) extra_valid.append(k)