Package httxlib :: Module httxpassmanager
[hide private]
[frames] | no frames]

Source Code for Module httxlib.httxpassmanager

  1  #!/usr/bin/env python 
  2  # -*- coding: latin-1; py-indent-offset:4 -*- 
  3  ################################################################################ 
  4  #  
  5  # This file is part of HttxLib 
  6  # 
  7  # HttxLib is an HTTP(s) Python library suited multithreaded/multidomain 
  8  # applications 
  9  # 
 10  # Copyright (C) 2010-2011 Daniel Rodriguez (aka Daniel Rodriksson) 
 11  # Copyright (C) 2011 Sensible Odds Ltd 
 12  # 
 13  # You can learn more and contact the author at: 
 14  # 
 15  #    http://code.google.com/p/httxlib/ 
 16  # 
 17  # HttxLib is free software: you can redistribute it and/or modify 
 18  # it under the terms of the GNU General Public License as published by 
 19  # the Free Software Foundation, either version 3 of the License, or 
 20  # (at your option) any later version. 
 21  # 
 22  # HttxLib is distributed in the hope that it will be useful, 
 23  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 24  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 25  # GNU General Public License for more details. 
 26  # 
 27  # You should have received a copy of the GNU General Public License 
 28  # along with HttxLib. If not, see <http://www.gnu.org/licenses/>. 
 29  # 
 30  ################################################################################ 
 31  ''' 
 32  HttxLib password manager implementation 
 33  ''' 
 34   
 35  from copy import deepcopy 
 36  from urllib2 import HTTPPasswordMgrWithDefaultRealm 
 37   
 38  from httxobject import HttxObject 
 39   
 40   
41 -class HttxPassManager(HttxObject):
42 ''' 43 An object manages username and password for url and realms 44 with locking semantics to be used in L{HttxOptions} 45 46 @ivar passmanager: storage for username, password credentials 47 @type passmanager: HTTPPasswordMgrWithDefaultRealm 48 ''' 49
50 - def __init__(self):
51 ''' 52 Constructor. It delegates construction to the base class 53 L{HttxObject} and initializes the member variables 54 ''' 55 HttxObject.__init__(self) 56 57 self.passmanager = HTTPPasswordMgrWithDefaultRealm()
58 59
60 - def __deepcopy__(self, memo):
61 ''' 62 Deepcopy support. 63 64 @param memo: standard __deepcopy__ parameter to avoid circular references 65 @type memo: dict 66 @return: a cloned object 67 @rtype: L{HttxPassManager} 68 ''' 69 clone = self.__class__() 70 with self.lock: 71 clone.passmanager = deepcopy(self.passmanager) 72 return clone
73 74
75 - def add_password(self, realm, url, user, passwd):
76 ''' 77 Stub replica for HTTPPasswordManagerWithDefaultRealm to 78 add a username and a password for a real, url combination 79 80 @param realm: where the credentials should be applied 81 None is a catch-all value 82 @type realm: str|None 83 @param url: base url for application of username, password 84 if realm matches. It can be empty to catch-all 85 @type url: str 86 @param user: username 87 @type user: str 88 @param passwd: username 89 @type passwd: str 90 ''' 91 with self.lock: 92 self.passmanager.add_password(realm, url, user, passwd)
93 94
95 - def find_user_password(self, realm, url):
96 ''' 97 Stub replica for HTTPPasswordManagerWithDefaultRealm to 98 retrieve username, password for the given realm and url 99 100 @param realm: where the credentials should be applied 101 None is a catch-all value 102 @type realm: str|None 103 @param url: base url for application of username, password 104 if realm matches. It can be empty to catch-all 105 @return: tuple with the username, password values. It can be 106 None, None if not found 107 @rtype: tuple 108 ''' 109 with self.lock: 110 return self.passmanager.find_user_password(realm, url)
111