@@ -1009,14 +1009,14 @@ def populate_tzstr_header(cls):
10091009
10101010 cls ._tzif_header = bytes (out )
10111011
1012- def zone_from_tzstr (self , tzstr ):
1012+ def zone_from_tzstr (self , tzstr , encoding = "ascii" ):
10131013 """Creates a zoneinfo file following a POSIX rule."""
10141014 zonefile = io .BytesIO (self ._tzif_header )
10151015 zonefile .seek (0 , 2 )
10161016
10171017 # Write the footer
10181018 zonefile .write (b"\x0A " )
1019- zonefile .write (tzstr .encode ("ascii" ))
1019+ zonefile .write (tzstr .encode (encoding ))
10201020 zonefile .write (b"\x0A " )
10211021
10221022 zonefile .seek (0 )
@@ -1231,23 +1231,12 @@ def test_invalid_tzstr_non_ascii_abbr(self):
12311231 # It needs a separate test: it can't be ASCII-encoded for the shared
12321232 # invalid_tzstrs list, and the C error message holds the bytes repr.
12331233 tzstr = "ABÀC3"
1234- footer = tzstr .encode ("utf-8" )
1235-
1236- def from_footer ():
1237- zonefile = io .BytesIO (self ._tzif_header )
1238- zonefile .seek (0 , 2 )
1239- zonefile .write (b"\x0A " )
1240- zonefile .write (footer )
1241- zonefile .write (b"\x0A " )
1242- zonefile .seek (0 )
1243- return self .klass .from_file (zonefile , key = tzstr )
1244-
12451234 if self .module is py_zoneinfo :
12461235 expected = re .escape (tzstr )
12471236 else :
1248- expected = re .escape (repr (footer ))
1237+ expected = re .escape (repr (tzstr . encode ( "utf-8" ) ))
12491238 with self .assertRaisesRegex (ValueError , expected ):
1250- from_footer ( )
1239+ self . zone_from_tzstr ( tzstr , encoding = "utf-8" )
12511240
12521241 @classmethod
12531242 def _populate_test_cases (cls ):
0 commit comments