免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: 瘦青蛙

snakelets 文档,我翻译了一部分。 [复制链接]

论坛徽章:
0
发表于 2005-09-01 11:13 |显示全部楼层

snakelets 文档,我翻译了一部分。

WebApp

Snakelets run inside a WebApp context (snakeserver.webapp.WebApp). You can get the current WebApp object by calling getWebApp() on the request or the snakelet object itself. You can then use the following methods from the webapp:
Snakelet在WebApp 环境中运行(snakeserver.webapp.WebApp)。您可以在请求或snakelet对象中通过调用getWebApp()得到当前的WebApp对象。


Method                  Description

    getName()       
    a tuple: (short name, full name). The short name is taken from the webapp directory it is in. Full name is specified in the webapp descriptor __init__.py file.a tuple: (short name ,full name)(好像是参数吧?)Name从webapp的目录中得到。全名被指定在webapp的描述文件 __init__.py中。

    getVirtualHost()         
    a tuple (hostname, portnumber) of the 'virtual host' this webapp is running on. Does not take vhost aliasing in account; if you need the 'real' vhost and port that the request arrived on, use request.getServerName().正在运行该webapp的’虚拟主机’ 的tuple (hostname, portnumber)。请不要与vhost混淆;当请求到达是如果您需要真实vhost和端口,请使用request.getServerName()。

    isEnabled()       
    is the webapp enabled? (True or False)webapp是否允许?(True / False)。

    setEnabled(enabled)       
    enable or disable this webapp开启或关闭webapp

    getFileSystemPath()       
    the filesystem path where the webapp's files are located得到当前的webapp文件的文件系统路径

    getDocRootPath()        
    the web document root, where the pages, images, etc are locatedweb 文档根,放置页面,图片的地方。

    getContext()        
    webapp context (ContextContainer object). Scope: web app. shared for all users/requestswebapp context(ContextContainer 对象)。范围:web app。对所有用户和请求共享

    getURLprefix()       
    the URL prefix that is used for urls inside this webapp (example: "/shop/" This prefix includes the (optional) server-wide prefix.得到 用于webapp url中的URL前缀(比如:”/shop/”),包括(可选择)server-wide前缀。

    getAssetprefix()        
    the asset base location as specified in the WebApp's config file.得到在WebApp的配置文件中所制定的资源路径前缀。

    mkUrl(path)mkUrl(path, arg="", params=[], htmlescape=True)         
    create a correct URL based on the webapp's url prefix, and automatically html-escapes the resulting string so you can directly use it in your html output. arg (optional) can be given a string that should become the url 'arg'. params (optional) can be given a dict or a sequence that contains the name/values that should become the query params. By setting the optional htmlescape param to False, no escaping will be done (and the resulting string can no longer be directly used in html output because there is a risk of generating invalid html) 建立正确的基于webapp url的前缀,并且对结果字符串自动进行html-escapes ,因此您可以在html输出中直接使用。arg(可选)参数,可以传递字符串作为url ‘arg’。 params (可选)参数,可以传递包括 name/values的dict或序列。设置 htmlescape参数为False,将不会进行html的escape操作(结果将不能直接用于html输出,因为这里在产生错误页面是存在安全问题)。


    mkAssetUrl(path)
    mkAssetUrl(path, htmlescape=True)
           
    create a correct URL for the static asset (images, files etc) based on the asset base location. It automatically html-escapes the resulting string so you can directly use it in your html output. By setting the optional htmlescape param to False, no escaping will be done (and the resulting string can no longer be directly used in html output because there is a risk of generating invalid html) 为静态资源创建正确的URL(images, files 等等)基于本地资源。自动对结果字符串进行html-escape,您可以在html的输出中直接使用它。通过修改 htmlescape参数选项可以关闭此功能。

    getSnakelet(urlpattern)         
    returns the snakelet instance belonging to the given urlpattern (from the webapp init file)从webapp的init文件中返回属于给出的urlpattern(url样式)的snakelet实例。

    getConfigItems()        
    the dictionary of all user config items所有用户配置选想的目录。

    getConfigItem(item)        
    the value of a single user config item单个用户配置项的值。

    addPlugin(plugin)        
    add a webapp-specific plugin (for instance to do things at session creation time). plugin is your plugin instance. If a plugin with the same name already exists, a ValueError will be raised. If your webapp is deployed on multiple vhosts, you should be prepared for this (the webapp's init code will be called multiple times). For more info, see the section on plugins.添加一个特殊插件。如果此插件名称已经存在,将产生一个ValueError的错误,如果您的webapp搭建在复合vhost上,您应该提前做好准备(wbapp的初始化代码段会被重复调用)。更多信息,请见章节 plugins


    serveStaticFile(filename, response, useResponseHeaders=False)             
    Use the server's internal code to serve a static file to the client. This is useful in snakelets that return files (such as download controllers). You can fool around with setting the correct headers, and reading/writing the file efficiently to the response stream yourself, but it's usually much better to use this function instead. The response object must not be used prior to this call. You cannot set custom HTTP headers, but the required ones will be generated for you automatically (such as content-lenth). The filename must be the absolute path to to file that must be served. This must be the last action in your snakelet that generates output (the response's output must not be used at all) The file serve loop is quite efficient, and will use the sendfile system call if available. NOTE: the server's RequestPlugins are not invoked on static files! (partly due to the efficient stripped down processing code for static files to obtain higher performance) The useResponseHeaders parameter tells the server if it should add the HTTP headers from the request object (such as Cache-Control, Content-Disposition and other headers). Defaults to False. 使用内部代码为客户端提供静态文件服务。对于返回文件来说这是非常实用的(比如下载控制)。你可以通过设置正确的header 和 有效率地 读/写 文件 来反馈数据流,但是通常最好的做法是用这个函数来代替它。Response 对象一定不能在调用这个函数之前使用。您不能设置自定义的HTTP header,被请求的响应会自动帮您生成相应的header(比如 content-lenth)。提供文件服务的文件名必须是绝对路径。这必须是在snakelet中最后执行的动作,它提供的文件输出(反馈输出一定不能使用)服务循环是很高效的、如果可能还将运用到文件传送系统。主意:RequestPlugin 不能在静态文件中被导入!(部分由于分开的处理代码分别对静态文件进行处理,所以效率很高??)useResponseHeader参数告诉server是否添加HTTP header(比如 Cache-Control, Content-Disposition 或者其他)。默认是False.

Snakelets manual - Back to index

论坛徽章:
0
发表于 2005-09-01 11:24 |显示全部楼层

snakelets 文档,我翻译了一部分。

学校放暑假了,一直在家里玩 wow  

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:55:28
发表于 2005-09-01 11:51 |显示全部楼层

snakelets 文档,我翻译了一部分。

多谢谢楼主
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP