FIX: problems with umlauten in reverse search
authorMichael Schmidt <drmichael@users.schwerkraft.elitedvb.net>
Sun, 3 Jan 2010 12:42:21 +0000 (12:42 +0000)
committerMichael Schmidt <drmichael@users.schwerkraft.elitedvb.net>
Sun, 3 Jan 2010 12:42:21 +0000 (12:42 +0000)
fritzcall/src/__init__.py
fritzcall/src/nrzuname.py
fritzcall/src/plugin.py

index 282ea48..1c66a30 100644 (file)
@@ -36,7 +36,7 @@ def debug(message):
                        deb.write(message + "\n")
                        deb.close()
                except Exception, e:
-                       debug("%s (retried debug: %s)" % (repr(message), e.message))
+                       debug("%s (retried debug: %s)" % (repr(message), str(e)))
                
 
 import re
index 6e0795b..9e59c59 100644 (file)
@@ -26,7 +26,7 @@ except ValueError:
                        print message
 
 import htmlentitydefs
-def html2unicode(in_html):
+def html2unicode(in_html, charset):
 #===============================================================================
 #      # sanity checks
 #      try:
@@ -69,7 +69,7 @@ def html2unicode(in_html):
        for key, codepoint in entitydict.items():
                try:
                        debug("[nrzuname] html2utf8: replace %s with %s" %(repr(key), str(codepoint)))
-                       in_html = in_html.replace(unicode(key), (unichr(int(codepoint))))
+                       in_html = in_html.replace(unicode(key), (unichr(int(codepoint))).encode(charset))
                except ValueError:
                        debug("[nrzuname] html2utf8: ValueError " + key + "/" + str(codepoint))
        return in_html
@@ -235,18 +235,22 @@ class ReverseLookupAndNotifier:
                def cleanName(text):
                        item = text.replace("%20"," ").replace("&nbsp;"," ").replace("</b>","").replace(","," ").replace('\n',' ').replace('\t',' ')
 
-                       item = html2unicode(item)
-                       try: # this works under Windows
-                               item = item.decode('iso-8859-1')
-                       except UnicodeDecodeError:
-                               try: # this works under Enigma2
-                                       item = item.decode('utf-8')
-                               except UnicodeDecodeError:
-                                       try: # fall back
-                                               item = item.decode(self.charset)
-                                       except UnicodeDecodeError:
-                                               # debug("[ReverseLookupAndNotifier] cleanName: " + traceback.format_exc())
-                                               debug("[ReverseLookupAndNotifier] cleanName: encoding problem")
+                       item = html2unicode(item, self.charset)
+                       #===================================================================
+                       # try: # this works under Windows
+                       #       item = item.encode('iso-8859-1')
+                       # except UnicodeEncodeError:
+                       #       debug("[ReverseLookupAndNotifier] cleanName: encoding problem with iso8859")
+                       #       try: # this works under Enigma2
+                       #               item = item.encode('utf-8')
+                       #       except UnicodeEncodeError:
+                       #               debug("[ReverseLookupAndNotifier] cleanName: encoding problem with utf-8")
+                       #               try: # fall back
+                       #                       item = item.encode(self.charset)
+                       #               except UnicodeEncodeError:
+                       #                       # debug("[ReverseLookupAndNotifier] cleanName: " + traceback.format_exc())
+                       #                       debug("[ReverseLookupAndNotifier] cleanName: encoding problem")
+                       #===================================================================
 
                        newitem = item.replace("  ", " ")
                        while newitem != item:
@@ -406,10 +410,10 @@ class ReverseLookupAndNotifier:
                # debug("1: " + repr(self.caller))
                if self.caller:
                        try:
-                               debug("2: " + repr(self.caller))
+                               debug("2: " + repr(self.caller))
                                self.caller = self.caller.encode(self.charset, 'replace')
-                               debug("3: " + repr(self.caller))
-                       except UnicodeEncodeError:
+                               debug("3: " + repr(self.caller))
+                       except UnicodeDecodeError:
                                debug("[ReverseLookupAndNotifier] cannot encode?!?!")
                        # self.caller = unicode(self.caller)
                        # debug("4: " + repr(self.caller))
index 0d81273..2480c04 100644 (file)
@@ -496,12 +496,14 @@ class FritzCallFBF:
                        if found:
                                charset = found.group(1)
                                debug("[FritzCallFBF] _parseFritzBoxPhonebook: found charset: " + charset)
-                               html = html2unicode(html.decode(charset)).encode('utf-8') # this looks silly, but has to be
+                               html = html2unicode(html.decode(charset), charset).encode('utf-8') # this looks silly, but has to be
                        else: # this is kind of emergency conversion...
                                try:
-                                       html = html2unicode(html.decode('utf-8')).encode('utf-8') # this looks silly, but has to be
+                                       charset = 'utf-8'
+                                       html = html2unicode(html.decode('utf-8'), 'utf-8').encode('utf-8') # this looks silly, but has to be
                                except UnicodeDecodeError:
-                                       html = html2unicode(html.decode('iso-8859-1')).encode('utf-8') # this looks silly, but has to be
+                                       charset = 'iso-8859-1'
+                                       html = html2unicode(html.decode('iso-8859-1'), 'iso-8859-1').encode('utf-8') # this looks silly, but has to be
                        entrymask = re.compile('(TrFonName\("[^"]+", "[^"]+", "[^"]*"\);.*?)document.write\(TrFon1\(\)', re.S)
                        entries = entrymask.finditer(html)
                        for entry in entries:
@@ -557,7 +559,7 @@ class FritzCallFBF:
                                if config.plugins.FritzCall.showVanity.value and found.group(4):
                                        name = name + ", " + _("Vanity") + ": " + found.group(4)
                                if thisnumber:
-                                       name = html2unicode(unicode(name)).encode('utf-8')
+                                       name = html2unicode(unicode(name), charset).encode('utf-8')
                                        debug("[FritzCallFBF] Adding '''%s''' with '''%s''' from FRITZ!Box Phonebook!" % (name, thisnumber))
                                        # Beware: strings in phonebook.phonebook have to be in utf-8!
                                        phonebook.phonebook[thisnumber] = name
@@ -676,7 +678,7 @@ class FritzCallFBF:
                                self._callScreen.updateStatus(_("done, using last list"))
                        lines = self._callList
                else:
-                       debug("[FritzCallFBF] _gotPageCalls: got no csv, no callList, leaving")
+                       debug("[FritzCallFBF] _gotPageCalls: got no csv, no callList, laving")
                        return
                        
                callListL = []
@@ -1783,7 +1785,8 @@ class FritzDisplayCalls(Screen, HelpableScreen):
                self["entries"].setList(sortlist)
 
        def updateStatus(self, text):
-               self["statusbar"].setText(_("Getting calls from FRITZ!Box...") + ' ' + text)
+               if self.has_key("statusbar"):
+                       self["statusbar"].setText(_("Getting calls from FRITZ!Box...") + ' ' + text)
 
        def showEntry(self):
                debug("[FritzDisplayCalls] showEntry")
@@ -2669,6 +2672,7 @@ class FritzCallSetup(Screen, ConfigListScreen, HelpableScreen):
                self.helpList.append((self["setupActions"], "EPGSelectActions", [("info", _("About FritzCall"))]))
 
                ConfigListScreen.__init__(self, self.list, session=session)
+                       
                self.createSetup()