Example #1
0
def get_application():

    imported_middlewares = []

    for middleware in settings.EXTRA_MIDDLEWARES:
        middleware_parts = list(middleware.rsplit('.', 1))
        mod = importlib.import_module(middleware_parts[0])
        imported_middlewares.append(getattr(mod, middleware_parts[1]))

    middlewares = [
        rit_http_error_middleware_factory,
        bootstrap_defaults(url_mapping=all_urls),
    ] + imported_middlewares + [
        path_routing_middleware_factory
    ]
    return WSGIApplication(
        middleware=middlewares,
        options={
            'render_template': get_template_handler(),
            'ticket': Ticket(
                max_age=settings.AUTH_MAX_AGE,
                salt=settings.AUTH_SALT,
                digestmod=hashlib.sha256,
                cypher=aes256,
                options={
                    'CRYPTO_VALIDATION_KEY': settings.CRYPTO_VALIDATION_KEY,
                    'CRYPTO_ENCRYPTION_KEY': settings.CRYPTO_ENCRYPTION_KEY
                }
            ),
            'AUTH_COOKIE': settings.AUTH_COOKIE,
            'XSRF_NAME': settings.XSRF_NAME
        }
    )
Example #2
0
    def start_http_server(self):
        """
        Start the HTTP server.
        """

        self.wsgi_app = WSGIApplication(middleware=[
            bootstrap_defaults(url_mapping=self.URLS),
            path_routing_middleware_factory
        ],
                                        options={})

        socket_pair = (self.http_host, self.http_port)
        self.wsgi_server = make_server(self.http_host, self.http_port,
                                       self.wsgi_app)
        message = "HTTP Server running on http://{}:{}"

        logging.info(message.format(self.http_host, self.http_port))

        self.wsgi_server.serve_forever()
Example #3
0
    def start_http_server(self):
        """
        Start the HTTP server.
        """

        self.wsgi_app = WSGIApplication(
            middleware=[
                bootstrap_defaults(url_mapping=self.URLS),
                path_routing_middleware_factory
            ],
            options={}
        )

        socket_pair = (self.http_host, self.http_port)
        self.wsgi_server = make_server(self.http_host, self.http_port, self.wsgi_app)
        message = "HTTP Server running on http://{}:{}"

        logging.info(message.format(self.http_host, self.http_port))

        self.wsgi_server.serve_forever()
Example #4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2015 blackshirt


__author__ = 'simbah'

from wheezy.http import WSGIApplication
from wheezy.web.middleware import bootstrap_defaults
from wheezy.web.middleware import path_routing_middleware_factory

from config import options
from urls import all_urls

main = WSGIApplication([bootstrap_defaults(url_mapping=all_urls), path_routing_middleware_factory], options)


def patch_locale():
    def getlocale():
        return None, None

    import locale

    locale.getlocale = getlocale


patch_locale()

if __name__ == "__main__":
Example #5
0
from wheezy.web.middleware import path_routing_middleware_factory
from wheezy.web.middleware.errors import http_error_middleware_factory
from wheezy.http.middleware import http_cache_middleware_factory
from wheezy.http.config import bootstrap_http_defaults

from config import options, DEBUG
from urls import all_urls
import socket

host = 'localhost'
if DEBUG:
    host = '0.0.0.0'

main = WSGIApplication(
    middleware=[
        bootstrap_defaults(url_mapping=all_urls),
        bootstrap_http_defaults,
        http_cache_middleware_factory,
        http_error_middleware_factory,
        path_routing_middleware_factory
    ],
    options=options)

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    try:
        print('Visit http://{0}:8080/'.format(host))
        make_server(host, 8080, main).serve_forever()
    except KeyboardInterrupt:
        pass
    print('\nThanks!')
Example #6
0
from wheezy.http import HTTPResponse
from wheezy.http import WSGIApplication
from wheezy.routing import url
from wheezy.web.handlers import BaseHandler
from wheezy.web.middleware import bootstrap_defaults
from wheezy.web.middleware import path_routing_middleware_factory
import json


class WelcomeHandler(BaseHandler):
    def get(self):
        response = HTTPResponse()
        quote = {'message': 'Hello, World!'}
        response.write(json.dumps(quote))
        return response


all_urls = [url('', WelcomeHandler, name='default')]

