Example #1
0
__author__ = 'Evolutiva'

from gluon.contrib.memcache import MemcacheClient
memcache_servers = ['127.0.0.1:11211']
cache.memcache = MemcacheClient(request, memcache_servers)
cache.ram = cache.disk = cache.memcache


Example #2
0
    return ''


def log(event, request_url):
    """ Log bannable events. """
    from firewall import Blacklist

    blacklist = Blacklist(db)
    blacklist.log(event, request_url)


# Basic app config.
logger = zero.getLogger('app')
T.is_writable = False  # No language file updates.
db = DAL('sqlite://app.db', lazy_tables=True)
cache.ram = MemcacheClient(request, ['127.0.0.1:11211'])

# Log and redirect HTTP requests to HTTPS.
if request.env.server_port == '80':
    auth = Auth(db, controller='auth', secure=False)
    auth.define_tables(signature=True)
    log('301', request.env.request_uri)
    redirect(URL('poems', 'index', scheme='https'), 301)

# Session/auth config.
session.connect(request, response, db)
session.secure()
auth = Auth(db,
            propagate_extension='',
            controller='auth',
            secure=True,
Example #3
0
                     pool_size=pool_size,
                     migrate_enabled=migrate)
    except:
        db_type = db_string.split(":", 1)[0]
        db_location = db_string.split("@", 1)[1]
        raise (HTTP(
            503, "Cannot connect to %s Database: %s" % (db_type, db_location)))

current.db = db
db.set_folder("upload")

# Sessions Storage
if settings.get_base_session_memcache():
    # Store sessions in Memcache
    from gluon.contrib.memcache import MemcacheClient
    cache.memcache = MemcacheClient(request,
                                    [settings.get_base_session_memcache()])
    from gluon.contrib.memdb import MEMDB
    session.connect(request, response, db=MEMDB(cache.memcache))

####################################################################
# Instantiate Classes from Modules                                 #
# - store instances in current to be accessible from other modules #
####################################################################

from gluon.tools import Mail
mail = Mail()
current.mail = mail

from gluon.storage import Messages
messages = Messages(T)
current.messages = messages
Example #4
0
def test_function():
    try:
        from gluon.contrib.memcache import MemcacheClient
        mc = MemcacheClient(['127.0.0.1:11211'], debug=0)

        mc.set("some_key", "Some value")
        value = mc.get("some_key")

        mc.set("another_key", 3)
        mc.delete("another_key")

        mc.set("key", "1")   # note that the key used for incr/decr must be a string.
        mc.incr("key")
        mc.decr("key")
        return dict(result="SC")
    except Exception as ex:
        return dict(error=str(ex) + " on line: " + str(sys.exc_traceback.tb_lineno))