Beispiel #1
0
    def get(self,keyword):
        keyword = urllib.unquote(keyword)
        try:
            start = int(self.get_argument('pos'))
        except:
            start = 0      
        ids = self.db_conn.lrange(keyword,start,start+100)        
        args = {'ids':ids}
        if len(ids) > 100:
          args['nextUrl'] = nextUrl="/keys/%s?pos=%d" % (keyword,start+100)
        return self.render_template('docs.html',**args)
class SitemapHandler(Jinja2Rendering):
    def get(self):
        ids = self.db_conn.lrange('ids',0,-1) 
        self.headers["Conent-Type"] = 'text/xml'
        return self.render_template('sitemap.xml',ids=ids)      
urls = [(r'^/sitemap.xml',SitemapHandler),
        (r'^/keys/(.+)$',KeyHandler), 
        (r'^/keys',KeysHandler),
        (r'^/docs/(.+)$', DocHandler),        
        (r'^/docs', DocsHandler),
        (r'^/', IndexHandler)]
                
mongrel2_pair = ('tcp://127.0.0.1:9997', 'tcp://127.0.0.1:9996')

app = Brubeck(mongrel2_pair=mongrel2_pair,
              handler_tuples=urls,
              db_conn = redis.Redis(),
              template_loader=load_jinja2_env('./templates'))
app.run()
Beispiel #2
0

class LogoutHandler(CustomAuthMixin, Jinja2Rendering):
    def get(self):
        """Clears cookie and sends user to login page
        """
        self.delete_cookies()
        return self.redirect('/login')


###
### Configuration
###

handler_tuples = [
    (r'^/login', LoginHandler),
    (r'^/logout', LogoutHandler),
    (r'^/', LandingHandler),
]

config = {
    'msg_conn': Mongrel2Connection('tcp://127.0.0.1:9999',
                                   'tcp://127.0.0.1:9998'),
    'handler_tuples': handler_tuples,
    'template_loader': load_jinja2_env('./templates/login'),
    'login_url': '/login',
}

app = Brubeck(**config)
app.run()
Beispiel #3
0
    def get(self):
        """Offers login form to user
        """
        return self.render_template('landing.html')

    def post(self):
        """Checks credentials with decorator and sends user authenticated
        users to the landing page.
        """
        if hasattr(self.message, 'files'):
            print 'FILES:', self.message.files['data'][0]['body']
            im = Image.open(
                StringIO.StringIO(self.message.files['data'][0]['body']))
            im.save('word.png')
        return self.redirect('/')


###
### Configuration
###

config = {
    'msg_conn': Mongrel2Connection("tcp://127.0.0.1:9999",
                                   "tcp://127.0.0.1:9998"),
    'handler_tuples': [(r'^/add_file', UploadHandler)],
    'template_loader': load_jinja2_env('./templates/multipart'),
}

app = Brubeck(**config)
app.run()
Beispiel #4
0

class TodosHandler(BaseHandler, Jinja2Rendering):
    def get(self):
        """A list display matching the parameters of a user's dashboard. The
        parameters essentially map to the variation in how `load_listitems` is
        called.
        """
        return self.render_template("todos.html")


###
### Configuration
###

# Routing config
handler_tuples = [(r"^/$", TodosHandler)]

# Application config
config = {
    "mongrel2_pair": ("ipc://127.0.0.1:9999", "ipc://127.0.0.1:9998"),
    "handler_tuples": handler_tuples,
    "template_loader": load_jinja2_env("."),
}


# Instantiate app instance
app = Brubeck(**config)
app.register_api(TodosAPI)
app.run()
Beispiel #5
0
class UploadHandler(Jinja2Rendering):
    def get(self):
        """Offers login form to user
        """
        return self.render_template("landing.html")

    def post(self):
        """Checks credentials with decorator and sends user authenticated
        users to the landing page.
        """
        if hasattr(self.message, "files"):
            print "FILES:", self.message.files["data"][0]["body"]
            im = Image.open(StringIO.StringIO(self.message.files["data"][0]["body"]))
            im.save("word.png")
        return self.redirect("/")


###
### Configuration
###

