~barry/mailman/templatecache

« back to all changes in this revision

Viewing changes to src/mailman/testing/helpers.py

  • Committer: Barry Warsaw
  • Date: 2012-10-31 16:37:22 UTC
  • mfrom: (7178.1.1 work2)
  • Revision ID: barry@list.org-20121031163722-3lszhsiv9ai0akfp
 * Python 2.7 is not required.  Python 2.6 is no longer officially supported.
   The code base is now also `python2.7 -3` clean, although there are still
   some warnings in 3rd party dependencies.  LP: #1073506

Show diffs side-by-side

added added

removed removed

Lines of Context:
249
249
            if not quiet:
250
250
                print(response)
251
251
            return lmtp
252
 
        except socket.error as error:
253
 
            if error[0] == errno.ECONNREFUSED:
 
252
        except IOError as error:
 
253
            if error.errno == errno.ECONNREFUSED:
254
254
                time.sleep(0.1)
255
255
            else:
256
256
                raise
284
284
        try:
285
285
            socket.socket().connect((config.webservice.hostname,
286
286
                                    int(config.webservice.port)))
287
 
        except socket.error as error:
288
 
            if error[0] == errno.ECONNREFUSED:
 
287
        except IOError as error:
 
288
            if error.errno == errno.ECONNREFUSED:
289
289
                time.sleep(0.1)
290
290
            else:
291
291
                raise
515
515
        with open(self._filename) as fp:
516
516
            fp.seek(self._filepos)
517
517
            return fp.readline()
518
 
 
519
 
 
520
 
 
521
 
# In Python 2.6, body_line_iterator() uses a cStringIO.StringIO() which cannot
522
 
# handle unicode.  In Python 2.7 this works fine.  I hate version checks but
523
 
# this is the easiest way to handle it.  OTOH, we could just use the manual
524
 
# way for all Python versions instead.
525
 
import sys
526
 
if sys.hexversion >= 0x2070000:
527
 
    from email.iterators import body_line_iterator
528
 
else:
529
 
    def body_line_iterator(msg, decode=False):
530
 
        payload = msg.get_payload(decode=decode)
531
 
        bytes_payload = payload.encode('utf-8')
532
 
        for line in bytes_payload.splitlines():
533
 
            yield line