コード例 #1
0
    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  # noqa: F401
        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)
コード例 #2
0
ファイル: utils.py プロジェクト: lene/nicotine-plus
def expand_alias(aliases, cmd):
    output = _expand_alias(aliases, cmd)
    return findBestEncoding(output, ['UTF-8', 'ASCII'])
コード例 #3
0
ファイル: utils.py プロジェクト: Nicotine-Plus/nicotine-plus
def expand_alias(aliases, cmd):
    output = _expand_alias(aliases, cmd)
    return findBestEncoding(output, ['UTF-8', 'ASCII'])