config = {
    "msg_conn": Mongrel2Connection("tcp://127.0.0.1:9999", "tcp://127.0.0.1:9998"),
    "handler_tuples": [(r"^/add_file", UploadHandler)],
    "template_loader": load_jinja2_env("./templates/multipart"),
}

app = Brubeck(**config)
app.run()
Beispiel #6
0
class TodosHandler(BaseHandler):
    def get(self):
        """A list display matching the parameters of a user's dashboard. The
        parameters essentially map to the variation in how `load_listitems` is
        called.
        """
        return self.render_template('todos.html')


###
### Configuration
###

# Routing config
handler_tuples = [
    (r'^/$', TodosHandler),
]

# Application config
config = {
    'mongrel2_pair': ('ipc://127.0.0.1:9999', 'ipc://127.0.0.1:9998'),
    'handler_tuples': handler_tuples,
    'template_loader': load_jinja2_env('./templates/apiable'),
}

# Instantiate app instance
app = Brubeck(**config)
app.register_api(TodosAPI)
app.run()

Beispiel #7
0
    def get(self):
        """Offers login form to user
        """
        return self.render_template('landing.html')
    
    def post(self):
        """Checks credentials with decorator and sends user authenticated
        users to the landing page.
        """
        if hasattr(self.message, 'files'):
            print 'FILES:', self.message.files['data'][0]['body']
            im = Image.open(StringIO.StringIO(self.message.files['data'][0]['body']))
            print 'IM:', im
            im.save('word.png')
        return self.redirect('/')


###
### Configuration
###
    
config = {
    #'msg_conn': WSGIConnection(),
    'msg_conn': Mongrel2Connection("tcp://127.0.0.1:9999", "tcp://127.0.0.1:9998"),
    'handler_tuples': [(r'^/', UploadHandler)],
    'template_loader': load_jinja2_env('./templates/multipart'),
}

app = Brubeck(**config)
app.run()
Beispiel #8
0
    import gevent

class DemoHandler(Jinja2Rendering):
    def get(self):
        name = self.get_argument('name', 'dude')
        self.set_body('Take five, %s!' % name)
        return self.render_template('base.html')


class FeedHandler(WebMessageHandler):
    def get(self):
        try:
            eventlet.sleep(5) # simple way to demo long polling :)
        except:
            gevent.sleep(5)
        self.set_body('The current time is: %s' % datetime.datetime.now(),
                      headers={'Content-Type': 'text/plain'})
        return self.render()


config = {
    'mongrel2_pair': ('ipc://127.0.0.1:9999', 'ipc://127.0.0.1:9998'),
    'handler_tuples': [(r'^/$', DemoHandler),
                       (r'^/feed', FeedHandler)],
    'template_loader': load_jinja2_env('./templates/longpolling'),
}


app = Brubeck(**config)
app.run()
Beispiel #9
0
# -*- coding: utf-8 -*-

"""Configuration of constant variables, template folder etc.
"""

import os
import logging
from brubeck.connections import Mongrel2Connection
from brubeck.templating import load_jinja2_env
from urls import URLS

GENERAL_LIMIT = 30
MAXLIMIT = 1000
TIMEOUT = 3600

DB_ENGINE = 'sqlite:////tmp/twidder.db?check_same_thread=False'
HASH_KEY = '6c4tn8et!y9gbt3b7+G=#+&v9uS^VtJg#s)bv7Wixh!E@jw'
SESSION_KEY = 'twidder'

def absolute(path):
  PROJECTDIR = os.path.dirname(os.path.abspath(__file__))
  return os.path.normpath(os.path.join(PROJECTDIR, path))

config = {
  'mongrel2_pair': Mongrel2Connection('ipc://127.0.0.1:9999', 'ipc://127.0.0.1:9998'),
  'handler_tuples': URLS,
  'log_level': logging.DEBUG,
  'template_loader': load_jinja2_env(absolute('app/templates')),
  'cookie_secret': HASH_KEY,
}
Beispiel #10
0
## runtime configuration
##
project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
template_dir = os.path.join(project_dir, 'templates')

