[Python-checkins] CVS: python/dist/src/Lib getopt.py,1.11,1.11.4.1 smtplib.py,1.29,1.29.2.1

Moshe Zadka moshez@users.sourceforge.net
Sat, 31 Mar 2001 01:12:53 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv8231/Lib

Modified Files:
      Tag: release20-maint
	getopt.py smtplib.py 
Log Message:
- #119833 - close socket in smtplib if there was an error connecting
- #126863 - getopt long option handling fixed


Index: getopt.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/getopt.py,v
retrieving revision 1.11
retrieving revision 1.11.4.1
diff -C2 -r1.11 -r1.11.4.1
*** getopt.py	2000/02/25 16:34:11	1.11
--- getopt.py	2001/03/31 09:12:51	1.11.4.1
***************
*** 66,71 ****
      else:
          longopts = list(longopts)
!     longopts.sort()
!     while args and args[0][:1] == '-' and args[0] != '-':
          if args[0] == '--':
              args = args[1:]
--- 66,70 ----
      else:
          longopts = list(longopts)
!     while args and args[0].startswith('-') and args[0] != '-':
          if args[0] == '--':
              args = args[1:]
***************
*** 81,87 ****
      try:
          i = opt.index('=')
-         opt, optarg = opt[:i], opt[i+1:]
      except ValueError:
          optarg = None
  
      has_arg, opt = long_has_args(opt, longopts)
--- 80,87 ----
      try:
          i = opt.index('=')
      except ValueError:
          optarg = None
+     else:
+         opt, optarg = opt[:i], opt[i+1:]
  
      has_arg, opt = long_has_args(opt, longopts)
***************
*** 100,115 ****
  #   full option name
  def long_has_args(opt, longopts):
!     optlen = len(opt)
!     for i in range(len(longopts)):
!         x, y = longopts[i][:optlen], longopts[i][optlen:]
!         if opt != x:
!             continue
!         if y != '' and y != '=' and i+1 < len(longopts):
!             if opt == longopts[i+1][:optlen]:
!                 raise GetoptError('option --%s not a unique prefix' % opt, opt)
!         if longopts[i][-1:] in ('=', ):
!             return 1, longopts[i][:-1]
!         return 0, longopts[i]
!     raise GetoptError('option --%s not recognized' % opt, opt)
  
  def do_shorts(opts, optstring, shortopts, args):
--- 100,122 ----
  #   full option name
  def long_has_args(opt, longopts):
!     possibilities = [o for o in longopts if o.startswith(opt)]
!     if not possibilities:
!         raise GetoptError('option --%s not recognized' % opt, opt)
!     # Is there an exact match?
!     if opt in possibilities:
!         return 0, opt
!     elif opt + '=' in possibilities:
!         return 1, opt
!     # No exact match, so better be unique.
!     if len(possibilities) > 1:
!         # XXX since possibilities contains all valid continuations, might be
!         # nice to work them into the error msg
!         raise GetoptError('option --%s not a unique prefix' % opt, opt)
!     assert len(possibilities) == 1
!     unique_match = possibilities[0]
!     has_arg = unique_match.endswith('=')
!     if has_arg:
!         unique_match = unique_match[:-1]
!     return has_arg, unique_match
  
  def do_shorts(opts, optstring, shortopts, args):

Index: smtplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/smtplib.py,v
retrieving revision 1.29
retrieving revision 1.29.2.1
diff -C2 -r1.29 -r1.29.2.1
*** smtplib.py	2000/09/01 06:40:07	1.29
--- smtplib.py	2001/03/31 09:12:51	1.29.2.1
***************
*** 215,219 ****
          self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          if self.debuglevel > 0: print 'connect:', (host, port)
!         self.sock.connect((host, port))
          (code,msg)=self.getreply()
          if self.debuglevel >0 : print "connect:", msg
--- 215,223 ----
          self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          if self.debuglevel > 0: print 'connect:', (host, port)
!         try:
!             self.sock.connect((host, port))
!         except socket.error:
!             self.close()
!             raise
          (code,msg)=self.getreply()
          if self.debuglevel >0 : print "connect:", msg