Ticket #5809: mail-open-5809.patch

File mail-open-5809.patch, 5.4 KB (added by thijs, 4 years ago)
  • twisted/mail/test/test_options.py

     
    2828    """
    2929    def setUp(self):
    3030        self.aliasFilename = self.mktemp()
    31         aliasFile = file(self.aliasFilename, 'w')
    32         aliasFile.write('someuser:\tdifferentuser\n')
    33         aliasFile.close()
     31        with open(self.aliasFilename, 'w') as aliasFile:
     32            aliasFile.write('someuser:\tdifferentuser\n')
    3433
    3534
    36     def testAliasesWithoutDomain(self):
     35    def test_aliasesWithoutDomain(self):
    3736        """
    3837        Test that adding an aliases(5) file before adding a domain raises a
    3938        UsageError.
     
    4443            ['--aliases', self.aliasFilename])
    4544
    4645
    47     def testAliases(self):
     46    def test_aliases(self):
    4847        """
    4948        Test that adding an aliases(5) file to an IAliasableDomain at least
    5049        doesn't raise an unhandled exception.
  • twisted/mail/test/test_mail.py

     
    162162        self.domain.addUser("bob", "password")
    163163        self.assertRaises(smtp.SMTPBadRcpt, self.domain.exists, "bob")
    164164
     165
     166
    165167class FileMessageTestCase(unittest.TestCase):
    166168    def setUp(self):
    167169        self.name = "fileMessage.testFile"
    168170        self.final = "final.fileMessage.testFile"
    169         self.f = file(self.name, 'w')
     171        self.f = open(self.name, 'w')
    170172        self.fp = mail.mail.FileMessage(self.f, self.name, self.final)
    171173
    172174    def tearDown(self):
     
    206208        self.failIf(os.path.exists(self.name))
    207209        self.failIf(os.path.exists(self.final))
    208210
     211
     212
    209213class MailServiceTestCase(unittest.TestCase):
    210214    def setUp(self):
    211215        self.service = mail.mail.MailService()
     
    537541        # Toss a few files into the mailbox
    538542        i = 1
    539543        for f in msgs:
    540             fObj = file(j(self.d, f), 'w')
    541             fObj.write('x' * i)
    542             fObj.close()
     544            with open(j(self.d, f), 'w') as fObj:
     545                fObj.write('x' * i)
    543546            i = i + 1
    544547
    545548        mb = mail.maildir.MaildirMailbox(self.d)
     
    846849
    847850            self.assertRaises(smtp.SMTPBadRcpt, domain.exists, user)
    848851
     852
     853
    849854class RelayerTestCase(unittest.TestCase):
    850855    def setUp(self):
    851856        self.tmpdir = self.mktemp()
     
    853858        self.messageFiles = []
    854859        for i in range(10):
    855860            name = os.path.join(self.tmpdir, 'body-%d' % (i,))
    856             f = file(name + '-H', 'w')
    857             pickle.dump(['from-%d' % (i,), 'to-%d' % (i,)], f)
    858             f.close()
     861            with open(name + '-H', 'w') as f:
     862                pickle.dump(['from-%d' % (i,), 'to-%d' % (i,)], f)
    859863
    860             f = file(name + '-D', 'w')
     864            f = open(name + '-D', 'w')
    861865            f.write(name)
    862866            f.seek(0, 0)
    863867            self.messageFiles.append(name)
     
    16901694        return m.eomReceived().addCallback(self._cbTestFileAlias, tmpfile)
    16911695
    16921696    def _cbTestFileAlias(self, ignored, tmpfile):
    1693         lines = file(tmpfile).readlines()
     1697        lines = open(tmpfile).readlines()
    16941698        self.assertEqual([L[:-1] for L in lines], self.lines)
    16951699
    16961700
     
    18421846            m.lineReceived(l)
    18431847
    18441848        def _cbProcessAlias(ignored):
    1845             lines = file('process.alias.out').readlines()
     1849            lines = open('process.alias.out').readlines()
    18461850            self.assertEqual([L[:-1] for L in lines], self.lines)
    18471851
    18481852        return m.eomReceived().addCallback(_cbProcessAlias)
  • twisted/mail/test/test_imap.py

     
    15601560        def login():
    15611561            return self.client.login('testuser', 'password-test')
    15621562        def append():
    1563             message = file(infile)
     1563            message = open(infile)
    15641564            return self.client.sendCommand(
    15651565                imap4.Command(
    15661566                    'APPEND',
  • twisted/mail/alias.py

     
    3737        user, alias = parts
    3838        result.setdefault(user.strip(), []).extend(map(str.strip, alias.split(',')))
    3939
     40
    4041def loadAliasFile(domains, filename=None, fp=None):
    41     """Load a file containing email aliases.
     42    """
     43    Load a file containing email aliases.
    4244
    4345    Lines in the file should be formatted like so::
    4446
     
    6769    """
    6870    result = {}
    6971    if fp is None:
    70         fp = file(filename)
     72        fp = open(filename)
    7173    else:
    7274        filename = getattr(fp, 'name', '<unknown>')
    7375    i = 0
     
    152154    def eomReceived(self):
    153155        self.fp.seek(0, 0)
    154156        try:
    155             f = file(self.finalname, 'a')
     157            f = open(self.finalname, 'a')
    156158        except:
    157159            return defer.fail(failure.Failure())
    158160
     
    400402            addr = items.pop().strip()
    401403            if addr.startswith(':'):
    402404                try:
    403                     f = file(addr[1:])
     405                    f = open(addr[1:])
    404406                except:
    405407                    log.err("Invalid filename in alias file %r" % (addr[1:],))
    406408                else: