3131USER_AGENT = "OrcaSlicer/2.4.0-dev"
3232IS_WINDOWS = sys .platform == "win32"
3333IS_MACOS = sys .platform == "darwin"
34- IS_LINUX = not IS_WINDOWS and not IS_MACOS
3534MAX_REDIRECTS = 5
3635MAX_DOWNLOAD_BYTES = 200 * 1024 * 1024
3736BUFFER_SIZE = 81920
@@ -60,9 +59,7 @@ def return_response(self, req, fp, code, msg, headers):
6059
6160
6261def parse_args (argv : list [str ]) -> argparse .Namespace :
63- parser = argparse .ArgumentParser (
64- description = "Open supported slicer-style URIs in local Bambu Studio."
65- )
62+ parser = argparse .ArgumentParser (description = "Open supported slicer-style URIs in local Bambu Studio." )
6663 parser .add_argument ("uri" , nargs = "?" )
6764 parser .add_argument ("--uri-file" , "-UriFile" , dest = "uri_file" )
6865 return parser .parse_args (argv )
@@ -151,19 +148,18 @@ def load_config() -> dict:
151148 if not isinstance (extension , str ) or not extension .strip ():
152149 logger .warning (f"Ignoring invalid extension in security.allowed_extensions: { extension !r} " )
153150 continue
154-
151+
155152 extension = extension .strip ().lower ()
156153 if not extension .startswith ("." ):
157154 extension = f".{ extension } "
158155 valid_extensions .append (extension )
159156
160157 security ["allowed_extensions" ] = valid_extensions
161- if not security ["allowed_extensions" ]:
158+ if not security ["allowed_extensions" ]:
162159 message = "Config value must be a list: security.allowed_extensions"
163160 logger .error (message )
164161 raise BridgeError (message )
165162
166-
167163 if not isinstance (config .get ("bambu_studio" ), dict ):
168164 message = "Missing [bambu_studio] in config"
169165 logger .error (message )
@@ -187,10 +183,10 @@ def read_protocol_uri(uri_file: str) -> str:
187183
188184def resolve_protocol_uri (args : argparse .Namespace ) -> str :
189185 if args .uri :
190- return args .uri .strip ()
186+ return str ( args .uri ) .strip ()
191187
192188 if args .uri_file :
193- return read_protocol_uri (args .uri_file ).strip ()
189+ return read_protocol_uri (str ( args .uri_file ) ).strip ()
194190
195191 raise BridgeError ("Missing URI argument." )
196192
@@ -303,8 +299,7 @@ def assert_public_host(host: str) -> None:
303299 for address in addresses :
304300 if not ipaddress .ip_address (address ).is_global :
305301 raise BridgeError (
306- "Host resolves to a local/private/reserved address and is not allowed: "
307- f"{ host } -> { address } "
302+ f"Host resolves to a local/private/reserved address and is not allowed: { host } -> { address } "
308303 )
309304
310305
@@ -483,9 +478,7 @@ def download_model(
483478 while chunk := response .read (BUFFER_SIZE ):
484479 total += len (chunk )
485480 if total > MAX_DOWNLOAD_BYTES :
486- raise BridgeError (
487- f"Download exceeded the size limit: { MAX_DOWNLOAD_BYTES } bytes"
488- )
481+ raise BridgeError (f"Download exceeded the size limit: { MAX_DOWNLOAD_BYTES } bytes" )
489482 output .write (chunk )
490483 except Exception :
491484 if output_created :
@@ -553,16 +546,9 @@ def post_process_message(path: Path, commands: list[str]) -> str:
553546 if len (commands ) == 1 :
554547 post_process = commands [0 ]
555548 else :
556- post_process = "\n \n " .join (
557- f"[{ index } ]\n { command } " for index , command in enumerate (commands , start = 1 )
558- )
549+ post_process = "\n \n " .join (f"[{ index } ]\n { command } " for index , command in enumerate (commands , start = 1 ))
559550
560- return (
561- "Downloaded 3MF file contains a post-processing script.\n \n "
562- f"File: { path } \n \n "
563- "post_process:\n "
564- f"{ post_process } "
565- )
551+ return f"Downloaded 3MF file contains a post-processing script.\n \n File: { path } \n \n post_process:\n { post_process } "
566552
567553
568554def check_3mf_post_process (path : Path , action : str ) -> None :
@@ -624,9 +610,7 @@ def resolve_bambu_command(config: dict) -> list[str]:
624610 if not resolved :
625611 if IS_WINDOWS :
626612 raise BridgeError (f"Bambu Studio executable not found on PATH: { configured_path } " )
627- return warn_and_resolve_default_open_command (
628- f"Bambu Studio executable not found on PATH: { configured_path } "
629- )
613+ return warn_and_resolve_default_open_command (f"Bambu Studio executable not found on PATH: { configured_path } " )
630614 return [resolved ]
631615
632616
0 commit comments