a  ze^ @sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z gdZ e e jZejdddddd Zd dd d Zd ddddZdddddZddddZdd ddddZedkredS) a Script to automatically generate a JSON file containing time zone information. This is done to allow "pinning" a small subset of the tzdata in the tests, since we are testing properties of a file that may be subject to change. For example, the behavior in the far future of any given zone is likely to change, but "does this give the right answer for this file in 2040" is still an important property to test. This must be run from a computer with zoneinfo data installed. ) annotationsN) zAfrica/AbidjanzAfrica/CasablancazAmerica/Los_AngeleszAmerica/Santiagoz Asia/TokyozAustralia/Sydneyz Europe/Dublinz Europe/Lisbonz Europe/LondonzPacific/KiritimatiUTC)maxsizez pathlib.Path)returncCs8d}ttjtjD]}||r|SqtddS)zEGet the first zoneinfo directory on TZPATH containing the "UTC" zone.rzCannot find time zone data.N)mappathlibPathzoneinfoZTZPATHexistsOSError)keypathr\/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_zoneinfo/data/update_test_data.pyget_zoneinfo_path)s   rztyping.Dict[str, str]cCst}|d}|stdt|d}t|}Wdn1sF0Y|dd\}}|ddrt|dks|dd st d d |d |iS) Nz tzdata.ziz*Time zone data does not include tzdata.zi.r rzJVersion string should be YYYYx, where YYYY is the year and x is a letter; zfound: version) rr r opennextstriprsplitisdigitlenisalpha ValueError)r Z tzdata_zifZ version_line_rrrrget_zoneinfo_metadata4s& & r!strbytes)r rcCs@t}t||d}|WdS1s20YdS)Nrb)rrread)r r rrrr get_zoneinfoOsr&ztyping.List[str])datarcCs0t|}t|}|d}tj|dd}|S)Nzutf-8F)width)lzmacompressbase64Z b85encodedecodetextwrapwrap)r'Zcompressed_zonerawZ raw_data_strZdata_strrrrencode_compressedVs    r1z"typing.Dict[str, typing.List[str]]cCsddtD}|S)NcSsi|]}|tt|qSr)r1r&).0r rrr az(load_compressed_keys..)KEYS)outputrrrload_compressed_keys`sr7zoneinfo_data.jsonNone)fnamercCsvtjdddtddd}t}t}||d}tt|d$}tj||fi|Wdn1sh0YdS)NT)exist_okparents)indentZ sort_keys)metadatar'w) TEST_DATA_LOCmkdirdictr7r!rjsondump)r:Z json_kwargsZcompressed_keysr?r6rrrrupdate_test_datafsrF__main__)r8)__doc__Z __future__rr, functoolsrDr*rr.typingr r5r__file__parentrA lru_cacherr!r&r1r7rF__name__rrrrs(