summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_multibytecodec_support.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-10-14 22:22:30 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-10-14 22:22:30 (GMT)
commit99d848bd4ba7bc0df689709f3854d67c6d82a757 (patch)
treed02592b257cb7411854f5f49e904b054af391a90 /Lib/test/test_multibytecodec_support.py
parent80800d35713912eb4b9486033c1ce86bce263728 (diff)
downloadcpython-99d848bd4ba7bc0df689709f3854d67c6d82a757.zip
cpython-99d848bd4ba7bc0df689709f3854d67c6d82a757.tar.gz
cpython-99d848bd4ba7bc0df689709f3854d67c6d82a757.tar.bz2
Merged revisions 85503 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r85503 | antoine.pitrou | 2010-10-15 00:11:44 +0200 (ven., 15 oct. 2010) | 2 lines More proper closing of files ........
Diffstat (limited to 'Lib/test/test_multibytecodec_support.py')
-rw-r--r--Lib/test/test_multibytecodec_support.py56
1 files changed, 29 insertions, 27 deletions
diff --git a/Lib/test/test_multibytecodec_support.py b/Lib/test/test_multibytecodec_support.py
index 9aa764a..0639032 100644
--- a/Lib/test/test_multibytecodec_support.py
+++ b/Lib/test/test_multibytecodec_support.py
@@ -252,7 +252,7 @@ class TestBase_Mapping(unittest.TestCase):
def __init__(self, *args, **kw):
unittest.TestCase.__init__(self, *args, **kw)
try:
- self.open_mapping_file() # test it to report the error early
+ self.open_mapping_file().close() # test it to report the error early
except (IOError, HTTPException):
self.skipTest("Could not retrieve "+self.mapfileurl)
@@ -270,36 +270,38 @@ class TestBase_Mapping(unittest.TestCase):
unichrs = lambda s: u''.join(_unichr(c) for c in s.split('+'))
urt_wa = {}
- for line in self.open_mapping_file():
- if not line:
- break
- data = line.split('#')[0].strip().split()
- if len(data) != 2:
- continue
-
- csetval = eval(data[0])
- if csetval <= 0x7F:
- csetch = chr(csetval & 0xff)
- elif csetval >= 0x1000000:
- csetch = chr(csetval >> 24) + chr((csetval >> 16) & 0xff) + \
- chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
- elif csetval >= 0x10000:
- csetch = chr(csetval >> 16) + \
- chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
- elif csetval >= 0x100:
- csetch = chr(csetval >> 8) + chr(csetval & 0xff)
- else:
- continue
+ with self.open_mapping_file() as f:
+ for line in f:
+ if not line:
+ break
+ data = line.split('#')[0].strip().split()
+ if len(data) != 2:
+ continue
+
+ csetval = eval(data[0])
+ if csetval <= 0x7F:
+ csetch = chr(csetval & 0xff)
+ elif csetval >= 0x1000000:
+ csetch = chr(csetval >> 24) + chr((csetval >> 16) & 0xff) + \
+ chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
+ elif csetval >= 0x10000:
+ csetch = chr(csetval >> 16) + \
+ chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
+ elif csetval >= 0x100:
+ csetch = chr(csetval >> 8) + chr(csetval & 0xff)
+ else:
+ continue
- unich = unichrs(data[1])
- if unich == u'\ufffd' or unich in urt_wa:
- continue
- urt_wa[unich] = csetch
+ unich = unichrs(data[1])
+ if unich == u'\ufffd' or unich in urt_wa:
+ continue
+ urt_wa[unich] = csetch
- self._testpoint(csetch, unich)
+ self._testpoint(csetch, unich)
def _test_mapping_file_ucm(self):
- ucmdata = self.open_mapping_file().read()
+ with self.open_mapping_file() as f:
+ ucmdata = f.read()
uc = re.findall('<a u="([A-F0-9]{4})" b="([0-9A-F ]+)"/>', ucmdata)
for uni, coded in uc:
unich = unichr(int(uni, 16))