def test_upnp( self ):
     
     internal_client = HydrusNATPunch.GetLocalIP()
     
     internal_port = random.randint( 1000, 1500 )
     
     external_port = random.randint( 1000, 1500 )
     
     description_tcp = 'hydrus test tcp'
     description_udp = 'hydrus test udp'
     
     HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, 'TCP', description_tcp )
     HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, 'UDP', description_udp )
     
     mappings = HydrusNATPunch.GetUPnPMappings()
     
     mappings_without_lease_times = [ mapping[:-1] for mapping in mappings ]
     
     self.assertIn( ( description_tcp, internal_client, internal_port, external_port, 'TCP' ), mappings_without_lease_times )
     self.assertIn( ( description_udp, internal_client, internal_port, external_port, 'UDP' ), mappings_without_lease_times )
     
     HydrusNATPunch.RemoveUPnPMapping( external_port, 'TCP' )
     HydrusNATPunch.RemoveUPnPMapping( external_port, 'UDP' )
     
     mappings = HydrusNATPunch.GetUPnPMappings()
     
     mappings_without_lease_times = [ mapping[:-1] for mapping in mappings ]
     
     self.assertNotIn( ( description_tcp, internal_client, internal_port, external_port, 'TCP' ), mappings_without_lease_times )
     self.assertNotIn( ( description_udp, internal_client, internal_port, external_port, 'UDP' ), mappings_without_lease_times )
        def work_callable():

            try:

                mappings = HydrusNATPunch.GetUPnPMappings()

            except Exception as e:

                HydrusData.ShowException(e)

                return e

            return mappings
Beispiel #3
0
 def THREADdo_it():
     
     try:
         
         mappings = HydrusNATPunch.GetUPnPMappings()
         
     except Exception as e:
         
         HydrusData.ShowException( e )
         
         QP.CallAfter( QW.QMessageBox.critical, self, 'Error', 'Could not load mappings:'+os.linesep*2+str(e) )
         
         return
         
     
     QP.CallAfter( qt_code, mappings )