@@ -445,33 +445,36 @@ def substitute_one_repo(
445445
446446 # 读取所有有效的输入数据
447447 valid_inputs = []
448+ # 首先读取文件内容,然后关闭文件
448449 with open (input_path , "rb" ) as f_input :
449- for line in f_input :
450- try :
451- # 尝试解码行以检查内容
452- decoded = line .decode ("utf-8" , errors = "replace" )
453-
454- # 只处理以 b' 或 b" 开头的行
455- if decoded .startswith (("b'" , 'b"' )):
456- if decoded .startswith ("b'" ) and decoded .endswith ("'\n " ):
457- byte_data = line [2 :- 2 ]
458- elif decoded .startswith ('b"' ) and decoded .endswith ('"\n ' ):
459- byte_data = line [2 :- 2 ]
460- else :
461- continue
462-
463- if 0 < len (byte_data ) <= max_len :
464- valid_inputs .append (byte_data )
465- except UnicodeDecodeError :
466- if 0 < len (line ) <= max_len :
467- valid_inputs .append (line )
450+ lines = f_input .readlines ()
451+
452+ # 文件已关闭,现在处理数据
453+ for line in lines :
454+ try :
455+ # 尝试解码行以检查内容
456+ decoded = line .decode ("utf-8" , errors = "replace" )
457+
458+ # 只处理以 b' 或 b" 开头的行
459+ if decoded .startswith (("b'" , 'b"' )):
460+ if decoded .startswith ("b'" ) and decoded .endswith ("'\n " ):
461+ byte_data = line [2 :- 2 ]
462+ elif decoded .startswith ('b"' ) and decoded .endswith ('"\n ' ):
463+ byte_data = line [2 :- 2 ]
464+ else :
465+ continue
466+
467+ if 0 < len (byte_data ) <= max_len :
468+ valid_inputs .append (byte_data )
469+ except UnicodeDecodeError :
470+ if 0 < len (line ) <= max_len :
471+ valid_inputs .append (line )
468472
469473 if not valid_inputs :
470474 logging .warning (f"No valid inputs found for { target_name } " )
471475 continue
472476
473477 logging .info (f"Loaded { len (valid_inputs )} inputs for { target_name } " )
474-
475478 # 策略选择输入
476479 if strategy == "shuffle" :
477480 random .shuffle (valid_inputs )
0 commit comments