1515
1616import zeroconf as r
1717from zeroconf import core
18+ from zeroconf import const
1819
1920from . import has_working_ipv6 , _inject_response
2021
@@ -39,8 +40,8 @@ def test_reaper(self):
3940 zeroconf = core .Zeroconf (interfaces = ['127.0.0.1' ])
4041 cache = zeroconf .cache
4142 original_entries = list (itertools .chain (* [cache .entries_with_name (name ) for name in cache .names ()]))
42- record_with_10s_ttl = r .DNSAddress ('a' , r ._TYPE_SOA , r ._CLASS_IN , 10 , b'a' )
43- record_with_1s_ttl = r .DNSAddress ('a' , r ._TYPE_SOA , r ._CLASS_IN , 1 , b'b' )
43+ record_with_10s_ttl = r .DNSAddress ('a' , const ._TYPE_SOA , const ._CLASS_IN , 10 , b'a' )
44+ record_with_1s_ttl = r .DNSAddress ('a' , const ._TYPE_SOA , const ._CLASS_IN , 1 , b'b' )
4445 zeroconf .cache .add (record_with_10s_ttl )
4546 zeroconf .cache .add (record_with_1s_ttl )
4647 entries_with_cache = list (itertools .chain (* [cache .entries_with_name (name ) for name in cache .names ()]))
@@ -102,34 +103,51 @@ def test_launch_and_close_v6_only(self):
102103 def test_handle_response (self ):
103104 def mock_incoming_msg (service_state_change : r .ServiceStateChange ) -> r .DNSIncoming :
104105 ttl = 120
105- generated = r .DNSOutgoing (r ._FLAGS_QR_RESPONSE )
106+ generated = r .DNSOutgoing (const ._FLAGS_QR_RESPONSE )
106107
107108 if service_state_change == r .ServiceStateChange .Updated :
108109 generated .add_answer_at_time (
109- r .DNSText (service_name , r ._TYPE_TXT , r ._CLASS_IN | r ._CLASS_UNIQUE , ttl , service_text ), 0
110+ r .DNSText (
111+ service_name ,
112+ const ._TYPE_TXT ,
113+ const ._CLASS_IN | const ._CLASS_UNIQUE ,
114+ ttl ,
115+ service_text ,
116+ ),
117+ 0 ,
110118 )
111119 return r .DNSIncoming (generated .packet ())
112120
113121 if service_state_change == r .ServiceStateChange .Removed :
114122 ttl = 0
115123
116124 generated .add_answer_at_time (
117- r .DNSPointer (service_type , r ._TYPE_PTR , r ._CLASS_IN , ttl , service_name ), 0
125+ r .DNSPointer (service_type , const ._TYPE_PTR , const ._CLASS_IN , ttl , service_name ), 0
118126 )
119127 generated .add_answer_at_time (
120128 r .DNSService (
121- service_name , r ._TYPE_SRV , r ._CLASS_IN | r ._CLASS_UNIQUE , ttl , 0 , 0 , 80 , service_server
129+ service_name ,
130+ const ._TYPE_SRV ,
131+ const ._CLASS_IN | const ._CLASS_UNIQUE ,
132+ ttl ,
133+ 0 ,
134+ 0 ,
135+ 80 ,
136+ service_server ,
122137 ),
123138 0 ,
124139 )
125140 generated .add_answer_at_time (
126- r .DNSText (service_name , r ._TYPE_TXT , r ._CLASS_IN | r ._CLASS_UNIQUE , ttl , service_text ), 0
141+ r .DNSText (
142+ service_name , const ._TYPE_TXT , const ._CLASS_IN | const ._CLASS_UNIQUE , ttl , service_text
143+ ),
144+ 0 ,
127145 )
128146 generated .add_answer_at_time (
129147 r .DNSAddress (
130148 service_server ,
131- r ._TYPE_A ,
132- r ._CLASS_IN | r ._CLASS_UNIQUE ,
149+ const ._TYPE_A ,
150+ const ._CLASS_IN | const ._CLASS_UNIQUE ,
133151 ttl ,
134152 socket .inet_aton (service_address ),
135153 ),
@@ -141,20 +159,27 @@ def mock_incoming_msg(service_state_change: r.ServiceStateChange) -> r.DNSIncomi
141159 def mock_split_incoming_msg (service_state_change : r .ServiceStateChange ) -> r .DNSIncoming :
142160 """Mock an incoming message for the case where the packet is split."""
143161 ttl = 120
144- generated = r .DNSOutgoing (r ._FLAGS_QR_RESPONSE )
162+ generated = r .DNSOutgoing (const ._FLAGS_QR_RESPONSE )
145163 generated .add_answer_at_time (
146164 r .DNSAddress (
147165 service_server ,
148- r ._TYPE_A ,
149- r ._CLASS_IN | r ._CLASS_UNIQUE ,
166+ const ._TYPE_A ,
167+ const ._CLASS_IN | const ._CLASS_UNIQUE ,
150168 ttl ,
151169 socket .inet_aton (service_address ),
152170 ),
153171 0 ,
154172 )
155173 generated .add_answer_at_time (
156174 r .DNSService (
157- service_name , r ._TYPE_SRV , r ._CLASS_IN | r ._CLASS_UNIQUE , ttl , 0 , 0 , 80 , service_server
175+ service_name ,
176+ const ._TYPE_SRV ,
177+ const ._CLASS_IN | const ._CLASS_UNIQUE ,
178+ ttl ,
179+ 0 ,
180+ 0 ,
181+ 80 ,
182+ service_server ,
158183 ),
159184 0 ,
160185 )
@@ -171,10 +196,10 @@ def mock_split_incoming_msg(service_state_change: r.ServiceStateChange) -> r.DNS
171196 try :
172197 # service added
173198 _inject_response (zeroconf , mock_incoming_msg (r .ServiceStateChange .Added ))
174- dns_text = zeroconf .cache .get_by_details (service_name , r ._TYPE_TXT , r ._CLASS_IN )
199+ dns_text = zeroconf .cache .get_by_details (service_name , const ._TYPE_TXT , const ._CLASS_IN )
175200 assert dns_text is not None
176201 assert cast (r .DNSText , dns_text ).text == service_text # service_text is b'path=/~paulsm/'
177- all_dns_text = zeroconf .cache .get_all_by_details (service_name , r ._TYPE_TXT , r ._CLASS_IN )
202+ all_dns_text = zeroconf .cache .get_all_by_details (service_name , const ._TYPE_TXT , const ._CLASS_IN )
178203 assert [dns_text ] == all_dns_text
179204
180205 # https://tools.ietf.org/html/rfc6762#section-10.2
@@ -188,7 +213,7 @@ def mock_split_incoming_msg(service_state_change: r.ServiceStateChange) -> r.DNS
188213 # service updated. currently only text record can be updated
189214 service_text = b'path=/~humingchun/'
190215 _inject_response (zeroconf , mock_incoming_msg (r .ServiceStateChange .Updated ))
191- dns_text = zeroconf .cache .get_by_details (service_name , r ._TYPE_TXT , r ._CLASS_IN )
216+ dns_text = zeroconf .cache .get_by_details (service_name , const ._TYPE_TXT , const ._CLASS_IN )
192217 assert dns_text is not None
193218 assert cast (r .DNSText , dns_text ).text == service_text # service_text is b'path=/~humingchun/'
194219
@@ -198,13 +223,13 @@ def mock_split_incoming_msg(service_state_change: r.ServiceStateChange) -> r.DNS
198223 # This should not evict TXT records from the cache
199224 _inject_response (zeroconf , mock_split_incoming_msg (r .ServiceStateChange .Updated ))
200225 time .sleep (1.1 )
201- dns_text = zeroconf .cache .get_by_details (service_name , r ._TYPE_TXT , r ._CLASS_IN )
226+ dns_text = zeroconf .cache .get_by_details (service_name , const ._TYPE_TXT , const ._CLASS_IN )
202227 assert dns_text is not None
203228 assert cast (r .DNSText , dns_text ).text == service_text # service_text is b'path=/~humingchun/'
204229
205230 # service removed
206231 _inject_response (zeroconf , mock_incoming_msg (r .ServiceStateChange .Removed ))
207- dns_text = zeroconf .cache .get_by_details (service_name , r ._TYPE_TXT , r ._CLASS_IN )
232+ dns_text = zeroconf .cache .get_by_details (service_name , const ._TYPE_TXT , const ._CLASS_IN )
208233 assert dns_text is None
209234
210235 finally :
0 commit comments