[nanny] Fix unicode error importing from Dansguadian
- From: Roberto Majadas <telemaco src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nanny] Fix unicode error importing from Dansguadian
- Date: Mon, 1 Feb 2010 21:16:28 +0000 (UTC)
commit 9dcf1dc5c9fa2e9499706b229a98cd0c5cfd5db7
Author: Roberto Majadas <roberto majadas openshine com>
Date: Mon Feb 1 19:29:27 2010 +0100
Fix unicode error importing from Dansguadian
daemon/src/DansGuardianImporter.py | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/daemon/src/DansGuardianImporter.py b/daemon/src/DansGuardianImporter.py
index cf2628b..3786044 100644
--- a/daemon/src/DansGuardianImporter.py
+++ b/daemon/src/DansGuardianImporter.py
@@ -32,6 +32,13 @@ import sqlite3
from hachoir_regex import PatternMatching
+def try_to_str(string):
+ try:
+ return str(string)
+ except:
+ print "Error importing : %s" % string
+ return None
+
class DansGuardianImporter (gobject.GObject):
__gsignals__ = {
'progress-status' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
@@ -111,7 +118,7 @@ class DansGuardianImporter (gobject.GObject):
if itype == "domain" :
domains = []
for line in fd.readlines() :
- dg_domain=line.replace("\r","").replace("\n", "").replace(" ","").decode("iso8859-15").lower()
+ dg_domain=line.replace("\r","").replace("\n", "").replace(" ","")
tmp_domain=''
tmp_domain_item_list = dg_domain.split(".")
tmp_domain_item_list.reverse()
@@ -129,7 +136,11 @@ class DansGuardianImporter (gobject.GObject):
current = 0
for domain in domains :
- p.addString(str(domain))
+ string = try_to_str(domain)
+ if string == None :
+ continue
+
+ p.addString(string)
i = i + 1
current = current + 1
if i < 1500 :
@@ -184,7 +195,11 @@ class DansGuardianImporter (gobject.GObject):
total = len(urls)
for url in urls :
- p.addString(str(url))
+ string = try_to_str(url)
+ if string == None :
+ continue
+
+ p.addString(string)
i = i + 1
current = current + 1
@@ -206,7 +221,11 @@ class DansGuardianImporter (gobject.GObject):
step = False
for domain in domains :
- p.addString(str(domain))
+ string = try_to_str(domain)
+ if string == None :
+ continue
+
+ p.addString(string)
i = i + 1
current = current + 1
if i < 1500 :
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]