From: Barry Warsaw Date: Tue, 10 Sep 2002 16:09:06 +0000 (+0000) Subject: _isstring(): Factor out "stringiness" test, e.g. for StringType or X-Git-Tag: v2.3c1~4153 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=356afac41ff5384e8c82236f9fae162cf83d0559;p=thirdparty%2FPython%2Fcpython.git _isstring(): Factor out "stringiness" test, e.g. for StringType or UnicodeType, which is different between Python 2.1 and 2.2. --- diff --git a/Lib/email/_compat21.py b/Lib/email/_compat21.py index 76d6f502bc23..de8c44753de4 100644 --- a/Lib/email/_compat21.py +++ b/Lib/email/_compat21.py @@ -30,6 +30,10 @@ def _floordiv(i, j): return i / j +def _isstring(obj): + return isinstance(obj, StringType) or isinstance(obj, UnicodeType) + + # These two functions are imported into the Iterators.py interface module. # The Python 2.2 version uses generators for efficiency. @@ -38,7 +42,7 @@ def body_line_iterator(msg): lines = [] for subpart in msg.walk(): payload = subpart.get_payload() - if isinstance(payload, StringType) or isinstance(payload, UnicodeType): + if _isstring(payload): for line in StringIO(payload).readlines(): lines.append(line) return lines diff --git a/Lib/email/_compat22.py b/Lib/email/_compat22.py index 258156805bff..a05451f25d96 100644 --- a/Lib/email/_compat22.py +++ b/Lib/email/_compat22.py @@ -31,6 +31,10 @@ def _floordiv(i, j): return i // j +def _isstring(obj): + return isinstance(obj, StringTypes) + + # These two functions are imported into the Iterators.py interface module. # The Python 2.2 version uses generators for efficiency. @@ -38,7 +42,7 @@ def body_line_iterator(msg): """Iterate over the parts, returning string payloads line-by-line.""" for subpart in msg.walk(): payload = subpart.get_payload() - if isinstance(payload, StringTypes): + if _isstring(payload): for line in StringIO(payload): yield line