当前位置: 首页>>代码示例>>Python>>正文


Python Authentication.authenticate方法代码示例

本文整理汇总了Python中authentication.Authentication.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Python Authentication.authenticate方法的具体用法?Python Authentication.authenticate怎么用?Python Authentication.authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在authentication.Authentication的用法示例。


在下文中一共展示了Authentication.authenticate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Connection

# 需要导入模块: from authentication import Authentication [as 别名]
# 或者: from authentication.Authentication import authenticate [as 别名]
class Connection(object):
    """
    Manages the connection to the storage system and serves as a factory
    for Container instances.

    @undocumented: http_connect
    @undocumented: make_request
    @undocumented: _check_container_name
    """

    def __init__(self, username=None, api_key=None, timeout=10, **kwargs):
        """
        Accepts keyword arguments for Rackspace Cloud username and api key.
        Optionally, you can omit these keywords and supply an
        Authentication object using the auth keyword.

        @type username: str
        @param username: a Rackspace Cloud username
        @type api_key: str
        @param api_key: a Rackspace Cloud API key
        """
        self.connection_args = None
        self.connection = None
        self.token = None
        self.debuglevel = int(kwargs.get('debuglevel', 0))
        self.user_agent = kwargs.get('useragent', consts.user_agent)
        self.timeout = timeout

        self.auth = 'auth' in kwargs and kwargs['auth'] or None

        if not self.auth:
            authurl = kwargs.get('authurl', consts.us_authurl)
            if username and api_key and authurl:
                self.auth = Authentication(username, api_key, authurl=authurl,
                            useragent=self.user_agent)
            else:
                raise TypeError("Incorrect or invalid arguments supplied")

        self._authenticate()

    def _authenticate(self):
        """
        Authenticate and setup this instance with the values returned.
        """
        (url, self.token) = self.auth.authenticate()
        self.connection_args = parse_url(url)

        if version_info[0] <= 2 and version_info[1] < 6:
            self.conn_class = self.connection_args[3] and THTTPSConnection or \
                                                              THTTPConnection
        else:
            self.conn_class = self.connection_args[3] and HTTPSConnection or \
                                                              HTTPConnection
        self.http_connect()

    def convert_iso_datetime(self, dt):
        """
        Convert iso8601 to datetime
        """
        isoFormat = "%Y-%m-%dT%H:%M:%S.000+0000"
        if type(dt) is datetime.datetime:
            return dt
        if dt.endswith("Z"):
            dt = dt.split('Z')[0]
            isoFormat = "%Y-%m-%dT%H:%M:%S"
        return datetime.datetime.strptime(dt, isoFormat)

    def http_connect(self):
        """
        Setup the http connection instance.
        """
        (host, port, self.uri, is_ssl) = self.connection_args
        self.connection = self.conn_class(host, port=port, \
                                              timeout=self.timeout)
        self.connection.set_debuglevel(self.debuglevel)

    def make_request(self, method, path=[], data='', hdrs=None, parms=None):
        """
        Given a method (i.e. GET, PUT, POST, etc), a path, data, header and
        metadata dicts, and an optional dictionary of query parameters,
        performs an http request.
        """
        query_args = ""
        path = '/%s/%s' % \
                 (self.uri.rstrip('/'), '/'.join(
                   [unicode_quote(i) for i in path]))
        if isinstance(parms, dict) and parms:
            query_args = \
                ['%s=%s' % (quote(x),
                            quote(str(y))) for (x, y) in parms.items()]
        elif isinstance(parms, list) and parms:
            query_args = \
                ["%s" % x for x in parms]
        path = '%s?%s' % (path, '&'.join(query_args))

        headers = {'Content-Length': str(len(data)),
                   'User-Agent': self.user_agent,
                   'X-Auth-Token': self.token}
        isinstance(hdrs, dict) and headers.update(hdrs)

#.........这里部分代码省略.........
开发者ID:meeuw,项目名称:python-clouddns,代码行数:103,代码来源:connection.py

示例2: Connection

