How to use the tornado.web.RequestHandler function in tornado

To help you get started, we’ve selected a few tornado examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github littlethunder / / View on Github external
class fanHandler(tornado.web.RequestHandler):  # 用户的粉丝

    def get(self, name):
        userid = self.get_cookie('hackerID')
        username = fetchName(userid)
        fans = showFans(name)
        fansN = len(fans)
        headpics = []
        for i in fans:
        self.render('fan.html', cookieName=username,
                    who=name, fans=fans, fansN=fansN, headpics=headpics)

class upHandler(tornado.web.RequestHandler):

    def post(self):
        selfid = self.get_cookie('hackerID')
        if selfid:
            selfname = fetchName(selfid)
            refer = self.request.headers.get('Referer')
            path = urllib.parse.urlparse(refer).path
            pathList = path.split('/')
            blogid = pathList[-1]
            addUp(blogid, selfname)
            author = showBlogAuthor(blogid)
            updateScore(author, 2)
github tunnelshade / pocuito / proxy / View on Github external
def __new__(cls, application, request, **kwargs):
        # Based on upgrade header, websocket request handler must be used
            if request.headers['Upgrade'].lower() == 'websocket':
                return CustomWebSocketHandler(application, request, **kwargs)
        except KeyError:
        return tornado.web.RequestHandler.__new__(cls, application, request, **kwargs)
github kootenpv / sky / sky / view / View on Github external
from sky.helper import extractDomain
from sky.scraper import Scraper

import json
# from textblob import TextBlob

def is_numeric(x):
        return True
    except ValueError:
        return False

class MainHandler(tornado.web.RequestHandler):

    def get(self):
        self.render('page_template.html', items=[], cached=False)

    def post(self):
            'collections_path': os.path.join(os.path.expanduser('~'), 'sky_view_collections/'),
            # 'max_workers': 10,
        args = self.request.arguments
        for arg in args:
            value = args[arg][0].decode('utf8')
            if value and arg != 'url' and arg != 'checkboxcache':
                print('pre', arg, CRAWL_CONFIG[arg])
github s57445560 / web_install_app / controller / View on Github external
ip_status = pickle.load(p_file)

    def get(self):
        message = self.get_argument('message',None)
        if message == "nojump":
        install_cookie = self.session_obj.get_seesion('install_cookie')
        install_cookie[message] = 1

class Runfabric(tornado.web.RequestHandler): # 异步处理

    def initialize(self):
        self.session_obj = Session(self)
#    def post(self):
#        self.num = message = self.get_argument('num',None)
#        os.remove("log/")
#        f1 = threading.Thread(target=self.thread_run)
#        f1.start()
#        self.write(json.dumps({'status':True}))
#    def thread_run(self):
#        self.run_status = os.system(run_dict[self.num])
    executor = ThreadPoolExecutor(1)

github koblas / spiro / spiro / web / View on Github external
from spiro.web.route import route

class RedirectHandler(tornado.web.RequestHandler):
    def get(self, path):
        return self.redirect('/#' + path)

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("main.html", production=False)

#  Post a URL to be crawled
class CrawlDataHandler(tornado.web.RequestHandler):
    def post(self, id=None):
        url = self.get_argument('url')

            if not url.startswith('http://'):
                url = "http://%s" % url

            task = Task(url, force=True)

            LogEvent("Added %s" % url).save()
        except Exception as e:
            logging.error("Exception in Adding URL", e) 
            LogEvent("Bad URL Syntax %s" % url).save()
github zynthian / zynthian-webconf / lib / View on Github external
def is_registered_for(cls, handler_name):
		return handler_name == 'UploadProgressHandler'

	def on_websocket_message(self, message):
		if message:
			self.clientId = message
		self.websocket.application.settings['upload_progress_handler'][self.clientId] = self"progress handler set for %s" % self.clientId)

	# client disconnected
	def on_close(self):
		if self.clientId in self.websocket.application.settings['upload_progress_handler']:
			del self.websocket.application.settings['upload_progress_handler'][self.clientId]

class UploadHandler(tornado.web.RequestHandler):

	def get_current_user(self):
		return self.get_secure_cookie("user")

	def get(self, errors=None):
		# is not really used
		if and"reporting percent: " +

	def post(self):
			# Use parts here!
