Fix ResourceWarnings in makeunicodedata.py.

This commit is contained in:
Ezio Melotti 2011-09-30 08:46:25 +03:00
parent 034f6cf10c
commit 2a1e926d63
1 changed files with 87 additions and 80 deletions

View File

@ -816,8 +816,8 @@ class UnicodeData:
expand=1,
cjk_check=True):
self.changed = []
file = open_data(UNICODE_DATA, version)
table = [None] * 0x110000
with open_data(UNICODE_DATA, version) as file:
while 1:
s = file.readline()
if not s:
@ -855,8 +855,8 @@ class UnicodeData:
self.table = table
self.chars = list(range(0x110000)) # unicode 3.2
file = open_data(COMPOSITION_EXCLUSIONS, version)
self.exclusions = {}
with open_data(COMPOSITION_EXCLUSIONS, version) as file:
for s in file:
s = s.strip()
if not s:
@ -867,7 +867,8 @@ class UnicodeData:
self.exclusions[char] = 1
widths = [None] * 0x110000
for s in open_data(EASTASIAN_WIDTH, version):
with open_data(EASTASIAN_WIDTH, version) as file:
for s in file:
s = s.strip()
if not s:
continue
@ -881,6 +882,7 @@ class UnicodeData:
chars = [int(s[0], 16)]
for char in chars:
widths[char] = s[1]
for i in range(0, 0x110000):
if table[i] is not None:
table[i].append(widths[i])
@ -888,7 +890,9 @@ class UnicodeData:
for i in range(0, 0x110000):
if table[i] is not None:
table[i].append(set())
for s in open_data(DERIVED_CORE_PROPERTIES, version):
with open_data(DERIVED_CORE_PROPERTIES, version) as file:
for s in file:
s = s.split('#', 1)[0].strip()
if not s:
continue
@ -907,7 +911,8 @@ class UnicodeData:
# apply to unassigned code points; ignore them
table[char][-1].add(p)
for s in open_data(LINE_BREAK, version):
with open_data(LINE_BREAK, version) as file:
for s in file:
s = s.partition('#')[0]
s = [i.strip() for i in s.split(';')]
if len(s) < 2 or s[1] not in MANDATORY_LINE_BREAKS:
@ -928,7 +933,8 @@ class UnicodeData:
# for older versions, and no delta records will be created.
quickchecks = [0] * 0x110000
qc_order = 'NFD_QC NFKD_QC NFC_QC NFKC_QC'.split()
for s in open_data(DERIVEDNORMALIZATION_PROPS, version):
with open_data(DERIVEDNORMALIZATION_PROPS, version) as file:
for s in file:
if '#' in s:
s = s[:s.index('#')]
s = [i.strip() for i in s.split(';')]
@ -948,7 +954,8 @@ class UnicodeData:
if table[i] is not None:
table[i].append(quickchecks[i])
zip = zipfile.ZipFile(open_data(UNIHAN, version))
with open_data(UNIHAN, version) as file:
zip = zipfile.ZipFile(file)
if version == '3.2.0':
data = zip.open('Unihan-3.2.0.txt').read()
else: