コード例 #1
0
ファイル: app.py プロジェクト: lowks/untwisted
    def load_index(self, con, header, fd, data, version):
        index = data['index'][0]
        name, quote = DB[index]
        HTML = render('view.jinja', name=name, quote=quote)
        response = Response()

        response.set_response('HTTP/1.1 200 OK')
        response.add_data(HTML)

        send_response(con, str(response))

    def add_quote(self, con, header, fd, data, version):
        name = data['name'][0]
        quote = data['quote'][0]
        index = str(len(DB))
        DB[index] = (name, quote)

        self.send_base(con, header, fd, data, version)


if __name__ == '__main__':
    import sys
    BACKLOG = 50
    app = RapidServ(sys.argv[1], int(sys.argv[2]), BACKLOG)

    app.add_handle(QuoteHandle)
    app.add_handle(Locate, make(__file__, 'static'))
    app.add_handle(DebugGet)
    core.gear.mainloop()
コード例 #2
0
ファイル: app.py プロジェクト: lowks/untwisted
        send_response(con, response)

    def load_index(self, con, header, fd, data, version):
        index = data['index'][0]

        response = Response()
        response.set_response('HTTP/1.1 200 OK')
        response.add_header(('Content-Type', 'image/jpeg'))

        response.add_data(DB[index])
        send_response(con, response)

    def add_image(self, con, header, fd, data, version):
        item              = fd['file']
        DB[item.filename] = item.file.read()
        self.send_base(con, header, None, None, version)

if __name__ == '__main__':
    import sys
    app = RapidServ('0.0.0.0', 5000, 50)
    app.add_handle(ImageUpload)
    app.add_handle(InvalidRequest)

    core.gear.mainloop()
    




コード例 #3
0
ファイル: app.py プロジェクト: lowks/untwisted
        xmap(con, 'GET /', self.send_base)

    def send_base(self, con, header, fd, data, version):
        # The http response.
        response = Response()
        response.set_response('HTTP/1.1 200 OK')

        HTML = """ <html> 
                   <body>
                   <p> It is simple :P </p>
                   </body> </html>
               """

        response.add_data(HTML)

        # This function should be called just once.
        send_response(con, response)
    

if __name__ == '__main__':
    app = RapidServ('0.0.0.0', 5000, 60)

    app.add_handle(Simple)
    core.gear.mainloop()
    





コード例 #4
0
ファイル: app.py プロジェクト: lowks/untwisted
        response.set_response('HTTP/1.1 200 OK')

        HTML = render('view.jinja', posts=DB.iterkeys())
        response.add_data(HTML)

        send_response(con, response)

    def load_index(self, con, header, fd, data, version):
        index = data['index'][0]

        response = Response()
        response.set_response('HTTP/1.1 200 OK')
        response.add_header(('Content-Type', 'image/jpeg'))

        response.add_data(DB[index])
        send_response(con, response)

    def add_image(self, con, header, fd, data, version):
        item = fd['file']
        DB[item.filename] = item.file.read()
        self.send_base(con, header, None, None, version)


if __name__ == '__main__':
    import sys
    app = RapidServ('0.0.0.0', 5000, 50)
    app.add_handle(ImageUpload)
    app.add_handle(InvalidRequest)

    core.gear.mainloop()
コード例 #5
0
from untwisted.plugins.rapidserv import RapidServ, send_response, Response, core, xmap


class Simple(object):
    def __init__(self, con):
        # Used to map a router to a handle.
        xmap(con, 'GET /', self.send_base)

    def send_base(self, con, header, fd, data, version):
        # The http response.
        response = Response()
        response.set_response('HTTP/1.1 200 OK')

        HTML = """ <html> 
                   <body>
                   <p> It is simple :P </p>
                   </body> </html>
               """

        response.add_data(HTML)

        # This function should be called just once.
        send_response(con, response)


if __name__ == '__main__':
    app = RapidServ('0.0.0.0', 5000, 60)

    app.add_handle(Simple)
    core.gear.mainloop()