Add a build test for monkeypatching zeroconf

This commit is contained in:
Kovid Goyal 2021-06-27 20:04:53 +05:30
parent c32052eaa5
commit 360e00722f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 15 additions and 5 deletions

View File

@ -394,10 +394,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
self.debug_start_time = time.time() self.debug_start_time = time.time()
self.debug_time = time.time() self.debug_time = time.time()
self.is_connected = False self.is_connected = False
# Hack to work around the newly-enforced 15 character service name limit. monkeypatch_zeroconf()
# "monkeypatch" zeroconf with a function without the check
import zeroconf
zeroconf.service_type_name = service_type_name
# Don't call this method from the GUI unless you are sure that there is no # Don't call this method from the GUI unless you are sure that there is no
# network traffic in progress. Otherwise the gui might hang waiting for the # network traffic in progress. Otherwise the gui might hang waiting for the
@ -2059,7 +2056,7 @@ from zeroconf import (
) )
def service_type_name(type_: str, *, strict: bool = True) -> str: def monkeypatched_service_type_name(type_: str, *, strict: bool = True) -> str:
""" """
Validate a fully qualified service name, instance or subtype. [rfc6763] Validate a fully qualified service name, instance or subtype. [rfc6763]
@ -2178,3 +2175,14 @@ def service_type_name(type_: str, *, strict: bool = True) -> str:
) )
return service_name + trailer return service_name + trailer
def monkeypatch_zeroconf():
# Hack to work around the newly-enforced 15 character service name limit.
# "monkeypatch" zeroconf with a function without the check
try:
from zeroconf._utils.name import service_type_name
service_type_name.__kwdefaults__['strict'] = False
except ImportError:
import zeroconf
zeroconf.service_type_name = monkeypatched_service_type_name

View File

@ -106,6 +106,8 @@ class BuildTest(unittest.TestCase):
def test_zeroconf(self): def test_zeroconf(self):
import zeroconf as z, ifaddr import zeroconf as z, ifaddr
from calibre.devices.smart_device_app.driver import monkeypatch_zeroconf
monkeypatch_zeroconf()
del z del z
del ifaddr del ifaddr