예제 #1
0
파일: https.py 프로젝트: pwoolcoc/suds-py3k
class HttpAuthenticated(HttpTransport):
    """
    Provides basic http authentication that follows the RFC-2617 specification.
    As defined by specifications, credentials are provided to the server
    upon request (HTTP/1.0 401 Authorization Required) by the server only.
    @ivar pm: The password manager.
    @ivar handler: The authentication handler.
    """
    
    def __init__(self, **kwargs):
        """
        @param kwargs: Keyword arguments.
            - B{proxy} - An http proxy to be specified on requests.
                 The proxy is defined as {protocol:proxy,}
                    - type: I{dict}
                    - default: {}
            - B{timeout} - Set the url open timeout (seconds).
                    - type: I{float}
                    - default: 90
            - B{username} - The username used for http authentication.
                    - type: I{str}
                    - default: None
            - B{password} - The password used for http authentication.
                    - type: I{str}
                    - default: None
        """
        HttpTransport.__init__(self, **kwargs)
        self.pm = HTTPPasswordMgrWithDefaultRealm()
        
    def open(self, request):
        self.addcredentials(request)
        return  HttpTransport.open(self, request)
    
    def send(self, request):
        self.addcredentials(request)
        return  HttpTransport.send(self, request)
    
    def addcredentials(self, request):
        credentials = self.credentials()
        if not (None in credentials):
            u = credentials[0]
            p = credentials[1]
            self.pm.add_password(None, request.url, u, p)
    
    def credentials(self):
        return (self.options.username, self.options.password)
    
    def u2handlers(self):
            handlers = HttpTransport.u2handlers(self)
            handlers.append(HTTPBasicAuthHandler(self.pm))
            return handlers
예제 #2
0
파일: https.py 프로젝트: pwoolcoc/suds-py3k
 def __init__(self, **kwargs):
     """
     @param kwargs: Keyword arguments.
         - B{proxy} - An http proxy to be specified on requests.
              The proxy is defined as {protocol:proxy,}
                 - type: I{dict}
                 - default: {}
         - B{timeout} - Set the url open timeout (seconds).
                 - type: I{float}
                 - default: 90
         - B{username} - The username used for http authentication.
                 - type: I{str}
                 - default: None
         - B{password} - The password used for http authentication.
                 - type: I{str}
                 - default: None
     """
     HttpTransport.__init__(self, **kwargs)
     self.pm = HTTPPasswordMgrWithDefaultRealm()