Skip to content

Commit a0b5d38

Browse files
committed
Download unicode data files in directory of unicode.py
1 parent f53022f commit a0b5d38

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/libcore/unicode/unicode.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
import fileinput, re, os, sys, operator, math
2727

28+
# The directory in which this file resides.
29+
fdir = os.path.dirname(os.path.realpath(__file__)) + "/"
30+
2831
preamble = '''// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
2932
// file at the top-level directory of this distribution and at
3033
// http://rust-lang.org/COPYRIGHT.
@@ -61,11 +64,12 @@
6164
surrogate_codepoints = (0xd800, 0xdfff)
6265

6366
def fetch(f):
64-
if not os.path.exists(os.path.basename(f)):
67+
path = fdir + os.path.basename(f)
68+
if not os.path.exists(path):
6569
os.system("curl -O http://www.unicode.org/Public/UNIDATA/%s"
6670
% f)
6771

68-
if not os.path.exists(os.path.basename(f)):
72+
if not os.path.exists(path):
6973
sys.stderr.write("cannot load %s" % f)
7074
exit(1)
7175

@@ -84,7 +88,7 @@ def load_unicode_data(f):
8488

8589
udict = {}
8690
range_start = -1
87-
for line in fileinput.input(f):
91+
for line in fileinput.input(fdir + f):
8892
data = line.split(';')
8993
if len(data) != 15:
9094
continue
@@ -156,7 +160,7 @@ def load_unicode_data(f):
156160

157161
def load_special_casing(f, to_upper, to_lower, to_title):
158162
fetch(f)
159-
for line in fileinput.input(f):
163+
for line in fileinput.input(fdir + f):
160164
data = line.split('#')[0].split(';')
161165
if len(data) == 5:
162166
code, lower, title, upper, _comment = data
@@ -243,7 +247,7 @@ def load_properties(f, interestingprops):
243247
re1 = re.compile("^ *([0-9A-F]+) *; *(\w+)")
244248
re2 = re.compile("^ *([0-9A-F]+)\.\.([0-9A-F]+) *; *(\w+)")
245249

246-
for line in fileinput.input(os.path.basename(f)):
250+
for line in fileinput.input(fdir + os.path.basename(f)):
247251
prop = None
248252
d_lo = 0
249253
d_hi = 0
@@ -456,7 +460,7 @@ def emit_norm_module(f, canon, compat, combine, norm_props):
456460
canon_comp_keys = sorted(canon_comp.keys())
457461

458462
if __name__ == "__main__":
459-
r = "tables.rs"
463+
r = fdir + "tables.rs"
460464
if os.path.exists(r):
461465
os.remove(r)
462466
with open(r, "w") as rf:
@@ -465,7 +469,7 @@ def emit_norm_module(f, canon, compat, combine, norm_props):
465469

466470
# download and parse all the data
467471
fetch("ReadMe.txt")
468-
with open("ReadMe.txt") as readme:
472+
with open(fdir + "ReadMe.txt") as readme:
469473
pattern = "for Version (\d+)\.(\d+)\.(\d+) of the Unicode"
470474
unicode_version = re.search(pattern, readme.read()).groups()
471475
rf.write("""

0 commit comments

Comments
 (0)