Commit Graph

167 Commits

Author SHA1 Message Date
Brian Crowell
952685faa1 py3k: Type coercion is gone
Types aren't automatically converted for operations for you.
2013-01-16 13:47:28 +08:00
Brian Crowell
12d8977542 py3k: Sort by key, not cmp
Py3k only supports key because it's more efficient. Not even sure 2to3
checks for this.
2013-01-16 13:47:28 +08:00
Brian Crowell
67316d78f9 py3k: Map long type to int
int() is really now long() in py3k, but to avoid breaking 2.6/2.7, we leave
the integer types where they are and just map long to int in py3k.

Also, pretty proud of myself for finding an easy way of detecting py3k.
2013-01-16 13:47:28 +08:00
Brian Crowell
73f7c7a187 py3k: 2to3's "idiom" filter
This is, I guess, a few things the Python devs were just fed up with.

* "while 1" is now "while True"
* Types are compared with isinstance instead of ==
* Sort a list in one go with sorted()

My own twist is to also replace type('') with str, type(()) with tuple,
type([]) with list, type(1) with int, and type(5000.0) with float.
2013-01-16 13:47:28 +08:00
Brian Crowell
da5ca4caea py3k: Change apply() to unpacking syntax
apply() is no longer available in py3k.
2013-01-16 13:47:28 +08:00
Brian Crowell
1a82abcad1 py3k: Integer long literals are no longer valid syntax 2013-01-16 13:47:28 +08:00
Brian Crowell
d37a2e192c py3k: Convert StringIO.StringIO to io.BytesIO
io.BytesIO is already in 2.6. Some of the more obvious bytes literals are
marked in this commit.
2013-01-16 13:47:28 +08:00
Brian Crowell
b0f6f95bdb py3k: Tkinter module is now tkinter 2013-01-16 13:47:28 +08:00
Brian Crowell
59d1372940 py3k: __builtin__ module is now builtins 2013-01-16 13:47:28 +08:00
Brian Crowell
2868e0cb0b py3k: Remove Image types import
For awhile now, str == type("") and so on. So we use the appropriate int,
str, basestring, or tuple type where applicable.
2013-01-16 13:47:28 +08:00
Brian Crowell
9cdb285398 py3k: Convert backticks to repr()
Backticks are no longer valid syntax for repr().
2013-01-16 13:47:27 +08:00
Brian Crowell
2a81f6266f py3k: sys.maxint renamed to sys.maxsize 2013-01-16 13:47:27 +08:00
Brian Crowell
6a68d03bab py3k: Use relative imports
In py3k, imports are absolute unless using the "from . import" syntax.

This commit also solves a recursive import between Image, ImageColor, and
ImagePalette by delay-importing ImagePalette in Image.

I'm not too keen on this commit because the syntax is ugly. I might go back
and prefer the prettier "from PIL import".
2013-01-16 13:47:27 +08:00
Brian Crowell
7a3feb2ae4 py3k: Remove tuples in parameter lists
Py3k no longer supports unpacking tuples in the parameters.
2013-01-16 13:47:27 +08:00
Brian Crowell
2b31043fbb py3k: print is a function
Seriously, if you didn't know that, you've been in a freaking cave, man.
2013-01-16 13:47:27 +08:00
Brian Crowell
61038ad796 py3k: Import reduce function
reduce() is no longer a built-in function in py3k.
2013-01-16 13:47:27 +08:00
Brian Crowell
659f1ba68f py3k: Use isinstance for numbers and sequences
operator.isNumberType() and .isSequenceType() go away in py3k.
2013-01-16 13:47:27 +08:00
Brian Crowell
3189876053 py3k: __nonzero__ is now __bool__ 2013-01-16 13:47:27 +08:00
Brian Crowell
a5e800bfc3 py3k: Add true Unicode support to OleFileIO
The day has arrived when Python provides an official way to handle Unicode
strings.
2013-01-16 13:47:27 +08:00
Brian Crowell
f1666cbb21 py3k: map and filter to list comprehensions
What's really going on is that map() and filter() return iterators in py3k.
I've just gone ahead and turned them all into list comprehensions, because
I find them much easier to read.
2013-01-16 13:47:27 +08:00
Brian Crowell
48b0e0c6e0 py3k: Rewrite dictionary support for Tiff ImageFileDictionary
This commit brings in the collections.MutableMapping mixin to provide full
dictionary support for ImageFileDictionary.
2013-01-16 13:47:27 +08:00
Brian Crowell
bb1f0b8609 py3k: Fix up uses of dictionary views, ranges, and has_key()
y.has_key(x) is gone (use x in y), and keys(), values(), items(), and
range() all return views.

