Skip to content

Commit

Permalink
Fixed redefinition of built-in
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Apr 24, 2015
1 parent 566153f commit 7f41405
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions PIL/ImImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def tell(self):
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)

Expand All @@ -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'))
Expand Down
4 changes: 2 additions & 2 deletions PIL/ImageFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the README file for information on usage and redistribution.
#

from functools import reduce
import functools


class Filter(object):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from PIL import Image
from PIL._util import isStringType
import operator
from functools import reduce
import functools


#
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions PIL/ImageStat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import math
import operator
from functools import reduce
import functools


class Stat:
Expand Down Expand Up @@ -71,18 +71,18 @@ def _getcount(self):

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):
"Get sum of all pixels in each layer"

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):
Expand Down
12 changes: 6 additions & 6 deletions PIL/MspImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def _open(self):
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"
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions Scripts/pilconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def usage():
print(v)
sys.exit(1)

format = None
output_format = None
convert = None

options = {}
Expand All @@ -68,7 +68,7 @@ def usage():
sys.exit(1)

elif o == "-c":
format = a
output_format = a

if o == "-g":
convert = "L"
Expand All @@ -90,8 +90,8 @@ def usage():
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:
Expand Down
10 changes: 5 additions & 5 deletions Scripts/pilprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
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 "
Expand Down Expand Up @@ -65,12 +65,12 @@ def description(file, image):
# 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)
Expand Down
24 changes: 12 additions & 12 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -53,18 +53,18 @@ def test_g4_large(self):
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))
self._assert_noerr(im)

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)
Expand All @@ -89,8 +89,8 @@ def test_g4_fillorder_eq_png(self):

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)
Expand All @@ -108,8 +108,8 @@ def test_g4_write(self):
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))
Expand Down Expand Up @@ -215,8 +215,8 @@ def test_big_endian(self):

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")

Expand Down

0 comments on commit 7f41405

Please sign in to comment.