| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,9 @@ | |||
| 1 | 1 | #!/usr/bin/env python | |
| 2 | 2 | ||
| 3 | + """ Unit tests for zeroconf.py """ | ||
| 4 | + | ||
| 3 | 5 | import zeroconf as r | |
| 6 | + import struct | ||
| 4 | 7 | import unittest | |
| 5 | 8 | ||
| 6 | 9 | class PacketGeneration(unittest.TestCase): | |
@@ -56,29 +59,25 @@ def testResponseHeaderBits(self): | |||
| 56 | 59 | def testNumbers(self): | |
| 57 | 60 | generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE) | |
| 58 | 61 | bytes = generated.packet() | |
| 59 | - numQuestions = ord(bytes[4]) << 8 | ord(bytes[5]) | ||
| 60 | - numAnswers = ord(bytes[6]) << 8 | ord(bytes[7]) | ||
| 61 | - numAuthorities = ord(bytes[8]) << 8 | ord(bytes[9]) | ||
| 62 | - numAddtionals = ord(bytes[10]) << 8 | ord(bytes[11]) | ||
| 62 | + (numQuestions, numAnswers, numAuthorities, | ||
| 63 | + numAdditionals) = struct.unpack('>4H', bytes[4:12]) | ||
| 63 | 64 | self.assertEqual(numQuestions, 0) | |
| 64 | 65 | self.assertEqual(numAnswers, 0) | |
| 65 | 66 | self.assertEqual(numAuthorities, 0) | |
| 66 | - self.assertEqual(numAddtionals, 0) | ||
| 67 | + self.assertEqual(numAdditionals, 0) | ||
| 67 | 68 | ||
| 68 | 69 | def testNumbersQuestions(self): | |
| 69 | 70 | generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE) | |
| 70 | 71 | question = r.DNSQuestion("testname.local.", r._TYPE_SRV, r._CLASS_IN) | |
| 71 | 72 | for i in xrange(10): | |
| 72 | 73 | generated.addQuestion(question) | |
| 73 | 74 | bytes = generated.packet() | |
| 74 | - numQuestions = ord(bytes[4]) << 8 | ord(bytes[5]) | ||
| 75 | - numAnswers = ord(bytes[6]) << 8 | ord(bytes[7]) | ||
| 76 | - numAuthorities = ord(bytes[8]) << 8 | ord(bytes[9]) | ||
| 77 | - numAddtionals = ord(bytes[10]) << 8 | ord(bytes[11]) | ||
| 75 | + (numQuestions, numAnswers, numAuthorities, | ||
| 76 | + numAdditionals) = struct.unpack('>4H', bytes[4:12]) | ||
| 78 | 77 | self.assertEqual(numQuestions, 10) | |
| 79 | 78 | self.assertEqual(numAnswers, 0) | |
| 80 | 79 | self.assertEqual(numAuthorities, 0) | |
| 81 | - self.assertEqual(numAddtionals, 0) | ||
| 80 | + self.assertEqual(numAdditionals, 0) | ||
| 82 | 81 | ||
| 83 | 82 | class Names(unittest.TestCase): | |
| 84 | 83 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,7 @@ | |||
| 1 | 1 | #!/usr/bin/env python | |
| 2 | 2 | ||
| 3 | + """ Example of browsing for a service (in this case, HTTP) """ | ||
| 4 | + | ||
| 3 | 5 | from zeroconf import * | |
| 4 | 6 | import socket | |
| 5 | 7 | import time | |
@@ -36,5 +38,5 @@ def addService(self, zeroconf, type, name): | |||
| 36 | 38 | type = "_http._tcp.local." | |
| 37 | 39 | listener = MyListener() | |
| 38 | 40 | browser = ServiceBrowser(r, type, listener) | |
| 39 | - time.sleep(10) | ||
| 41 | + time.sleep(5) | ||
| 40 | 42 | r.close() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,7 @@ | |||
| 1 | 1 | #!/usr/bin/env python | |
| 2 | 2 | ||
| 3 | + """ Example of announcing a service (in this case, a fake HTTP server) """ | ||
| 4 | + | ||
| 3 | 5 | from zeroconf import * | |
| 4 | 6 | import socket | |
| 5 | 7 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments