Skip to content

Commit a727aa8

Browse files
committed
another mailed refactoring, thanks Hadi
1 parent 31fc308 commit a727aa8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

py4web/utils/mailer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def to_bytes(text, encoding="utf8"):
5555
# if the text is not a string or bytes, maybe it is a file
5656
if text is None:
5757
text = b""
58-
if not isinstance(text, (str, bytes)):
58+
elif hasattr(text, "read") and callable(text.read):
5959
text = text.read()
6060
# if it is a unicode string encode it
6161
if isinstance(text, str):
@@ -73,7 +73,7 @@ def to_unicode(text, encoding="utf8"):
7373
# if the text is not a string or bytes, maybe it is a file
7474
if text is None:
7575
text = ""
76-
elif not isinstance(text, (str, bytes)):
76+
elif hasattr(text, "read") and callable(text.read):
7777
text = text.read()
7878
# if it is a bytes string encode it
7979
if isinstance(text, bytes):

0 commit comments

Comments
 (0)