1- from __future__ import (
2- absolute_import , division , print_function , unicode_literals )
3-
41""" Multicast DNS Service Discovery for Python, v0.14-wmcbrine
52 Copyright 2003 Paul Scott-Murphy, 2014 William McBrine
63
3633from functools import reduce
3734
3835import netifaces
39- from six import binary_type , indexbytes , int2byte , iteritems , text_type
40- from six .moves import xrange
4136
4237__author__ = 'Paul Scott-Murphy, William McBrine'
4338__maintainer__ = 'Jakub Stasiak <jakub@stasiak.at>'
151146_HAS_ONLY_A_TO_Z_NUM_HYPHEN = re .compile (r'^[A-Za-z0-9\-]+$' )
152147_HAS_ASCII_CONTROL_CHARS = re .compile (r'[\x00-\x1f\x7f]' )
153148
149+ int2byte = struct .Struct (">B" ).pack
150+
154151
155152@enum .unique
156153class InterfaceChoice (enum .Enum ):
@@ -309,7 +306,7 @@ class BadTypeInNameException(Error):
309306# implementation classes
310307
311308
312- class QuietLogger ( object ) :
309+ class QuietLogger :
313310 _seen_logs = {}
314311
315312 @classmethod
@@ -338,7 +335,7 @@ def log_warning_once(cls, *args):
338335 logger (* args )
339336
340337
341- class DNSEntry ( object ) :
338+ class DNSEntry :
342339
343340 """A DNS entry"""
344341
@@ -666,7 +663,7 @@ def read_header(self):
666663
667664 def read_questions (self ):
668665 """Reads questions section of packet"""
669- for i in xrange (self .num_questions ):
666+ for i in range (self .num_questions ):
670667 name = self .read_name ()
671668 type_ , class_ = self .unpack (b'!HH' )
672669
@@ -679,7 +676,7 @@ def read_questions(self):
679676
680677 def read_character_string (self ):
681678 """Reads a character string from the packet"""
682- length = indexbytes ( self .data , self .offset )
679+ length = self .data [ self .offset ]
683680 self .offset += 1
684681 return self .read_string (length )
685682
@@ -697,7 +694,7 @@ def read_others(self):
697694 """Reads the answers, authorities and additionals section of the
698695 packet"""
699696 n = self .num_answers + self .num_authorities + self .num_additionals
700- for i in xrange (n ):
697+ for i in range (n ):
701698 domain = self .read_name ()
702699 type_ , class_ , ttl , length = self .unpack (b'!HHiH' )
703700
@@ -742,7 +739,7 @@ def is_response(self):
742739
743740 def read_utf (self , offset , length ):
744741 """Reads a UTF-8 string of a given length from the packet"""
745- return text_type (self .data [offset :offset + length ], 'utf-8' , 'replace' )
742+ return str (self .data [offset :offset + length ], 'utf-8' , 'replace' )
746743
747744 def read_name (self ):
748745 """Reads a domain name from the packet"""
@@ -752,7 +749,7 @@ def read_name(self):
752749 first = off
753750
754751 while True :
755- length = indexbytes ( self .data , off )
752+ length = self .data [ off ]
756753 off += 1
757754 if length == 0 :
758755 break
@@ -763,7 +760,7 @@ def read_name(self):
763760 elif t == 0xC0 :
764761 if next_ < 0 :
765762 next_ = off + 1
766- off = ((length & 0x3F ) << 8 ) | indexbytes ( self .data , off )
763+ off = ((length & 0x3F ) << 8 ) | self .data [ off ]
767764 if off >= first :
768765 raise IncomingDecodeError (
769766 "Bad domain name (circular) at %s" % (off ,))
@@ -779,7 +776,7 @@ def read_name(self):
779776 return result
780777
781778
782- class DNSOutgoing ( object ) :
779+ class DNSOutgoing :
783780
784781 """Object representation of an outgoing packet"""
785782
@@ -1033,7 +1030,7 @@ def packet(self):
10331030 return b'' .join (self .data )
10341031
10351032
1036- class DNSCache ( object ) :
1033+ class DNSCache :
10371034
10381035 """A cache of DNS entries"""
10391036
@@ -1217,7 +1214,7 @@ def run(self):
12171214 self .zc .cache .remove (record )
12181215
12191216
1220- class Signal ( object ) :
1217+ class Signal :
12211218 def __init__ (self ):
12221219 self ._handlers = []
12231220
@@ -1230,7 +1227,7 @@ def registration_interface(self):
12301227 return SignalRegistrationInterface (self ._handlers )
12311228
12321229
1233- class SignalRegistrationInterface ( object ) :
1230+ class SignalRegistrationInterface :
12341231
12351232 def __init__ (self , handlers ):
12361233 self ._handlers = handlers
@@ -1363,7 +1360,7 @@ def run(self):
13631360 handler (self .zc )
13641361
13651362
1366- class ServiceInfo ( object ) :
1363+ class ServiceInfo :
13671364
13681365 """Service information"""
13691366
@@ -1406,15 +1403,15 @@ def _set_properties(self, properties):
14061403 self ._properties = properties
14071404 list_ = []
14081405 result = b''
1409- for key , value in iteritems ( properties ):
1410- if isinstance (key , text_type ):
1406+ for key , value in properties . items ( ):
1407+ if isinstance (key , str ):
14111408 key = key .encode ('utf-8' )
14121409
14131410 if value is None :
14141411 suffix = b''
1415- elif isinstance (value , text_type ):
1412+ elif isinstance (value , str ):
14161413 suffix = value .encode ('utf-8' )
1417- elif isinstance (value , binary_type ):
1414+ elif isinstance (value , bytes ):
14181415 suffix = value
14191416 elif isinstance (value , int ):
14201417 if value :
@@ -1438,7 +1435,7 @@ def _set_text(self, text):
14381435 index = 0
14391436 strs = []
14401437 while index < end :
1441- length = indexbytes ( text , index )
1438+ length = text [ index ]
14421439 index += 1
14431440 strs .append (text [index :index + length ])
14441441 index += length
@@ -1571,7 +1568,7 @@ def __repr__(self):
15711568 )
15721569
15731570
1574- class ZeroconfServiceTypes ( object ) :
1571+ class ZeroconfServiceTypes :
15751572 """
15761573 Return all of the advertised services on any local networks
15771574 """
0 commit comments