Example #1
0
 def __init__(self):
     self.u = UPnPPlatformIndependent()
Example #2
0
 def __init__(self):
     self.u = UPnPPlatformIndependent()
Example #3
0
class _UPnP3:

    def __init__(self):
        self.u = UPnPPlatformIndependent()

    def test(self):
        try:
            retries = 0
            interval = 4
            while retries < 10:
                self.u.discover()
                if self.u.found_wanted_services():
                    if DEBUG:
                        print >> sys.stderr, '_UPnP3::test: success'
                    return True
                retries += 1
                interval *= 2
                if DEBUG:
                    print >> sys.stderr, '_UPnP3::test: failed: retry in %d seconds' % interval
                time.sleep(interval)

            return False
        except:
            if DEBUG:
                print_exc()
            return False

    def open(self, ip, p, iproto = 'TCP'):
        try:
            self.u.add_port_map(ip, p, iproto=iproto)
            return True
        except UPnPError as e:
            if DEBUG:
                print_exc()
            raise e
        except:
            if DEBUG:
                print_exc()
            return False

    def close(self, p, iproto = 'TCP'):
        try:
            self.u.del_port_map(p, iproto=iproto)
            return True
        except UPnPError as e:
            if DEBUG:
                print_exc()
            raise e
        except:
            if DEBUG:
                print_exc()
            return False

    def get_ext_ip(self):
        try:
            return self.u.get_ext_ip()
        except UPnPError as e:
            if DEBUG:
                print_exc()
            raise e
        except:
            if DEBUG:
                print_exc()
            return None
Example #4
0
class _UPnP3:
    def __init__(self):
        self.u = UPnPPlatformIndependent()

    def test(self):
        try:
            retries = 0
            interval = 4
            while retries < 10:
                self.u.discover()
                if self.u.found_wanted_services():
                    if DEBUG:
                        print >> sys.stderr, '_UPnP3::test: success'
                    return True
                retries += 1
                interval *= 2
                if DEBUG:
                    print >> sys.stderr, '_UPnP3::test: failed: retry in %d seconds' % interval
                time.sleep(interval)

            return False
        except:
            if DEBUG:
                print_exc()
            return False

    def open(self, ip, p, iproto='TCP'):
        try:
            self.u.add_port_map(ip, p, iproto=iproto)
            return True
        except UPnPError as e:
            if DEBUG:
                print_exc()
            raise e
        except:
            if DEBUG:
                print_exc()
            return False

    def close(self, p, iproto='TCP'):
        try:
            self.u.del_port_map(p, iproto=iproto)
            return True
        except UPnPError as e:
            if DEBUG:
                print_exc()
            raise e
        except:
            if DEBUG:
                print_exc()
            return False

    def get_ext_ip(self):
        try:
            return self.u.get_ext_ip()
        except UPnPError as e:
            if DEBUG:
                print_exc()
            raise e
        except:
            if DEBUG:
                print_exc()
            return None