mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 07:57:27 +03:00 
			
		
		
		
	Apply @Arfrever patch, fixes #258
This commit is contained in:
		
							parent
							
								
									54cb132b83
								
							
						
					
					
						commit
						fd29e707e9
					
				|  | @ -26,6 +26,7 @@ | |||
| __version__ = "0.1" | ||||
| 
 | ||||
| from PIL import ImageFile, ImagePalette, _binary | ||||
| from PIL._util import isPath | ||||
| 
 | ||||
| try: | ||||
|     import builtins | ||||
|  | @ -77,7 +78,7 @@ def open(fp, mode = "r"): | |||
|     if mode != "r": | ||||
|         raise ValueError("bad mode") | ||||
| 
 | ||||
|     if isinstance(fp, str): | ||||
|     if isPath(fp): | ||||
|         filename = fp | ||||
|         fp = builtins.open(fp, "rb") | ||||
|     else: | ||||
|  |  | |||
							
								
								
									
										23
									
								
								PIL/Image.py
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								PIL/Image.py
									
									
									
									
									
								
							|  | @ -81,6 +81,7 @@ except ImportError: | |||
| 
 | ||||
| from PIL import ImageMode | ||||
| from PIL._binary import i8, o8 | ||||
| from PIL._util import isPath, isStringType | ||||
| 
 | ||||
| import os, sys | ||||
| 
 | ||||
|  | @ -88,26 +89,12 @@ import os, sys | |||
| import collections | ||||
| import numbers | ||||
| 
 | ||||
| if bytes is str: | ||||
|     def isStringType(t): | ||||
|         return isinstance(t, basestring) | ||||
| else: | ||||
|     def isStringType(t): | ||||
|         return isinstance(t, str) | ||||
| 
 | ||||
| ## | ||||
| # (Internal) Checks if an object is an image object. | ||||
| 
 | ||||
| def isImageType(t): | ||||
|     return hasattr(t, "im") | ||||
| 
 | ||||
| ## | ||||
| # (Internal) Checks if an object is a string, and that it points to a | ||||
| # directory. | ||||
| 
 | ||||
| def isDirectory(f): | ||||
|     return isStringType(f) and os.path.isdir(f) | ||||
| 
 | ||||
| # | ||||
| # Debug level | ||||
| 
 | ||||
|  | @ -1421,10 +1408,10 @@ class Image: | |||
|     def save(self, fp, format=None, **params): | ||||
|         "Save image to file or stream" | ||||
| 
 | ||||
|         if isStringType(fp): | ||||
|         if isPath(fp): | ||||
|             filename = fp | ||||
|         else: | ||||
|             if hasattr(fp, "name") and isStringType(fp.name): | ||||
|             if hasattr(fp, "name") and isPath(fp.name): | ||||
|                 filename = fp.name | ||||
|             else: | ||||
|                 filename = "" | ||||
|  | @ -1455,7 +1442,7 @@ class Image: | |||
|             init() | ||||
|             save_handler = SAVE[format.upper()] # unknown format | ||||
| 
 | ||||
|         if isStringType(fp): | ||||
|         if isPath(fp): | ||||
|             fp = builtins.open(fp, "wb") | ||||
|             close = 1 | ||||
|         else: | ||||
|  | @ -1984,7 +1971,7 @@ def open(fp, mode="r"): | |||
|     if mode != "r": | ||||
|         raise ValueError("bad mode") | ||||
| 
 | ||||
|     if isStringType(fp): | ||||
|     if isPath(fp): | ||||
|         filename = fp | ||||
|         fp = builtins.open(fp, "rb") | ||||
|     else: | ||||
|  |  | |||
|  | @ -83,6 +83,7 @@ VERSION = "0.1.0 pil" | |||
| 
 | ||||
| from PIL import Image | ||||
| from PIL import _imagingcms | ||||
| from PIL._util import isStringType | ||||
| 
 | ||||
