mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Fix BytesWarning discovered while running tests
Discovered using the command: python -b -m nose -vx Tests/test_*.py
This commit is contained in:
		
							parent
							
								
									eb3b9618cd
								
							
						
					
					
						commit
						7992d2a65a
					
				| 
						 | 
					@ -696,7 +696,7 @@ def getheader(im, palette=None, info=None):
 | 
				
			||||||
            version = b"89a"
 | 
					            version = b"89a"
 | 
				
			||||||
            break
 | 
					            break
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        if im.info.get("version") == "89a":
 | 
					        if im.info.get("version") == b"89a":
 | 
				
			||||||
            version = b"89a"
 | 
					            version = b"89a"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    header = [
 | 
					    header = [
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -69,7 +69,7 @@ class ImtImageFile(ImageFile.ImageFile):
 | 
				
			||||||
                s = s + self.fp.readline()
 | 
					                s = s + self.fp.readline()
 | 
				
			||||||
                if len(s) == 1 or len(s) > 100:
 | 
					                if len(s) == 1 or len(s) > 100:
 | 
				
			||||||
                    break
 | 
					                    break
 | 
				
			||||||
                if s[0] == b"*":
 | 
					                if s[0] == ord(b"*"):
 | 
				
			||||||
                    continue  # comment
 | 
					                    continue  # comment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                m = field.match(s)
 | 
					                m = field.match(s)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,7 +132,7 @@ class ChunkStream(object):
 | 
				
			||||||
    def call(self, cid, pos, length):
 | 
					    def call(self, cid, pos, length):
 | 
				
			||||||
        "Call the appropriate chunk handler"
 | 
					        "Call the appropriate chunk handler"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        logger.debug("STREAM %s %s %s", cid, pos, length)
 | 
					        logger.debug("STREAM %r %s %s", cid, pos, length)
 | 
				
			||||||
        return getattr(self, "chunk_" + cid.decode('ascii'))(pos, length)
 | 
					        return getattr(self, "chunk_" + cid.decode('ascii'))(pos, length)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def crc(self, cid, data):
 | 
					    def crc(self, cid, data):
 | 
				
			||||||
| 
						 | 
					@ -148,10 +148,10 @@ class ChunkStream(object):
 | 
				
			||||||
            crc1 = Image.core.crc32(data, Image.core.crc32(cid))
 | 
					            crc1 = Image.core.crc32(data, Image.core.crc32(cid))
 | 
				
			||||||
            crc2 = i16(self.fp.read(2)), i16(self.fp.read(2))
 | 
					            crc2 = i16(self.fp.read(2)), i16(self.fp.read(2))
 | 
				
			||||||
            if crc1 != crc2:
 | 
					            if crc1 != crc2:
 | 
				
			||||||
                raise SyntaxError("broken PNG file (bad header checksum in %s)"
 | 
					                raise SyntaxError("broken PNG file (bad header checksum in %r)"
 | 
				
			||||||
                                  % cid)
 | 
					                                  % cid)
 | 
				
			||||||
        except struct.error:
 | 
					        except struct.error:
 | 
				
			||||||
            raise SyntaxError("broken PNG file (incomplete checksum in %s)"
 | 
					            raise SyntaxError("broken PNG file (incomplete checksum in %r)"
 | 
				
			||||||
                              % cid)
 | 
					                              % cid)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def crc_skip(self, cid, data):
 | 
					    def crc_skip(self, cid, data):
 | 
				
			||||||
| 
						 | 
					@ -309,7 +309,7 @@ class PngStream(ChunkStream):
 | 
				
			||||||
        # Compression method    1 byte (0)
 | 
					        # Compression method    1 byte (0)
 | 
				
			||||||
        # Compressed profile    n bytes (zlib with deflate compression)
 | 
					        # Compressed profile    n bytes (zlib with deflate compression)
 | 
				
			||||||
        i = s.find(b"\0")
 | 
					        i = s.find(b"\0")
 | 
				
			||||||
        logger.debug("iCCP profile name %s", s[:i])
 | 
					        logger.debug("iCCP profile name %r", s[:i])
 | 
				
			||||||
        logger.debug("Compression method %s", i8(s[i]))
 | 
					        logger.debug("Compression method %s", i8(s[i]))
 | 
				
			||||||
        comp_method = i8(s[i])
 | 
					        comp_method = i8(s[i])
 | 
				
			||||||
        if comp_method != 0:
 | 
					        if comp_method != 0:
 | 
				
			||||||
| 
						 | 
					@ -539,7 +539,7 @@ class PngImageFile(ImageFile.ImageFile):
 | 
				
			||||||
            except EOFError:
 | 
					            except EOFError:
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
            except AttributeError:
 | 
					            except AttributeError:
 | 
				
			||||||
                logger.debug("%s %s %s (unknown)", cid, pos, length)
 | 
					                logger.debug("%r %s %s (unknown)", cid, pos, length)
 | 
				
			||||||
                s = ImageFile._safe_read(self.fp, length)
 | 
					                s = ImageFile._safe_read(self.fp, length)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            self.png.crc(cid, s)
 | 
					            self.png.crc(cid, s)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -338,7 +338,7 @@ class TestFileGif(PillowTestCase):
 | 
				
			||||||
        self.assertEqual(reread.info["version"], b"GIF87a")
 | 
					        self.assertEqual(reread.info["version"], b"GIF87a")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Test that a GIF89a image is also saved in that format
 | 
					        # Test that a GIF89a image is also saved in that format
 | 
				
			||||||
        im.info["version"] = "GIF89a"
 | 
					        im.info["version"] = b"GIF89a"
 | 
				
			||||||
        im.save(out)
 | 
					        im.save(out)
 | 
				
			||||||
        reread = Image.open(out)
 | 
					        reread = Image.open(out)
 | 
				
			||||||
        self.assertEqual(reread.info["version"], b"GIF87a")
 | 
					        self.assertEqual(reread.info["version"], b"GIF87a")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -119,7 +119,7 @@ class TestFileTiff(PillowTestCase):
 | 
				
			||||||
        self.assertRaises(SyntaxError,
 | 
					        self.assertRaises(SyntaxError,
 | 
				
			||||||
                          lambda: TiffImagePlugin.TiffImageFile(invalid_file))
 | 
					                          lambda: TiffImagePlugin.TiffImageFile(invalid_file))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        TiffImagePlugin.PREFIXES.append("\xff\xd8\xff\xe0")
 | 
					        TiffImagePlugin.PREFIXES.append(b"\xff\xd8\xff\xe0")
 | 
				
			||||||
        self.assertRaises(SyntaxError,
 | 
					        self.assertRaises(SyntaxError,
 | 
				
			||||||
                          lambda: TiffImagePlugin.TiffImageFile(invalid_file))
 | 
					                          lambda: TiffImagePlugin.TiffImageFile(invalid_file))
 | 
				
			||||||
        TiffImagePlugin.PREFIXES.pop()
 | 
					        TiffImagePlugin.PREFIXES.pop()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user