Exemple #1
0
    def get(self):   # overload get() from parent
        """Get the next response from the network.

        Arguments: None
        Returns: a received datagram, may be empty only with time and retry
        number.
        """
        if self._count < 0:
            return

        while True:
            _o_datagram = super().get()
            if _o_datagram is None:
                self._count -= 1
                _o_dummy_datagram = SSDPdatagram()
                if self._count > 0:
                    super().request()
                    self._retry += 1
                    _o_dummy_datagram.request = self._retry
                    #return _rel_time + 's ' + str(self._retry) + '\r\n'
                else:
                    self._count = -1
                    _o_dummy_datagram.request = 0
                    #return _rel_time + 's ' + '0' + '\r\n'
                return _o_dummy_datagram.fdevice(
                    base_time=self._timestamp_first_request)
            else:
                _device = _o_datagram.ipaddr + ' ' +_o_datagram.uuid
                if _device not in self._devicelist:
                    self._devicelist.append(_device)
                    _o_datagram.request = self._retry
                    return _o_datagram.fdevice(
                        base_time=self._timestamp_first_request,
                        verbose=self._verbose)
Exemple #2
0
 def test10_fdevice(self):
     """Test formating device verbose from listen datagram without addr."""
     o_datagram = SSDPdatagram(raw_data=LDATAGRAM1)
     o_datagram.request = 4
     result = o_datagram.fdevice(verbose=True)
     self.assertEqual(result, '0000.0000s 4\r\n' + LDATAGRAM1.decode())
     result = o_datagram.fdevice(base_time=time() - 1.5, verbose=True)
     self.assertRegex(result[:9], r'^0001\.\d\d\d\d$')
     self.assertEqual(result[9:], 's 4\r\n' + LDATAGRAM1.decode())
Exemple #3
0
 def test9_fdevice(self):
     """Test formating device verbose from listen datagram without data."""
     o_datagram = SSDPdatagram(addr=LADDR1)
     o_datagram.request = 2
     result = o_datagram.fdevice(verbose=True)
     self.assertEqual(result, '0000.0000s 2 192.168.10.86:57535\r\n')
     result = o_datagram.fdevice(base_time=time() - 1.5, verbose=True)
     self.assertRegex(result, (r'^0001\.\d\d\d\ds 2 '
                               r'192\.168\.10\.86:57535\r\n$'))
Exemple #4
0
 def test7_fdevice(self):
     """Test formating a device verbose output from a listen datagram."""
     o_datagram = SSDPdatagram(addr=LADDR1, raw_data=LDATAGRAM1)
     o_datagram.request = 3
     result = o_datagram.fdevice(verbose=True)
     self.assertEqual(
         result,
         '0000.0000s 3 192.168.10.86:57535\r\n' + LDATAGRAM1.decode())
     result = o_datagram.fdevice(base_time=time() - 1.5, verbose=True)
     self.assertRegex(result[:9], r'^0001\.\d\d\d\d$')
     self.assertEqual(result[9:],
                      's 3 192.168.10.86:57535\r\n' + LDATAGRAM1.decode())
Exemple #5
0
 def test5_fdevice(self):
     """Test formating device output from a listen datagram without addr."""
     o_datagram = SSDPdatagram(raw_data=LDATAGRAM1)
     o_datagram.request = 4
     result = o_datagram.fdevice()
     self.assertEqual(
         result,
         ('0000.0000s 4 NOTIFY uuid:f4f7681c-3056-11e8-86bd-87a6e4e2c42d '
          'Linux/4.14.71-v7+, UPnP/1.0, Portable SDK for UPnP '
          'devices/1.6.19+git20160116\r\n'))
     result = o_datagram.fdevice(base_time=time() - 1.5)
     self.assertRegex(result, (
         r'^0001\.\d\d\d\ds 4 NOTIFY '
         r'uuid:f4f7681c-3056-11e8-86bd-87a6e4e2c42d Linux/4\.14\.71-v7\+, '
         r'UPnP/1\.0, Portable SDK for UPnP devices/1\.6\.19\+git20160116'
         r'\r\n$'))
Exemple #6
0
 def test2_fdevice(self):
     """Test formating a device output from a listen datagram."""
     o_datagram = SSDPdatagram(addr=LADDR1, raw_data=LDATAGRAM1)
     o_datagram.request = 3
     result = o_datagram.fdevice()
     self.assertEqual(
         result,
         ('0000.0000s 3 NOTIFY 192.168.10.86:57535 '
          'uuid:f4f7681c-3056-11e8-86bd-87a6e4e2c42d Linux/4.14.71-v7+, '
          'UPnP/1.0, Portable SDK for UPnP devices/1.6.19+git20160116\r\n'))
     result = o_datagram.fdevice(base_time=time() - 1.5)
     self.assertRegex(result, (
         r'^0001\.\d\d\d\ds 3 NOTIFY 192\.168\.10\.86:57535 '
         r'uuid:f4f7681c-3056-11e8-86bd-87a6e4e2c42d Linux/4\.14\.71-v7\+, '
         r'UPnP/1\.0, Portable SDK for UPnP devices/1\.6\.19\+git20160116'
         r'\r\n$'))