def IsPossible(self): """Function to check the requirements for doing a port mapping. It tries to import the MiniUPnPc python binding: miniupnpc. If it fails, it tries to use the MiniUPnPc binary: upnpc. If neither of them are available UPnP Port Mapping is unavailable. """ try: # First we try to import the python binding import miniupnpc except ImportError as e1: try: # We fail to import the python module: fallback to the binary. self.run_binary([self.upnpcbinary]) except Exception as e2: # Nothing works :/ errors = [ _('Failed to import miniupnpc module: %(error)s') % {'error': str(e1)}, _('Failed to run upnpc binary: %(error)s') % { 'error': findBestEncoding( str(e2), ['utf-8', 'ascii', 'iso8859-1'] ) } ] return (False, errors) else: # If the binary is available we define the resulting mode self.mode = 'Binary' return (True, None) else: # If the python binding import is successful we define the # resulting mode self.mode = 'Module' return (True, None)
def IsPossible(self): """Function to check the requirements for doing a port mapping. It tries to import the MiniUPnPc python binding: miniupnpc. If it fails, it tries to use the MiniUPnPc binary: upnpc. If neither of them are available UPnP Port Mapping is unavailable. """ try: # First we try to import the python binding import miniupnpc except ImportError as e1: try: # We fail to import the python module: fallback to the binary. self.run_binary([self.upnpcbinary]) except Exception as e2: # Nothing works :/ errors = [ _('Failed to import miniupnpc module: %(error)s') % { 'error': str(e1) }, _('Failed to run upnpc binary: %(error)s') % { 'error': findBestEncoding(str(e2), ['utf-8', 'ascii', 'iso8859-1']) } ] return (False, errors) else: # If the binary is available we define the resulting mode self.mode = 'Binary' return (True, None) else: # If the python binding import is successful we define the # resulting mode self.mode = 'Module' return (True, None)
if val is not None and val != "None": self.sections[i][j] = val else: self.sections[i][j] = None else: try: self.sections[i][j] = eval(val, {}) except: self.sections[i][j] = None log.addwarning("CONFIG ERROR: Couldn't decode '%s' section '%s' value '%s'" % (str(j), str(i), str(val))) # If we stored any of the following as bytes (pre 1.2.15, pre 1.2.16), convert them to unicode unicodes = [('ticker', 'default'), ('server', 'autoreply')] for (section, subsection) in unicodes: try: self.sections[section][subsection] = findBestEncoding(self.sections[section][subsection], ['utf-8']) except TypeError: pass # Already unicode for room in self.sections["ticker"]["rooms"]: encodings = ['utf-8'] try: encodings.append(self.sections["server"]["roomencoding"][room]) except KeyError: pass try: self.sections["ticker"]["rooms"][room] = findBestEncoding(self.sections["ticker"]["rooms"][room], encodings) except TypeError: pass # already unicode # Convert fs-based shared to virtual shared (pre 1.2.16+)
self.sections["ui"]["speechcommand"] = self.sections["ui"]["speechcommand"].replace('%s','$') except KeyError: pass try: for (protocol, command) in self.sections["urls"]["protocols"].iteritems(): self.sections["urls"]["protocols"][protocol] = command.replace('%s','$') except KeyError: pass if "pyslsk" in autojoin and not "nicotine" in autojoin: autojoin.append("nicotine") # If we stored any of the following as bytes (pre 1.2.15, pre 1.2.16), convert them to unicode unicodes = [('ticker','default'), ('server','autoreply')] for (section, subsection) in unicodes: try: self.sections[section][subsection] = findBestEncoding(self.sections[section][subsection], ['utf-8']) except TypeError: pass # Already unicode for room in self.sections["ticker"]["rooms"]: encodings = ['utf-8'] try: encodings.append(self.sections["server"]["roomencoding"][room]) except KeyError: pass try: self.sections["ticker"]["rooms"][room] = findBestEncoding(self.sections["ticker"]["rooms"][room], encodings) except TypeError: pass # already unicode # decode the userinfo from local encoding to utf8 (1.0.3 -> 1.0.4 change) if not self.sections["userinfo"]["descrutf8"]: