Skip to content

Commit

Permalink
py3k: print is a function
Browse files Browse the repository at this point in the history
Seriously, if you didn't know that, you've been in a freaking cave, man.
  • Loading branch information
Brian Crowell authored and Brian Crowell committed Jan 10, 2013
1 parent aeab3f5 commit 5076c35
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 153 deletions.
16 changes: 9 additions & 7 deletions PIL/ArgImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# See the README file for information on usage and redistribution.
#

from __future__ import print_function

__version__ = "0.4"

import Image, ImageFile, ImagePalette
Expand Down Expand Up @@ -70,8 +72,8 @@ def chunk_AHDR(self, offset, bytes):
raise SyntaxError("unknown ARG mode")

if Image.DEBUG:
print "AHDR size", self.size
print "AHDR mode", self.mode, self.rawmode
print("AHDR size", self.size)
print("AHDR mode", self.mode, self.rawmode)

return s

Expand All @@ -98,7 +100,7 @@ def chunk_AFRM(self, offset, bytes):
self.repair = None

if Image.DEBUG:
print "AFRM", self.id, self.count
print("AFRM", self.id, self.count)

return s

Expand All @@ -121,7 +123,7 @@ def chunk_ADEF(self, offset, bytes):
self.count = i16(s[2:4])

if Image.DEBUG:
print "ADEF", self.id, self.count
print("ADEF", self.id, self.count)

return s

Expand All @@ -141,7 +143,7 @@ def chunk_AEND(self, offset, bytes):
"AEND -- end of animation"

if Image.DEBUG:
print "AEND"
print("AEND")

self.eof = 1

Expand Down Expand Up @@ -256,7 +258,7 @@ def chunk_DHDR(self, offset, bytes):
bbox = offs + (offs[0]+size[0], offs[1]+size[1])

if Image.DEBUG:
print "DHDR", diff, bbox
print("DHDR", diff, bbox)

# FIXME: decode and apply image
self.action = ("DHDR", diff, bbox)
Expand Down Expand Up @@ -473,7 +475,7 @@ def seek(self, frame):

except "glurk": # AttributeError
if Image.DEBUG:
print cid, bytes, "(unknown)"
print(cid, bytes, "(unknown)")
s = self.fp.read(bytes)

self.arg.crc(cid, s)
Expand Down
6 changes: 4 additions & 2 deletions PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# See the README file for information on usage and redistribution.
#

from __future__ import print_function

VERSION = "1.1.7"

try:
Expand Down Expand Up @@ -355,8 +357,8 @@ def init():
del sys.path[0]
except ImportError:
if DEBUG:
print "Image: failed to import",
print f, ":", sys.exc_info()[1]
print("Image: failed to import", end=' ')
print(f, ":", sys.exc_info()[1])
visited[fullpath] = None

if OPEN or SAVE:
Expand Down
10 changes: 6 additions & 4 deletions PIL/ImageCms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# below for the original description.
#

from __future__ import print_function

DESCRIPTION = """
pyCMS
Expand Down Expand Up @@ -770,16 +772,16 @@ def versions():
# create a cheap manual from the __doc__ strings for the functions above

import ImageCms
print __doc__
print(__doc__)

for f in dir(pyCMS):
print "="*80
print "%s" %f
print("="*80)
print("%s" %f)

try:
exec ("doc = ImageCms.%s.__doc__" %(f))
if "pyCMS" in doc:
# so we don't get the __doc__ string for imported modules
print doc
print(doc)
except AttributeError:
pass
12 changes: 7 additions & 5 deletions PIL/ImageFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# See the README file for information on usage and redistribution.
#

from __future__ import print_function

import Image
import os, sys

Expand Down Expand Up @@ -381,10 +383,10 @@ def load_default():
# create font data chunk for embedding
import base64, os, sys
font = "../Images/courB08"
print " f._load_pilfont_data("
print " # %s" % os.path.basename(font)
print " StringIO(base64.decodestring('''"
print(" f._load_pilfont_data(")
print(" # %s" % os.path.basename(font))
print(" StringIO(base64.decodestring('''")
base64.encode(open(font + ".pil", "rb"), sys.stdout)
print "''')), Image.open(StringIO(base64.decodestring('''"
print("''')), Image.open(StringIO(base64.decodestring('''")
base64.encode(open(font + ".pbm", "rb"), sys.stdout)
print "'''))))"
print("'''))))")
4 changes: 3 additions & 1 deletion PIL/ImageShow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the README file for information on usage and redistribution.
#

from __future__ import print_function

import Image
import os, sys

Expand Down Expand Up @@ -160,4 +162,4 @@ def get_command_ex(self, file, title=None, **options):

if __name__ == "__main__":
# usage: python ImageShow.py imagefile [title]
print show(Image.open(sys.argv[1]), *sys.argv[2:])
print(show(Image.open(sys.argv[1]), *sys.argv[2:]))
5 changes: 3 additions & 2 deletions PIL/IptcImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# See the README file for information on usage and redistribution.
#

from __future__ import print_function

__version__ = "0.3"

Expand Down Expand Up @@ -44,8 +45,8 @@ def i(c):

def dump(c):
for i in c:
print "%02x" % ord(i),
print
print("%02x" % ord(i), end=' ')
print()

##
# Image plugin for IPTC/NAA datastreams. To read IPTC/NAA fields
Expand Down
22 changes: 12 additions & 10 deletions PIL/OleFileIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
# See the README file for information on usage and redistribution.
#

from __future__ import print_function

import StringIO
import sys

Expand Down Expand Up @@ -208,12 +210,12 @@ def dump(self, tab = 0):
TYPES = ["(invalid)", "(storage)", "(stream)", "(lockbytes)",
"(property)", "(root)"]

print " "*tab + repr(self.name), TYPES[self.type],
print(" "*tab + repr(self.name), TYPES[self.type], end=' ')
if self.type in (2, 5):
print self.size, "bytes",
print
print(self.size, "bytes", end=' ')
print()
if self.type in (1, 5) and self.clsid:
print " "*tab + "{%s}" % self.clsid
print(" "*tab + "{%s}" % self.clsid)

for kid in self.kids:
kid.dump(tab + 2)
Expand Down Expand Up @@ -515,17 +517,17 @@ def getproperties(self, filename):
for file in sys.argv[1:]:
try:
ole = OleFileIO(file)
print "-" * 68
print file
print "-" * 68
print("-" * 68)
print(file)
print("-" * 68)
ole.dumpdirectory()
for file in ole.listdir():
if file[-1][0] == "\005":
print file
print(file)
props = ole.getproperties(file)
props = list(props.items())
props.sort()
for k, v in props:
print " ", k, v
print(" ", k, v)
except IOError as v:
print "***", "cannot read", file, "-", v
print("***", "cannot read", file, "-", v)
4 changes: 3 additions & 1 deletion PIL/PSDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the README file for information on usage and redistribution.
#

from __future__ import print_function

import EpsImagePlugin

##
Expand Down Expand Up @@ -60,7 +62,7 @@ def setfont(self, font, size):
self.fp.write("/F0 %d /PSDraw-%s F\n" % (size, font))

def setink(self, ink):
print "*** NOT YET IMPLEMENTED ***"
print("*** NOT YET IMPLEMENTED ***")

def line(self, xy0, xy1):
xy = xy0 + xy1
Expand Down
10 changes: 6 additions & 4 deletions PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
# See the README file for information on usage and redistribution.
#

from __future__ import print_function

__version__ = "0.9"

import re
Expand Down Expand Up @@ -111,7 +113,7 @@ def call(self, cid, pos, len):
"Call the appropriate chunk handler"

if Image.DEBUG:
print "STREAM", cid, pos, len
print("STREAM", cid, pos, len)
return getattr(self, "chunk_" + cid)(pos, len)

def crc(self, cid, data):
Expand Down Expand Up @@ -191,8 +193,8 @@ def chunk_iCCP(self, pos, len):
# Compressed profile n bytes (zlib with deflate compression)
i = s.find(chr(0))
if Image.DEBUG:
print "iCCP profile name", s[:i]
print "Compression method", ord(s[i])
print("iCCP profile name", s[:i])
print("Compression method", ord(s[i]))
comp_method = ord(s[i])
if comp_method != 0:
raise SyntaxError("Unknown compression method %s in iCCP chunk" % comp_method)
Expand Down Expand Up @@ -333,7 +335,7 @@ def _open(self):
break
except AttributeError:
if Image.DEBUG:
print cid, pos, len, "(unknown)"
print(cid, pos, len, "(unknown)")
s = ImageFile._safe_read(self.fp, len)

self.png.crc(cid, s)
Expand Down
24 changes: 13 additions & 11 deletions PIL/SpiderImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
# http://www.wadsworth.org/spider_doc/spider/docs/image_doc.html
#

from __future__ import print_function

import Image, ImageFile
import os, struct, sys

Expand Down Expand Up @@ -186,13 +188,13 @@ def loadImageSeries(filelist=None):
imglist = []
for img in filelist:
if not os.path.exists(img):
print "unable to find %s" % img
print("unable to find %s" % img)
continue
try:
im = Image.open(img).convert2byte()
except:
if not isSpiderImage(img):
print img + " is not a Spider image file"
print(img + " is not a Spider image file")
continue
im.info['filename'] = img
imglist.append(im)
Expand Down Expand Up @@ -267,28 +269,28 @@ def _save_spider(im, fp, filename):
if __name__ == "__main__":

if not sys.argv[1:]:
print "Syntax: python SpiderImagePlugin.py Spiderimage [outfile]"
print("Syntax: python SpiderImagePlugin.py Spiderimage [outfile]")
sys.exit()

filename = sys.argv[1]
if not isSpiderImage(filename):
print "input image must be in Spider format"
print("input image must be in Spider format")
sys.exit()

outfile = ""
if len(sys.argv[1:]) > 1:
outfile = sys.argv[2]

im = Image.open(filename)
print "image: " + str(im)
print "format: " + str(im.format)
print "size: " + str(im.size)
print "mode: " + str(im.mode)
print "max, min: ",
print im.getextrema()
print("image: " + str(im))
print("format: " + str(im.format))
print("size: " + str(im.size))
print("mode: " + str(im.mode))
print("max, min: ", end=' ')
print(im.getextrema())

if outfile != "":
# perform some image operation
im = im.transpose(Image.FLIP_LEFT_RIGHT)
print "saving a flipped version of %s as %s " % (os.path.basename(filename), outfile)
print("saving a flipped version of %s as %s " % (os.path.basename(filename), outfile))
im.save(outfile, "SPIDER")
Loading

0 comments on commit 5076c35

Please sign in to comment.