mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +03:00
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.
This commit is contained in:
parent
f6fa0941fd
commit
dfb1b144d8
32
PIL/Image.py
32
PIL/Image.py
|
@ -71,27 +71,15 @@ from . import ImageMode
|
||||||
import os, sys
|
import os, sys
|
||||||
|
|
||||||
# type stuff
|
# type stuff
|
||||||
from types import IntType, StringType, TupleType
|
|
||||||
import collections
|
import collections
|
||||||
import numbers
|
import numbers
|
||||||
|
|
||||||
try:
|
if sys.version_info >= (3,0):
|
||||||
UnicodeStringType = type(unicode(""))
|
|
||||||
##
|
|
||||||
# (Internal) Checks if an object is a string. If the current
|
|
||||||
# Python version supports Unicode, this checks for both 8-bit
|
|
||||||
# and Unicode strings.
|
|
||||||
def isStringType(t):
|
def isStringType(t):
|
||||||
return isinstance(t, StringType) or isinstance(t, UnicodeStringType)
|
return isinstance(t, str)
|
||||||
except NameError:
|
else:
|
||||||
def isStringType(t):
|
def isStringType(t):
|
||||||
return isinstance(t, StringType)
|
return isinstance(t, basestring)
|
||||||
|
|
||||||
##
|
|
||||||
# (Internal) Checks if an object is a tuple.
|
|
||||||
|
|
||||||
def isTupleType(t):
|
|
||||||
return isinstance(t, TupleType)
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# (Internal) Checks if an object is an image object.
|
# (Internal) Checks if an object is an image object.
|
||||||
|
@ -372,7 +360,7 @@ def _getdecoder(mode, decoder_name, args, extra=()):
|
||||||
# tweak arguments
|
# tweak arguments
|
||||||
if args is None:
|
if args is None:
|
||||||
args = ()
|
args = ()
|
||||||
elif not isTupleType(args):
|
elif not isinstance(args, tuple):
|
||||||
args = (args,)
|
args = (args,)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -388,7 +376,7 @@ def _getencoder(mode, encoder_name, args, extra=()):
|
||||||
# tweak arguments
|
# tweak arguments
|
||||||
if args is None:
|
if args is None:
|
||||||
args = ()
|
args = ()
|
||||||
elif not isTupleType(args):
|
elif not isinstance(args, tuple):
|
||||||
args = (args,)
|
args = (args,)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -523,7 +511,7 @@ class Image:
|
||||||
"Return image as a binary string"
|
"Return image as a binary string"
|
||||||
|
|
||||||
# may pass tuple instead of argument list
|
# may pass tuple instead of argument list
|
||||||
if len(args) == 1 and isTupleType(args[0]):
|
if len(args) == 1 and isinstance(args[0], tuple):
|
||||||
args = args[0]
|
args = args[0]
|
||||||
|
|
||||||
if encoder_name == "raw" and args == ():
|
if encoder_name == "raw" and args == ():
|
||||||
|
@ -578,7 +566,7 @@ class Image:
|
||||||
"Load data to image from binary string"
|
"Load data to image from binary string"
|
||||||
|
|
||||||
# may pass tuple instead of argument list
|
# may pass tuple instead of argument list
|
||||||
if len(args) == 1 and isTupleType(args[0]):
|
if len(args) == 1 and isinstance(args[0], tuple):
|
||||||
args = args[0]
|
args = args[0]
|
||||||
|
|
||||||
# default format
|
# default format
|
||||||
|
@ -1789,7 +1777,7 @@ def fromstring(mode, size, data, decoder_name="raw", *args):
|
||||||
"Load image from string"
|
"Load image from string"
|
||||||
|
|
||||||
# may pass tuple instead of argument list
|
# may pass tuple instead of argument list
|
||||||
if len(args) == 1 and isTupleType(args[0]):
|
if len(args) == 1 and isinstance(args[0], tuple):
|
||||||
args = args[0]
|
args = args[0]
|
||||||
|
|
||||||
if decoder_name == "raw" and args == ():
|
if decoder_name == "raw" and args == ():
|
||||||
|
@ -1836,7 +1824,7 @@ def frombuffer(mode, size, data, decoder_name="raw", *args):
|
||||||
"Load image from string or buffer"
|
"Load image from string or buffer"
|
||||||
|
|
||||||
# may pass tuple instead of argument list
|
# may pass tuple instead of argument list
|
||||||
if len(args) == 1 and isTupleType(args[0]):
|
if len(args) == 1 and isinstance(args[0], tuple):
|
||||||
args = args[0]
|
args = args[0]
|
||||||
|
|
||||||
if decoder_name == "raw":
|
if decoder_name == "raw":
|
||||||
|
|
|
@ -53,7 +53,7 @@ class ImagePalette:
|
||||||
# experimental: given an rgb tuple, allocate palette entry
|
# experimental: given an rgb tuple, allocate palette entry
|
||||||
if self.rawmode:
|
if self.rawmode:
|
||||||
raise ValueError("palette contains raw palette data")
|
raise ValueError("palette contains raw palette data")
|
||||||
if Image.isTupleType(color):
|
if isinstance(color, tuple):
|
||||||
try:
|
try:
|
||||||
return self.colors[color]
|
return self.colors[color]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
@ -116,7 +116,6 @@ The PIL.Image Module
|
||||||
**isDirectory(f)** [`# <#PIL.Image.isDirectory-function>`_]
|
**isDirectory(f)** [`# <#PIL.Image.isDirectory-function>`_]
|
||||||
**isImageType(t)** [`# <#PIL.Image.isImageType-function>`_]
|
**isImageType(t)** [`# <#PIL.Image.isImageType-function>`_]
|
||||||
**isStringType(t)** [`# <#PIL.Image.isStringType-function>`_]
|
**isStringType(t)** [`# <#PIL.Image.isStringType-function>`_]
|
||||||
**isTupleType(t)** [`# <#PIL.Image.isTupleType-function>`_]
|
|
||||||
**merge(mode, bands)** [`# <#PIL.Image.merge-function>`_]
|
**merge(mode, bands)** [`# <#PIL.Image.merge-function>`_]
|
||||||
|
|
||||||
*mode*
|
*mode*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user