mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Fixed redefinition of built-in
This commit is contained in:
		
							parent
							
								
									566153f59f
								
							
						
					
					
						commit
						7f414057c9
					
				| 
						 | 
					@ -313,7 +313,7 @@ SAVE = {
 | 
				
			||||||
def _save(im, fp, filename, check=0):
 | 
					def _save(im, fp, filename, check=0):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        type, rawmode = SAVE[im.mode]
 | 
					        image_type, rawmode = SAVE[im.mode]
 | 
				
			||||||
    except KeyError:
 | 
					    except KeyError:
 | 
				
			||||||
        raise ValueError("Cannot save %s images as IM" % im.mode)
 | 
					        raise ValueError("Cannot save %s images as IM" % im.mode)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -325,7 +325,7 @@ def _save(im, fp, filename, check=0):
 | 
				
			||||||
    if check:
 | 
					    if check:
 | 
				
			||||||
        return check
 | 
					        return check
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fp.write(("Image type: %s image\r\n" % type).encode('ascii'))
 | 
					    fp.write(("Image type: %s image\r\n" % image_type).encode('ascii'))
 | 
				
			||||||
    if filename:
 | 
					    if filename:
 | 
				
			||||||
        fp.write(("Name: %s\r\n" % filename).encode('ascii'))
 | 
					        fp.write(("Name: %s\r\n" % filename).encode('ascii'))
 | 
				
			||||||
    fp.write(("Image size (x*y): %d*%d\r\n" % im.size).encode('ascii'))
 | 
					    fp.write(("Image size (x*y): %d*%d\r\n" % im.size).encode('ascii'))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@
 | 
				
			||||||
# See the README file for information on usage and redistribution.
 | 
					# See the README file for information on usage and redistribution.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from functools import reduce
 | 
					import functools
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Filter(object):
 | 
					class Filter(object):
 | 
				
			||||||
| 
						 | 
					@ -43,7 +43,7 @@ class Kernel(Filter):
 | 
				
			||||||
    def __init__(self, size, kernel, scale=None, offset=0):
 | 
					    def __init__(self, size, kernel, scale=None, offset=0):
 | 
				
			||||||
        if scale is None:
 | 
					        if scale is None:
 | 
				
			||||||
            # default scale is sum of kernel
 | 
					            # default scale is sum of kernel
 | 
				
			||||||
            scale = reduce(lambda a, b: a+b, kernel)
 | 
					            scale = functools.reduce(lambda a, b: a+b, kernel)
 | 
				
			||||||
        if size[0] * size[1] != len(kernel):
 | 
					        if size[0] * size[1] != len(kernel):
 | 
				
			||||||
            raise ValueError("not enough coefficients in kernel")
 | 
					            raise ValueError("not enough coefficients in kernel")
 | 
				
			||||||
        self.filterargs = size, scale, offset, kernel
 | 
					        self.filterargs = size, scale, offset, kernel
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,7 @@
 | 
				
			||||||
from PIL import Image
 | 
					from PIL import Image
 | 
				
			||||||
from PIL._util import isStringType
 | 
					from PIL._util import isStringType
 | 
				
			||||||
import operator
 | 
					import operator
 | 
				
			||||||
from functools import reduce
 | 
					import functools
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
| 
						 | 
					@ -213,7 +213,7 @@ def equalize(image, mask=None):
 | 
				
			||||||
        if len(histo) <= 1:
 | 
					        if len(histo) <= 1:
 | 
				
			||||||
            lut.extend(list(range(256)))
 | 
					            lut.extend(list(range(256)))
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            step = (reduce(operator.add, histo) - histo[-1]) // 255
 | 
					            step = (functools.reduce(operator.add, histo) - histo[-1]) // 255
 | 
				
			||||||
            if not step:
 | 
					            if not step:
 | 
				
			||||||
                lut.extend(list(range(256)))
 | 
					                lut.extend(list(range(256)))
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import math
 | 
					import math
 | 
				
			||||||
import operator
 | 
					import operator
 | 
				
			||||||
from functools import reduce
 | 
					import functools
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Stat:
 | 
					class Stat:
 | 
				
			||||||
| 
						 | 
					@ -71,7 +71,7 @@ class Stat:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        v = []
 | 
					        v = []
 | 
				
			||||||
        for i in range(0, len(self.h), 256):
 | 
					        for i in range(0, len(self.h), 256):
 | 
				
			||||||
            v.append(reduce(operator.add, self.h[i:i+256]))
 | 
					            v.append(functools.reduce(operator.add, self.h[i:i+256]))
 | 
				
			||||||
        return v
 | 
					        return v
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _getsum(self):
 | 
					    def _getsum(self):
 | 
				
			||||||
| 
						 | 
					@ -79,10 +79,10 @@ class Stat:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        v = []
 | 
					        v = []
 | 
				
			||||||
        for i in range(0, len(self.h), 256):
 | 
					        for i in range(0, len(self.h), 256):
 | 
				
			||||||
            sum = 0.0
 | 
					            layerSum = 0.0
 | 
				
			||||||
            for j in range(256):
 | 
					            for j in range(256):
 | 
				
			||||||
                sum += j * self.h[i + j]
 | 
					                layerSum += j * self.h[i + j]
 | 
				
			||||||
            v.append(sum)
 | 
					            v.append(layerSum)
 | 
				
			||||||
        return v
 | 
					        return v
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _getsum2(self):
 | 
					    def _getsum2(self):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,10 +49,10 @@ class MspImageFile(ImageFile.ImageFile):
 | 
				
			||||||
            raise SyntaxError("not an MSP file")
 | 
					            raise SyntaxError("not an MSP file")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Header checksum
 | 
					        # Header checksum
 | 
				
			||||||
        sum = 0
 | 
					        checksum = 0
 | 
				
			||||||
        for i in range(0, 32, 2):
 | 
					        for i in range(0, 32, 2):
 | 
				
			||||||
            sum = sum ^ i16(s[i:i+2])
 | 
					            checksum = checksum ^ i16(s[i:i+2])
 | 
				
			||||||
        if sum != 0:
 | 
					        if checksum != 0:
 | 
				
			||||||
            raise SyntaxError("bad MSP checksum")
 | 
					            raise SyntaxError("bad MSP checksum")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.mode = "1"
 | 
					        self.mode = "1"
 | 
				
			||||||
| 
						 | 
					@ -83,10 +83,10 @@ def _save(im, fp, filename):
 | 
				
			||||||
    header[6], header[7] = 1, 1
 | 
					    header[6], header[7] = 1, 1
 | 
				
			||||||
    header[8], header[9] = im.size
 | 
					    header[8], header[9] = im.size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sum = 0
 | 
					    checksum = 0
 | 
				
			||||||
    for h in header:
 | 
					    for h in header:
 | 
				
			||||||
        sum = sum ^ h
 | 
					        checksum = checksum ^ h
 | 
				
			||||||
    header[12] = sum  # FIXME: is this the right field?
 | 
					    header[12] = checksum  # FIXME: is this the right field?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # header
 | 
					    # header
 | 
				
			||||||
    for h in header:
 | 
					    for h in header:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,7 +49,7 @@ except getopt.error as v:
 | 
				
			||||||
    print(v)
 | 
					    print(v)
 | 
				
			||||||
    sys.exit(1)
 | 
					    sys.exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
format = None
 | 
					output_format = None
 | 
				
			||||||
convert = None
 | 
					convert = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
options = {}
 | 
					options = {}
 | 
				
			||||||
| 
						 | 
					@ -68,7 +68,7 @@ for o, a in opt:
 | 
				
			||||||
        sys.exit(1)
 | 
					        sys.exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    elif o == "-c":
 | 
					    elif o == "-c":
 | 
				
			||||||
        format = a
 | 
					        output_format = a
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if o == "-g":
 | 
					    if o == "-g":
 | 
				
			||||||
        convert = "L"
 | 
					        convert = "L"
 | 
				
			||||||
| 
						 | 
					@ -90,8 +90,8 @@ try:
 | 
				
			||||||
    if convert and im.mode != convert:
 | 
					    if convert and im.mode != convert:
 | 
				
			||||||
        im.draft(convert, im.size)
 | 
					        im.draft(convert, im.size)
 | 
				
			||||||
        im = im.convert(convert)
 | 
					        im = im.convert(convert)
 | 
				
			||||||
    if format:
 | 
					    if output_format:
 | 
				
			||||||
        im.save(argv[1], format, **options)
 | 
					        im.save(argv[1], output_format, **options)
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        im.save(argv[1], **options)
 | 
					        im.save(argv[1], **options)
 | 
				
			||||||
except:
 | 
					except:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,8 +24,8 @@ from PIL import PSDraw
 | 
				
			||||||
letter = (1.0*72, 1.0*72, 7.5*72, 10.0*72)
 | 
					letter = (1.0*72, 1.0*72, 7.5*72, 10.0*72)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def description(file, image):
 | 
					def description(filepath, image):
 | 
				
			||||||
    title = os.path.splitext(os.path.split(file)[1])[0]
 | 
					    title = os.path.splitext(os.path.split(filepath)[1])[0]
 | 
				
			||||||
    format = " (%dx%d "
 | 
					    format = " (%dx%d "
 | 
				
			||||||
    if image.format:
 | 
					    if image.format:
 | 
				
			||||||
        format = " (" + image.format + " %dx%d "
 | 
					        format = " (" + image.format + " %dx%d "
 | 
				
			||||||
| 
						 | 
					@ -65,12 +65,12 @@ for o, a in opt:
 | 
				
			||||||
        # printer channel
 | 
					        # printer channel
 | 
				
			||||||
        printer = "lpr -P%s" % a
 | 
					        printer = "lpr -P%s" % a
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for file in argv:
 | 
					for filepath in argv:
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        im = Image.open(file)
 | 
					        im = Image.open(filepath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        title = description(file, im)
 | 
					        title = description(filepath, im)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if monochrome and im.mode not in ["1", "L"]:
 | 
					        if monochrome and im.mode not in ["1", "L"]:
 | 
				
			||||||
            im.draft("L", im.size)
 | 
					            im.draft("L", im.size)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,8 +39,8 @@ class TestFileLibTiff(LibTiffTestCase):
 | 
				
			||||||
    def test_g4_tiff(self):
 | 
					    def test_g4_tiff(self):
 | 
				
			||||||
        """Test the ordinary file path load path"""
 | 
					        """Test the ordinary file path load path"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        file = "Tests/images/hopper_g4_500.tif"
 | 
					        test_file = "Tests/images/hopper_g4_500.tif"
 | 
				
			||||||
        im = Image.open(file)
 | 
					        im = Image.open(test_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.assertEqual(im.size, (500, 500))
 | 
					        self.assertEqual(im.size, (500, 500))
 | 
				
			||||||
        self._assert_noerr(im)
 | 
					        self._assert_noerr(im)
 | 
				
			||||||
| 
						 | 
					@ -53,8 +53,8 @@ class TestFileLibTiff(LibTiffTestCase):
 | 
				
			||||||
    def test_g4_tiff_file(self):
 | 
					    def test_g4_tiff_file(self):
 | 
				
			||||||
        """Testing the string load path"""
 | 
					        """Testing the string load path"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        file = "Tests/images/hopper_g4_500.tif"
 | 
					        test_file = "Tests/images/hopper_g4_500.tif"
 | 
				
			||||||
        with open(file, 'rb') as f:
 | 
					        with open(test_file, 'rb') as f:
 | 
				
			||||||
            im = Image.open(f)
 | 
					            im = Image.open(f)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            self.assertEqual(im.size, (500, 500))
 | 
					            self.assertEqual(im.size, (500, 500))
 | 
				
			||||||
| 
						 | 
					@ -62,9 +62,9 @@ class TestFileLibTiff(LibTiffTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_g4_tiff_bytesio(self):
 | 
					    def test_g4_tiff_bytesio(self):
 | 
				
			||||||
        """Testing the stringio loading code path"""
 | 
					        """Testing the stringio loading code path"""
 | 
				
			||||||
        file = "Tests/images/hopper_g4_500.tif"
 | 
					        test_file = "Tests/images/hopper_g4_500.tif"
 | 
				
			||||||
        s = io.BytesIO()
 | 
					        s = io.BytesIO()
 | 
				
			||||||
        with open(file, 'rb') as f:
 | 
					        with open(test_file, 'rb') as f:
 | 
				
			||||||
            s.write(f.read())
 | 
					            s.write(f.read())
 | 
				
			||||||
            s.seek(0)
 | 
					            s.seek(0)
 | 
				
			||||||
        im = Image.open(s)
 | 
					        im = Image.open(s)
 | 
				
			||||||
| 
						 | 
					@ -89,8 +89,8 @@ class TestFileLibTiff(LibTiffTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_g4_write(self):
 | 
					    def test_g4_write(self):
 | 
				
			||||||
        """Checking to see that the saved image is the same as what we wrote"""
 | 
					        """Checking to see that the saved image is the same as what we wrote"""
 | 
				
			||||||
        file = "Tests/images/hopper_g4_500.tif"
 | 
					        test_file = "Tests/images/hopper_g4_500.tif"
 | 
				
			||||||
        orig = Image.open(file)
 | 
					        orig = Image.open(test_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        out = self.tempfile("temp.tif")
 | 
					        out = self.tempfile("temp.tif")
 | 
				
			||||||
        rot = orig.transpose(Image.ROTATE_90)
 | 
					        rot = orig.transpose(Image.ROTATE_90)
 | 
				
			||||||
| 
						 | 
					@ -108,8 +108,8 @@ class TestFileLibTiff(LibTiffTestCase):
 | 
				
			||||||
        self.assertNotEqual(orig.tobytes(), reread.tobytes())
 | 
					        self.assertNotEqual(orig.tobytes(), reread.tobytes())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_adobe_deflate_tiff(self):
 | 
					    def test_adobe_deflate_tiff(self):
 | 
				
			||||||
        file = "Tests/images/tiff_adobe_deflate.tif"
 | 
					        test_file = "Tests/images/tiff_adobe_deflate.tif"
 | 
				
			||||||
        im = Image.open(file)
 | 
					        im = Image.open(test_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.assertEqual(im.mode, "RGB")
 | 
					        self.assertEqual(im.mode, "RGB")
 | 
				
			||||||
        self.assertEqual(im.size, (278, 374))
 | 
					        self.assertEqual(im.size, (278, 374))
 | 
				
			||||||
| 
						 | 
					@ -215,8 +215,8 @@ class TestFileLibTiff(LibTiffTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_g4_string_info(self):
 | 
					    def test_g4_string_info(self):
 | 
				
			||||||
        """Tests String data in info directory"""
 | 
					        """Tests String data in info directory"""
 | 
				
			||||||
        file = "Tests/images/hopper_g4_500.tif"
 | 
					        test_file = "Tests/images/hopper_g4_500.tif"
 | 
				
			||||||
        orig = Image.open(file)
 | 
					        orig = Image.open(test_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        out = self.tempfile("temp.tif")
 | 
					        out = self.tempfile("temp.tif")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user