| 904 | DATA_DIR = os.path.join('Tools', 'unicode', 'data') |
| 905 | |
| 906 | def open_data(template, version): |
| 907 | local = os.path.join(DATA_DIR, template % ('-'+version,)) |
| 908 | if not os.path.exists(local): |
| 909 | import urllib.request |
| 910 | if version == '3.2.0': |
| 911 | # irregular url structure |
| 912 | url = ('https://www.unicode.org/Public/3.2-Update/'+template) % ('-'+version,) |
| 913 | else: |
| 914 | url = ('https://www.unicode.org/Public/%s/ucd/'+template) % (version, '') |
| 915 | os.makedirs(os.path.dirname(local), exist_ok=True) |
| 916 | urllib.request.urlretrieve(url, filename=local) |
| 917 | if local.endswith('.txt'): |
| 918 | return open(local, encoding='utf-8') |
| 919 | else: |
| 920 | # Unihan.zip |
| 921 | return open(local, 'rb') |
| 922 | |
| 923 | |
| 924 | def expand_range(char_range: str) -> Iterator[int]: |