[Inteproxy-commits] r20 - trunk

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 7 16:33:31 CET 2007


Author: bh
Date: 2007-02-07 16:33:31 +0100 (Wed, 07 Feb 2007)
New Revision: 20

Added:
   trunk/getpassword.py
Modified:
   trunk/ChangeLog
   trunk/InteProxy.py
Log:
* getpassword.py: New module for the password handling code.

* InteProxy.py: Move the password handling into a separate module.
(InteProxyHTTPRequestHandler.convert_url): Use the new getpassword
module


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-01-30 17:37:03 UTC (rev 19)
+++ trunk/ChangeLog	2007-02-07 15:33:31 UTC (rev 20)
@@ -1,3 +1,11 @@
+2007-02-07  Bernhard Herzog  <bh at intevation.de>
+
+	* getpassword.py: New module for the password handling code.
+
+	* InteProxy.py: Move the password handling into a separate module.
+	(InteProxyHTTPRequestHandler.convert_url): Use the new getpassword
+	module
+
 2007-01-30  Bernhard Herzog  <bh at intevation.de>
 
 	* InteProxy.py (getpassword_crt, getpassword_tty): renamed

Modified: trunk/InteProxy.py
===================================================================
--- trunk/InteProxy.py	2007-01-30 17:37:03 UTC (rev 19)
+++ trunk/InteProxy.py	2007-02-07 15:33:31 UTC (rev 20)
@@ -25,38 +25,15 @@
 import Queue
 import socket
 import proxyconnection
+from getpassword import get_password_with_cache
 
 inteproxy_version = "0.1.1"
 
-try:
-    import pywin.dialogs.login
-    windowsystem = "pywin"
-except ImportError:
-    windowsystem = "tty"
 
-
-def getpassword_pywin(title):
-    return pywin.dialogs.login.GetLogin(title)
-
-def getpassword_tty(title):
-    import getpass
-    try:
-        user = raw_input(title)
-        password = getpass.getpass()
-    except IOError:
-        import traceback
-        traceback.print_exception()
-        user = password = None
-    return user, password
-
-getpassword = globals()["getpassword_" + windowsystem]
-
 # the central queue for the communication between master and worker
 # thread.
 the_queue = Queue.Queue(0)
 
-# password cache
-pw_cache = {}
 
 def worker_thread():
     """The worker thread
@@ -257,14 +234,9 @@
         # Eventually this should be moved to a method of its own
         # and anyway this is just a dirty solution since passwords
         # are not really managed.
-        if pw_cache.has_key(path):
-            user, password = pw_cache[path]
-        else:
-            title = "Username for %s: " % path
-            user, password = getpassword(title)
+        user, password = get_password_with_cache(path)
         # TODO: Building the query this way is not safe.
         query += "&user=%s&password=%s" % (user, password)
-        pw_cache[path] = (user, password)
 
         # both scheme and netloc must be empty strings because the url
         # we work with is the url on the first line of a HTTP request

Added: trunk/getpassword.py
===================================================================
--- trunk/getpassword.py	2007-01-30 17:37:03 UTC (rev 19)
+++ trunk/getpassword.py	2007-02-07 15:33:31 UTC (rev 20)
@@ -0,0 +1,58 @@
+# Copyright (C) 2007 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Code to ask the user for username and password"""
+
+import traceback
+import Queue
+
+# Determine the window system we're using.  This determines how the user
+# is asked for the username/password.
+try:
+    import pywin.dialogs.login
+    windowsystem = "pywin"
+except ImportError:
+    windowsystem = "tty"
+
+def getpassword_pywin(title):
+    return pywin.dialogs.login.GetLogin(title)
+
+def getpassword_tty(title):
+    import getpass
+    try:
+        user = raw_input(title)
+        password = getpass.getpass()
+    except IOError:
+        import traceback
+        traceback.print_exception()
+        user = password = None
+    return user, password
+
+getpassword = globals()["getpassword_" + windowsystem]
+
+# password cache
+pw_cache = {}
+
+def get_password_with_cache(path):
+    """Ask the user for a username and password and cache the
+    information.  The path parameter should be a string with hostname
+    and path of the URL the caller is trying to access.  If a username
+    and password for that string is already stored in the cache, the
+    cached information is returned.  Otherwise this function uses the
+    getpassword function to ask the user and then adds this information
+    to the cache and returns it.
+
+    The return value is the tuple (username, password).
+    """
+    if path in pw_cache:
+        user, password = pw_cache[path]
+    else:
+        title = "Username for %s: " % path
+        user, password = getpassword(title)
+        pw_cache[path] = user, password
+
+    return user, password


Property changes on: trunk/getpassword.py
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native



More information about the Inteproxy-commits mailing list