Skip to content

Commit 6de4426

Browse files
author
Steve Canny
committed
py3: add docx.compat.is_string()
1 parent 31f88da commit 6de4426

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docx/compat.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,22 @@
1818

1919
from io import BytesIO
2020

21+
def is_string(obj):
22+
"""
23+
Return True if *obj* is a string, False otherwise.
24+
"""
25+
return isinstance(obj, str)
26+
2127
# ===========================================================================
2228
# Python 2 versions
2329
# ===========================================================================
2430

2531
else:
2632

2733
from StringIO import StringIO as BytesIO # noqa
34+
35+
def is_string(obj):
36+
"""
37+
Return True if *obj* is a string, False otherwise.
38+
"""
39+
return isinstance(obj, basestring)

docx/parts/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
except ImportError:
1717
import Image as PIL_Image
1818

19-
from docx.compat import BytesIO
19+
from docx.compat import BytesIO, is_string
2020
from docx.opc.constants import CONTENT_TYPE as CT
2121
from docx.opc.package import Part
2222
from docx.shared import Emu, Inches, lazyproperty
@@ -80,7 +80,7 @@ def from_file(cls, image_descriptor):
8080
Return a new |Image| instance loaded from the image file identified
8181
by *image_descriptor*, a path or file-like object.
8282
"""
83-
if isinstance(image_descriptor, basestring):
83+
if is_string(image_descriptor):
8484
path = image_descriptor
8585
with open(path, 'rb') as f:
8686
blob = f.read()

0 commit comments

Comments
 (0)