Exemplo n.º 1
0
    value = String(default=None)


class Root(object):
    def __init__(self, context):
        self._ctx = context

    def get(self):
        return repr(self._ctx.session.__data__)

    def set(self, value):
        self._ctx.session.value = value
        return "OK"


app = Application(
    Root,
    extensions=[
        DebugExtension(),
        DatabaseExtension(
            session=MongoDBConnection('mongodb://localhost/test')),
        SessionExtension(
            secret='xyzzy',
            expires=24 * 90,
            default=MongoSession(Session, database='session'),
        ),
    ])

if __name__ == "__main__":
    app.serve('wsgiref', host='0.0.0.0', port=8080)
Exemplo n.º 2
0
from web.ext.annotation import AnnotationExtension  # Built-in to WebCore.
from web.ext.debug import DebugExtension
from web.ext.serialize import SerializationExtension  # New in 2.0.3!
from web.ext.db import DatabaseExtension  # From external dependency: web.db

# Get a reference to our database connection adapter.
from web.db.mongo import MongoDBConnection  # From extenral dependency: marrow.mongo

# Get a reference to our Wiki root object.
from web.app.wiki.root import Wiki

# This is our WSGI application instance.
app = Application(
    Wiki,
    extensions=[
        # Extensions that are always enabled.
        AnnotationExtension(
        ),  # Allows us to use Python 3 function annotations.
        SerializationExtension(
        ),  # Allows the return of mappings from endpoints, transformed to JSON.
        DatabaseExtension(MongoDBConnection("mongodb://localhost/test")),
    ] + ([
        # Extensions that are only enabled in development or testing environments.
        DebugExtension(
        )  # Interactive traceback debugger, but gives remote code execution access.
    ] if __debug__ else []))

# If we're run as the "main script", serve our application over HTTP.
if __name__ == "__main__":
    app.serve('wsgiref')
Exemplo n.º 3
0
# encoding: utf-8

"""Template rendering sample application.

This renders the test.html file contained in the current working directory.
"""


def template(context):
	context.log.info("Returning template result.")
	return 'mako:./template.html', dict()


if __name__ == '__main__':
	from web.core import Application
	from web.ext.template import TemplateExtension
	
	# Create the underlying WSGI application, passing the extensions to it.
	app = Application(template, extensions=[TemplateExtension()])
	
	# Start the development HTTP server.
	app.serve('wsgiref')

Exemplo n.º 4
0
Arquivo: sess.py Projeto: marrow/mongo
	__collection__ = 'sessions'
	
	value = String(default=None)


class Root(object):
	def __init__(self, context):
		self._ctx = context
	
	def get(self):
		return repr(self._ctx.session.__data__)
	
	def set(self, value):
		self._ctx.session.value = value
		return "OK"


app = Application(Root, extensions=[
		DebugExtension(),
		DatabaseExtension(session=MongoDBConnection('mongodb://localhost/test')),
		SessionExtension(
			secret = 'xyzzy',
			expires = 24 * 90,
			default = MongoSession(Session, database='session'),
		),
	])


if __name__ == "__main__":
	app.serve('wsgiref', host='0.0.0.0', port=8080)
Exemplo n.º 5
0
                            config=config),
        SelectiveDefaultDatabase(),
        DJExtension(config=config['site']),
        ThemeExtension(default=config['site']['default_theme']),
        ACLExtension(default=when.always),
        AuthExtension(intercept=None,
                      name=None,
                      session='authenticated',
                      lookup=Auth.lookup,
                      authenticate=Auth.authenticate),
        SessionExtension(
            secret=config['session']['secret'],
            expires=timedelta(days=config['session']['expires']),
            refresh=True,
            default=MongoSession(Session,
                                 database=config['session']['database']),
        ),
        LocaleExtension(),
    ] + ([
        DebugExtension(),
    ] if __debug__ else []),
)

if __name__ == "__main__":
    if __debug__:
        app.serve('wsgiref', host='0.0.0.0')
    else:
        app.serve('fcgi',
                  socket=config['socket']['file'],
                  umask=config['socket']['umask'])
Exemplo n.º 6
0
						'web.app.redirect': {
								'level': 'DEBUG' if __debug__ else 'INFO',
								'handlers': ['console'],
								'propagate': False,
							},
						'web': {
								'level': 'DEBUG' if __debug__ else 'WARN',
								'handlers': ['console'],
								'propagate': False,
							},
					},
				'root': {
						'level': 'INFO' if __debug__ else 'WARN',
						'handlers': ['console']
					},
				'formatters': {
						'json': {'()': 'marrow.mongo.util.logger.JSONFormatter'}
					}
			}
		
	)


# If we're run as the "main script", serve our application over HTTP.
if __name__ == "__main__":
	app.serve(
			'wsgiref' if __debug__ else 'waitress',
			host = '127.0.0.1' if __debug__ else '0.0.0.0',
			port = int(ENV('PORT', 8080))
		)