From 282562ec19d6e88ea054e11f327e7fd1cbc97870 Mon Sep 17 00:00:00 2001 From: Nicolas Pieuchot Date: Thu, 25 Apr 2013 22:03:37 +0200 Subject: [PATCH] Adding Python3 basestring compatibility without changing basestring --- PIL/ImageFont.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/PIL/ImageFont.py b/PIL/ImageFont.py index 7ae57a389..fcff4eb81 100644 --- a/PIL/ImageFont.py +++ b/PIL/ImageFont.py @@ -41,6 +41,15 @@ try: except ImportError: 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) # -------------------------------------------------------------------- @@ -136,7 +145,7 @@ class FreeTypeFont: warnings.warn('file parameter deprecated, please use font parameter instead.', DeprecationWarning) font = file - if isinstance(font, basestring): + if isstr(font): self.font = core.getfont(font, size, index, encoding) else: bytes = font.read()