当前位置: 首页>>代码示例>>Python>>正文


Python tornado.web方法代码示例

本文整理汇总了Python中tornado.web方法的典型用法代码示例。如果您正苦于以下问题:Python tornado.web方法的具体用法?Python tornado.web怎么用?Python tornado.web使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado的用法示例。


在下文中一共展示了tornado.web方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def get(self, slug: str) -> None:  # type: ignore
        """Render the new paste form, optionally have a lexer preselected from
           the URL."""

        with database.session() as session:
            paste = (
                session.query(database.Paste)
                .filter(database.Paste.slug == slug)
                .first()
            )

            if not paste:
                raise tornado.web.HTTPError(404)

            lexers_available = utility.list_languages()

            await self.render(
                "create.html",
                lexers=["text"],  # XXX make this majority of file lexers?
                lexers_available=lexers_available,
                pagetitle="repaste",
                message=None,
                paste=paste,
            ) 
开发者ID:supakeen,项目名称:pinnwand,代码行数:26,代码来源:website.py

示例2: get

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def get(self, douban_id):
        try:
            subject = db.User.get(db.User.douban_id == douban_id)
            history = db.UserHistorical.select().where(db.UserHistorical.id == subject.id)
        except db.User.DoesNotExist:
            raise tornado.web.HTTPError(404)

        is_follower = db.Follower.select().where(
            db.Follower.follower == subject,
            db.Follower.user == self.get_current_user()
        ).exists()

        is_following = db.Following.select().where(
            db.Following.following_user == subject,
            db.Following.user == self.get_current_user()
        ).exists()

        self.render('user.html', subject=subject, history=history, is_follower=is_follower, is_following=is_following) 
开发者ID:tabris17,项目名称:doufen,代码行数:20,代码来源:handlers.py

示例3: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def __init__(self, figure):
        self.figure = figure
        self.manager = new_figure_manager_given_figure(id(figure), figure)

        super().__init__([
            # Static files for the CSS and JS
            (r'/_static/(.*)',
             tornado.web.StaticFileHandler,
             {'path': FigureManagerWebAgg.get_static_file_path()}),

            # The page that contains all of the pieces
            ('/', self.MainPage),

            ('/mpl.js', self.MplJs),

            # Sends images and events to the browser, and receives
            # events from the browser
            ('/ws', self.WebSocket),

            # Handles the downloading (i.e., saving) of static images
            (r'/download.([a-z0-9.]+)', self.Download),
        ]) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:24,代码来源:embedding_webagg_sgskip.py

示例4: require

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def require(self, **kwargs):
        def actual(handler):
            assert(issubclass(handler, tornado.web.RequestHandler))
            handler.__needcheck__ = kwargs
            category = kwargs.get('category',CATEGORY)
            if not ACL.get(category,None):ACL[category] = {}


            groupnode = kwargs.get('group', None)

            if groupnode:
                """ 分组权限 """
                ACL[category][groupnode.name] = groupnode
                groupnode.append(handler)
                handler.__checkname__ = groupnode.name
            else:
                aclnode = ACLNode(handler)
                ACL[category][aclnode.name] = aclnode
                handler.__checkname__ = aclnode.name
            

            handler.check_access  = check_access
            return handler
    
        return actual 
开发者ID:comger,项目名称:tor_access,代码行数:27,代码来源:__init__.py

示例5: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def __init__(self, figure):
        self.figure = figure
        self.manager = new_figure_manager_given_figure(
            id(figure), figure)

        super(MyApplication, self).__init__([
            # Static files for the CSS and JS
            (r'/_static/(.*)',
             tornado.web.StaticFileHandler,
             {'path': FigureManagerWebAgg.get_static_file_path()}),

            # The page that contains all of the pieces
            ('/', self.MainPage),

            ('/mpl.js', self.MplJs),

            # Sends images and events to the browser, and receives
            # events from the browser
            ('/ws', self.WebSocket),

            # Handles the downloading (i.e., saving) of static images
            (r'/download.([a-z0-9.]+)', self.Download),
        ], debug=True) 
开发者ID:pythonstock,项目名称:stock,代码行数:25,代码来源:demo-chart.py

示例6: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def __init__(self,services,object=None,wsdl=None):
		""" Initializes the application for web services

		    Instances of this class are callable and can be passed to
		    HTTPServer of tornado to serve the web services.

		    The constructor for this class takes the name for the web 
		    service (service), the class with the web service (object) 
		    and wsdl with the wsdl file path (if this exist).
		 """
		if isinstance(services,list) and object == None:
			srvs = []
			for s in services:
				srv = s[0]
				obj = s[1]
				dic = s[2]
				srvs.append((r"/" + str(srv), obj, dic))
				srvs.append((r"/" + str(srv) + "/", obj, dic))
			tornado.web.Application.__init__(self, srvs)
		else:
			self._service = services
			self._object = object
			self._services = [(r"/"+str(self._service),self._object),
					  (r"/"+str(self._service)+"/",self._object),]
			tornado.web.Application.__init__(self,self._services) 
