Skip to content

Commit

Permalink
Switch to snake case and clean up import order
Browse files Browse the repository at this point in the history
Closes paulsm#2
  • Loading branch information
jstasiak committed Nov 2, 2014
1 parent ada563c commit 5429748
Show file tree
Hide file tree
Showing 7 changed files with 347 additions and 368 deletions.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ Here's an example:
class MyListener(object):
def removeService(self, zeroconf, type, name):
def remove_service(self, zeroconf, type, name):
print("Service %s removed" % (name,))
def addService(self, zeroconf, type, name):
info = zeroconf.getServiceInfo(type, name)
def add_service(self, zeroconf, type, name):
info = zeroconf.get_service_info(type, name)
print("Service %s added, service info: %s" % (name, info))
Expand Down Expand Up @@ -182,7 +182,7 @@ Changelog
* new style objects
* fixed hostname/interface problem
* fixed socket timeout problem
* fixed addServiceListener() typo bug
* fixed add_service_listener() typo bug
* using select() for socket reads
* tested on Debian unstable with Python 2.2.2

Expand Down
21 changes: 10 additions & 11 deletions examples/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@

class MyListener(object):

def removeService(self, zeroconf, type, name):
def remove_service(self, zeroconf, type, name):
print("Service %s removed" % (name,))
print('\n')

def addService(self, zeroconf, type, name):
def add_service(self, zeroconf, type, name):
print("Service %s added" % (name,))
print(" Type is %s" % (type,))
info = zeroconf.getServiceInfo(type, name)
info = zeroconf.get_service_info(type, name)
if info:
print(" Address is %s:%d" % (socket.inet_ntoa(info.getAddress()),
info.getPort()))
print(" Weight is %d, Priority is %d" % (info.getWeight(),
info.getPriority()))
print(" Server is", info.getServer())
prop = info.getProperties()
if prop:
print(" Address is %s:%d" % (socket.inet_ntoa(info.address),
info.port))
print(" Weight is %d, Priority is %d" % (info.weight,
info.priority))
print(" Server is", info.server)
if info.properties:
print(" Properties are")
for key, value in prop.items():
for key, value in info.properties.items():
print(" %s: %s" % (key, value))
else:
print(" No info")
Expand Down
4 changes: 2 additions & 2 deletions examples/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

zeroconf = Zeroconf()
print("Registration of a service...")
zeroconf.registerService(info)
zeroconf.register_service(info)
try:
raw_input("Waiting (press Enter to exit)...")
finally:
print("Unregistering...")
zeroconf.unregisterService(info)
zeroconf.unregister_service(info)
zeroconf.close()
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ coveralls
coverage
flake8
flake8-blind-except
flake8-import-order>=0.4.0
mock
nose
pep8-naming
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[wheel]
universal = 1

[flake8]
show-source = 1
import-order-style=google
application-import-names=zeroconf
56 changes: 28 additions & 28 deletions test_zeroconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@

class PacketGeneration(unittest.TestCase):

def testParseOwnPacketSimple(self):
def test_parse_own_packet_simple(self):
generated = r.DNSOutgoing(0)
r.DNSIncoming(generated.packet())

def testParseOwnPacketSimpleUnicast(self):
def test_parse_own_packet_simple_unicast(self):
generated = r.DNSOutgoing(0, 0)
r.DNSIncoming(generated.packet())

def testParseOwnPacketFlags(self):
def test_parse_own_packet_flags(self):
generated = r.DNSOutgoing(r._FLAGS_QR_QUERY)
r.DNSIncoming(generated.packet())

def testParseOwnPacketQuestion(self):
def test_parse_own_packet_question(self):
generated = r.DNSOutgoing(r._FLAGS_QR_QUERY)
generated.addQuestion(r.DNSQuestion("testname.local.", r._TYPE_SRV,
r._CLASS_IN))
generated.add_question(r.DNSQuestion("testname.local.", r._TYPE_SRV,
r._CLASS_IN))
r.DNSIncoming(generated.packet())

def testMatchQuestion(self):
def test_match_question(self):
generated = r.DNSOutgoing(r._FLAGS_QR_QUERY)
question = r.DNSQuestion("testname.local.", r._TYPE_SRV, r._CLASS_IN)
generated.addQuestion(question)
generated.add_question(question)
parsed = r.DNSIncoming(generated.packet())
self.assertEqual(len(generated.questions), 1)
self.assertEqual(len(generated.questions), len(parsed.questions))
Expand All @@ -52,26 +52,26 @@ def testMatchQuestion(self):

