# Path: social/utils.py
# def setting_name(*names):
#     names = [val.upper().replace('-', '_') for val in names if val]
#     return '_'.join((SETTING_PREFIX,) + tuple(names))
# 
# Path: social/store.py
# class OpenIdStore(BaseOpenIDStore):
#     """Storage class"""
#     def __init__(self, strategy):
#         """Init method"""
#         super(OpenIdStore, self).__init__()
#         self.strategy = strategy
#         self.storage = strategy.storage
#         self.assoc = self.storage.association
#         self.nonce = self.storage.nonce
#         self.max_nonce_age = 6 * 60 * 60  # Six hours
# 
#     def storeAssociation(self, server_url, association):
#         """Store new assocition if doesn't exist"""
#         self.assoc.store(server_url, association)
# 
#     def removeAssociation(self, server_url, handle):
#         """Remove association"""
#         associations_ids = list(dict(self.assoc.oids(server_url,
#                                                      handle)).keys())
#         if associations_ids:
#             self.assoc.remove(associations_ids)
# 
#     def getAssociation(self, server_url, handle=None):
#         """Return stored assocition"""
#         oid_associations = self.assoc.oids(server_url, handle)
#         associations = [association
#                         for assoc_id, association in oid_associations
#                         if association.getExpiresIn() > 0]
#         expired = [assoc_id for assoc_id, association in oid_associations
#                    if association.getExpiresIn() == 0]
# 
#         if expired:  # clear expired associations
#             self.assoc.remove(expired)
# 
#         if associations:  # return most recet association
#             return associations[0]
# 
#     def useNonce(self, server_url, timestamp, salt):
#         """Generate one use number and return *if* it was created"""
#         if abs(timestamp - time.time()) > SKEW:
#             return False
#         return self.nonce.use(server_url, timestamp, salt)


import time
import random
import hashlib
from social.utils import setting_name
from social.store import OpenIdStore

    def render_template(self, tpl, context):
        raise NotImplementedError('Implement in subclass')

    def render_string(self, html, context):
        raise NotImplementedError('Implement in subclass')


class BaseStrategy(object):
    ALLOWED_CHARS = 'abcdefghijklmnopqrstuvwxyz' \
                    'ABCDEFGHIJKLMNOPQRSTUVWXYZ' \
                    '0123456789'

    def __init__(self, backend=None, storage=None, request=None, tpl=None,
                 backends=None, *args, **kwargs):
        tpl = tpl or BaseTemplateStrategy
        if not isinstance(tpl, BaseTemplateStrategy):
            tpl = tpl(self)
        self.tpl = tpl
        self.request = request
        self.storage = storage
        self.backends = backends
        if backend:
            self.backend_name = backend.name
            self.backend = backend(strategy=self, *args, **kwargs)
        else:
            self.backend_name = None
            self.backend = backend

    def setting(self, name, default=None):

# Path: social/utils.py
# def setting_name(*names):
#     names = [val.upper().replace('-', '_') for val in names if val]
#     return '_'.join((SETTING_PREFIX,) + tuple(names))
# 
# Path: social/store.py
# class OpenIdStore(BaseOpenIDStore):
#     """Storage class"""
#     def __init__(self, strategy):
#         """Init method"""
#         super(OpenIdStore, self).__init__()
#         self.strategy = strategy
#         self.storage = strategy.storage
#         self.assoc = self.storage.association
#         self.nonce = self.storage.nonce
#         self.max_nonce_age = 6 * 60 * 60  # Six hours
# 
#     def storeAssociation(self, server_url, association):
#         """Store new assocition if doesn't exist"""
#         self.assoc.store(server_url, association)
# 
#     def removeAssociation(self, server_url, handle):
#         """Remove association"""
#         associations_ids = list(dict(self.assoc.oids(server_url,
#                                                      handle)).keys())
#         if associations_ids:
#             self.assoc.remove(associations_ids)
# 
#     def getAssociation(self, server_url, handle=None):
#         """Return stored assocition"""
#         oid_associations = self.assoc.oids(server_url, handle)
#         associations = [association
#                         for assoc_id, association in oid_associations
#                         if association.getExpiresIn() > 0]
#         expired = [assoc_id for assoc_id, association in oid_associations
#                    if association.getExpiresIn() == 0]
# 
#         if expired:  # clear expired associations
#             self.assoc.remove(expired)
# 
#         if associations:  # return most recet association
#             return associations[0]
# 
#     def useNonce(self, server_url, timestamp, salt):
#         """Generate one use number and return *if* it was created"""
#         if abs(timestamp - time.time()) > SKEW:
#             return False
#         return self.nonce.use(server_url, timestamp, salt)


# Path: social/strategies/base.py
import time
import random
import hashlib
from social.utils import setting_name
from social.store import OpenIdStore


    def render_template(self, tpl, context):
        raise NotImplementedError('Implement in subclass')

    def render_string(self, html, context):
        raise NotImplementedError('Implement in subclass')


class BaseStrategy(object):
    ALLOWED_CHARS = 'abcdefghijklmnopqrstuvwxyz' \
                    'ABCDEFGHIJKLMNOPQRSTUVWXYZ' \
                    '0123456789'

    def __init__(self, backend=None, storage=None, request=None, tpl=None,
                 backends=None, *args, **kwargs):
        tpl = tpl or BaseTemplateStrategy
        if not isinstance(tpl, BaseTemplateStrategy):
            tpl = tpl(self)
        self.tpl = tpl
        self.request = request
        self.storage = storage
        self.backends = backends
        if backend:
            self.backend_name = backend.name
            self.backend = backend(strategy=self, *args, **kwargs)
        else:
            self.backend_name = None
            self.backend = backend

    def setting(self, name, default=None):

        names = (setting_name(self.backend_name, name),