开发者ID:bshao001,项目名称:ChatLearner,代码行数:27,代码来源:webservices.py

示例7: post

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def post(self):
		""" Method post() to process of requests and responses SOAP messages """
		def done(response):
			soapmsg = response.getSoap().toxml()
			self.write(soapmsg)
			self.finish()
		try:
			self._request = self._parseSoap(self.request.body)
			soapaction = self.request.headers['SOAPAction'].replace('"','')
			self.set_header('Content-Type','text/xml')
			for operations in dir(self):
				operation = getattr(self,operations)
				method = ''
				if callable(operation) and hasattr(operation,'_is_operation'):
					num_methods = self._countOperations()
					if hasattr(operation,'_operation') and soapaction.endswith(getattr(operation,'_operation')) and num_methods > 1:
						method = getattr(operation,'_operation') 
						self._executeOperation(operation, done, method=method)
						break
					elif num_methods == 1:
						self._executeOperation(operation, done, method='')
						break
		except Exception as detail:
			fault = soapfault('Error in web service : %s'%detail)
			self.write(fault.getSoap().toxml()) 
开发者ID:bshao001,项目名称:ChatLearner,代码行数:27,代码来源:soaphandler.py

示例8: get

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def get(self) -> None:
        raise tornado.web.HTTPError(404) 
开发者ID:supakeen,项目名称:pinnwand,代码行数:4,代码来源:api_deprecated.py

示例9: post

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def post(self) -> None:
        raise tornado.web.HTTPError(405) 
开发者ID:supakeen,项目名称:pinnwand,代码行数:4,代码来源:api_deprecated.py

示例10: write

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def write(self, chunk):
        """把给定块写到输出buffer.

        为了把输出写到网络, 使用下面的flush()方法.

        如果给定的块是一个字典, 我们会把它作为JSON来写同时会把响应头
        设置为 ``application/json``. (如果你写JSON但是设置不同的
        ``Content-Type``,  可以调用set_header *在调用write()之后* ).

        注意列表不能转换为JSON 因为一个潜在的跨域安全漏洞. 所有的JSON
        输出应该包在一个字典中. 更多细节参考
        http://haacked.com/archive/2009/06/25/json-hijacking.aspx/ 和
        https://github.com/facebook/tornado/issues/1009
        """
        if self._finished:
            raise RuntimeError("Cannot write() after finish()")
        if not isinstance(chunk, (bytes, unicode_type, dict)):
            message = "write() only accepts bytes, unicode, and dict objects"
            if isinstance(chunk, list):
                message += ". Lists not accepted for security reasons; see http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.write"
            raise TypeError(message)
        if isinstance(chunk, dict):
            chunk = escape.json_encode(chunk)
            self.set_header("Content-Type", "application/json; charset=UTF-8")
        chunk = utf8(chunk)
        self._write_buffer.append(chunk) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:28,代码来源:web.py

示例11: get_login_url

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def get_login_url(self):
        """复写这个方法自定义基于请求的登陆URL.

        默认情况下, 我们使用application设置中的 ``login_url`` 值.
        """
        self.require_setting("login_url", "@tornado.web.authenticated")
        return self.application.settings["login_url"] 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:web.py

示例12: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def __init__(self, application):
        if isinstance(application, WSGIApplication):
            self.application = lambda request: web.Application.__call__(
                application, request)
        else:
            self.application = application 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:wsgi.py

示例13: write

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def write(self, chunk: Union[str, bytes, dict]) -> None:
        """Writes the given chunk to the output buffer.

        To write the output to the network, use the `flush()` method below.

        If the given chunk is a dictionary, we write it as JSON and set
        the Content-Type of the response to be ``application/json``.
        (if you want to send JSON as a different ``Content-Type``, call
        ``set_header`` *after* calling ``write()``).

        Note that lists are not converted to JSON because of a potential
        cross-site security vulnerability.  All JSON output should be
        wrapped in a dictionary.  More details at
        http://haacked.com/archive/2009/06/25/json-hijacking.aspx/ and
        https://github.com/facebook/tornado/issues/1009
        """
        if self._finished:
            raise RuntimeError("Cannot write() after finish()")
        if not isinstance(chunk, (bytes, unicode_type, dict)):
            message = "write() only accepts bytes, unicode, and dict objects"
            if isinstance(chunk, list):
                message += (
                    ". Lists not accepted for security reasons; see "
                    + "http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.write"  # noqa: E501
                )
            raise TypeError(message)
        if isinstance(chunk, dict):
            chunk = escape.json_encode(chunk)
            self.set_header("Content-Type", "application/json; charset=UTF-8")
        chunk = utf8(chunk)
        self._write_buffer.append(chunk) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:33,代码来源:web.py

示例14: get_login_url

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import web [as 别名]
def get_login_url(self) -> str:
        """Override to customize the login URL based on the request.

        By default, we use the ``login_url`` application setting.
        """
        self.require_setting("login_url", "@tornado.web.authenticated")
        return self.application.settings["login_url"] 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:9,代码来源:web.py


注:本文中的tornado.web方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。