Some iterables needed to be packed into lists, either because the code
expected a list (such as "range(256) * 3") or because the original
collection was being modified (automatic global declarations).

The Tiff ImageFileDictionary is a special case and will be dealt with in
another commit.
2013-01-16 13:47:27 +08:00
Brian Crowell
4f120b9757 py3k: Remove callable() function
callable(c) is isinstance(x, collections.Callable) in py3k.
2013-01-16 13:47:27 +08:00
Brian Crowell
f760f9f8d5 py3k: Provide the missing pngtest_bad.png.base64
This is from http://scary.beasts.org/security/CESA-2004-001.txt. This was
missing from Gohlke's tests. With this file, I see 79 tests and no failures
on my setup from 2.6/2.7.
2013-01-16 13:47:27 +08:00
Brian Crowell
3400e6b573 FIX: Handle long values in _imaging getink
This gets the putdata test case to run correctly under 2.6/2.7. It fixes an
issue where the value 0xFFFFFFFF (which is long in old Python) isn't
recognized and putdata tries to parse it as a tuple.

The original fix comes from Christoph Gohlke. It was adapted to work in
both 2.* and 3.*.
2013-01-16 13:47:27 +08:00
Brian Crowell
c35207cbc1 py3k: Backport Gohlke's tests to run on 2.6/2.7
Most of the differences are in tobytes/tostring naming and expected
behavior of the bytes() constructor. The latter was usually easy to fix
with the right bytes literal.

This is a good preview of what will have to happen in the Python 3 code.
2013-01-16 13:47:27 +08:00
Brian Crowell
e1009da27c py3k: Import Christoph Gohlke's test suite
This is Christoph Gohlke's test suite from his personal PIL package found
at http://www.lfd.uci.edu/~gohlke/pythonlibs/.

This is just to bring it in as a separate commit. Future commits will align
it with Pillow.
2013-01-16 13:47:27 +08:00
Brian Crowell
7de6ab5108 py3k: Use "y#" code in PyArg_ParseTuple where we expect byte data
This commit also renames some functions from "fromstring" and the like to
"frombytes". I'll probably need to come back later and update any
references to "string," here or in the docs.

I also noticed that encode allocates some data for certain codecs, but
never frees them. That would be a good bug to fix. I fixed the one where it
outright stole a pointer from Python.
2013-01-16 13:47:26 +08:00
Brian Crowell
a948d0a3ac py3k: Fix strict aliasing warnings under Python 3 2013-01-16 13:47:26 +08:00
Brian Crowell
39484c3632 py3k: Add module initialization and unicode/bytes int/long thunks
This commit:

* Adds Python 3 module initialization functions. I split out the main init
  of each module into a static setup_module function.
* Adds a py3.h which unifies int/long in Python 3 and unicode/bytes in
  Python 2. _imagingft.c unfortunately looks a little kludgy after this
  because it was already using PyUnicode functions, and I had to mix and
  match there manually.

With this commit, the modules all build successfully under Python 3.

What this commit does NOT do is patch all of the uses of PyArg_ParseTuple
and Py_BuildValue, which all need to be checked for proper use of bytes
and unicode codes. It also does not let selftest.py run yet, because there
are probably hundreds of issues to fix in the Python code itself.
2013-01-16 13:47:26 +08:00
Brian Crowell
30333de036 py3k: Fix strict aliasing slip-up in _imaging
Python 3 enables C's strict aliasing rules for the first time, which means
you need to be careful about the ways you reference pointers. Here, we're
using a char[4] as an INT32, so we cast between them using a union.
2013-01-16 13:47:26 +08:00
Brian Crowell
77256df067 py3k: Remove HAVE_UNICODE from _imagingft
I'm pretty sure this preserves the intent of the code. HAVE_UNICODE is now
assumed, and PyString is only used if we're not in Py3k.

