[kupfer] plugin.opera: Use codecs.open to read the bookmarks file
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] plugin.opera: Use codecs.open to read the bookmarks file
- Date: Sun, 25 Oct 2009 13:48:23 +0000 (UTC)
commit e96b22d5cde78568b909ecef685cd0ae0400c7c7
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Sat Oct 24 14:07:23 2009 +0200
plugin.opera: Use codecs.open to read the bookmarks file
Opera by default writes bookmarks.adr in UTF-8, but they include an
encoding declaration in the file (that we ignore, we assume always
UTF-8).
Use codecs.open to open with transparent decoding from UTF-8. If we
get a decoding error we write an error and abort bookmarks parsing.
kupfer/plugin/opera.py | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/kupfer/plugin/opera.py b/kupfer/plugin/opera.py
index f407410..1af6e4b 100644
--- a/kupfer/plugin/opera.py
+++ b/kupfer/plugin/opera.py
@@ -1,6 +1,7 @@
# -*- coding: UTF-8 -*-
from __future__ import with_statement
+import codecs
import os
from kupfer.objects import (Source, UrlLeaf, FilesystemWatchMixin,
@@ -39,15 +40,19 @@ class BookmarksSource(AppLeafContentMixin, Source, FilesystemWatchMixin):
def get_items(self):
name = None
try:
- with open(self._bookmarks_path, 'r') as bfile:
+ with codecs.open(self._bookmarks_path, "r", "UTF-8") as bfile:
for line in bfile:
line = line.strip()
- if line.startswith('NAME='):
- name = objects.tounicode(line[5:])
- elif line.startswith('URL=') and name:
+ if line.startswith(u'NAME='):
+ name = line[5:]
+ elif line.startswith(u'URL=') and name:
yield UrlLeaf(line[4:], name)
except EnvironmentError, exc:
self.output_error(exc)
+ except UnicodeError, exc:
+ self.output_error("File %s not in expected encoding (UTF-8)" %
+ self._bookmarks_path)
+ self.output_error(exc)
def get_description(self):
return _("Index of Opera bookmarks")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]