diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-14 22:11:44 (GMT) | 
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-14 22:11:44 (GMT) | 
| commit | 92f60ed82a302035009835a8d63ff714118a96ad (patch) | |
| tree | a119000028c02ecf0317859d0bcda37fe4c505b4 /Lib/test/test_multibytecodec_support.py | |
| parent | 73315e92009c88acf53e497a0b9fcd93cd735aed (diff) | |
| download | cpython-92f60ed82a302035009835a8d63ff714118a96ad.zip cpython-92f60ed82a302035009835a8d63ff714118a96ad.tar.gz cpython-92f60ed82a302035009835a8d63ff714118a96ad.tar.bz2  | |
More proper closing of files
Diffstat (limited to 'Lib/test/test_multibytecodec_support.py')
| -rw-r--r-- | Lib/test/test_multibytecodec_support.py | 56 | 
1 files changed, 29 insertions, 27 deletions
diff --git a/Lib/test/test_multibytecodec_support.py b/Lib/test/test_multibytecodec_support.py index 70e4d75..ed15ce1 100644 --- a/Lib/test/test_multibytecodec_support.py +++ b/Lib/test/test_multibytecodec_support.py @@ -278,7 +278,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) @@ -295,36 +295,38 @@ class TestBase_Mapping(unittest.TestCase):          unichrs = lambda s: ''.join(map(chr, map(eval, 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 = bytes([csetval & 0xff]) -            elif csetval >= 0x1000000: -                csetch = bytes([(csetval >> 24), ((csetval >> 16) & 0xff), -                                ((csetval >> 8) & 0xff), (csetval & 0xff)]) -            elif csetval >= 0x10000: -                csetch = bytes([(csetval >> 16), ((csetval >> 8) & 0xff), -                                (csetval & 0xff)]) -            elif csetval >= 0x100: -                csetch = bytes([(csetval >> 8), (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 = bytes([csetval & 0xff]) +                elif csetval >= 0x1000000: +                    csetch = bytes([(csetval >> 24), ((csetval >> 16) & 0xff), +                                    ((csetval >> 8) & 0xff), (csetval & 0xff)]) +                elif csetval >= 0x10000: +                    csetch = bytes([(csetval >> 16), ((csetval >> 8) & 0xff), +                                    (csetval & 0xff)]) +                elif csetval >= 0x100: +                    csetch = bytes([(csetval >> 8), (csetval & 0xff)]) +                else: +                    continue -            unich = unichrs(data[1]) -            if ord(unich) == 0xfffd or unich in urt_wa: -                continue -            urt_wa[unich] = csetch +                unich = unichrs(data[1]) +                if ord(unich) == 0xfffd 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 = chr(int(uni, 16))  | 