Since this is the only file that uses PyUnicode, I'm going to go ahead and
#define PyUnicode and PyBytes back to PyString for 2.6, and explicitly
change out every call so I have to check them all.
2013-01-16 13:47:26 +08:00
Brian Crowell
71c817c707 py3k: Use new buffer protocol
Other ports have taken advantage of the fact that Python 3 has wrappers for
the old buffer protocol, but there's a significant disadvantage: you can't
let the buffered object know when you're done with it.

Since Python 2.6 supports the new protocol, we just go ahead and move to
it.
2013-01-16 13:47:26 +08:00
Brian Crowell
4a4d7dcf3b py3k: Modernize type declarations
This updates several Python type definitions and uses to bring us closer
to Python 3 compatibility. This includes:

* Replacing staticforward and statichere with static. These were a hack for
  old compilers and are not supported/needed anymore.
* Using Py_TYPE() instead of ob_type; ob_type is hidden in Py3.
* Replacing getattr with getters/setters. getattr is sort-of supported in
  Py3, but Py_FindMethod is not. So we just use the newer
  methods/getsetters mechanisms and start using PyType_Ready everywhere.
* Use PyVarObject_HEAD_INIT for types, since types are PyVarObject.
* Use PyMODINIT_FUNC for module initialization functions.

There are some tab/space issues in this commit. I'm set for spaces; the
source is a little schizo.
2013-01-16 13:47:26 +08:00
Brian Crowell
edfe1062ef py3k: Get setup.py to run under python3
First real fix: open the temp file in text mode.
2013-01-16 13:47:26 +08:00
Brian Crowell
ab29a5a223 py3k: Update exception usage to modern syntax 2013-01-16 13:47:26 +08:00
Brian Crowell
3ab0a29887 py3k: Use string methods instead of string module
First, we go for the obvious stuff. The string module methods are gone in
3.0, so we translate them to the appropriate methods on the string class.
2013-01-16 13:47:26 +08:00
d-schmidt
a9d42aebc7 fixed crash loading broken color profile from file-like object 2013-01-16 13:47:26 +08:00
Alex Po
5e7920d0f6 Move custom path of JPEG_ROOT, TIFF_ROOT, etc. before system. 2013-01-16 13:47:26 +08:00
Tom Payne
23ebec0080 Avoid rounding error in Image.alpha_composite 2013-01-16 13:47:26 +08:00
cgohlke
4204c24df6 Make FLI image detection more stringent 2013-01-16 13:47:26 +08:00
Manuel Ebert
ab94dde3da Radius was hardcoded to 2.
This will probably, some time in the future get fixed upstream in PIL. Maybe.
2013-01-16 13:47:26 +08:00
Brian J. Crowell
d03b1fbb24 Add files to the MANIFEST which were missing from the source distribution 2013-01-16 13:47:26 +08:00
Tom Payne
3a21c8893a Add Image.alpha_composite 2013-01-16 13:47:26 +08:00
Alex Clark
833b2b5f63 Release 1.7.8 2013-01-16 13:47:26 +08:00
Alex Clark
8e0c27437e Fix formatting of installation summary 2013-01-16 13:47:26 +08:00
tdesvenain
4d4e2de42b Removed doctests.py that made tests of other packages fail. 2013-01-16 13:47:26 +08:00
tdesvenain
f4d9eaca53 revert last commit, images rendered didn't match very well 2013-01-16 13:47:26 +08:00
tdesvenain
f242f72736 Added a psd mode (mode 4, 16 bits). 2013-01-16 13:47:26 +08:00
tdesvenain
1a8f45bc50 Fix opening psd files with RGBA layers when A mode is not of type 65535
but 3.
Fixes issue https://github.com/python-imaging/Pillow/issues/3
2013-01-16 13:47:26 +08:00