# 需要导入模块: from authentication import Authentication [as 别名]
# 或者: from authentication.Authentication import authenticate [as 别名]
class Connection(object):
    """
    Manages the connection to the storage system and serves as a factory 
    for Container instances.

    @undocumented: cdn_connect
    @undocumented: http_connect
    @undocumented: cdn_request
    @undocumented: make_request
    @undocumented: _check_container_name
    """
    def __init__(self, username=None, api_key=None, **kwargs):
        """
        Accepts keyword arguments for Mosso username and api key.
        Optionally, you can omit these keywords and supply an
        Authentication object using the auth keyword.
        
        @type username: str
        @param username: a Mosso username
        @type api_key: str
        @param api_key: a Mosso API key
        """
        self.cdn_enabled = False
        self.cdn_args = None
        self.connection_args = None
        self.cdn_connection = None
        self.connection = None
        self.token = None
        self.debuglevel = int(kwargs.get('debuglevel', 0))
        socket.setdefaulttimeout = int(kwargs.get('timeout', 5))
        self.auth = kwargs.has_key('auth') and kwargs['auth'] or None
        
        if not self.auth:
            authurl = kwargs.get('authurl', consts.default_authurl)
            if username and api_key and authurl:
                self.auth = Authentication(username, api_key, authurl)
            else:
                raise TypeError("Incorrect or invalid arguments supplied")
        
        self._authenticate()
        
    def _authenticate(self):
        """
        Authenticate and setup this instance with the values returned.
        """
        (url, self.cdn_url, self.token) = self.auth.authenticate()
        self.connection_args = parse_url(url)
        self.conn_class = self.connection_args[3] and HTTPSConnection or \
                                                      HTTPConnection
        self.http_connect()
        if self.cdn_url:
            self.cdn_connect()

    def cdn_connect(self):
        """
        Setup the http connection instance for the CDN service.
        """
        (host, port, cdn_uri, is_ssl) = parse_url(self.cdn_url)
        conn_class = is_ssl and HTTPSConnection or HTTPConnection
        self.cdn_connection = conn_class(host, port)
        self.cdn_enabled = True

    def http_connect(self):
        """
        Setup the http connection instance.
        """
        (host, port, self.uri, is_ssl) = self.connection_args
        self.connection = self.conn_class(host, port=port)
        self.connection.set_debuglevel(self.debuglevel)

    def cdn_request(self, method, path=[], data='', hdrs=None):
        """
        Given a method (i.e. GET, PUT, POST, etc), a path, data, header and
        metadata dicts, performs an http request against the CDN service.
        """
        if not self.cdn_enabled:
            raise CDNNotEnabled()

        path = '/%s/%s' % \
                 (self.uri.rstrip('/'), '/'.join([quote(i) for i in path]))
        headers = {'Content-Length': len(data), 'User-Agent': consts.user_agent, 
                   'X-Auth-Token': self.token}
        if isinstance(hdrs, dict):
            headers.update(hdrs)
        
        # Send the request
        self.cdn_connection.request(method, path, data, headers)

        def retry_request():
            '''Re-connect and re-try a failed request once'''
            self.cdn_connect()
            self.cdn_connection.request(method, path, data, headers)
            return self.cdn_connection.getresponse()

        try:
            response = self.cdn_connection.getresponse()
        except HTTPException:
            response = retry_request()

        if response.status == 401:
#.........这里部分代码省略.........
开发者ID:GunioRobot,项目名称:fileconveyor,代码行数:103,代码来源:connection.py

示例3: Connection

