def deny_no_redirect(cls_or_func):
    """Decorator function that ensures that any denied response will not
    be redirected, but will instead raise a 401 Unauthorized.  Useful for
    AJAX calls.
    """
    return cherrypy.config(**{ 
        'tools.lg_authority.deny_page_anon': None
        ,'tools.lg_authority.deny_page_auth': None
        })(cls_or_func)
Example #2
0
import MySQLdb

import cherrypy

import os

import json

from cherrypy.lib import static

from require import require

json_out = cherrypy.config(**{'tools.json_out.on': True})
json_in = cherrypy.config(**{'tools.json_in.on': True})


class MyPosts(object):

    _cp_config = {
        'tools.sessions.on': True,
        'tools.auth.on': True,
        'tools.sessions.locking':
        'explicit'  #this and the acquire_lock and the release_lock statements in the login and logout functions are necessary so that multiple ajax requests can be processed in parallel in a single session
    }

    @cherrypy.expose
    @require()
    def index(self):

        gtag_string = open("gtag.js").read()
Example #3
0
import cherrypy
from cherrypy.test import helper

from cherrypy._cpcompat import json


json_out = cherrypy.config(**{'tools.json_out.on': True})
json_in = cherrypy.config(**{'tools.json_in.on': True})

class JsonTest(helper.CPWebCase):

    @staticmethod
    def setup_server():
        class Root(object):

            @cherrypy.expose
            def plain(self):
                return 'hello'

            @cherrypy.expose
            @json_out
            def json_string(self):
                return 'hello'

            @cherrypy.expose
            @json_out
            def json_list(self):
                return ['a', 'b', 42]

            @cherrypy.expose
            @json_out
def groups(*groups):
    """Decorator function that winds up calling cherrypy.config(**{ 'tools.lg_authority.groups': groups })"""
    if len(groups) == 1 and type(groups[0]) == list:
        groups = groups[0]

    return cherrypy.config(**{ 'tools.lg_authority.groups': groups })