Beispiel #1
0
 def testDefaultAddress(self):
     l = list(
         read_client_registrations("client=:1111&transport=websocket",
                                   defhost="1.2.3.4"))
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     l = list(
         read_client_registrations("client=1.2.3.4:&transport=websocket",
                                   defport=1111))
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
Beispiel #2
0
 def testMultiple(self):
     l = list(read_client_registrations("client=1.2.3.4:1111&foo=bar\nfoo=bar&client=5.6.7.8:2222"))
     self.assertEqual(len(l), 2)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     self.assertEqual(l[1].addr, ("5.6.7.8", 2222))
     l = list(read_client_registrations("client=1.2.3.4:1111&foo=bar\nfoo=bar&client=%5b1::2%5d:3333"))
     self.assertEqual(len(l), 2)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     self.assertEqual(l[1].addr, ("1::2", 3333))
Beispiel #3
0
 def testInvalid(self):
     # Missing "client".
     with self.assertRaises(ValueError):
         list(read_client_registrations("foo=bar"))
     # More than one "client".
     with self.assertRaises(ValueError):
         list(read_client_registrations("client=1.2.3.4:1111&foo=bar&client=5.6.7.8:2222"))
     # Single client with bad syntax.
     with self.assertRaises(ValueError):
         list(read_client_registrations("client=1.2.3.4,1111"))
Beispiel #4
0
 def testInvalid(self):
     # Missing "client".
     with self.assertRaises(ValueError):
         list(read_client_registrations("foo=bar"))
     # More than one "client".
     with self.assertRaises(ValueError):
         list(
             read_client_registrations(
                 "client=1.2.3.4:1111&foo=bar&client=5.6.7.8:2222"))
     # Single client with bad syntax.
     with self.assertRaises(ValueError):
         list(read_client_registrations("client=1.2.3.4,1111"))
Beispiel #5
0
 def testMultiple(self):
     l = list(
         read_client_registrations(
             "client=1.2.3.4:1111&foo=bar\nfoo=bar&client=5.6.7.8:2222"))
     self.assertEqual(len(l), 2)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     self.assertEqual(l[1].addr, ("5.6.7.8", 2222))
     l = list(
         read_client_registrations(
             "client=1.2.3.4:1111&foo=bar\nfoo=bar&client=%5b1::2%5d:3333"))
     self.assertEqual(len(l), 2)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     self.assertEqual(l[1].addr, ("1::2", 3333))
Beispiel #6
0
 def testSingle(self):
     l = list(read_client_registrations(""))
     self.assertEqual(len(l), 0)
     l = list(read_client_registrations("client=1.2.3.4:1111"))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     l = list(read_client_registrations("client=1.2.3.4:1111\n"))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     l = list(read_client_registrations("foo=bar&client=1.2.3.4:1111&baz=quux"))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     l = list(read_client_registrations("foo=b%3dar&client=1.2.3.4%3a1111"))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     l = list(read_client_registrations("client=%5b1::2%5d:3333"))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0].addr, ("1::2", 3333))
Beispiel #7
0
 def testSingle(self):
     l = list(read_client_registrations(""))
     self.assertEqual(len(l), 0)
     l = list(read_client_registrations("client=1.2.3.4:1111"))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     l = list(read_client_registrations("client=1.2.3.4:1111\n"))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     l = list(
         read_client_registrations("foo=bar&client=1.2.3.4:1111&baz=quux"))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     l = list(read_client_registrations("foo=b%3dar&client=1.2.3.4%3a1111"))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     l = list(read_client_registrations("client=%5b1::2%5d:3333"))
     self.assertEqual(len(l), 1)
     self.assertEqual(l[0].addr, ("1::2", 3333))
Beispiel #8
0
 def testDefaultTransport(self):
     l = list(read_client_registrations("client=1.2.3.4:1111"))
     self.assertEqual(l[0].transport, "websocket")
Beispiel #9
0
 def testDefaultTransport(self):
     l = list(read_client_registrations("client=1.2.3.4:1111"))
     self.assertEqual(l[0].transport, "websocket")
Beispiel #10
0
 def testDefaultAddress(self):
     l = list(read_client_registrations("client=:1111&transport=websocket", defhost="1.2.3.4"))
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
     l = list(read_client_registrations("client=1.2.3.4:&transport=websocket", defport=1111))
     self.assertEqual(l[0].addr, ("1.2.3.4", 1111))