config = {
    'mongrel2_pair': ('ipc://run/mongrel2_send', 'ipc://run/mongrel2_recv'),
    'handler_tuples': [
        (r'^/$', ChatifyHandler),
        (r'^/feed$', FeedHandler),
        (r'^/login/(?P<nickname>.+)$', LoginHandler),
    ],
    'cookie_secret':
    '1a^O9s$4clq#09AlOO1!',
    'template_loader':
    load_jinja2_env(template_dir),
    'enforce_using_redis':
    False,  # This should be true in production 
}

##
## get us started!
##

app = Brubeck(**config)
if using_redis:
    """try to use redis if possible. Only required for persistance across instance restarts and using more than one instance to handle requests.
       Yeah, so you should REALLY use redis in production.
    """
    try:
        ## attach to our redis server
Beispiel #11
0
## this allows us to import the demo as a module for unit tests without running the server
##
## runtime configuration
##
project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
template_dir = os.path.join(project_dir, 'templates')

config = {
    'mongrel2_pair': ('ipc://run/mongrel2_send', 'ipc://run/mongrel2_recv'),
    'handler_tuples': [
        (r'^/$', ChatifyHandler),
        (r'^/feed$', FeedHandler),
        (r'^/login/(?P<nickname>.+)$', LoginHandler),
    ],
    'cookie_secret': '1a^O9s$4clq#09AlOO1!',
    'template_loader': load_jinja2_env(template_dir),
    'enforce_using_redis': False, # This should be true in production 
}


##
## get us started!
##


app = Brubeck(**config)
if using_redis:
    """try to use redis if possible. Only required for persistance across instance restarts and using more than one instance to handle requests.
       Yeah, so you should REALLY use redis in production.
    """
    try:
Beispiel #12
0
#!/usr/bin/env python

from brubeck.request_handling import Brubeck
from brubeck.templating import Jinja2Rendering, load_jinja2_env
from brubeck.connections import Mongrel2Connection
import sys


class DemoHandler(Jinja2Rendering):
    def get(self):
        name = self.get_argument("name", "dude")
        context = {"name": name}
        raise
        return self.render_template("success.html", **context)


app = Brubeck(
    msg_conn=Mongrel2Connection("tcp://127.0.0.1:9999", "tcp://127.0.0.1:9998"),
    handler_tuples=[(r"^/brubeck", DemoHandler)],
    template_loader=load_jinja2_env("./templates/jinja2"),
)
app.run()
Beispiel #13
0
class TodosHandler(Jinja2Rendering):
    def get(self):
        """A list display matching the parameters of a user's dashboard. The
        parameters essentially map to the variation in how `load_listitems` is
        called.
        """
        return self.render_template('todos.html')


###
### Configuration
###

# Routing config
handler_tuples = [
    (r'^/$', TodosHandler),
]

# Application config
config = {
    'msg_conn': Mongrel2Connection('tcp://127.0.0.1:9999', 'tcp://127.0.0.1:9998'),
    'handler_tuples': handler_tuples,
    'template_loader': load_jinja2_env('./templates/autoapi'),
}

# Instantiate app instance
app = Brubeck(**config)
app.register_api(TodosAPI)
app.run()

Beispiel #14
0
logging.info("Using project directory: " + project_dir)

config = {
    "project_dir": project_dir,
    "msg_conn": Mongrel2Connection("ipc://run/qoorateserver/mongrel2_send", "ipc://run/qoorateserver/mongrel2_rcv"),
    "handler_tuples": [  ## Set up our routes
        (r"^/q/feed", FeedHandler),
        (r"^/q/embed/json", EmbedHandlerJSON),
        (r"^/q/embed", EmbedHandler),
        (r"^/q/uploader/images/(?P<file_name>.+)$", TemporaryImageViewHandler),
        (r"^/q/uploader", TemporaryImageUploadHandler),
        (r"^/q/oauth/(?P<provider>.+)/(?P<action>.+)$", QoorateOAuthHandler),
        (r"^/", FourOhFourHandler),
    ],
    "cookie_secret": "_1sRe%%66a^O9s$4c6ld!@_F%&9AlH)-6OO1!",
    "template_loader": load_jinja2_env(project_dir + "/templates/qoorateserver"),
    "settings_file": project_dir + "/conf/qoorateserver/development.py",
    "log_level": logging.DEBUG,
}

## other settings should be put in the file specified by 'settings_file'

##
## get us started!
##