github littlethunder / / View on Github external
fans = showFans(username)
        fansN = len(fans)
        follows = showFollows(username)
        followsN = len(follows)
        score = getScore(username)
        rank = getRank(username, score)
        self.render('user.html', headpic=headpic,
                cookieName=selfname, user=username, blogs=blogs_new,
                blogs_ask=blogs_ask_new, mail=mail, level=level, sex=sex,
                birthday=birthday, city=city, intro=intro,
                regtime=regtime, fans=fans, follows=follows,
                fansN=fansN, followsN=followsN, rank=rank,

class blogHandler(tornado.web.RequestHandler):

    def get(self, idvalue):
        selfid = self.get_cookie('hackerID')
        selfname = fetchName(selfid)
        blog = showOneBlog(idvalue)
        username = blog[1]
        blogTitle = urllib.parse.unquote(blog[2])
        blogContent_md = urllib.parse.unquote(blog[3])
        blogContent = translate(blogContent_md)
        blogTime = blog[4]
        blogTag = blog[5]
        blogCategory = blog[6]
        info = showUser(username)
        city = info[6]
        intro = info[7]
        headpic = info[9]
github bokeh / bokeh / bokeh / server / View on Github external
def _validate(self):
        if self.get_user and self.get_user_async:
            raise ValueError("Only one of get_user or get_user_async should be supplied")

        if (self.get_user or self.get_user_async) and not (self.login_url or self.get_login_url):
            raise ValueError("When user authentication is enabled, one of login_url or get_login_url must be supplied")

        if self.login_url and self.get_login_url:
            raise ValueError("At most one of login_url or get_login_url should be supplied")
        if self.login_handler and self.get_login_url:
            raise ValueError("LoginHandler cannot be used with a get_login_url() function")
        if self.login_handler and not issubclass(self.login_handler, RequestHandler):
            raise ValueError("LoginHandler must be a Tornado RequestHandler")
        if self.login_url and not probably_relative_url(self.login_url):
            raise ValueError("LoginHandler can only be used with a relative login_url")

        if self.logout_handler and not issubclass(self.logout_handler, RequestHandler):
            raise ValueError("LogoutHandler must be a Tornado RequestHandler")
        if self.logout_url and not probably_relative_url(self.logout_url):
            raise ValueError("LogoutHandler can only be used with a relative login_url")
github gmr / tinman / tinman / handlers / View on Github external
from tornado import gen
import logging
import pika
from pika.adapters import tornado_connection
from tornado import web

LOGGER = logging.getLogger(__name__)

from tinman import exceptions

message_stack = list()
pending_rabbitmq_connection = None
rabbitmq_connection = None

class RabbitMQRequestHandler(web.RequestHandler):
    """The request handler will connect to RabbitMQ on the first request,
    buffering any messages that need to be published until the Channel to
    RabbitMQ is opened, sending the stack of previously buffered messages at
    that time. If RabbitMQ closes it's connection to the app at any point, a
    connection attempt will be made on the next request.

    Expects configuration in the YAML file under a "rabbitmq" node. All of the
    configuration values are optional but username and password:

        host: Hostname, defaults to localhost if omitted
        port: RabbitMQ port, defaults to 5672 if omitted
        virtual_host: The virtual host, defaults to / if omitted
        username: The username to connect with
        password: The password to connect with
        channel_max: Maximum number of channels to allow, defaults to 0
        frame_max: The maximum byte size for an AMQP frame, defaults to 131072
github embedly / jquery-preview / demo / stream / View on Github external
def all(self):
        return self.posts

db = DB()

class MainHandler(tornado.web.RequestHandler):
    def get(self):

class Posts(tornado.web.RequestHandler):
    def get(self):

class UpdateHandler(tornado.web.RequestHandler):

    def post(self):
        #Overly verbose
        data = {}
        for name in ['type', 'original_url', 'url', 'title', 'description',
            'favicon_url', 'provider_url', 'provider_display', 'safe',
            'html', 'thumbnail_url', 'object_type', 'image_url']:
            data[name] = self.get_argument(name, None)

        # This also works
        # data = dict([(k, v[0]) for k, v in self.request.arguments.items()])
        # Save the data off and return the object that we will pass back.
        obj =

        # Write a json response