| core = _imagingcms | ||||
| 
 | ||||
|  | @ -139,7 +140,7 @@ class ImageCmsProfile: | |||
|     def __init__(self, profile): | ||||
|         # accepts a string (filename), a file-like object, or a low-level | ||||
|         # profile object | ||||
|         if Image.isStringType(profile): | ||||
|         if isStringType(profile): | ||||
|             self._set(core.profile_open(profile), profile) | ||||
|         elif hasattr(profile, "read"): | ||||
|             self._set(core.profile_frombytes(profile.read())) | ||||
|  |  | |||
|  | @ -33,6 +33,7 @@ | |||
| import numbers | ||||
| 
 | ||||
| from PIL import Image, ImageColor | ||||
| from PIL._util import isStringType | ||||
| 
 | ||||
| try: | ||||
|     import warnings | ||||
|  | @ -98,7 +99,7 @@ class ImageDraw: | |||
|                 "'setink' is deprecated; use keyword arguments instead", | ||||
|                 DeprecationWarning, stacklevel=2 | ||||
|                 ) | ||||
|         if Image.isStringType(ink): | ||||
|         if isStringType(ink): | ||||
|             ink = ImageColor.getcolor(ink, self.mode) | ||||
|         if self.palette and not isinstance(ink, numbers.Number): | ||||
|             ink = self.palette.getcolor(ink) | ||||
|  | @ -141,13 +142,13 @@ class ImageDraw: | |||
|                 ink = self.ink | ||||
|         else: | ||||
|             if ink is not None: | ||||
|                 if Image.isStringType(ink): | ||||
|                 if isStringType(ink): | ||||
|                     ink = ImageColor.getcolor(ink, self.mode) | ||||
|                 if self.palette and not isinstance(ink, numbers.Number): | ||||
|                     ink = self.palette.getcolor(ink) | ||||
|                 ink = self.draw.draw_ink(ink, self.mode) | ||||
|             if fill is not None: | ||||
|                 if Image.isStringType(fill): | ||||
|                 if isStringType(fill): | ||||
|                     fill = ImageColor.getcolor(fill, self.mode) | ||||
|                 if self.palette and not isinstance(fill, numbers.Number): | ||||
|                     fill = self.palette.getcolor(fill) | ||||
|  |  | |||
|  | @ -28,6 +28,7 @@ | |||
| # | ||||
| 
 | ||||
| from PIL import Image | ||||
| from PIL._util import isPath | ||||
| import traceback, os | ||||
| import io | ||||
| 
 | ||||
|  | @ -81,7 +82,7 @@ class ImageFile(Image.Image): | |||
|         self.decoderconfig = () | ||||
|         self.decodermaxblock = MAXBLOCK | ||||
| 
 | ||||
|         if Image.isStringType(fp): | ||||
|         if isPath(fp): | ||||
|             # filename | ||||
|             self.fp = open(fp, "rb") | ||||
|             self.filename = fp | ||||
|  |  | |||
|  | @ -28,6 +28,7 @@ | |||
| from __future__ import print_function | ||||
| 
 | ||||
| from PIL import Image | ||||
| from PIL._util import isDirectory, isPath | ||||
| import os, sys | ||||
| 
 | ||||
| try: | ||||
|  | @ -45,13 +46,6 @@ try: | |||
| except ImportError: | ||||
|     core = _imagingft_not_installed() | ||||
| 
 | ||||
| if bytes is str: | ||||
|     def isStringType(t): | ||||
|         return isinstance(t, basestring) | ||||
| else: | ||||
|     def isStringType(t): | ||||
|         return isinstance(t, str) | ||||
| 
 | ||||
| # FIXME: add support for pilfont2 format (see FontFile.py) | ||||
| 
 | ||||
| # -------------------------------------------------------------------- | ||||
|  | @ -148,7 +142,7 @@ class FreeTypeFont: | |||
|                 warnings.warn('file parameter deprecated, please use font parameter instead.', DeprecationWarning) | ||||
|             font = file | ||||
| 
 | ||||
