#!/usr/bin/env python
#
# Copyright 2009 Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web

from tornado.options import define, options

define("port", default=8888, help="run on the given port", type=int)


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        # self.write("Hello, world 123")
        # Tornado 用户指南 模板和UI
        # items = ["Item 1", "Item 2", "Item 3"]
        # self.render("template.html", title="My Title", items=items)

        # Tornado 用户指南 认证和安全
        if not self.get_cookie("mycookie"):
            self.set_cookie("mycookie", "myvalue")
            self.write("Your cookie was not set yet")
        else:
            self.write("Your cookie was set!")

class StoryHandler(tornado.web.RequestHandler):
    def get(self, story_id):
        self.write("this is story %s" % story_id)


class MyFormHandler(tornado.web.RequestHandler):
    def get(self):
        self.write('<html><body><form action="/form" method="POST">'
                   '<input type="text" name="message">'
                   '<input type="submit" value="Submit">'
                   '</form></body></html>')

    def post(self):
        self.set_header("Content-Type", "text/plain")
        self.write("You wrote " + self.get_body_argument("message"))


def main():
    tornado.options.parse_command_line()
    application = tornado.web.Application([
        (r"/", MainHandler),
        (r"/story/([0-9]+)", StoryHandler),
        (r"/form", MyFormHandler)
    ], cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__")
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.current().start()


if __name__ == "__main__":
    main()

5f16134cdcdace923373c8902db3c48889a96c59
<mask token>


class MainHandler(tornado.web.RequestHandler):
    <mask token>


class StoryHandler(tornado.web.RequestHandler):

    def get(self, story_id):
        self.write('this is story %s' % story_id)


class MyFormHandler(tornado.web.RequestHandler):

    def get(self):
        self.write(
            '<html><body><form action="/form" method="POST"><input type="text" name="message"><input type="submit" value="Submit"></form></body></html>'
            )

    def post(self):
        self.set_header('Content-Type', 'text/plain')
        self.write('You wrote ' + self.get_body_argument('message'))


<mask token>

<mask token>


class MainHandler(tornado.web.RequestHandler):

    def get(self):
        if not self.get_cookie('mycookie'):
            self.set_cookie('mycookie', 'myvalue')
            self.write('Your cookie was not set yet')
        else:
            self.write('Your cookie was set!')


class StoryHandler(tornado.web.RequestHandler):

    def get(self, story_id):
        self.write('this is story %s' % story_id)


class MyFormHandler(tornado.web.RequestHandler):

    def get(self):
        self.write(
            '<html><body><form action="/form" method="POST"><input type="text" name="message"><input type="submit" value="Submit"></form></body></html>'
            )

    def post(self):
        self.set_header('Content-Type', 'text/plain')
        self.write('You wrote ' + self.get_body_argument('message'))


<mask token>

<mask token>


class MainHandler(tornado.web.RequestHandler):

    def get(self):
        if not self.get_cookie('mycookie'):
            self.set_cookie('mycookie', 'myvalue')
            self.write('Your cookie was not set yet')
        else:
            self.write('Your cookie was set!')


class StoryHandler(tornado.web.RequestHandler):

    def get(self, story_id):
        self.write('this is story %s' % story_id)


class MyFormHandler(tornado.web.RequestHandler):

    def get(self):
        self.write(
            '<html><body><form action="/form" method="POST"><input type="text" name="message"><input type="submit" value="Submit"></form></body></html>'
            )

    def post(self):
        self.set_header('Content-Type', 'text/plain')
        self.write('You wrote ' + self.get_body_argument('message'))


def main():
    tornado.options.parse_command_line()
    application = tornado.web.Application([('/', MainHandler), (
        '/story/([0-9]+)', StoryHandler), ('/form', MyFormHandler)],
        cookie_secret='__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__')
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.current().start()


<mask token>

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
define('port', default=8888, help='run on the given port', type=int)


class MainHandler(tornado.web.RequestHandler):

    def get(self):
        if not self.get_cookie('mycookie'):
            self.set_cookie('mycookie', 'myvalue')
            self.write('Your cookie was not set yet')
        else:
            self.write('Your cookie was set!')


class StoryHandler(tornado.web.RequestHandler):

    def get(self, story_id):
        self.write('this is story %s' % story_id)


class MyFormHandler(tornado.web.RequestHandler):

    def get(self):
        self.write(
            '<html><body><form action="/form" method="POST"><input type="text" name="message"><input type="submit" value="Submit"></form></body></html>'
            )

    def post(self):
        self.set_header('Content-Type', 'text/plain')
        self.write('You wrote ' + self.get_body_argument('message'))


def main():
    tornado.options.parse_command_line()
    application = tornado.web.Application([('/', MainHandler), (
        '/story/([0-9]+)', StoryHandler), ('/form', MyFormHandler)],
        cookie_secret='__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__')
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.current().start()


if __name__ == '__main__':
    main()

#!/usr/bin/env python
#
# Copyright 2009 Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web

from tornado.options import define, options

define("port", default=8888, help="run on the given port", type=int)


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        # self.write("Hello, world 123")
        # Tornado 用户指南 模板和UI
        # items = ["Item 1", "Item 2", "Item 3"]
        # self.render("template.html", title="My Title", items=items)

        # Tornado 用户指南 认证和安全
        if not self.get_cookie("mycookie"):
            self.set_cookie("mycookie", "myvalue")
            self.write("Your cookie was not set yet")
        else:
            self.write("Your cookie was set!")

class StoryHandler(tornado.web.RequestHandler):
    def get(self, story_id):
        self.write("this is story %s" % story_id)


class MyFormHandler(tornado.web.RequestHandler):
    def get(self):
        self.write('<html><body><form action="/form" method="POST">'
                   '<input type="text" name="message">'
                   '<input type="submit" value="Submit">'
                   '</form></body></html>')

    def post(self):
        self.set_header("Content-Type", "text/plain")
        self.write("You wrote " + self.get_body_argument("message"))


def main():
    tornado.options.parse_command_line()
    application = tornado.web.Application([
        (r"/", MainHandler),
        (r"/story/([0-9]+)", StoryHandler),
        (r"/form", MyFormHandler)
    ], cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__")
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.current().start()


if __name__ == "__main__":
    main()
