@@ -1681,31 +1681,38 @@ def prepare():
16811681
16821682 def test_undecodable_env (self ):
16831683 for key , value in (('test' , 'abc\uDCFF ' ), ('test\uDCFF ' , '42' )):
1684+ encoded_value = value .encode ("ascii" , "surrogateescape" )
1685+
16841686 # test str with surrogates
16851687 script = "import os; print(ascii(os.getenv(%s)))" % repr (key )
16861688 env = os .environ .copy ()
16871689 env [key ] = value
1688- # Use C locale to get ascii for the locale encoding to force
1690+ # Use C locale to get ASCII for the locale encoding to force
16891691 # surrogate-escaping of \xFF in the child process; otherwise it can
16901692 # be decoded as-is if the default locale is latin-1.
16911693 env ['LC_ALL' ] = 'C'
1694+ if sys .platform .startswith ("aix" ):
1695+ # On AIX, the C locale uses the Latin1 encoding
1696+ decoded_value = encoded_value .decode ("latin1" , "surrogateescape" )
1697+ else :
1698+ # On other UNIXes, the C locale uses the ASCII encoding
1699+ decoded_value = value
16921700 stdout = subprocess .check_output (
16931701 [sys .executable , "-c" , script ],
16941702 env = env )
16951703 stdout = stdout .rstrip (b'\n \r ' )
1696- self .assertEqual (stdout .decode ('ascii' ), ascii (value ))
1704+ self .assertEqual (stdout .decode ('ascii' ), ascii (decoded_value ))
16971705
16981706 # test bytes
16991707 key = key .encode ("ascii" , "surrogateescape" )
1700- value = value .encode ("ascii" , "surrogateescape" )
17011708 script = "import os; print(ascii(os.getenvb(%s)))" % repr (key )
17021709 env = os .environ .copy ()
1703- env [key ] = value
1710+ env [key ] = encoded_value
17041711 stdout = subprocess .check_output (
17051712 [sys .executable , "-c" , script ],
17061713 env = env )
17071714 stdout = stdout .rstrip (b'\n \r ' )
1708- self .assertEqual (stdout .decode ('ascii' ), ascii (value ))
1715+ self .assertEqual (stdout .decode ('ascii' ), ascii (encoded_value ))
17091716
17101717 def test_bytes_program (self ):
17111718 abs_program = os .fsencode (sys .executable )
0 commit comments