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