當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。