String method conversion.

This commit is contained in:
Eric S. Raymond 2001-02-09 05:40:38 +00:00
parent 5ff63d6780
commit c013f30060

View file

@ -205,10 +205,10 @@ class SMTP:
""" """
if not port: if not port:
i = string.find(host, ':') i = host.find(':')
if i >= 0: if i >= 0:
host, port = host[:i], host[i+1:] host, port = host[:i], host[i+1:]
try: port = string.atoi(port) try: port = int(port)
except string.atoi_error: except string.atoi_error:
raise socket.error, "nonnumeric port" raise socket.error, "nonnumeric port"
if not port: port = SMTP_PORT if not port: port = SMTP_PORT
@ -266,12 +266,12 @@ class SMTP:
self.close() self.close()
raise SMTPServerDisconnected("Connection unexpectedly closed") raise SMTPServerDisconnected("Connection unexpectedly closed")
if self.debuglevel > 0: print 'reply:', `line` if self.debuglevel > 0: print 'reply:', `line`
resp.append(string.strip(line[4:])) resp.append(line[4:].strip())
code=line[:3] code=line[:3]
# Check that the error code is syntactically correct. # Check that the error code is syntactically correct.
# Don't attempt to read a continuation line if it is broken. # Don't attempt to read a continuation line if it is broken.
try: try:
errcode = string.atoi(code) errcode = int(code)
except ValueError: except ValueError:
errcode = -1 errcode = -1
break break
@ -279,7 +279,7 @@ class SMTP:
if line[3:4]!="-": if line[3:4]!="-":
break break
errmsg = string.join(resp,"\n") errmsg = "\n".join(resp)
if self.debuglevel > 0: if self.debuglevel > 0:
print 'reply: retcode (%s); Msg: %s' % (errcode,errmsg) print 'reply: retcode (%s); Msg: %s' % (errcode,errmsg)
return errcode, errmsg return errcode, errmsg
@ -323,19 +323,19 @@ class SMTP:
return (code,msg) return (code,msg)
self.does_esmtp=1 self.does_esmtp=1
#parse the ehlo response -ddm #parse the ehlo response -ddm
resp=string.split(self.ehlo_resp,'\n') resp=self.ehlo_resp.split('\n')
del resp[0] del resp[0]
for each in resp: for each in resp:
m=re.match(r'(?P<feature>[A-Za-z0-9][A-Za-z0-9\-]*)',each) m=re.match(r'(?P<feature>[A-Za-z0-9][A-Za-z0-9\-]*)',each)
if m: if m:
feature=string.lower(m.group("feature")) feature=m.group("feature").lower()
params=string.strip(m.string[m.end("feature"):]) params=m.string[m.end("feature"):].strip()
self.esmtp_features[feature]=params self.esmtp_features[feature]=params
return (code,msg) return (code,msg)
def has_extn(self, opt): def has_extn(self, opt):
"""Does the server support a given SMTP service extension?""" """Does the server support a given SMTP service extension?"""
return self.esmtp_features.has_key(string.lower(opt)) return self.esmtp_features.has_key(opt.lower())
def help(self, args=''): def help(self, args=''):
"""SMTP 'help' command. """SMTP 'help' command.
@ -355,7 +355,7 @@ class SMTP:
"""SMTP 'mail' command -- begins mail xfer session.""" """SMTP 'mail' command -- begins mail xfer session."""
optionlist = '' optionlist = ''
if options and self.does_esmtp: if options and self.does_esmtp:
optionlist = ' ' + string.join(options, ' ') optionlist = ' ' + ' '.join(options)
self.putcmd("mail", "FROM:%s%s" % (quoteaddr(sender) ,optionlist)) self.putcmd("mail", "FROM:%s%s" % (quoteaddr(sender) ,optionlist))
return self.getreply() return self.getreply()
@ -363,7 +363,7 @@ class SMTP:
"""SMTP 'rcpt' command -- indicates 1 recipient for this mail.""" """SMTP 'rcpt' command -- indicates 1 recipient for this mail."""
optionlist = '' optionlist = ''
if options and self.does_esmtp: if options and self.does_esmtp:
optionlist = ' ' + string.join(options, ' ') optionlist = ' ' + ' '.join(options)
self.putcmd("rcpt","TO:%s%s" % (quoteaddr(recip),optionlist)) self.putcmd("rcpt","TO:%s%s" % (quoteaddr(recip),optionlist))
return self.getreply() return self.getreply()
@ -520,10 +520,10 @@ if __name__ == '__main__':
def prompt(prompt): def prompt(prompt):
sys.stdout.write(prompt + ": ") sys.stdout.write(prompt + ": ")
return string.strip(sys.stdin.readline()) return sys.stdin.readline().strip()
fromaddr = prompt("From") fromaddr = prompt("From")
toaddrs = string.splitfields(prompt("To"), ',') toaddrs = ','.split(prompt("To"))
print "Enter message, end with ^D:" print "Enter message, end with ^D:"
msg = '' msg = ''
while 1: while 1: