Package suds :: Package transport :: Module https
[hide private]
[frames] | no frames]

Source Code for Module suds.transport.https

  1  # This program is free software; you can redistribute it and/or modify 
  2  # it under the terms of the (LGPL) GNU Lesser General Public License as 
  3  # published by the Free Software Foundation; either version 3 of the  
  4  # License, or (at your option) any later version. 
  5  # 
  6  # This program is distributed in the hope that it will be useful, 
  7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  9  # GNU Library Lesser General Public License for more details at 
 10  # ( http://www.gnu.org/licenses/lgpl.html ). 
 11  # 
 12  # You should have received a copy of the GNU Lesser General Public License 
 13  # along with this program; if not, write to the Free Software 
 14  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 15  # written by: Jeff Ortel ( jortel@redhat.com ) 
 16   
 17  """ 
 18  Contains classes for basic HTTP (authenticated) transport implementations. 
 19  """ 
 20   
 21  import urllib2 as u2 
 22  from suds.transport import * 
 23  from suds.transport.http import HttpTransport 
 24  from logging import getLogger 
 25   
 26  log = getLogger(__name__) 
 27   
 28   
29 -class HttpAuthenticated(HttpTransport):
30 """ 31 Provides basic http authentication that follows the RFC-2617 specification. 32 As defined by specifications, credentials are provided to the server 33 upon request (HTTP/1.0 401 Authorization Required) by the server only. 34 @ivar pm: The password manager. 35 @ivar handler: The authentication handler. 36 """ 37
38 - def __init__(self, **kwargs):
39 """ 40 @param kwargs: Keyword arguments. 41 - B{proxy} - An http proxy to be specified on requests. 42 The proxy is defined as {protocol:proxy,} 43 - type: I{dict} 44 - default: {} 45 - B{timeout} - Set the url open timeout (seconds). 46 - type: I{float} 47 - default: 90 48 - B{username} - The username used for http authentication. 49 - type: I{str} 50 - default: None 51 - B{password} - The password used for http authentication. 52 - type: I{str} 53 - default: None 54 """ 55 HttpTransport.__init__(self, **kwargs) 56 self.pm = u2.HTTPPasswordMgrWithDefaultRealm()
57
58 - def open(self, request):
59 self.addcredentials(request) 60 return HttpTransport.open(self, request)
61
62 - def send(self, request):
63 self.addcredentials(request) 64 return HttpTransport.send(self, request)
65
66 - def addcredentials(self, request):
67 credentials = self.credentials() 68 if not (None in credentials): 69 u = credentials[0] 70 p = credentials[1] 71 self.pm.add_password(None, request.url, u, p)
72
73 - def credentials(self):
74 return (self.options.username, self.options.password)
75
76 - def u2handlers(self):
77 handlers = HttpTransport.u2handlers(self) 78 handlers.append(u2.HTTPBasicAuthHandler(self.pm)) 79 return handlers
80 81
82 -class WindowsHttpAuthenticated(HttpAuthenticated):
83 """ 84 Provides Windows (NTLM) http authentication. 85 @ivar pm: The password manager. 86 @ivar handler: The authentication handler. 87 @author: Christopher Bess 88 """ 89
90 - def u2handlers(self):
91 # try to import ntlm support 92 try: 93 from ntlm import HTTPNtlmAuthHandler 94 except ImportError: 95 raise Exception("Cannot import python-ntlm module") 96 handlers = HttpTransport.u2handlers(self) 97 handlers.append(HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(self.pm)) 98 return handlers
99