mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
Adding Python3 basestring compatibility without changing basestring
This commit is contained in:
parent
5577801aaa
commit
282562ec19
|
@ -41,6 +41,15 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
core = _imagingft_not_installed()
|
core = _imagingft_not_installed()
|
||||||
|
|
||||||
|
# Python3 compatibility for basestring
|
||||||
|
try:
|
||||||
|
basestring # attempt to evaluate basestring
|
||||||
|
def isstr(s):
|
||||||
|
return isinstance(s, basestring) # Python2.x
|
||||||
|
except NameError:
|
||||||
|
def isstr(s):
|
||||||
|
return isinstance(s, str) # Python3.x
|
||||||
|
|
||||||
# FIXME: add support for pilfont2 format (see FontFile.py)
|
# FIXME: add support for pilfont2 format (see FontFile.py)
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
@ -136,7 +145,7 @@ class FreeTypeFont:
|
||||||
warnings.warn('file parameter deprecated, please use font parameter instead.', DeprecationWarning)
|
warnings.warn('file parameter deprecated, please use font parameter instead.', DeprecationWarning)
|
||||||
font = file
|
font = file
|
||||||
|
|
||||||
if isinstance(font, basestring):
|
if isstr(font):
|
||||||
self.font = core.getfont(font, size, index, encoding)
|
self.font = core.getfont(font, size, index, encoding)
|
||||||
else:
|
else:
|
||||||
bytes = font.read()
|
bytes = font.read()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user