# 需要导入模块: from authentication import Authentication [as 别名]
# 或者: from authentication.Authentication import authenticate [as 别名]
class Connection(object):
    """
    Manages the connection to the storage system and serves as a factory
    for Container instances.

    create container ---> PUT
    delete container ---> DELETE
    rename container ---> POST  没实现
    set ACL          ---> POST  没实现
    get container    ---> GET
    get info         ---> HEAD
    list containers  ---> GET 解析json数据
    _authenticate ---> 认证
    http_connect  ---> 生成conn连接
    make_request  ---> 向服务端发送http请求
    """

    def __init__(self, username=None, api_key=None, timeout=5, **kwargs):
        """
        Accepts keyword arguments for chouti username and api key.
        Optionally, you can omit these keywords and supply an
        Authentication object using the auth keyword. 

        @type username: str
        @param username: a chouti username, pattern is account:admin
        @type api_key: str
        @param api_key: a chouti password
        container.
        """
        self.connection_args = None
        self.connection = None
        self.token = None
        self.debuglevel = int(kwargs.get('debuglevel', 0))
        self.servicenet = kwargs.get('servicenet', False)
        self.user_agent = kwargs.get('useragent', consts.user_agent)
        self.timeout = timeout

        self.username = username
        self.api_key = api_key
        self._share_user_uri = kwargs.get('_share_user_uri', None)
        self._share_request = kwargs.get('_share_request', False)

        if kwargs.get('share_request', False):
            # 产生一个专为共享请求的请求连接方法
            self.make_request = self.make_share_requst

        self.auth = 'auth' in kwargs and kwargs['auth'] or None

        if not self.auth:
            authurl = kwargs.get('authurl', consts.chouti_authurl)
            if username and api_key and authurl:
                # 此处的auth为Authentication类的实例
                self.auth = Authentication(username, api_key, authurl=authurl,
                            useragent=self.user_agent)
            else:
                raise TypeError("Incorrect or invalid arguments supplied")

        self._authenticate()

    def _authenticate(self):
        """
        Authenticate and setup this instance with the values returned.
        私有方法,开始认证
        """
        (url, self.token) = self.auth.authenticate()
        self.connection_args = parse_url(url)

        if version_info[0] <= 2 and version_info[1] < 6:
            self.conn_class = self.connection_args[3] and THTTPSConnection or \
                                                              THTTPConnection
        else:
            self.conn_class = self.connection_args[3] and HTTPSConnection or \
                                                              HTTPConnection
        self.http_connect()

    def authorization(self, url=None):
        """
        授权功能
        @type url: str
        @param url: 用户接收到的共享文件的链接. url需要解析,解析出container与object
        先认证授权,成功后返回连接对象,此对象所使用的make_request均为share_request
        """
        path = []
        self._share_user_uri, cont = url.rsplit('/', 1)
        # 临时开关,临时使用share_request
        self._share_request = True
        path.append(cont)
        resp = self.make_request('HEAD', path)
        if resp.status == 204:
            self._share_request = False
            return Connection(self.username, self.api_key, _share_request=True, _share_user_uri = self._share_user_uri)
        else:
            self._share_request = False
            return None

    def http_connect(self):
        """
        Setup the http connection instance.
        """
        (host, port, self.uri, is_ssl) = self.connection_args
#.........这里部分代码省略.........
开发者ID:roamin9,项目名称:python-cloudfiles,代码行数:103,代码来源:connection.py

示例4: Connection

