print message
import htmlentitydefs
-def html2unicode(in_html):
+def html2unicode(in_html, charset):
#===============================================================================
# # sanity checks
# try:
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
def cleanName(text):
item = text.replace("%20"," ").replace(" "," ").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:
# 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))
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:
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
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 = []
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")
self.helpList.append((self["setupActions"], "EPGSelectActions", [("info", _("About FritzCall"))]))
ConfigListScreen.__init__(self, self.list, session=session)
+
self.createSetup()