@@ -261,17 +261,28 @@ impl VirtualMachine {
261261 Ok ( ( ) )
262262 }
263263
264- fn import_utf8_encodings ( & mut self ) -> PyResult < ( ) > {
264+ fn import_ascii_utf8_encodings ( & mut self ) -> PyResult < ( ) > {
265265 import:: import_frozen ( self , "codecs" ) ?;
266- // FIXME: See corresponding part of `core_frozen_inits`
267- // let encoding_module_name = if cfg!(feature = "freeze-stdlib") {
268- // "encodings.utf_8"
269- // } else {
270- // "encodings_utf_8"
271- // };
272- let encoding_module_name = "encodings_utf_8" ;
273- let encoding_module = import:: import_frozen ( self , encoding_module_name) ?;
274- let getregentry = encoding_module. get_attr ( "getregentry" , self ) ?;
266+
267+ // Use dotted names when freeze-stdlib is enabled (modules come from Lib/encodings/),
268+ // otherwise use underscored names (modules come from core_modules/).
269+ let ( ascii_module_name, utf8_module_name) = if cfg ! ( feature = "freeze-stdlib" ) {
270+ ( "encodings.ascii" , "encodings.utf_8" )
271+ } else {
272+ ( "encodings_ascii" , "encodings_utf_8" )
273+ } ;
274+
275+ // Register ascii encoding
276+ let ascii_module = import:: import_frozen ( self , ascii_module_name) ?;
277+ let getregentry = ascii_module. get_attr ( "getregentry" , self ) ?;
278+ let codec_info = getregentry. call ( ( ) , self ) ?;
279+ self . state
280+ . codec_registry
281+ . register_manual ( "ascii" , codec_info. try_into_value ( self ) ?) ?;
282+
283+ // Register utf-8 encoding
284+ let utf8_module = import:: import_frozen ( self , utf8_module_name) ?;
285+ let getregentry = utf8_module. get_attr ( "getregentry" , self ) ?;
275286 let codec_info = getregentry. call ( ( ) , self ) ?;
276287 self . state
277288 . codec_registry
@@ -298,7 +309,7 @@ impl VirtualMachine {
298309 #[ cfg( not( feature = "threading" ) ) ]
299310 import:: import_frozen ( self , "_thread" ) ?;
300311 let importlib = import:: init_importlib_base ( self ) ?;
301- self . import_utf8_encodings ( ) ?;
312+ self . import_ascii_utf8_encodings ( ) ?;
302313
303314 #[ cfg( any( not( target_arch = "wasm32" ) , target_os = "wasi" ) ) ]
304315 {
@@ -1015,6 +1026,8 @@ pub fn resolve_frozen_alias(name: &str) -> &str {
10151026 match name {
10161027 "_frozen_importlib" => "importlib._bootstrap" ,
10171028 "_frozen_importlib_external" => "importlib._bootstrap_external" ,
1029+ "encodings_ascii" => "encodings.ascii" ,
1030+ "encodings_utf_8" => "encodings.utf_8" ,
10181031 _ => name,
10191032 }
10201033}
0 commit comments