]> granicus.if.org Git - python/commitdiff
_isstring(): Factor out "stringiness" test, e.g. for StringType or
authorBarry Warsaw <barry@python.org>
Tue, 10 Sep 2002 16:09:06 +0000 (16:09 +0000)
committerBarry Warsaw <barry@python.org>
Tue, 10 Sep 2002 16:09:06 +0000 (16:09 +0000)
UnicodeType, which is different between Python 2.1 and 2.2.

Lib/email/_compat21.py
Lib/email/_compat22.py

index 76d6f502bc23887299bfa7e85e76985388daf6d2..de8c44753de43601210714d835b08051ac21a9ad 100644 (file)
@@ -30,6 +30,10 @@ def _floordiv(i, j):
     return i / j
 
 
+def _isstring(obj):
+    return isinstance(obj, StringType) or isinstance(obj, UnicodeType)    
+
+
 \f
 # 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
index 258156805bff36086b43f7239af686c8999fe224..a05451f25d9637a40cdd63c0bc27edc79455a21a 100644 (file)
@@ -31,6 +31,10 @@ def _floordiv(i, j):
     return i // j
 
 
+def _isstring(obj):
+    return isinstance(obj, StringTypes)
+
+
 \f
 # 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