app = Qoorate(**config)
## start our server to handle requests
if __name__ == "__main__":
    app.run()
Beispiel #15
0
project_dir = '.'
logging.info("Using project directory: " + project_dir)

config = {
    'project_dir': project_dir,
    'mongrel2_pair': ('ipc://run/qoorateserver/mongrel2_send', 'ipc://run/qoorateserver/mongrel2_rcv'),
    'handler_tuples': [ ## Set up our routes
        (r'^/q/feed', FeedHandler),
        (r'^/q/embed/json', EmbedHandlerJSON),
        (r'^/q/embed', EmbedHandler),
        (r'^/q/uploader/images/(?P<file_name>.+)$', TemporaryImageViewHandler),
        (r'^/q/uploader', TemporaryImageUploadHandler),
        (r'^/q/oauth/(?P<provider>.+)/(?P<action>.+)$', QoorateOAuthHandler),
    ],
    'cookie_secret': '_1sRe%%66a^O9s$4c6ld!@_F%&9AlH)-6OO1!',
    'template_loader': load_jinja2_env( project_dir + '/apps/qoorateserver/templates'),
    'settings_file': project_dir + '/config/qoorateserver/settings.py',
    'log_level': logging.DEBUG,
}

## other settings should be put in the file specified by 'settings_file'

##
## get us started!
##


app = Qoorate(**config)
## start our server to handle requests
if __name__ == "__main__":
    app.run()
Beispiel #16
0
#!/usr/bin/env python

from brubeck.request_handling import Brubeck
from brubeck.templating import Jinja2Rendering, load_jinja2_env
from brubeck.connections import Mongrel2Connection
import sys

class DemoHandler(Jinja2Rendering):
    def get(self):
        name = self.get_argument('name', 'dude')
        context = {
            'name': name,
        }
        return self.render_template('success.html', **context)

app = Brubeck(msg_conn=Mongrel2Connection('tcp://127.0.0.1:9999', 'tcp://127.0.0.1:9998'),
              handler_tuples=[(r'^/brubeck', DemoHandler)],
              template_loader=load_jinja2_env('./templates/jinja2'))
app.run()
Beispiel #17
0

### Flat page handler
class TodosHandler(Jinja2Rendering):
    def get(self):
        """A list display matching the parameters of a user's dashboard. The
        parameters essentially map to the variation in how `load_listitems` is
        called.
        """
        return self.render_template("todos.html")


###
### Configuration
###

# Routing config
handler_tuples = [(r"^/$", TodosHandler)]

# Application config
config = {
    "msg_conn": Mongrel2Connection("tcp://127.0.0.1:9999", "tcp://127.0.0.1:9998"),
    "handler_tuples": handler_tuples,
    "template_loader": load_jinja2_env("./templates/autoapi"),
}

# Instantiate app instance
app = Brubeck(**config)
app.register_api(TodosAPI)
app.run()
Beispiel #18
0
except:
    import gevent


class DemoHandler(Jinja2Rendering):
    def get(self):
        name = self.get_argument('name', 'dude')
        self.set_body('Take five, %s!' % name)
        return self.render_template('base.html')


class FeedHandler(WebMessageHandler):
    def get(self):
        try:
            eventlet.sleep(5)  # simple way to demo long polling :)
        except:
            gevent.sleep(5)
        self.set_body('The current time is: %s' % datetime.datetime.now(),
                      headers={'Content-Type': 'text/plain'})
        return self.render()


config = {
    'mongrel2_pair': ('ipc://127.0.0.1:9999', 'ipc://127.0.0.1:9998'),
    'handler_tuples': [(r'^/$', DemoHandler), (r'^/feed', FeedHandler)],
    'template_loader': load_jinja2_env('./templates/longpolling'),
}

app = Brubeck(**config)
app.run()
Beispiel #19
0
class TodosHandler(Jinja2Rendering):
    def get(self):
        """A list display matching the parameters of a user's dashboard. The
        parameters essentially map to the variation in how `load_listitems` is
        called.
        """
        return self.render_template('todos.html')


###
### Configuration
###

# Routing config
handler_tuples = [
    (r'^/$', TodosHandler),
]