# 需要导入模块: from authentication import Authentication [as 别名]
# 或者: from authentication.Authentication import authenticate [as 别名]
class Connection(object):
    """
    Manages the connection to the storage system and serves as a factory
    for Container instances.

    @undocumented: cdn_connect
    @undocumented: http_connect
    @undocumented: cdn_request
    @undocumented: make_request
    @undocumented: _check_container_name
    """

    def __init__(self, username=None, api_key=None, timeout=15, **kwargs):
        """
        Accepts keyword arguments for Mosso username and api key.
        Optionally, you can omit these keywords and supply an
        Authentication object using the auth keyword. Setting the argument
        servicenet to True will make use of Rackspace servicenet network.

        @type username: str
        @param username: a Mosso username
        @type api_key: str
        @param api_key: a Mosso API key
        @type servicenet: bool
        @param servicenet: Use Rackspace servicenet to access Cloud Files.
        @type cdn_log_retention: bool
        @param cdn_log_retention: set logs retention for this cdn enabled
        container.
        """
        self.cdn_enabled = False
        self.cdn_args = None
        self.connection_args = None
        self.cdn_connection = None
        self.connection = None
        self.token = None
        self.debuglevel = int(kwargs.get('debuglevel', 0))
        self.servicenet = kwargs.get('servicenet', False)
        self.user_agent = kwargs.get('useragent', consts.user_agent)
        self.timeout = timeout

        # if the environement variable RACKSPACE_SERVICENET is set (to
        # anything) it will automatically set servicenet=True
        if not 'servicenet' in kwargs \
                and 'RACKSPACE_SERVICENET' in os.environ:
            self.servicenet = True

        self.auth = 'auth' in kwargs and kwargs['auth'] or None

        if not self.auth:
            authurl = kwargs.get('authurl', consts.us_authurl)
            if username and api_key and authurl:
                self.auth = Authentication(username, api_key, authurl=authurl,
                            useragent=self.user_agent, timeout=self.timeout)
            else:
                raise TypeError("Incorrect or invalid arguments supplied")
        self._authenticate()
    def _authenticate(self):
        """
        Authenticate and setup this instance with the values returned.
        """
        (url, self.cdn_url, self.token) = self.auth.authenticate()
        url = self._set_storage_url(url)
        self.connection_args = parse_url(url)

        if version_info[0] <= 2 and version_info[1] < 6:
            self.conn_class = self.connection_args[3] and THTTPSConnection or \
                                                              THTTPConnection
        else:
            self.conn_class = self.connection_args[3] and HTTPSConnection or \
                                                              HTTPConnection
        self.http_connect()
        if self.cdn_url:
            self.cdn_connect()

    def _set_storage_url(self, url):
        if self.servicenet:
            return "https://snet-%s" % url.replace("https://", "")
        return url

    def cdn_connect(self):
        """
        Setup the http connection instance for the CDN service.
        """
        (host, port, cdn_uri, is_ssl) = parse_url(self.cdn_url)
        self.cdn_connection = self.conn_class(host, port, timeout=self.timeout)
        self.cdn_enabled = True

    def http_connect(self):
        """
        Setup the http connection instance.
        """
        (host, port, self.uri, is_ssl) = self.connection_args
        self.connection = self.conn_class(host, port=port, \
                                              timeout=self.timeout)
        self.connection.set_debuglevel(self.debuglevel)

    def cdn_request(self, method, path=[], data='', hdrs=None):
        """
        Given a method (i.e. GET, PUT, POST, etc), a path, data, header and
        metadata dicts, performs an http request against the CDN service.
#.........这里部分代码省略.........
开发者ID:ConsumerAffairs,项目名称:python-cloudfiles,代码行数:103,代码来源:connection.py

示例5: Connection

# 需要导入模块: from authentication import Authentication [as 别名]
# 或者: from authentication.Authentication import authenticate [as 别名]
class Connection(object):
    """
    Manages the connection to the storage system and serves as a factory
    for Container instances.

    @undocumented: http_connect
    @undocumented: make_request
    @undocumented: _check_container_name
    """

    def __init__(self, username=None, api_key=None, timeout=10, **kwargs):
        """
        Accepts keyword arguments for Rackspace Cloud username and api key.
        Optionally, you can omit these keywords and supply an
        Authentication object using the auth keyword.

        @type username: str
        @param username: a Rackspace Cloud username
        @type api_key: str
        @param api_key: a Rackspace Cloud API key
        """
        self.connection_args = None
        self.connection = None
        self.token = None
        self.debuglevel = int(kwargs.get("debuglevel", 0))
        self.user_agent = kwargs.get("useragent", consts.user_agent)
        self.timeout = timeout

        self.auth = "auth" in kwargs and kwargs["auth"] or None

        if not self.auth:
            authurl = kwargs.get("authurl", consts.us_authurl)
            if username and api_key and authurl:
                self.auth = Authentication(username, api_key, authurl=authurl, useragent=self.user_agent)
            else:
                raise TypeError("Incorrect or invalid arguments supplied")

        self._authenticate()

    def _authenticate(self):
        """
        Authenticate and setup this instance with the values returned.
        """
        (url, self.token) = self.auth.authenticate()
        self.connection_args = parse_url(url)

        if version_info[0] <= 2 and version_info[1] < 6:
            self.conn_class = self.connection_args[3] and THTTPSConnection or THTTPConnection
        else:
            self.conn_class = self.connection_args[3] and HTTPSConnection or HTTPConnection
        self.http_connect()

    def convert_iso_datetime(self, dt):
        """
        Convert iso8601 to datetime
        """
        isoFormat = "%Y-%m-%dT%H:%M:%S.000+0000"
        if type(dt) is datetime.datetime:
            return dt
        if dt.endswith("Z"):
            dt = dt.split("Z")[0]
            isoFormat = "%Y-%m-%dT%H:%M:%S"
        return datetime.datetime.strptime(dt, isoFormat)

    def http_connect(self):
        """
        Setup the http connection instance.
        """
        (host, port, self.uri, is_ssl) = self.connection_args
        self.connection = self.conn_class(host, port=port, timeout=self.timeout)
        self.connection.set_debuglevel(self.debuglevel)

    def make_request(self, method, path=[], data="", hdrs=None, parms=None):
        """
        Given a method (i.e. GET, PUT, POST, etc), a path, data, header and
        metadata dicts, and an optional dictionary of query parameters,
        performs an http request.
        """
        query_args = ""
        path = "/%s/%s" % (self.uri.rstrip("/"), "/".join([unicode_quote(i) for i in path]))
        if isinstance(parms, dict) and parms:
            query_args = ["%s=%s" % (quote(x), quote(str(y))) for (x, y) in parms.items()]
        elif isinstance(parms, list) and parms:
            query_args = ["%s" % x for x in parms]
        path = "%s?%s" % (path, "&".join(query_args))

        headers = {
            "Content-Length": str(len(data)),
            "User-Agent": self.user_agent,
            "X-Auth-Token": self.token,
            "Content-Type": "application/xml",
        }
        isinstance(hdrs, dict) and headers.update(hdrs)

        def retry_request():
            """Re-connect and re-try a failed request once"""
            self.http_connect()
            self.connection.request(method, path, data, headers)
            return self.connection.getresponse()

#.........这里部分代码省略.........
开发者ID:adregner,项目名称:python-clouddns,代码行数:103,代码来源:connection.py

示例6: Connection

# 需要导入模块: from authentication import Authentication [as 别名]
# 或者: from authentication.Authentication import authenticate [as 别名]
class Connection(object):
    """
    Manages the connection to the storage system and serves as a factory
    for Container instances.

    @undocumented: http_connect
    @undocumented: make_request
    @undocumented: _check_container_name
    """

    def __init__(self, username=None, api_key=None, timeout=10, **kwargs):
        """
        Accepts keyword arguments for Rackspace Cloud username and api key.
        Optionally, you can omit these keywords and supply an
        Authentication object using the auth keyword.

        @type username: str
        @param username: a Rackspace Cloud username
        @type api_key: str
        @param api_key: a Rackspace Cloud API key
        """
        self.connection_args = None
        self.connection = None
        self.defaultAccountId = None
        self.accountId = None
        self.token = None
        self.debuglevel = int(kwargs.get("debuglevel", 0))
        self.user_agent = kwargs.get("useragent", consts.user_agent)
        self.timeout = timeout

        self.auth = "auth" in kwargs and kwargs["auth"] or None

        if not self.auth:
            authurl = kwargs.get("authurl", consts.us_authurl)
            if username and api_key and authurl:
                self.auth = Authentication(username, api_key, authurl=authurl, useragent=self.user_agent)
            else:
                raise TypeError("Incorrect or invalid arguments supplied")

        self._authenticate()

    def _authenticate(self):
        """
        Authenticate and setup this instance with the values returned.
        """
        (url, self.token) = self.auth.authenticate()
        self.connection_args = parse_url(url)

        if version_info[0] <= 2 and version_info[1] < 6:
            self.conn_class = self.connection_args[3] and THTTPSConnection or THTTPConnection
        else:
            self.conn_class = self.connection_args[3] and HTTPSConnection or HTTPConnection
        self.http_connect()

    def convert_iso_datetime(self, dt):
        """
        Convert iso8601 to datetime
        """
        isoFormat = "%Y-%m-%dT%H:%M:%S.000+0000"
        if type(dt) is datetime.datetime:
            return dt
        if dt.endswith("Z"):
            dt = dt.split("Z")[0]
            isoFormat = "%Y-%m-%dT%H:%M:%S"
        return datetime.datetime.strptime(dt, isoFormat)

    def http_connect(self):
        """
        Setup the http connection instance.
        """
        (host, port, self.uri, is_ssl) = self.connection_args
        self.connection = self.conn_class(host, port=port, timeout=self.timeout)
        self.connection.set_debuglevel(self.debuglevel)

        self.set_account()

    def make_request(self, method, path=[], data="", hdrs=None, parms=None):
        """
        Given a method (i.e. GET, PUT, POST, etc), a path, data, header and
        metadata dicts, and an optional dictionary of query parameters,
        performs an http request.
        """
        query_args = ""
        path = "/%s/%s" % (self.uri.rstrip("/"), "/".join([unicode_quote(i) for i in path]))
        if isinstance(parms, dict) and parms:
            query_args = ["%s=%s" % (quote(x), quote(str(y))) for (x, y) in parms.items()]
        elif isinstance(parms, list) and parms:
            query_args = ["%s" % x for x in parms]
        path = "%s?%s" % (path, "&".join(query_args))

        headers = {"Content-Length": str(len(data)), "User-Agent": self.user_agent, "X-Auth-Token": self.token}
        isinstance(hdrs, dict) and headers.update(hdrs)

        def retry_request():
            """Re-connect and re-try a failed request once"""
            self.http_connect()
            self.connection.request(method, path, data, headers)
            return self.connection.getresponse()

        try:
#.........这里部分代码省略.........
开发者ID:TJM,项目名称:python-clouddns,代码行数:103,代码来源:connection.py


注:本文中的authentication.Authentication.authenticate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。