commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/common/src GConnections.py


From: Jason Cater
Subject: gnue/common/src GConnections.py
Date: Sat, 07 Sep 2002 11:26:08 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/09/07 11:26:08

Modified files:
        common/src     : GConnections.py 

Log message:
        added netrc support [patches by Papo team]

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/GConnections.py.diff?cvsroot=OldCVS&tr1=1.35&tr2=1.36&r1=text&r2=text

Patches:
Index: gnue/common/src/GConnections.py
diff -c gnue/common/src/GConnections.py:1.35 
gnue/common/src/GConnections.py:1.36
*** gnue/common/src/GConnections.py:1.35        Fri May  3 12:46:32 2002
--- gnue/common/src/GConnections.py     Sat Sep  7 11:26:07 2002
***************
*** 31,37 ****
  #
  
  from ConfigParser import *
! import sys, string, copy
  import GDebug
  import GDataObjects
  import GLoginHandler
--- 31,37 ----
  #
  
  from ConfigParser import *
! import sys, string, copy, netrc
  import GDebug
  import GDataObjects
  import GLoginHandler
***************
*** 209,259 ****
        GDebug.printMesg(5,'Reusing data connection to %s' % connection_name)
  
      else:
-       attempts = 4
  
!       GDebug.printMesg(5,'Getting new data connection to %s' % 
connection_name)
! 
!       errortext = None
!       while attempts:
! 
!         try:
! 
!           # Ask the UI to prompt for our login data
!           loginData = self._loginHandler.getLogin(
!               [connection_name, 
self.getConnectionParameter(connection_name,'comment',''),
!                dataObject.getLoginFields()], errortext)
  
!           # Add the parameters from the Connections Definition File
!           loginData.update(self.getConnectionParameters(connection_name))
  
!           # Ask the data object to connect to the database
!           dataObject.connect(loginData)
  
!           # Save the newly opened connection for future datasources
!           self._openConnections[connection_name] = \
!               dataObject.getDataConnection()
  
!           # We're done!
!           attempts = 0
!           self._loginHandler.destroyLoginDialog()
  
!         except GDataObjects.LoginError, error:
!           # Oops, they must have entered an invalid user/password.
!           # Those silly users.
!         # user: Hey! Who are you calling silly?!!!
!           attempts = attempts - 1
!           errortext = string.replace("%s" % error,'\n','')
  
!           if not attempts:
!             # Four times is plenty...
              self._loginHandler.destroyLoginDialog()
!             raise GDataObjects.LoginError, \
!                _("Unable to log in after 4 attempts.\n\nError: %s") % error
! 
!         except GLoginHandler.UserCanceledLogin:
!           # Guess they changed their minds. Treat as a login error.
!           self._loginHandler.destroyLoginDialog()
!           raise GDataObjects.LoginError, _("User canceled the login request.")
  
  
  
--- 209,292 ----
        GDebug.printMesg(5,'Reusing data connection to %s' % connection_name)
  
      else:
  
!       # Get the parameters from the Connections Definition File
!       loginData = self.getConnectionParameters(connection_name)
!       try:
!         # load the user's netrc file
!         netrcData = netrc.netrc().authenticators(
!               "'gnue://%s/'" % connection_name )
!         GDebug.printMesg(5, 'Read the user\'s .netrc file')
!       except IOError:
!         pass
! 
!       if (netrcData):
!         loginData['_username'] = netrcData[0][1:-1]
!         loginData['_password'] = netrcData[2][1:-1]
!         GDebug.printMesg(5, 'Found useful stuff for connection %s in the 
user\'s .netrc file' % connection_name)
! 
!       if (loginData.has_key('username')):
!         loginData['_username'] = loginData['username']
!         del loginData['username']
! 
!       if (loginData.has_key('password')):
!         loginData['_password'] = loginData['password']
!         del loginData['password']
  
!       loginData.setdefault('_username')
!       loginData.setdefault('_password')
  
!       try:
  
!         dataObject.connect(loginData)
!         GDebug.printMesg(5, 'I had enough information to connect to %s 
without asking the user' % connection_name)
!         # Save the newly opened connection for future datasources
!         self._openConnections[connection_name] = 
dataObject.getDataConnection()
! 
!       except GDataObjects.LoginError:
!         attempts = 4
! 
!         GDebug.printMesg(5,'Getting new data connection to %s' % 
connection_name)
!         
!         errortext = None
!         while attempts:
! 
!           try:
! 
!             # Ask the UI to prompt for our login data
!             loginData.update(self._loginHandler.getLogin(
!               [connection_name,
!                self.getConnectionParameter(connection_name,'comment',''),
!                dataObject.getLoginFields()], errortext))
! 
!             # Ask the data object to connect to the database
!             dataObject.connect(loginData)
! 
!             # Save the newly opened connection for future datasources
!             self._openConnections[connection_name] = \
!                 dataObject.getDataConnection()
  
!             # We're done!
!             attempts = 0
!             self._loginHandler.destroyLoginDialog()
  
!           except GDataObjects.LoginError, error:
!             # Oops, they must have entered an invalid user/password.
!             # Those silly users.
!             # user: Hey! Who are you calling silly?!!!
!             attempts = attempts - 1
!             errortext = string.replace("%s" % error,'\n','')
! 
!             if not attempts:
!               # Four times is plenty...
!               self._loginHandler.destroyLoginDialog()
!               raise GDataObjects.LoginError, \
!                     _("Unable to log in after 4 attempts.\n\nError: %s") % 
error
  
!           except GLoginHandler.UserCanceledLogin:
!             # Guess they changed their minds. Treat as a login error.
              self._loginHandler.destroyLoginDialog()
!             raise GDataObjects.LoginError, _("User canceled the login 
request.")
  
  
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]