Mercurial > p > roundup > code
comparison scripts/imapServer.py @ 5378:35ea9b1efc14
Python 3 preparation: "raise" syntax.
Changing "raise Exception, value" to "raise Exception(value)".
Tool-assisted patch. Particular cases to check carefully are the one
place in frontends/ZRoundup/ZRoundup.py where a string exception
needed to be fixed, and the one in roundup/cgi/client.py involving
raising an exception with a traceback (requires three-argument form of
raise in Python 2, which as I understand it requires exec() to avoid a
Python 3 syntax error).
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Tue, 24 Jul 2018 21:39:58 +0000 |
| parents | 64b05e24dbd8 |
| children | 0942fe89e82e |
comparison
equal
deleted
inserted
replaced
| 5377:12fe83f90f0d | 5378:35ea9b1efc14 |
|---|---|
| 59 | 59 |
| 60 try: | 60 try: |
| 61 if not self.dbhome: | 61 if not self.dbhome: |
| 62 self.dbhome = raw_input('Tracker home: ') | 62 self.dbhome = raw_input('Tracker home: ') |
| 63 if not os.path.exists(self.dbhome): | 63 if not os.path.exists(self.dbhome): |
| 64 raise ValueError, 'Invalid home address: ' \ | 64 raise ValueError('Invalid home address: ' \ |
| 65 'directory "%s" does not exist.' % self.dbhome | 65 'directory "%s" does not exist.' % self.dbhome) |
| 66 | 66 |
| 67 if not self.server: | 67 if not self.server: |
| 68 self.server = raw_input('Server: ') | 68 self.server = raw_input('Server: ') |
| 69 if not self.server: | 69 if not self.server: |
| 70 raise ValueError, 'No Servername supplied' | 70 raise ValueError('No Servername supplied') |
| 71 protocol = raw_input('protocol [imaps]? ') | 71 protocol = raw_input('protocol [imaps]? ') |
| 72 self.protocol = protocol | 72 self.protocol = protocol |
| 73 | 73 |
| 74 if not self.username: | 74 if not self.username: |
| 75 self.username = raw_input('Username: ') | 75 self.username = raw_input('Username: ') |
| 76 if not self.username: | 76 if not self.username: |
| 77 raise ValueError, 'Invalid Username' | 77 raise ValueError('Invalid Username') |
| 78 | 78 |
| 79 if not self.password: | 79 if not self.password: |
| 80 print('For server %s, user %s' % (self.server, self.username)) | 80 print('For server %s, user %s' % (self.server, self.username)) |
| 81 self.password = getpass.getpass() | 81 self.password = getpass.getpass() |
| 82 # password can be empty because it could be superceeded | 82 # password can be empty because it could be superceeded |
| 86 # self.mailbox = raw_input('Mailbox [INBOX]: ') | 86 # self.mailbox = raw_input('Mailbox [INBOX]: ') |
| 87 # # We allow an empty mailbox because that will | 87 # # We allow an empty mailbox because that will |
| 88 # # select the INBOX, whatever it is called | 88 # # select the INBOX, whatever it is called |
| 89 | 89 |
| 90 except (KeyboardInterrupt, EOFError): | 90 except (KeyboardInterrupt, EOFError): |
| 91 raise ValueError, 'Canceled by User' | 91 raise ValueError('Canceled by User') |
| 92 | 92 |
| 93 def __str__(self): | 93 def __str__(self): |
| 94 return 'Mailbox{ server:%(server)s, protocol:%(protocol)s, ' \ | 94 return 'Mailbox{ server:%(server)s, protocol:%(protocol)s, ' \ |
| 95 'username:%(username)s, mailbox:%(mailbox)s, ' \ | 95 'username:%(username)s, mailbox:%(mailbox)s, ' \ |
| 96 'dbhome:%(dbhome)s }' % self.__dict__ | 96 'dbhome:%(dbhome)s }' % self.__dict__ |
| 148 user = server['users'][mailbox.username] | 148 user = server['users'][mailbox.username] |
| 149 if mailbox.password: | 149 if mailbox.password: |
| 150 user['password'] = mailbox.password | 150 user['password'] = mailbox.password |
| 151 | 151 |
| 152 if user['mailboxes'].has_key(mailbox.mailbox): | 152 if user['mailboxes'].has_key(mailbox.mailbox): |
| 153 raise ValueError, 'Mailbox is already defined' | 153 raise ValueError('Mailbox is already defined') |
| 154 | 154 |
| 155 user['mailboxes'][mailbox.mailbox] = mailbox.dbhome | 155 user['mailboxes'][mailbox.mailbox] = mailbox.dbhome |
| 156 | 156 |
| 157 def _process(self, message, dbhome): | 157 def _process(self, message, dbhome): |
| 158 """Actually process one of the email messages""" | 158 """Actually process one of the email messages""" |
| 189 if protocol == 'imaps': | 189 if protocol == 'imaps': |
| 190 serv = imaplib.IMAP4_SSL(server) | 190 serv = imaplib.IMAP4_SSL(server) |
| 191 elif protocol == 'imap': | 191 elif protocol == 'imap': |
| 192 serv = imaplib.IMAP4(server) | 192 serv = imaplib.IMAP4(server) |
| 193 else: | 193 else: |
| 194 raise ValueError, 'Unknown protocol %s' % protocol | 194 raise ValueError('Unknown protocol %s' % protocol) |
| 195 | 195 |
| 196 password = u_vals['password'] | 196 password = u_vals['password'] |
| 197 | 197 |
| 198 try: | 198 try: |
| 199 log.info('Connecting as user: %s', user) | 199 log.info('Connecting as user: %s', user) |
