1818import  subprocess 
1919import  sys 
2020import  traceback 
21+ from  collections .abc  import  AsyncIterable 
2122from  contextlib  import  redirect_stdout 
2223from  dataclasses  import  dataclass , field 
2324from  enum  import  Enum 
2425from  io  import  StringIO 
2526from  os  import  system 
2627from  shutil  import  make_archive 
27- from  typing  import  (
28-     Any ,
29-     AsyncIterable ,
30-     Dict ,
31-     List ,
32-     Literal ,
33-     NewType ,
34-     Optional ,
35-     Tuple ,
36-     Union ,
37-     cast ,
38- )
28+ from  typing  import  Any , Literal , NewType , Optional , Union , cast 
3929
4030import  aiohttp 
4131import  msgpack 
@@ -80,15 +70,15 @@ class ConfigurationPayload:
8070    ipv6 : Optional [str ] =  None 
8171    route : Optional [str ] =  None 
8272    ipv6_gateway : Optional [str ] =  None 
83-     dns_servers : List [str ] =  field (default_factory = list )
84-     volumes : List [Volume ] =  field (default_factory = list )
85-     variables : Optional [Dict [str , str ]] =  None 
86-     authorized_keys : Optional [List [str ]] =  None 
73+     dns_servers : list [str ] =  field (default_factory = list )
74+     volumes : list [Volume ] =  field (default_factory = list )
75+     variables : Optional [dict [str , str ]] =  None 
76+     authorized_keys : Optional [list [str ]] =  None 
8777
8878
8979@dataclass  
9080class  RunCodePayload :
91-     scope : Dict 
81+     scope : dict 
9282
9383
9484# Open a socket to receive instructions from the host 
@@ -117,7 +107,7 @@ def setup_hostname(hostname: str):
117107    system (f"hostname { hostname }  " )
118108
119109
120- def  setup_variables (variables : Optional [Dict [str , str ]]):
110+ def  setup_variables (variables : Optional [dict [str , str ]]):
121111    if  variables  is  None :
122112        return 
123113    for  key , value  in  variables .items ():
@@ -129,7 +119,7 @@ def setup_network(
129119    ipv6 : Optional [str ],
130120    ipv4_gateway : Optional [str ],
131121    ipv6_gateway : Optional [str ],
132-     dns_servers : Optional [List [str ]] =  None ,
122+     dns_servers : Optional [list [str ]] =  None ,
133123):
134124    """Setup the system with info from the host.""" 
135125    dns_servers  =  dns_servers  or  []
@@ -180,13 +170,13 @@ def setup_input_data(input_data: bytes):
180170            os .system ("unzip -q /opt/input.zip -d /data" )
181171
182172
183- def  setup_authorized_keys (authorized_keys : List [str ]) ->  None :
173+ def  setup_authorized_keys (authorized_keys : list [str ]) ->  None :
184174    path  =  Path ("/root/.ssh/authorized_keys" )
185175    path .parent .mkdir (exist_ok = True )
186176    path .write_text ("\n " .join (key  for  key  in  authorized_keys ))
187177
188178
189- def  setup_volumes (volumes : List [Volume ]):
179+ def  setup_volumes (volumes : list [Volume ]):
190180    for  volume  in  volumes :
191181        logger .debug (f"Mounting /dev/{ volume .device }   on { volume .mount }  " )
192182        os .makedirs (volume .mount , exist_ok = True )
@@ -213,7 +203,7 @@ async def receive():
213203            "type" : f"lifespan.{ event }  " ,
214204        }
215205
216-     async  def  send (response : Dict ):
206+     async  def  send (response : dict ):
217207        response_type  =  response .get ("type" )
218208        if  response_type  ==  f"lifespan.{ event }  .complete" :
219209            lifespan_completion .set ()
@@ -260,7 +250,7 @@ async def setup_code_asgi(code: bytes, encoding: Encoding, entrypoint: str) -> A
260250        app  =  getattr (module , app_name )
261251    elif  encoding  ==  Encoding .plain :
262252        # Execute the code and extract the entrypoint 
263-         locals : Dict [str , Any ] =  {}
253+         locals : dict [str , Any ] =  {}
264254        exec (code , globals (), locals )
265255        app  =  locals [entrypoint ]
266256    else :
@@ -313,7 +303,7 @@ async def setup_code(
313303        raise  ValueError ("Invalid interface. This should never happen." )
314304
315305
316- async  def  run_python_code_http (application : ASGIApplication , scope : dict ) ->  Tuple [ Dict ,  Dict , str , Optional [bytes ]]:
306+ async  def  run_python_code_http (application : ASGIApplication , scope : dict ) ->  tuple [ dict ,  dict , str , Optional [bytes ]]:
317307    logger .debug ("Running code" )
318308    with  StringIO () as  buf , redirect_stdout (buf ):
319309        # Execute in the same process, saves ~20ms than a subprocess 
@@ -335,14 +325,14 @@ async def send(dico):
335325        await  application (scope , receive , send )
336326
337327        logger .debug ("Waiting for headers" )
338-         headers : Dict 
328+         headers : dict 
339329        if  scope ["type" ] ==  "http" :
340330            headers  =  await  send_queue .get ()
341331        else :
342332            headers  =  {}
343333
344334        logger .debug ("Waiting for body" )
345-         response_body : Dict  =  await  send_queue .get ()
335+         response_body : dict  =  await  send_queue .get ()
346336
347337        logger .debug ("Waiting for buffer" )
348338        output  =  buf .getvalue ()
@@ -394,7 +384,7 @@ def show_loading():
394384    return  headers , body 
395385
396386
397- async  def  run_executable_http (scope : dict ) ->  Tuple [ Dict ,  Dict , str , Optional [bytes ]]:
387+ async  def  run_executable_http (scope : dict ) ->  tuple [ dict ,  dict , str , Optional [bytes ]]:
398388    logger .debug ("Calling localhost" )
399389
400390    tries  =  0 
@@ -453,8 +443,8 @@ async def process_instruction(
453443
454444        output : Optional [str ] =  None 
455445        try :
456-             headers : Dict 
457-             body : Dict 
446+             headers : dict 
447+             body : dict 
458448            output_data : Optional [bytes ]
459449
460450            if  interface  ==  Interface .asgi :
@@ -532,7 +522,7 @@ def setup_system(config: ConfigurationPayload):
532522    logger .debug ("Setup finished" )
533523
534524
535- def  umount_volumes (volumes : List [Volume ]):
525+ def  umount_volumes (volumes : list [Volume ]):
536526    "Umount user related filesystems" 
537527    system ("sync" )
538528    for  volume  in  volumes :
0 commit comments