Skip to content

Commit 35a0beb

Browse files
encukousethmlarson
authored andcommitted
Have mkstringprep.py download the RFC if it's missing
1 parent d978d13 commit 35a0beb

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Tools/unicode/mkstringprep.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import re
2+
import os
23
import unicodedata as unicodedata_current
34
from unicodedata import ucd_3_2_0 as unicodedata_320
45

6+
FILENAME = "Tools/unicode/data/rfc3454.txt"
7+
URL = "https://www.rfc-editor.org/rfc/rfc3454.txt"
8+
59
def gen_category(cats):
610
for i in range(0, 0x110000):
711
if unicodedata_320.category(chr(i)) in cats:
@@ -48,8 +52,16 @@ def compact_set(l):
4852

4953
############## Read the tables in the RFC #######################
5054

51-
with open("rfc3454.txt") as f:
52-
data = f.readlines()
55+
try:
56+
data_file = open(FILENAME, encoding='utf-8')
57+
except FileNotFoundError:
58+
import urllib.request
59+
os.makedirs(os.path.dirname(FILENAME), exist_ok=True)
60+
urllib.request.urlretrieve(URL, filename=FILENAME)
61+
data_file = open(FILENAME, encoding='utf-8')
62+
63+
with data_file:
64+
data = data_file.readlines()
5365

5466
tables = []
5567
curname = None

0 commit comments

Comments
 (0)