Esempio n. 1
0
def loadPlugins(app, plugins):
    if not plugins:
        plugins = DEFAULT_PLUGINS
    for plugin in plugins:
        try:
            plugin_class = import_class(plugin)
            app.install(plugin_class())
        except Exception as e:
            print "Failed to load plugin %s because of error %s" % (plugin, e.message)
            continue
Esempio n. 2
0
def get_key_func(key_func):
    """
    Function to decide which key function to use.

    Defaults to ``default_key_func``.
    """
    if key_func is not None:
        if callable(key_func):
            return key_func
        else:
            return import_class(key_func)
    return default_key_func
Esempio n. 3
0
from chembl_beaker.beaker import config
from chembl_beaker.beaker.utils import import_class
from chembl_beaker.beaker.throttle.backends.base import BaseThrottle

throttle = None

throttle_class = config.get('throttle_backend', 'chembl_beaker.beaker.throttle.backends.cacheThrottle.CacheThrottle')

if throttle_class:
    try:
        throttle = import_class(throttle_class)()
        if not isinstance(throttle, BaseThrottle):
            print "Configured throttle class (%s) is not a BaseThrottle instance, skipping throttling." % throttle_class
            throttle = None
    except ImportError:
        print 'Error importing %s' % throttle_class






Esempio n. 4
0
        decrypted_key = aes.decrypt(decoded_key)
        decrypted = filter(bool, decrypted_key.split('\t'))
        dates = [pytz.utc.localize(datetime.strptime(date, DATE_FORMAT)) for date in decrypted]
        if dates[0] < now < dates[1]:
            return True
    except:
        pass

    return False

#-----------------------------------------------------------------------------------------------------------------------

key_verification_function = config.get('throttling_key_verification_function')
if key_verification_function:
    try:
        verified_key = import_class(key_verification_function)
    except ImportError:
        err = 'Error importing function %s' % key_verification_function
        print err
        raise Exception(err)

else:
    if not AES:
        print "API Key verification will be switched off - can't find pycrypto library"
    if not secret_key:
        print "API Key verification will be switched off - no AES key defined"
    verified_key = verify_key

#-----------------------------------------------------------------------------------------------------------------------

def get_identifier(req):
Esempio n. 5
0
            for date in decrypted
        ]
        if dates[0] < now < dates[1]:
            return True
    except:
        pass

    return False


#-----------------------------------------------------------------------------------------------------------------------

key_verification_function = config.get('throttling_key_verification_function')
if key_verification_function:
    try:
        verified_key = import_class(key_verification_function)
    except ImportError:
        err = 'Error importing function %s' % key_verification_function
        print err
        raise Exception(err)

else:
    if not AES:
        print "API Key verification will be switched off - can't find pycrypto library"
    if not secret_key:
        print "API Key verification will be switched off - no AES key defined"
    verified_key = verify_key

#-----------------------------------------------------------------------------------------------------------------------

Esempio n. 6
0
__author__ = 'mnowotka'

from chembl_beaker.beaker import config
from chembl_beaker.beaker.utils import import_class
from chembl_beaker.beaker.cache.backends.base import BaseCache

cache = None

cache_class = config.get('cache_backend')

if cache_class:
    try:
        cache = import_class(cache_class)()
        if not isinstance(cache, BaseCache):
            print "Configured cache class (%s) is not a BaseCache instance, skipping caching." % cache_class
            cache = None
    except ImportError:
        print 'Error importing %s' % cache_class


Esempio n. 7
0
from chembl_beaker.beaker import config
from chembl_beaker.beaker.utils import import_class
from chembl_beaker.beaker.throttle.backends.base import BaseThrottle

throttle = None

throttle_class = config.get(
    'throttle_backend',
    'chembl_beaker.beaker.throttle.backends.cacheThrottle.CacheThrottle')

if throttle_class:
    try:
        throttle = import_class(throttle_class)()
        if not isinstance(throttle, BaseThrottle):
            print "Configured throttle class (%s) is not a BaseThrottle instance, skipping throttling." % throttle_class
            throttle = None
    except ImportError:
        print 'Error importing %s' % throttle_class