Changeset 391 for python/trunk/Lib/smtpd.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/smtpd.py
r2 r391 35 35 and if remoteport is not given, then 25 is used. 36 36 """ 37 38 39 37 40 38 # Overview: … … 98 96 99 97 100 101 102 98 def usage(code, msg=''): 103 99 print >> sys.stderr, __doc__ % globals() … … 105 101 print >> sys.stderr, msg 106 102 sys.exit(code) 107 108 109 103 110 104 … … 125 119 self.__data = '' 126 120 self.__fqdn = socket.getfqdn() 127 self.__peer = conn.getpeername() 121 try: 122 self.__peer = conn.getpeername() 123 except socket.error, err: 124 # a race condition may occur if the other end is closing 125 # before we can get the peername 126 self.close() 127 if err[0] != errno.ENOTCONN: 128 raise 129 return 128 130 print >> DEBUGSTREAM, 'Peer:', repr(self.__peer) 129 131 self.push('220 %s %s' % (self.__fqdn, __version__)) … … 272 274 273 275 274 275 276 276 class SMTPServer(asyncore.dispatcher): 277 277 def __init__(self, localaddr, remoteaddr): … … 279 279 self._remoteaddr = remoteaddr 280 280 asyncore.dispatcher.__init__(self) 281 self.create_socket(socket.AF_INET, socket.SOCK_STREAM) 282 # try to re-use a server port if possible 283 self.set_reuse_addr() 284 self.bind(localaddr) 285 self.listen(5) 286 print >> DEBUGSTREAM, \ 287 '%s started at %s\n\tLocal addr: %s\n\tRemote addr:%s' % ( 288 self.__class__.__name__, time.ctime(time.time()), 289 localaddr, remoteaddr) 281 try: 282 self.create_socket(socket.AF_INET, socket.SOCK_STREAM) 283 # try to re-use a server port if possible 284 self.set_reuse_addr() 285 self.bind(localaddr) 286 self.listen(5) 287 except: 288 # cleanup asyncore.socket_map before raising 289 self.close() 290 raise 291 else: 292 print >> DEBUGSTREAM, \ 293 '%s started at %s\n\tLocal addr: %s\n\tRemote addr:%s' % ( 294 self.__class__.__name__, time.ctime(time.time()), 295 localaddr, remoteaddr) 290 296 291 297 def handle_accept(self): 292 conn, addr = self.accept() 293 print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr) 294 channel = SMTPChannel(self, conn, addr) 298 pair = self.accept() 299 if pair is not None: 300 conn, addr = pair 301 print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr) 302 channel = SMTPChannel(self, conn, addr) 295 303 296 304 # API for "doing something useful with the message" … … 318 326 """ 319 327 raise NotImplementedError 320 321 322 328 323 329 … … 335 341 print line 336 342 print '------------ END MESSAGE ------------' 337 338 339 343 340 344 … … 377 381 refused[r] = (errcode, errmsg) 378 382 return refused 379 380 381 383 382 384 … … 459 461 460 462 461 462 463 463 class Options: 464 464 setuid = 1 465 465 classname = 'PureProxy' 466 467 468 466 469 467 … … 524 522 525 523 526 527 528 524 if __name__ == '__main__': 529 525 options = parseargs() 530 526 # Become nobody 527 classname = options.classname 528 if "." in classname: 529 lastdot = classname.rfind(".") 530 mod = __import__(classname[:lastdot], globals(), locals(), [""]) 531 classname = classname[lastdot+1:] 532 else: 533 import __main__ as mod 534 class_ = getattr(mod, classname) 535 proxy = class_((options.localhost, options.localport), 536 (options.remotehost, options.remoteport)) 531 537 if options.setuid: 532 538 try: … … 544 550 'Cannot setuid "nobody"; try running with -n option.' 545 551 sys.exit(1) 546 classname = options.classname547 if "." in classname:548 lastdot = classname.rfind(".")549 mod = __import__(classname[:lastdot], globals(), locals(), [""])550 classname = classname[lastdot+1:]551 else:552 import __main__ as mod553 class_ = getattr(mod, classname)554 proxy = class_((options.localhost, options.localport),555 (options.remotehost, options.remoteport))556 552 try: 557 553 asyncore.loop()
Note:
See TracChangeset
for help on using the changeset viewer.