Show More
@@ -490,7 +490,8 class DNSIncoming(object): | |||
|
490 | 490 | """Reads header portion of packet""" |
|
491 | 491 | format = '!HHHHHH' |
|
492 | 492 | length = struct.calcsize(format) |
|
493 |
info = struct.unpack(format, |
|
|
493 | info = struct.unpack(format, | |
|
494 | self.data[self.offset:self.offset + length]) | |
|
494 | 495 | self.offset += length |
|
495 | 496 | |
|
496 | 497 | self.id = info[0] |
@@ -507,7 +508,7 class DNSIncoming(object): | |||
|
507 | 508 | for i in range(0, self.numQuestions): |
|
508 | 509 | name = self.readName() |
|
509 | 510 | info = struct.unpack(format, |
|
510 | self.data[self.offset:self.offset+length]) | |
|
511 | self.data[self.offset:self.offset + length]) | |
|
511 | 512 | self.offset += length |
|
512 | 513 | |
|
513 | 514 | try: |
@@ -520,7 +521,8 class DNSIncoming(object): | |||
|
520 | 521 | """Reads an integer from the packet""" |
|
521 | 522 | format = '!I' |
|
522 | 523 | length = struct.calcsize(format) |
|
523 |
info = struct.unpack(format, |
|
|
524 | info = struct.unpack(format, | |
|
525 | self.data[self.offset:self.offset + length]) | |
|
524 | 526 | self.offset += length |
|
525 | 527 | return info[0] |
|
526 | 528 | |
@@ -534,7 +536,8 class DNSIncoming(object): | |||
|
534 | 536 | """Reads a string of a given length from the packet""" |
|
535 | 537 | format = '!' + str(len) + 's' |
|
536 | 538 | length = struct.calcsize(format) |
|
537 |
info = struct.unpack(format, |
|
|
539 | info = struct.unpack(format, | |
|
540 | self.data[self.offset:self.offset + length]) | |
|
538 | 541 | self.offset += length |
|
539 | 542 | return info[0] |
|
540 | 543 | |
@@ -542,7 +545,8 class DNSIncoming(object): | |||
|
542 | 545 | """Reads an unsigned short from the packet""" |
|
543 | 546 | format = '!H' |
|
544 | 547 | length = struct.calcsize(format) |
|
545 |
info = struct.unpack(format, |
|
|
548 | info = struct.unpack(format, | |
|
549 | self.data[self.offset:self.offset + length]) | |
|
546 | 550 | self.offset += length |
|
547 | 551 | return info[0] |
|
548 | 552 | |
@@ -554,7 +558,7 class DNSIncoming(object): | |||
|
554 | 558 | for i in range(0, n): |
|
555 | 559 | domain = self.readName() |
|
556 | 560 | info = struct.unpack(format, |
|
557 | self.data[self.offset:self.offset+length]) | |
|
561 | self.data[self.offset:self.offset + length]) | |
|
558 | 562 | self.offset += length |
|
559 | 563 | |
|
560 | 564 | rec = None |
@@ -604,7 +608,7 class DNSIncoming(object): | |||
|
604 | 608 | |
|
605 | 609 | def readUTF(self, offset, len): |
|
606 | 610 | """Reads a UTF-8 string of a given length from the packet""" |
|
607 | return self.data[offset:offset+len].decode('utf-8') | |
|
611 | return self.data[offset:offset + len].decode('utf-8') | |
|
608 | 612 | |
|
609 | 613 | def readName(self): |
|
610 | 614 | """Reads a domain name from the packet""" |
@@ -848,7 +852,7 class DNSCache(object): | |||
|
848 | 852 | |
|
849 | 853 | def entries(self): |
|
850 | 854 | """Returns a list of all entries""" |
|
851 | def add(x, y): return x+y | |
|
855 | def add(x, y): return x + y | |
|
852 | 856 | try: |
|
853 | 857 | return reduce(add, self.cache.values()) |
|
854 | 858 | except Exception: |
@@ -1123,7 +1127,7 class ServiceInfo(object): | |||
|
1123 | 1127 | while index < end: |
|
1124 | 1128 | length = ord(text[index]) |
|
1125 | 1129 | index += 1 |
|
1126 | strs.append(text[index:index+length]) | |
|
1130 | strs.append(text[index:index + length]) | |
|
1127 | 1131 | index += length |
|
1128 | 1132 | |
|
1129 | 1133 | for s in strs: |
@@ -1134,7 +1138,7 class ServiceInfo(object): | |||
|
1134 | 1138 | value = 0 |
|
1135 | 1139 | else: |
|
1136 | 1140 | key = s[:eindex] |
|
1137 | value = s[eindex+1:] | |
|
1141 | value = s[eindex + 1:] | |
|
1138 | 1142 | if value == 'true': |
|
1139 | 1143 | value = 1 |
|
1140 | 1144 | elif value == 'false' or not value: |
@@ -1346,7 +1350,7 class Zeroconf(object): | |||
|
1346 | 1350 | """Calling thread waits for a given number of milliseconds or |
|
1347 | 1351 | until notified.""" |
|
1348 | 1352 | self.condition.acquire() |
|
1349 | self.condition.wait(timeout/1000) | |
|
1353 | self.condition.wait(timeout / 1000) | |
|
1350 | 1354 | self.condition.release() |
|
1351 | 1355 | |
|
1352 | 1356 | def notifyAll(self): |
@@ -1386,9 +1390,9 class Zeroconf(object): | |||
|
1386 | 1390 | self.checkService(info) |
|
1387 | 1391 | self.services[info.name.lower()] = info |
|
1388 | 1392 | if self.servicetypes.has_key(info.type): |
|
1389 | self.servicetypes[info.type]+=1 | |
|
1393 | self.servicetypes[info.type] += 1 | |
|
1390 | 1394 | else: |
|
1391 | self.servicetypes[info.type]=1 | |
|
1395 | self.servicetypes[info.type] = 1 | |
|
1392 | 1396 | now = currentTimeMillis() |
|
1393 | 1397 | nextTime = now |
|
1394 | 1398 | i = 0 |
@@ -1420,8 +1424,8 class Zeroconf(object): | |||
|
1420 | 1424 | """Unregister a service.""" |
|
1421 | 1425 | try: |
|
1422 | 1426 | del(self.services[info.name.lower()]) |
|
1423 | if self.servicetypes[info.type]>1: | |
|
1424 | self.servicetypes[info.type]-=1 | |
|
1427 | if self.servicetypes[info.type] > 1: | |
|
1428 | self.servicetypes[info.type] -= 1 | |
|
1425 | 1429 | else: |
|
1426 | 1430 | del self.servicetypes[info.type] |
|
1427 | 1431 | except KeyError: |
General Comments 0
You need to be logged in to leave comments.
Login now