options = {}
main = WSGIApplication(middleware=[
    bootstrap_defaults(url_mapping=all_urls), path_routing_middleware_factory
],
                       options=options)

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    try:
        make_server('', 8888, main).serve_forever()
    except KeyboardInterrupt:
        pass
    def on_message(self, message):
        data=json.loads(message)
        if(data['register']):
            self.aux['ids'].append(data['id'])
            dic=get_data(data['id'])
            self.ws.send(json.dumps(dic))
        else:
            self.aux['ids'].remove(data['id'])

    def on_close(self, reason):
        #clients.remove(self)
        print (reason)

main = WSGIApplication(
    middleware=[
        bootstrap_defaults(url_mapping=all_urls),
        path_routing_middleware_factory
    ],
    options=options
)
# Funcion principal
if __name__ == '__main__':
    global counter
    counter=0

    # Comunicacion soportada en el Smart Gateway: Zigbee
    xbee = ZigBee(ser, escaped=True, callback=receiver)

    xbee.send('at', frame_id=b'A', command=b'SH')
    xbee.send('at', frame_id=b'B', command=b'SL')
    xbee.send('at', frame_id=b'C', command=b'ID')
Example #8
0
    def get(self):
        rows = find_all()
        response = HTTPResponse()
        response.write(rows)
        return response

    def post(self):
        data = self.request.form
        insert(data)
        response = HTTPResponse()
        response.status_code = 201
        return response


all_urls = [
    url('', DatabaseHandler, name='database'),
    url('hello', HelloHandler, name='hello'),
]


main = WSGIApplication(
    middleware=[bootstrap_defaults(url_mapping=all_urls), path_routing_middleware_factory],
    options={}
)


if __name__ == '__main__':
    bjoern.listen(main, '0.0.0.0', 8080)
    bjoern.run()
Example #9
0
    def __str__(self):
        msg = []
        for v in self.line.values():
            msg.append(unicode(v))
        msg.append(unicode(self.exc))
        return u' | '.join(msg)

url_map = [
    url('', MainView, name='index'),
    url('static/{path:any}',
        file_handler(root=config.app_path('static/')),
        name='static'),
]

application = WSGIApplication(
    middleware=[
        bootstrap_defaults(url_mapping=url_map),
        path_routing_middleware_factory
    ],
    options=config.options)

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    try:
        LOG.info('Launching on http://localhost:5000/ ...')
        make_server('', 5000, application).serve_forever()
    except KeyboardInterrupt:
        LOG.info('... exiting')
    LOG.info('\nThanks for trying me!')
Example #10
0
}
</script>
</body></html>"""
}

engine = Engine(
    loader=DictLoader(templates),
    extensions=[CoreExtension(),
                WidgetExtension(),
                WhitespaceExtension()])

all_urls = [('', WelcomeHandler),
            url('captcha.jpg', captcha_handler, name='captcha')]

options = {'http_cache': cache, 'render_template': WheezyTemplate(engine)}
main = WSGIApplication([
    bootstrap_defaults(url_mapping=all_urls), http_cache_middleware_factory,
    path_routing_middleware_factory
], options)

if __name__ == '__main__':
    from wsgiref.handlers import BaseHandler
    from wsgiref.simple_server import make_server
    try:
        print('Visit http://localhost:8080/')
        BaseHandler.http_version = '1.1'
        make_server('', 8080, main).serve_forever()
    except KeyboardInterrupt:
        pass
    print('\nThanks!')
Example #11
0
from wheezy.http import WSGIApplication
from wheezy.routing import url
from wheezy.web.handlers import BaseHandler
from wheezy.web.middleware import bootstrap_defaults
from wheezy.web.middleware import path_routing_middleware_factory

def test(request):
    response = HTTPResponse()
    response.write('<html><body>Hello World</body></html>')
    return response


routes = [
    url('test', test, name='test')
]


options = {}
main = WSGIApplication(
    middleware=[
        bootstrap_defaults(url_mapping=routes),
        path_routing_middleware_factory
    ],
    options=options
)


server = pywsgi.WSGIServer(('127.0.0.1', 5000), main, backlog=128000)
server.serve_forever()

Example #12
0
from wheezy.http import HTTPResponse, WSGIApplication
from wheezy.routing import url
from wheezy.web.handlers import BaseHandler
from wheezy.web.middleware import bootstrap_defaults
from wheezy.web.middleware import path_routing_middleware_factory

from config import PING_MESSAGE


class Ping(BaseHandler):
    def get(self):
        response = HTTPResponse()
        response.write(PING_MESSAGE.format(app='wheezyweb'))
        return response


app = WSGIApplication(middleware=[
    bootstrap_defaults([url('', Ping)]), path_routing_middleware_factory
],
                      options={})