# Application config
config = {
    'msg_conn': Mongrel2Connection('tcp://127.0.0.1:9999',
                                   'tcp://127.0.0.1:9998'),
    'handler_tuples': handler_tuples,
    'template_loader': load_jinja2_env('./templates/autoapi'),
}

# Instantiate app instance
app = Brubeck(**config)
app.register_api(TodosAPI)
app.run()
Beispiel #20
0
class TodosHandler(BaseHandler):
    def get(self):
        """A list display matching the parameters of a user's dashboard. The
        parameters essentially map to the variation in how `load_listitems` is
        called.
        """
        return self.render_template('todos.html')


###
### Configuration
###

# Routing config
handler_tuples = [
    (r'^/$', TodosHandler),
]

# Application config
config = {
    'mongrel2_pair': ('ipc://127.0.0.1:9999', 'ipc://127.0.0.1:9998'),
    'handler_tuples': handler_tuples,
    'template_loader': load_jinja2_env('./templates/apiable'),
}

# Instantiate app instance
app = Brubeck(**config)
app.register_api(TodosAPI)
app.run()
Beispiel #21
0
        return self.redirect('/')


class LogoutHandler(CustomAuthMixin, Jinja2Rendering):
    def get(self):
        """Clears cookie and sends user to login page
        """
        self.delete_cookies()
        return self.redirect('/login')


###
### Configuration
###
    
handler_tuples = [
    (r'^/login', LoginHandler),
    (r'^/logout', LogoutHandler),
    (r'^/', LandingHandler),
]

config = {
    'msg_conn': Mongrel2Connection('tcp://127.0.0.1:9999', 'tcp://127.0.0.1:9998'),
    'handler_tuples': handler_tuples,
    'template_loader': load_jinja2_env('./templates/login'),
    'login_url': '/login',
}

app = Brubeck(**config)
app.run()
Beispiel #22
0
#!/usr/bin/env python

from gevent import Greenlet
from brubeck.request_handling import Brubeck
from brubeck.templating import load_jinja2_env
import handlers
import os
import sys

Greenlet.spawn(handlers.PollHandler.loop, delay=5)

config = {
    'mongrel2_pair': ('ipc://run/mongrel2_send', 'ipc://run/mongrel2_recv'),
    'handler_tuples': [
        (r'^/$', handlers.IndexHandler),
        (r'^/poll$', handlers.PollHandler),
    ],
    'template_loader':
    load_jinja2_env('./templates'),
}

app = Brubeck(**config)
if __name__ == '__main__':
    app.run()
Beispiel #23
0
###

# Instantiate database connection
db_conn = init_db_conn()

# Routing config
handler_tuples = [
    (r'^/login', AccountLoginHandler),
    (r'^/logout', AccountLogoutHandler),
    (r'^/create', AccountCreateHandler),
    (r'^/add_item', ListAddHandler),
    (r'^/api', APIListDisplayHandler),
    (r'^/$', ListDisplayHandler),
]

# Application config
config = {
    'msg_conn': Mongrel2Connection('tcp://127.0.0.1:9999','tcp://127.0.0.1:9998'),
    'handler_tuples': handler_tuples,
    'template_loader': load_jinja2_env('./templates'),
    'db_conn': db_conn,
    'login_url': '/login',
    'cookie_secret': 'OMGSOOOOOSECRET',
    'log_level': logging.DEBUG,
}


# Instantiate app instance
app = Brubeck(**config)
app.run()
Beispiel #24
0
    def post(self):
        """Checks credentials with decorator and sends user authenticated
        users to the landing page.
        """
        return self.redirect("/")


class LogoutHandler(CustomAuthMixin, Jinja2Rendering):
    def get(self):
        """Clears cookie and sends user to login page
        """
        self.delete_cookies()
        return self.redirect("/login")


###
### Configuration
###

handler_tuples = [(r"^/login", LoginHandler), (r"^/logout", LogoutHandler), (r"^/$", LandingHandler)]

config = {
    "mongrel2_pair": ("ipc://127.0.0.1:9999", "ipc://127.0.0.1:9998"),
    "handler_tuples": handler_tuples,
    "template_loader": load_jinja2_env("./templates/login"),
    "login_url": "/login",
}

app = Brubeck(**config)
app.run()