@@ -188,7 +188,9 @@ def _legacy_kwargs_to_plan(
188188
189189 if server_url is None :
190190 if port is None :
191- return ConnectionPlan (mode = ConnectionMode .OFFLINE , source = "legacy-offline" )
191+ return ConnectionPlan (
192+ mode = ConnectionMode .OFFLINE , source = "legacy-offline"
193+ )
192194 url = DEFAULT_SERVER_URL
193195 return ConnectionPlan (
194196 mode = ConnectionMode .LOCAL_PROXY ,
@@ -1233,6 +1235,7 @@ def server_stop(self, port: int = DEFAULT_PORT) -> None:
12331235def _is_local_url (url : str ) -> bool :
12341236 """True if ``url`` points at this host (loopback or local interface IP)."""
12351237 from urllib .parse import urlparse
1238+
12361239 try :
12371240 host = urlparse (url ).hostname or ""
12381241 except ValueError :
@@ -1243,6 +1246,7 @@ def _is_local_url(url: str) -> bool:
12431246 return True
12441247 try :
12451248 from cli .discover import _is_loopback , _local_interface_ips
1249+
12461250 if _is_loopback (host ):
12471251 return True
12481252 return host in _local_interface_ips ()
@@ -1253,6 +1257,7 @@ def _is_local_url(url: str) -> bool:
12531257def _localhost_status_ok (port : int = DEFAULT_PORT , timeout : float = 0.3 ) -> bool :
12541258 """Quick TCP probe — does http://127.0.0.1:port answer /api/status?"""
12551259 import urllib .request
1260+
12561261 try :
12571262 with urllib .request .urlopen (
12581263 f"http://127.0.0.1:{ port } /api/status" , timeout = timeout
@@ -1278,7 +1283,9 @@ def _classify_url(url: str, *, token: Optional[str], source: str) -> ConnectionP
12781283 )
12791284
12801285
1281- def _attach_serial_port (plan : ConnectionPlan , port : Optional [str ], baudrate : int ) -> ConnectionPlan :
1286+ def _attach_serial_port (
1287+ plan : ConnectionPlan , port : Optional [str ], baudrate : int
1288+ ) -> ConnectionPlan :
12821289 """Return a new plan with serial_port/baudrate filled and launch flags set
12831290 according to whether the plan is local + has a serial port."""
12841291 if not port :
@@ -1297,7 +1304,9 @@ def _attach_serial_port(plan: ConnectionPlan, port: Optional[str], baudrate: int
12971304 )
12981305
12991306
1300- def _with_cache_handle (plan : ConnectionPlan , cache_handle : Optional [str ]) -> ConnectionPlan :
1307+ def _with_cache_handle (
1308+ plan : ConnectionPlan , cache_handle : Optional [str ]
1309+ ) -> ConnectionPlan :
13011310 """Return a new plan tagged with the cache handle (so a connect failure
13021311 can invalidate the right entry)."""
13031312 if cache_handle is None :
@@ -1401,6 +1410,7 @@ def _refresh_handle_cache(value: str) -> None:
14011410def invalidate_cached_handle (value : str ) -> None :
14021411 """Public hook so the connector can drop a bad cache entry."""
14031412 from cli import handle_cache
1413+
14041414 handle_cache .invalidate (value )
14051415
14061416
@@ -1454,7 +1464,10 @@ def resolve_connection_plan(args) -> ConnectionPlan:
14541464 if server_handle :
14551465 url = _resolve_handle_to_url (server_handle , source = "-s flag" )
14561466 from cli .discover import classify_handle
1457- cache_key = server_handle if classify_handle (server_handle ) == "host_port" else None
1467+
1468+ cache_key = (
1469+ server_handle if classify_handle (server_handle ) == "host_port" else None
1470+ )
14581471 plan = _classify_url (url , token = token , source = "flag" )
14591472 plan = _attach_serial_port (plan , port , baudrate )
14601473 return _with_cache_handle (plan , cache_key )
@@ -1463,6 +1476,7 @@ def resolve_connection_plan(args) -> ConnectionPlan:
14631476 if env_handle :
14641477 url = _resolve_handle_to_url (env_handle , source = "FPB_SERVER env" )
14651478 from cli .discover import classify_handle
1479+
14661480 cache_key = env_handle if classify_handle (env_handle ) == "host_port" else None
14671481 plan = _classify_url (url , token = token , source = "env" )
14681482 plan = _attach_serial_port (plan , port , baudrate )
@@ -1487,7 +1501,9 @@ def resolve_connection_plan(args) -> ConnectionPlan:
14871501 file = sys .stderr ,
14881502 )
14891503 return _attach_serial_port (
1490- _classify_url (legacy_env_url , token = token , source = "legacy-env" ), port , baudrate
1504+ _classify_url (legacy_env_url , token = token , source = "legacy-env" ),
1505+ port ,
1506+ baudrate ,
14911507 )
14921508
14931509 pid_servers = list_cli_servers ()
@@ -1507,19 +1523,15 @@ def resolve_connection_plan(args) -> ConnectionPlan:
15071523
15081524 if getattr (args , "no_discovery" , False ) or discover_sync is None :
15091525 return _attach_serial_port (
1510- _classify_url (
1511- DEFAULT_SERVER_URL , token = token , source = "localhost-fallback"
1512- ),
1526+ _classify_url (DEFAULT_SERVER_URL , token = token , source = "localhost-fallback" ),
15131527 port ,
15141528 baudrate ,
15151529 )
15161530
15171531 servers = discover_sync ()
15181532 if not servers :
15191533 return _attach_serial_port (
1520- _classify_url (
1521- DEFAULT_SERVER_URL , token = token , source = "localhost-fallback"
1522- ),
1534+ _classify_url (DEFAULT_SERVER_URL , token = token , source = "localhost-fallback" ),
15231535 port ,
15241536 baudrate ,
15251537 )
@@ -1578,7 +1590,10 @@ def resolve_server_url(args):
15781590 if len (servers ) == 1 :
15791591 s = servers [0 ]
15801592 if getattr (args , "verbose" , False ):
1581- print (f"Using discovered server { s .url } (version={ s .version } )" , file = sys .stderr )
1593+ print (
1594+ f"Using discovered server { s .url } (version={ s .version } )" ,
1595+ file = sys .stderr ,
1596+ )
15821597 return s .url
15831598 print (
15841599 "Multiple FPBInject servers discovered; pass --server-url to choose:" ,
@@ -1717,7 +1732,8 @@ def main():
17171732 help = "Force direct serial connection (skip WebServer proxy detection)." ,
17181733 )
17191734 parser .add_argument (
1720- "-s" , "--server" ,
1735+ "-s" ,
1736+ "--server" ,
17211737 type = str ,
17221738 default = None ,
17231739 help = "Server to talk to. Accepts a discovery handle (e.g. "
@@ -1995,7 +2011,9 @@ def main():
19952011 subparsers .add_parser ("connect" , help = "Connect to device (requires device)" )
19962012
19972013 # disconnect command
1998- disconnect_parser = subparsers .add_parser ("disconnect" , help = "Disconnect from device" )
2014+ disconnect_parser = subparsers .add_parser (
2015+ "disconnect" , help = "Disconnect from device"
2016+ )
19992017 disconnect_parser .set_defaults (command_policy = CommandPolicy .OFFLINE )
20002018
20012019 # discover command — list FPBInject WebServers visible via mDNS
0 commit comments