|         if isStringType(font): | ||||
|         if isPath(font): | ||||
|             self.font = core.getfont(font, size, index, encoding) | ||||
|         else: | ||||
|             self.font_bytes = font.read() | ||||
|  | @ -266,7 +260,12 @@ def truetype(font=None, size=10, index=0, encoding="", filename=None): | |||
| def load_path(filename): | ||||
|     "Load a font file, searching along the Python path." | ||||
|     for dir in sys.path: | ||||
|         if Image.isDirectory(dir): | ||||
|         if isDirectory(dir): | ||||
|             if not isinstance(filename, "utf-8"): | ||||
|                 if bytes is str: | ||||
|                     filename = filename.encode("utf-8") | ||||
|                 else: | ||||
|                     filename = filename.decode("utf-8") | ||||
|             try: | ||||
|                 return load(os.path.join(dir, filename)) | ||||
|             except IOError: | ||||
|  |  | |||
|  | @ -18,6 +18,7 @@ | |||
| # | ||||
| 
 | ||||
| from PIL import Image | ||||
| from PIL._util import isStringType | ||||
| import operator | ||||
| from functools import reduce | ||||
| 
 | ||||
|  | @ -43,7 +44,7 @@ def _border(border): | |||
|     return left, top, right, bottom | ||||
| 
 | ||||
| def _color(color, mode): | ||||
|     if Image.isStringType(color): | ||||
|     if isStringType(color): | ||||
|         from PIL import ImageColor | ||||
|         color = ImageColor.getcolor(color, mode) | ||||
|     return color | ||||
|  |  | |||
|  | @ -16,6 +16,7 @@ | |||
| # | ||||
| 
 | ||||
| from PIL import Image | ||||
| from PIL._util import isPath | ||||
| 
 | ||||
| from PyQt4.QtGui import QImage, qRgb | ||||
| 
 | ||||
|  | @ -45,7 +46,7 @@ class ImageQt(QImage): | |||
|         if hasattr(im, "toUtf8"): | ||||
|             # FIXME - is this really the best way to do this? | ||||
|             im = unicode(im.toUtf8(), "utf-8") | ||||
|         if Image.isStringType(im): | ||||
|         if isPath(im): | ||||
|             im = Image.open(im) | ||||
| 
 | ||||
|         if im.mode == "1": | ||||
|  |  | |||
|  | @ -37,6 +37,7 @@ __version__ = "0.6" | |||
| import array, struct | ||||
| from PIL import Image, ImageFile, _binary | ||||
| from PIL.JpegPresets import presets | ||||
| from PIL._util import isStringType | ||||
| 
 | ||||
| i8 = _binary.i8 | ||||
| o8 = _binary.o8 | ||||
|  | @ -488,7 +489,7 @@ def _save(im, fp, filename): | |||
|     def validate_qtables(qtables): | ||||
|         if qtables is None: | ||||
|             return qtables | ||||
|         if isinstance(qtables, basestring): | ||||
|         if isStringType(qtables): | ||||
|             try: | ||||
|                 lines = [int(num) for line in qtables.splitlines() | ||||
|                          for num in line.split('#', 1)[0].split()] | ||||
|  |  | |||
|  | @ -41,6 +41,7 @@ from __future__ import print_function | |||
| import io | ||||
| import sys | ||||
| from PIL import _binary | ||||
| from PIL._util import isPath | ||||
| 
 | ||||
| if str is not bytes: | ||||
|     long = int | ||||
|  | @ -269,7 +270,7 @@ class OleFileIO: | |||
|     def open(self, filename): | ||||
|         """Open an OLE2 file""" | ||||
| 
 | ||||
|         if isinstance(filename, str): | ||||
|         if isPath(filename): | ||||
|             self.fp = open(filename, "rb") | ||||
|         else: | ||||
|             self.fp = filename | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user