GeezerVison is showing github.com — Upgrade syntax to python 3.6 (#907) · python-zeroconf/python-zeroconf@0578731
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: examples/async_apple_scanner.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 36 | 36 | def async_on_service_state_change( | 37 | 37 | zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange | 38 | 38 | ) -> None: | 39 | | - print("Service %s of type %s state changed: %s" % (name, service_type, state_change)) | | 39 | + print(f"Service {name} of type {service_type} state changed: {state_change}") | 40 | 40 | if state_change is not ServiceStateChange.Added: | 41 | 41 | return | 42 | 42 | base_name = name[: -len(service_type) - 1] | @@ -55,11 +55,11 @@ async def _async_show_service_info(zeroconf: Zeroconf, service_type: str, name: | 55 | 55 | print(" Name: %s" % name) | 56 | 56 | print(" Addresses: %s" % ", ".join(addresses)) | 57 | 57 | print(" Weight: %d, priority: %d" % (info.weight, info.priority)) | 58 | | - print(" Server: %s" % (info.server,)) | | 58 | + print(f" Server: {info.server}") | 59 | 59 | if info.properties: | 60 | 60 | print(" Properties are:") | 61 | 61 | for key, value in info.properties.items(): | 62 | | - print(" %s: %s" % (key, value)) | | 62 | + print(f" {key}: {value}") | 63 | 63 | else: | 64 | 64 | print(" No properties") | 65 | 65 | else: | |
Collapse file Copy file name to clipboardExpand all lines: examples/async_browser.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 17 | 17 | def async_on_service_state_change( | 18 | 18 | zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange | 19 | 19 | ) -> None: | 20 | | - print("Service %s of type %s state changed: %s" % (name, service_type, state_change)) | | 20 | + print(f"Service {name} of type {service_type} state changed: {state_change}") | 21 | 21 | if state_change is not ServiceStateChange.Added: | 22 | 22 | return | 23 | 23 | asyncio.ensure_future(async_display_service_info(zeroconf, service_type, name)) | @@ -32,11 +32,11 @@ async def async_display_service_info(zeroconf: Zeroconf, service_type: str, name | 32 | 32 | print(" Name: %s" % name) | 33 | 33 | print(" Addresses: %s" % ", ".join(addresses)) | 34 | 34 | print(" Weight: %d, priority: %d" % (info.weight, info.priority)) | 35 | | - print(" Server: %s" % (info.server,)) | | 35 | + print(f" Server: {info.server}") | 36 | 36 | if info.properties: | 37 | 37 | print(" Properties are:") | 38 | 38 | for key, value in info.properties.items(): | 39 | | - print(" %s: %s" % (key, value)) | | 39 | + print(f" {key}: {value}") | 40 | 40 | else: | 41 | 41 | print(" No properties") | 42 | 42 | else: | |
Collapse file Copy file name to clipboardExpand all lines: examples/async_service_info_request.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,11 +36,11 @@ async def async_watch_services(aiozc: AsyncZeroconf) -> None: | 36 | 36 | addresses = ["%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_addresses()] | 37 | 37 | print(" Addresses: %s" % ", ".join(addresses)) | 38 | 38 | print(" Weight: %d, priority: %d" % (info.weight, info.priority)) | 39 | | - print(" Server: %s" % (info.server,)) | | 39 | + print(f" Server: {info.server}") | 40 | 40 | if info.properties: | 41 | 41 | print(" Properties are:") | 42 | 42 | for key, value in info.properties.items(): | 43 | | - print(" %s: %s" % (key, value)) | | 43 | + print(f" {key}: {value}") | 44 | 44 | else: | 45 | 45 | print(" No properties") | 46 | 46 | else: | |
Collapse file Copy file name to clipboardExpand all lines: examples/browser.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 | def on_service_state_change( | 17 | 17 | zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange | 18 | 18 | ) -> None: | 19 | | - print("Service %s of type %s state changed: %s" % (name, service_type, state_change)) | | 19 | + print(f"Service {name} of type {service_type} state changed: {state_change}") | 20 | 20 |
| 21 | 21 | if state_change is ServiceStateChange.Added: | 22 | 22 | info = zeroconf.get_service_info(service_type, name) | @@ -26,11 +26,11 @@ def on_service_state_change( | 26 | 26 | addresses = ["%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_scoped_addresses()] | 27 | 27 | print(" Addresses: %s" % ", ".join(addresses)) | 28 | 28 | print(" Weight: %d, priority: %d" % (info.weight, info.priority)) | 29 | | - print(" Server: %s" % (info.server,)) | | 29 | + print(f" Server: {info.server}") | 30 | 30 | if info.properties: | 31 | 31 | print(" Properties are:") | 32 | 32 | for key, value in info.properties.items(): | 33 | | - print(" %s: %s" % (key, value)) | | 33 | + print(f" {key}: {value}") | 34 | 34 | else: | 35 | 35 | print(" No properties") | 36 | 36 | else: | |
Collapse file Copy file name to clipboardExpand all lines: examples/self_test.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 |
| 15 | 15 | # Test a few module features, including service registration, service | 16 | 16 | # query (for Zoe), and service unregistration. | 17 | | - print("Multicast DNS Service Discovery for Python, version %s" % (__version__,)) | | 17 | + print(f"Multicast DNS Service Discovery for Python, version {__version__}") | 18 | 18 | r = Zeroconf() | 19 | 19 | print("1. Testing registration of a service...") | 20 | 20 | desc = {'version': '0.10', 'a': 'test value', 'b': 'another value'} | | 40 | 40 | queried_info = r.get_service_info("_http._tcp.local.", "My Service Name._http._tcp.local.") | 41 | 41 | assert queried_info | 42 | 42 | assert set(queried_info.parsed_addresses()) == expected | 43 | | - print(" Getting self: %s" % (queried_info,)) | | 43 | + print(f" Getting self: {queried_info}") | 44 | 44 | print(" Query done.") | 45 | 45 | print("4. Testing unregister of service information...") | 46 | 46 | r.unregister_service(info) | |
Collapse file Copy file name to clipboardExpand all lines: tests/conftest.py -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #!/usr/bin/env python | 2 | | -# -*- coding: utf-8 -*- | 3 | 2 |
| 4 | 3 |
| 5 | 4 | """ conftest for zeroconf tests. """ | |
Collapse file Copy file name to clipboardExpand all lines: tests/test_asyncio.py +16-19Lines changed: 16 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #!/usr/bin/env python | 2 | | -# -*- coding: utf-8 -*- | 3 | 2 |
| 4 | 3 |
| 5 | 4 | """Unit tests for aio.py.""" | @@ -57,11 +56,9 @@ def verify_threads_ended(): | 57 | 56 | yield | 58 | 57 | threads_after = frozenset(threading.enumerate()) | 59 | 58 | non_executor_threads = frozenset( | 60 | | - [ | 61 | | - thread | 62 | | - for thread in threads_after | 63 | | - if "asyncio" not in thread.name and "ThreadPoolExecutor" not in thread.name | 64 | | - ] | | 59 | + thread | | 60 | + for thread in threads_after | | 61 | + if "asyncio" not in thread.name and "ThreadPoolExecutor" not in thread.name | 65 | 62 | ) | 66 | 63 | threads = non_executor_threads - threads_before | 67 | 64 | assert not threads | @@ -119,7 +116,7 @@ async def test_async_service_registration() -> None: | 119 | 116 | aiozc = AsyncZeroconf(interfaces=['127.0.0.1']) | 120 | 117 | type_ = "_test1-srvc-type._tcp.local." | 121 | 118 | name = "xxxyyy" | 122 | | - registration_name = "%s.%s" % (name, type_) | | 119 | + registration_name = f"{name}.{type_}" | 123 | 120 |
| 124 | 121 | calls = [] | 125 | 122 |
| @@ -179,7 +176,7 @@ async def test_async_service_registration_name_conflict() -> None: | 179 | 176 | aiozc = AsyncZeroconf(interfaces=['127.0.0.1']) | 180 | 177 | type_ = "_test-srvc2-type._tcp.local." | 181 | 178 | name = "xxxyyy" | 182 | | - registration_name = "%s.%s" % (name, type_) | | 179 | + registration_name = f"{name}.{type_}" | 183 | 180 |
| 184 | 181 | desc = {'path': '/~paulsm/'} | 185 | 182 | info = ServiceInfo( | @@ -227,7 +224,7 @@ async def test_async_service_registration_name_does_not_match_type() -> None: | 227 | 224 | aiozc = AsyncZeroconf(interfaces=['127.0.0.1']) | 228 | 225 | type_ = "_test-srvc3-type._tcp.local." | 229 | 226 | name = "xxxyyy" | 230 | | - registration_name = "%s.%s" % (name, type_) | | 227 | + registration_name = f"{name}.{type_}" | 231 | 228 |
| 232 | 229 | desc = {'path': '/~paulsm/'} | 233 | 230 | info = ServiceInfo( | @@ -254,7 +251,7 @@ async def test_async_tasks() -> None: | 254 | 251 | aiozc = AsyncZeroconf(interfaces=['127.0.0.1']) | 255 | 252 | type_ = "_test-srvc4-type._tcp.local." | 256 | 253 | name = "xxxyyy" | 257 | | - registration_name = "%s.%s" % (name, type_) | | 254 | + registration_name = f"{name}.{type_}" | 258 | 255 |
| 259 | 256 | calls = [] | 260 | 257 |
| @@ -320,7 +317,7 @@ async def test_async_wait_unblocks_on_update() -> None: | 320 | 317 | aiozc = AsyncZeroconf(interfaces=['127.0.0.1']) | 321 | 318 | type_ = "_test-srvc4-type._tcp.local." | 322 | 319 | name = "xxxyyy" | 323 | | - registration_name = "%s.%s" % (name, type_) | | 320 | + registration_name = f"{name}.{type_}" | 324 | 321 |
| 325 | 322 | desc = {'path': '/~paulsm/'} | 326 | 323 | info = ServiceInfo( | @@ -356,8 +353,8 @@ async def test_service_info_async_request() -> None: | 356 | 353 | type_ = "_test1-srvc-type._tcp.local." | 357 | 354 | name = "xxxyyy" | 358 | 355 | name2 = "abc" | 359 | | - registration_name = "%s.%s" % (name, type_) | 360 | | - registration_name2 = "%s.%s" % (name2, type_) | | 356 | + registration_name = f"{name}.{type_}" | | 357 | + registration_name2 = f"{name2}.{type_}" | 361 | 358 |
| 362 | 359 | # Start a tasks BEFORE the registration that will keep trying | 363 | 360 | # and see the registration a bit later | @@ -454,7 +451,7 @@ async def test_async_service_browser() -> None: | 454 | 451 | aiozc = AsyncZeroconf(interfaces=['127.0.0.1']) | 455 | 452 | type_ = "_test9-srvc-type._tcp.local." | 456 | 453 | name = "xxxyyy" | 457 | | - registration_name = "%s.%s" % (name, type_) | | 454 | + registration_name = f"{name}.{type_}" | 458 | 455 |
| 459 | 456 | calls = [] | 460 | 457 |
| @@ -513,7 +510,7 @@ async def test_async_context_manager() -> None: | 513 | 510 | """Test using an async context manager.""" | 514 | 511 | type_ = "_test10-sr-type._tcp.local." | 515 | 512 | name = "xxxyyy" | 516 | | - registration_name = "%s.%s" % (name, type_) | | 513 | + registration_name = f"{name}.{type_}" | 517 | 514 |
| 518 | 515 | async with AsyncZeroconf(interfaces=['127.0.0.1']) as aiozc: | 519 | 516 | info = ServiceInfo( | @@ -539,8 +536,8 @@ async def test_async_unregister_all_services() -> None: | 539 | 536 | type_ = "_test1-srvc-type._tcp.local." | 540 | 537 | name = "xxxyyy" | 541 | 538 | name2 = "abc" | 542 | | - registration_name = "%s.%s" % (name, type_) | 543 | | - registration_name2 = "%s.%s" % (name2, type_) | | 539 | + registration_name = f"{name}.{type_}" | | 540 | + registration_name2 = f"{name2}.{type_}" | 544 | 541 |
| 545 | 542 | desc = {'path': '/~paulsm/'} | 546 | 543 | info = ServiceInfo( | @@ -594,7 +591,7 @@ async def test_async_unregister_all_services() -> None: | 594 | 591 | async def test_async_zeroconf_service_types(): | 595 | 592 | type_ = "_test-srvc-type._tcp.local." | 596 | 593 | name = "xxxyyy" | 597 | | - registration_name = "%s.%s" % (name, type_) | | 594 | + registration_name = f"{name}.{type_}" | 598 | 595 |
| 599 | 596 | zeroconf_registrar = AsyncZeroconf(interfaces=['127.0.0.1']) | 600 | 597 | desc = {'path': '/~paulsm/'} | @@ -808,7 +805,7 @@ async def test_info_asking_default_is_asking_qm_questions_after_the_first_qu(): | 808 | 805 | zeroconf_info = aiozc.zeroconf | 809 | 806 |
| 810 | 807 | name = "xxxyyy" | 811 | | - registration_name = "%s.%s" % (name, type_) | | 808 | + registration_name = f"{name}.{type_}" | 812 | 809 |
| 813 | 810 | desc = {'path': '/~paulsm/'} | 814 | 811 | info = ServiceInfo( | |
Collapse file Copy file name to clipboardExpand all lines: tests/test_cache.py +10-11Lines changed: 10 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #!/usr/bin/env python | 2 | | -# -*- coding: utf-8 -*- | 3 | 2 |
| 4 | 3 |
| 5 | 4 | """ Unit tests for zeroconf._cache. """ | @@ -98,7 +97,7 @@ def test_async_all_by_details(self): | 98 | 97 | record2 = r.DNSAddress('a', const._TYPE_A, const._CLASS_IN, 1, b'b') | 99 | 98 | cache = r.DNSCache() | 100 | 99 | cache.async_add_records([record1, record2]) | 101 | | - assert set(cache.async_all_by_details('a', const._TYPE_A, const._CLASS_IN)) == set([record1, record2]) | | 100 | + assert set(cache.async_all_by_details('a', const._TYPE_A, const._CLASS_IN)) == {record1, record2} | 102 | 101 |
| 103 | 102 | def test_async_entries_with_server(self): | 104 | 103 | record1 = r.DNSService( | @@ -109,8 +108,8 @@ def test_async_entries_with_server(self): | 109 | 108 | ) | 110 | 109 | cache = r.DNSCache() | 111 | 110 | cache.async_add_records([record1, record2]) | 112 | | - assert set(cache.async_entries_with_server('ab')) == set([record1, record2]) | 113 | | - assert set(cache.async_entries_with_server('AB')) == set([record1, record2]) | | 111 | + assert set(cache.async_entries_with_server('ab')) == {record1, record2} | | 112 | + assert set(cache.async_entries_with_server('AB')) == {record1, record2} | 114 | 113 |
| 115 | 114 | def test_async_entries_with_name(self): | 116 | 115 | record1 = r.DNSService( | @@ -121,8 +120,8 @@ def test_async_entries_with_name(self): | 121 | 120 | ) | 122 | 121 | cache = r.DNSCache() | 123 | 122 | cache.async_add_records([record1, record2]) | 124 | | - assert set(cache.async_entries_with_name('irrelevant')) == set([record1, record2]) | 125 | | - assert set(cache.async_entries_with_name('Irrelevant')) == set([record1, record2]) | | 123 | + assert set(cache.async_entries_with_name('irrelevant')) == {record1, record2} | | 124 | + assert set(cache.async_entries_with_name('Irrelevant')) == {record1, record2} | 126 | 125 |
| 127 | 126 |
| 128 | 127 | # These functions have been seen in other projects so | @@ -152,7 +151,7 @@ def test_get_all_by_details(self): | 152 | 151 | record2 = r.DNSAddress('a', const._TYPE_A, const._CLASS_IN, 1, b'b') | 153 | 152 | cache = r.DNSCache() | 154 | 153 | cache.async_add_records([record1, record2]) | 155 | | - assert set(cache.get_all_by_details('a', const._TYPE_A, const._CLASS_IN)) == set([record1, record2]) | | 154 | + assert set(cache.get_all_by_details('a', const._TYPE_A, const._CLASS_IN)) == {record1, record2} | 156 | 155 |
| 157 | 156 | def test_entries_with_server(self): | 158 | 157 | record1 = r.DNSService( | @@ -163,8 +162,8 @@ def test_entries_with_server(self): | 163 | 162 | ) | 164 | 163 | cache = r.DNSCache() | 165 | 164 | cache.async_add_records([record1, record2]) | 166 | | - assert set(cache.entries_with_server('ab')) == set([record1, record2]) | 167 | | - assert set(cache.entries_with_server('AB')) == set([record1, record2]) | | 165 | + assert set(cache.entries_with_server('ab')) == {record1, record2} | | 166 | + assert set(cache.entries_with_server('AB')) == {record1, record2} | 168 | 167 |
| 169 | 168 | def test_entries_with_name(self): | 170 | 169 | record1 = r.DNSService( | @@ -175,8 +174,8 @@ def test_entries_with_name(self): | 175 | 174 | ) | 176 | 175 | cache = r.DNSCache() | 177 | 176 | cache.async_add_records([record1, record2]) | 178 | | - assert set(cache.entries_with_name('irrelevant')) == set([record1, record2]) | 179 | | - assert set(cache.entries_with_name('Irrelevant')) == set([record1, record2]) | | 177 | + assert set(cache.entries_with_name('irrelevant')) == {record1, record2} | | 178 | + assert set(cache.entries_with_name('Irrelevant')) == {record1, record2} | 180 | 179 |
| 181 | 180 | def test_current_entry_with_name_and_alias(self): | 182 | 181 | record1 = r.DNSPointer( | |
Collapse file Copy file name to clipboardExpand all lines: tests/test_core.py +20-23Lines changed: 20 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #!/usr/bin/env python | 2 | | -# -*- coding: utf-8 -*- | 3 | 2 |
| 4 | 3 |
| 5 | 4 | """ Unit tests for zeroconf._core """ | @@ -55,28 +54,26 @@ async def test_reaper(): | 55 | 54 | aiozc = AsyncZeroconf(interfaces=['127.0.0.1']) | 56 | 55 | zeroconf = aiozc.zeroconf | 57 | 56 | cache = zeroconf.cache | 58 | | - original_entries = list(itertools.chain(*[cache.entries_with_name(name) for name in cache.names()])) | | 57 | + original_entries = list(itertools.chain(*(cache.entries_with_name(name) for name in cache.names()))) | 59 | 58 | record_with_10s_ttl = r.DNSAddress('a', const._TYPE_SOA, const._CLASS_IN, 10, b'a') | 60 | 59 | record_with_1s_ttl = r.DNSAddress('a', const._TYPE_SOA, const._CLASS_IN, 1, b'b') | 61 | 60 | zeroconf.cache.async_add_records([record_with_10s_ttl, record_with_1s_ttl]) | 62 | 61 | question = r.DNSQuestion("_hap._tcp._local.", const._TYPE_PTR, const._CLASS_IN) | 63 | 62 | now = r.current_time_millis() | 64 | | - other_known_answers = set( | 65 | | - [ | 66 | | - r.DNSPointer( | 67 | | - "_hap._tcp.local.", | 68 | | - const._TYPE_PTR, | 69 | | - const._CLASS_IN, | 70 | | - 10000, | 71 | | - 'known-to-other._hap._tcp.local.', | 72 | | - ) | 73 | | - ] | 74 | | - ) | | 63 | + other_known_answers = { | | 64 | + r.DNSPointer( | | 65 | + "_hap._tcp.local.", | | 66 | + const._TYPE_PTR, | | 67 | + const._CLASS_IN, | | 68 | + 10000, | | 69 | + 'known-to-other._hap._tcp.local.', | | 70 | + ) | | 71 | + } | 75 | 72 | zeroconf.question_history.add_question_at_time(question, now, other_known_answers) | 76 | 73 | assert zeroconf.question_history.suppresses(question, now, other_known_answers) | 77 | | - entries_with_cache = list(itertools.chain(*[cache.entries_with_name(name) for name in cache.names()])) | | 74 | + entries_with_cache = list(itertools.chain(*(cache.entries_with_name(name) for name in cache.names()))) | 78 | 75 | await asyncio.sleep(1.2) | 79 | | - entries = list(itertools.chain(*[cache.entries_with_name(name) for name in cache.names()])) | | 76 | + entries = list(itertools.chain(*(cache.entries_with_name(name) for name in cache.names()))) | 80 | 77 | await aiozc.async_close() | 81 | 78 | assert not zeroconf.question_history.suppresses(question, now, other_known_answers) | 82 | 79 | assert entries != original_entries | @@ -367,7 +364,7 @@ def test_register_service_with_custom_ttl(): | 367 | 364 | name = "MyTestHome" | 368 | 365 | info_service = r.ServiceInfo( | 369 | 366 | type_, | 370 | | - '%s.%s' % (name, type_), | | 367 | + f'{name}.{type_}', | 371 | 368 | 80, | 372 | 369 | 0, | 373 | 370 | 0, | @@ -423,9 +420,9 @@ def test_tc_bit_defers(): | 423 | 420 | name2 = "knownname2" | 424 | 421 | name3 = "knownname3" | 425 | 422 |
| 426 | | - registration_name = "%s.%s" % (name, type_) | 427 | | - registration2_name = "%s.%s" % (name2, type_) | 428 | | - registration3_name = "%s.%s" % (name3, type_) | | 423 | + registration_name = f"{name}.{type_}" | | 424 | + registration2_name = f"{name2}.{type_}" | | 425 | + registration3_name = f"{name3}.{type_}" | 429 | 426 |
| 430 | 427 | desc = {'path': '/~paulsm/'} | 431 | 428 | server_name = "ash-2.local." | @@ -502,9 +499,9 @@ def test_tc_bit_defers_last_response_missing(): | 502 | 499 | name2 = "knownname2" | 503 | 500 | name3 = "knownname3" | 504 | 501 |
| 505 | | - registration_name = "%s.%s" % (name, type_) | 506 | | - registration2_name = "%s.%s" % (name2, type_) | 507 | | - registration3_name = "%s.%s" % (name3, type_) | | 502 | + registration_name = f"{name}.{type_}" | | 503 | + registration2_name = f"{name2}.{type_}" | | 504 | + registration3_name = f"{name3}.{type_}" | 508 | 505 |
| 509 | 506 | desc = {'path': '/~paulsm/'} | 510 | 507 | server_name = "ash-2.local." | @@ -729,7 +726,7 @@ def test_shutdown_while_register_in_process(): | 729 | 726 | name = "MyTestHome" | 730 | 727 | info_service = r.ServiceInfo( | 731 | 728 | type_, | 732 | | - '%s.%s' % (name, type_), | | 729 | + f'{name}.{type_}', | 733 | 730 | 80, | 734 | 731 | 0, | 735 | 732 | 0, | |
|