class PacketForm(unittest.TestCase):

def testTransactionID(self):
def test_transaction_id(self):
"""ID must be zero in a DNS-SD packet"""
generated = r.DNSOutgoing(r._FLAGS_QR_QUERY)
bytes = generated.packet()
id = byte_ord(bytes[0]) << 8 | byte_ord(bytes[1])
self.assertEqual(id, 0)

def testQueryHeaderBits(self):
def test_query_header_bits(self):
generated = r.DNSOutgoing(r._FLAGS_QR_QUERY)
bytes = generated.packet()
flags = byte_ord(bytes[2]) << 8 | byte_ord(bytes[3])
self.assertEqual(flags, 0x0)

def testResponseHeaderBits(self):
def test_response_header_bits(self):
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
bytes = generated.packet()
flags = byte_ord(bytes[2]) << 8 | byte_ord(bytes[3])
self.assertEqual(flags, 0x8000)

def testNumbers(self):
def test_numbers(self):
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
bytes = generated.packet()
(numQuestions, numAnswers, numAuthorities,
Expand All @@ -81,11 +81,11 @@ def testNumbers(self):
self.assertEqual(numAuthorities, 0)
self.assertEqual(numAdditionals, 0)

def testNumbersQuestions(self):
def test_numbers_questions(self):
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
question = r.DNSQuestion("testname.local.", r._TYPE_SRV, r._CLASS_IN)
for i in xrange(10):
generated.addQuestion(question)
generated.add_question(question)
bytes = generated.packet()
(numQuestions, numAnswers, numAuthorities,
numAdditionals) = struct.unpack('!4H', bytes[4:12])
Expand All @@ -97,39 +97,39 @@ def testNumbersQuestions(self):

class Names(unittest.TestCase):

def testLongName(self):
def test_long_name(self):
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
question = r.DNSQuestion("this.is.a.very.long.name.with.lots.of.parts.in.it.local.",
r._TYPE_SRV, r._CLASS_IN)
generated.addQuestion(question)
generated.add_question(question)
r.DNSIncoming(generated.packet())

def testExceedinglyLongName(self):
def test_exceedingly_long_name(self):
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
name = "%slocal." % ("part." * 1000)
question = r.DNSQuestion(name, r._TYPE_SRV, r._CLASS_IN)
generated.addQuestion(question)
generated.add_question(question)
r.DNSIncoming(generated.packet())

def testExceedinglyLongNamePart(self):
def test_exceedingly_long_name_part(self):
name = "%s.local." % ("a" * 1000)
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
question = r.DNSQuestion(name, r._TYPE_SRV, r._CLASS_IN)
generated.addQuestion(question)
generated.add_question(question)
self.assertRaises(r.NamePartTooLongException, generated.packet)

def testSameName(self):
def test_same_name(self):
name = "paired.local."
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
question = r.DNSQuestion(name, r._TYPE_SRV, r._CLASS_IN)
generated.addQuestion(question)
generated.addQuestion(question)
generated.add_question(question)
generated.add_question(question)
r.DNSIncoming(generated.packet())


class Framework(unittest.TestCase):

def testLaunchAndClose(self):
def test_launch_and_close(self):
rv = r.Zeroconf()
rv.close()

Expand All @@ -143,11 +143,11 @@ def test_integration():

class MyListener(object):

def removeService(self, zeroconf, type_, name):
def remove_service(self, zeroconf, type_, name):
if name == registration_name:
service_removed.set()

def addService(self, zeroconf, type_, name):
def add_service(self, zeroconf, type_, name):
if name == registration_name:
service_added.set()

Expand All @@ -161,12 +161,12 @@ def addService(self, zeroconf, type_, name):
type_, registration_name,
socket.inet_aton("10.0.1.2"), 80, 0, 0,
desc, "ash-2.local.")
zeroconf_registrar.registerService(info)
zeroconf_registrar.register_service(info)

try:
service_added.wait(1)
assert service_added.is_set()
zeroconf_registrar.unregisterService(info)
zeroconf_registrar.unregister_service(info)
service_removed.wait(1)
assert service_removed.is_set()
finally:
Expand Down
Loading

0 comments on commit 5429748

Please sign in to comment.