diff --git a/src/calibre/web/feeds/recipes/__init__.py b/src/calibre/web/feeds/recipes/__init__.py index 6337031367..d65c245a33 100644 --- a/src/calibre/web/feeds/recipes/__init__.py +++ b/src/calibre/web/feeds/recipes/__init__.py @@ -1,4 +1,5 @@ #!/usr/bin/env python2 +from __future__ import unicode_literals __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ' ''' @@ -36,7 +37,7 @@ def compile_recipe(src): enc = match.group(1).decode('utf-8') if match else 'utf-8' src = src.decode(enc) # Python complains if there is a coding declaration in a unicode string - src = re.sub(r'^#.*coding\s*[:=]\s*([-\w.]+)', '#', src.lstrip(u'\ufeff'), flags=re.MULTILINE) + src = re.sub(r'^#.*coding\s*[:=]\s*([-\w.]+)', '#', src.lstrip('\ufeff'), flags=re.MULTILINE) # Translate newlines to \n src = io.StringIO(src, newline=None).getvalue() diff --git a/src/calibre/web/feeds/recipes/collection.py b/src/calibre/web/feeds/recipes/collection.py index 07eff6f545..3a4cedf829 100644 --- a/src/calibre/web/feeds/recipes/collection.py +++ b/src/calibre/web/feeds/recipes/collection.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement, print_function +from __future__ import with_statement, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' @@ -53,7 +53,7 @@ def serialize_recipe(urn, recipe_class): if ns is True: ns = 'yes' return E.recipe({ - 'id' : str(urn), + 'id' : unicode_type(urn), 'title' : attr('title', _('Unknown')), 'author' : attr('__author__', default_author), 'language' : attr('language', 'und'), @@ -80,7 +80,7 @@ def serialize_collection(mapping_of_recipe_classes): traceback.print_exc() continue collection.append(recipe) - collection.set('count', str(len(collection))) + collection.set('count', unicode_type(len(collection))) return etree.tostring(collection, encoding='utf-8', xml_declaration=True, pretty_print=True) @@ -137,7 +137,7 @@ def update_custom_recipes(script_ids): bdir = os.path.dirname(custom_recipes.file_path) for id_, title, script in script_ids: - id_ = str(int(id_)) + id_ = unicode_type(int(id_)) existing = custom_recipes.get(id_, None) if existing is None: @@ -170,7 +170,7 @@ def add_custom_recipes(script_map): bdir = os.path.dirname(custom_recipes.file_path) with custom_recipes: for title, script in iteritems(script_map): - fid = str(id_) + fid = unicode_type(id_) fname = custom_recipe_filename(fid, title) if isinstance(script, unicode_type): @@ -188,7 +188,7 @@ def add_custom_recipes(script_map): def remove_custom_recipe(id_): from calibre.web.feeds.recipes import custom_recipes - id_ = str(int(id_)) + id_ = unicode_type(int(id_)) existing = custom_recipes.get(id_, None) if existing is not None: bdir = os.path.dirname(custom_recipes.file_path) @@ -202,7 +202,7 @@ def remove_custom_recipe(id_): def get_custom_recipe(id_): from calibre.web.feeds.recipes import custom_recipes - id_ = str(int(id_)) + id_ = unicode_type(int(id_)) existing = custom_recipes.get(id_, None) if existing is not None: bdir = os.path.dirname(custom_recipes.file_path) @@ -400,7 +400,7 @@ class SchedulerConfig(object): elif typ == 'day/time': text = '%d:%d:%d'%schedule elif typ in ('days_of_week', 'days_of_month'): - dw = ','.join(map(str, map(int, schedule[0]))) + dw = ','.join(map(unicode_type, map(int, schedule[0]))) text = '%s:%d:%d'%(dw, schedule[1], schedule[2]) else: raise ValueError('Unknown schedule type: %r'%typ) diff --git a/src/calibre/web/feeds/recipes/model.py b/src/calibre/web/feeds/recipes/model.py index 458aa347ed..3bc75b33e5 100644 --- a/src/calibre/web/feeds/recipes/model.py +++ b/src/calibre/web/feeds/recipes/model.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement +from __future__ import with_statement, unicode_literals __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' @@ -125,7 +125,7 @@ class NewsItem(NewsTreeItem): try: with zipfile.ZipFile(self.zf, 'r') as zf: p.loadFromData(zf.read(self.favicons[icon])) - except: + except Exception: pass if not p.isNull(): self.icon = (QIcon(p)) @@ -215,7 +215,7 @@ class RecipeModel(QAbstractItemModel, AdaptSQP): remove_custom_recipe(id_) self.custom_recipe_collection = get_custom_recipe_collection() - def do_refresh(self, restrict_to_urns=set([])): + def do_refresh(self, restrict_to_urns=frozenset()): self.custom_recipe_collection = get_custom_recipe_collection() zf = P('builtin_recipes.zip', allow_user_override=False) @@ -238,7 +238,7 @@ class RecipeModel(QAbstractItemModel, AdaptSQP): scheduled = factory(NewsCategory, new_root, _('Scheduled')) custom = factory(NewsCategory, new_root, _('Custom')) lang_map = {} - self.all_urns = set([]) + self.all_urns = set() self.showing_count = 0 self.builtin_count = 0 for x in self.custom_recipe_collection: