Podobne

[ Pobierz całość w formacie PDF ]

class in cherrypy.lib.sessions globals. For example,  file will use the FileSession class.
path The  path value to stick in the response cookie metadata.
path_header If  path is None (the default), then the response cookie  path will be pulled from re-
quest.headers[path_header].
name The name of the cookie.
timeout The expiration timeout (in minutes) for the stored session data. If  persistent is True (the default), this
is also the timeout for the cookie.
domain The cookie domain.
secure If False (the default) the cookie  secure value will not be set. If True, the cookie  secure value will be
set (to 1).
clean_freq (minutes) The poll rate for expired session cleanup.
persistent If True (the default), the  timeout argument will be used to expire the cookie. If False, the cookie
will not have an expiry, and the cookie will be a  session cookie which expires when the browser is
closed.
7.13. cherrypy.lib 147
CherryPy Documentation, Release 3.2.4
httponly If False (the default) the cookie  httponly value will not be set. If True, the cookie  httponly value
will be set (to 1).
Any additional kwargs will be bound to the new Session instance, and may be specific to the storage type. See
the subclass of Session you re using for more information.
cherrypy.lib.sessions.set_response_cookie(path=None, path_header=None,
name= session_id , timeout=60, domain=None,
secure=False, httponly=False)
Set a response cookie for the client.
path the  path value to stick in the response cookie metadata.
path_header if  path is None (the default), then the response cookie  path will be pulled from re-
quest.headers[path_header].
name the name of the cookie.
timeout the expiration timeout for the cookie. If 0 or other boolean False, no  expires param will be set, and
the cookie will be a  session cookie which expires when the browser is closed.
domain the cookie domain.
secure if False (the default) the cookie  secure value will not be set. If True, the cookie  secure value will be
set (to 1).
httponly If False (the default) the cookie  httponly value will not be set. If True, the cookie  httponly value
will be set (to 1).
cherrypy.lib.sessions.expire()
Expire the current session cookie.
7.13.15 cherrypy.lib.static
Functions
cherrypy.lib.static.serve_file(path, content_type=None, disposition=None, name=None, de-
bug=False)
Set status, headers, and body in order to serve the given path.
The Content-Type header will be set to the content_type arg, if provided. If not provided, the Content-Type will
be guessed by the file extension of the  path argument.
If disposition is not None, the Content-Disposition header will be set to  ; filename= . If
name is None, it will be set to the basename of path. If disposition is None, no Content-Disposition header will
be written.
cherrypy.lib.static.serve_fileobj(fileobj, content_type=None, disposition=None,
name=None, debug=False)
Set status, headers, and body in order to serve the given file object.
The Content-Type header will be set to the content_type arg, if provided.
If disposition is not None, the Content-Disposition header will be set to  ; filename= . If
name is None,  filename will not be set. If disposition is None, no Content-Disposition header will be written.
CAUTION: If the request contains a  Range header, one or more seek()s will be performed on the file object.
This may cause undesired behavior if the file object is not seekable. It could also produce undesired results if
the caller set the read position of the file object prior to calling serve_fileobj(), expecting that the data would be
served starting from that position.
148 Chapter 7. Reference Manual
CherryPy Documentation, Release 3.2.4
cherrypy.lib.static.serve_download(path, name=None)
Serve  path as an application/x-download attachment.
cherrypy.lib.static.staticdir(section, dir, root=  , match=  , content_types=None, index=  ,
debug=False)
Serve a static resource from the given (root +) dir.
match If given, request.path_info will be searched for the given regular expression before attempting to serve
static content.
content_types If given, it should be a Python dictionary of {file-extension: content-type} pairs, where  file-
extension is a string (e.g.  gif ) and  content-type is the value to write out in the Content-Type response
header (e.g.  image/gif ).
index If provided, it should be the (relative) name of a file to serve for directory requests. For example, if
the dir argument is  /home/me , the Request-URI is  myapp , and the index arg is  index.html , the file
 /home/me/myapp/index.html will be sought.
cherrypy.lib.static.staticfile(filename, root=None, match=  , content_types=None, de-
bug=False)
Serve a static resource from the given (root +) filename.
match If given, request.path_info will be searched for the given regular expression before attempting to serve
static content.
content_types If given, it should be a Python dictionary of {file-extension: content-type} pairs, where  file-
extension is a string (e.g.  gif ) and  content-type is the value to write out in the Content-Type response
header (e.g.  image/gif ).
7.13.16 cherrypy.lib.xmlrpcutil
Functions
cherrypy.lib.xmlrpcutil.process_body()
Return (params, method) from request body.
cherrypy.lib.xmlrpcutil.patched_path(path)
Return  path , doctored for RPC.
cherrypy.lib.xmlrpcutil.respond(body, encoding= utf-8 , allow_none=0)
cherrypy.lib.xmlrpcutil.on_error(*args, **kwargs)
7.14 cherrypy.process
7.14.1 cherrypy.process.servers HTTP Server interfaces
Starting in CherryPy 3.1, cherrypy.server is implemented as an Engine Plu-
gin. It s an instance of cherrypy._cpserver.Server, which is a subclass of
cherrypy.process.servers.ServerAdapter. The ServerAdapter class is designed to control
other servers, as well.
Multiple servers/ports
If you need to start more than one HTTP server (to serve on multiple ports, or protocols, etc.), you can manually
register each one and then start them all with engine.start:
7.14. cherrypy.process 149
CherryPy Documentation, Release 3.2.4
s1 = ServerAdapter(cherrypy.engine, MyWSGIServer(host= 0.0.0.0 , port=80))
s2 = ServerAdapter(cherrypy.engine, another.HTTPServer(host= 127.0.0.1 , SSL=True))
s1.subscribe()
s2.subscribe()
cherrypy.engine.start()
FastCGI/SCGI
There are also FlupFCGIServer and FlupSCGIServer classes incherrypy.process.servers. To start an fcgi
server, for example, wrap an instance of it in a ServerAdapter:
addr = ( 0.0.0.0 , 4000)
f = servers.FlupFCGIServer(application=cherrypy.tree, bindAddress=addr)
s = servers.ServerAdapter(cherrypy.engine, httpserver=f, bind_addr=addr)
s.subscribe()
The cherryd startup script will do the above for you via its -f flag. Note that you need to download and install flup
yourself, whether you usecherrydor not.
FastCGI
A very simple setup lets your cherry run with FastCGI. You just need the flup library, plus a running Apache server
(withmod_fastcgi) or lighttpd server.
CherryPy code hello.py:
#!/usr/bin/python
import cherrypy
class HelloWorld:
"""Sample request handler class."""
def index(self):
return "Hello world!"
index.exposed = True
cherrypy.tree.mount(HelloWorld()) [ Pobierz całość w formacie PDF ]




Powered by MyScript