FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Docstrings for examples; shorter timeout; struct.unpack() vs. ord(). · python-zeroconf/python-zeroconf@0884d6a · GitHub

Repository navigation

Commit 0884d6a

Browse files
committed
Docstrings for examples; shorter timeout; struct.unpack() vs. ord().
1 parent 5e5e78e commit 0884d6a

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

‎zunittest.py‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env python
22

3+
""" Unit tests for zeroconf.py """
4+
35
import zeroconf as r
6+
import struct
47
import unittest
58

69
class PacketGeneration(unittest.TestCase):
@@ -56,29 +59,25 @@ def testResponseHeaderBits(self):
5659
def testNumbers(self):
5760
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
5861
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])
6364
self.assertEqual(numQuestions, 0)
6465
self.assertEqual(numAnswers, 0)
6566
self.assertEqual(numAuthorities, 0)
66-
self.assertEqual(numAddtionals, 0)
67+
self.assertEqual(numAdditionals, 0)
6768

6869
def testNumbersQuestions(self):
6970
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
7071
question = r.DNSQuestion("testname.local.", r._TYPE_SRV, r._CLASS_IN)
7172
for i in xrange(10):
7273
generated.addQuestion(question)
7374
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])
7877
self.assertEqual(numQuestions, 10)
7978
self.assertEqual(numAnswers, 0)
8079
self.assertEqual(numAuthorities, 0)
81-
self.assertEqual(numAddtionals, 0)
80+
self.assertEqual(numAdditionals, 0)
8281

8382
class Names(unittest.TestCase):
8483

‎zwebbrowse.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
""" Example of browsing for a service (in this case, HTTP) """
4+
35
from zeroconf import *
46
import socket
57
import time
@@ -36,5 +38,5 @@ def addService(self, zeroconf, type, name):
3638
type = "_http._tcp.local."
3739
listener = MyListener()
3840
browser = ServiceBrowser(r, type, listener)
39-
time.sleep(10)
41+
time.sleep(5)
4042
r.close()

‎zwebtest.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
""" Example of announcing a service (in this case, a fake HTTP server) """
4+
35
from zeroconf import *
46
import socket
57

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL