| | 371 | <section> |
|---|
| | 372 | <title>getRanges(content_length)</title> |
|---|
| | 373 | <para>Returns a list of (start, stop) indices from a Range request header. Returns |
|---|
| | 374 | None if no such header is provided in the request. Each (start, stop) tuple will be |
|---|
| | 375 | composed of two ints, which are suitable for use in a slicing operation. That is, the |
|---|
| | 376 | header "Range: bytes=3-6", if applied against a Python string, is requesting |
|---|
| | 377 | resource[3:7]. This function will return the list [(3, 7)].</para> |
|---|
| | 378 | </section> |
|---|
| | 379 | <section> |
|---|
| | 380 | <title>serveFile(path, contentType=None, disposition=None, name=None)</title> |
|---|
| | 381 | <para>Set status, headers, and body in order to serve the file at the given path. The |
|---|
| | 382 | Content-Type header will be set to the contentType arg, if provided. If not provided, |
|---|
| | 383 | the Content-Type will be guessed by the extension of the file. If disposition is not |
|---|
| | 384 | None, the Content-Disposition header will be set to "<disposition>; |
|---|
| | 385 | filename=<name>". If name is None, it will be set to the basename of path. If |
|---|
| | 386 | disposition is None, no Content-Disposition header will be written.</para> |
|---|
| | 387 | </section> |
|---|
| | 388 | </section> |
|---|
| | 389 | <section> |
|---|
| | 390 | <title>cherrypy.lib.covercp</title> |
|---|
| | 391 | <para>This module both provides code-coverage tools, and may also be run as a script. To |
|---|
| | 392 | use this module, or the coverage tools in the test suite, you need to download |
|---|
| | 393 | 'coverage.py', either Gareth Rees' <ulink url="???">original implementation</ulink> or |
|---|
| | 394 | Ned Batchelder's <ulink |
|---|
| | 395 | url="http://www.nedbatchelder.com/code/modules/coverage.html">enhanced |
|---|
| | 396 | version</ulink>.</para> |
|---|
| | 397 | <para>Set cherrypy.codecoverage to True to turn on coverage tracing. Then, use the |
|---|
| | 398 | covercp.serve() function to browse the results in a web browser. If you run this module |
|---|
| | 399 | as a script (i.e., from the command line), it will call serve() for you.</para> |
|---|
| | 400 | </section> |
|---|
| | 401 | <section> |
|---|
| | 402 | <title>cherrypy.lib.profiler</title> |
|---|
| | 403 | <para>You can profile any of your page handlers (exposed methods) as follows:</para> |
|---|
| | 404 | <example> |
|---|
| | 405 | <title>Profiling example</title> |
|---|
| | 406 | <para> |
|---|
| | 407 | <code>from cherrypy.lib import profile class Root: p = |
|---|
| | 408 | profile.Profiler("/path/to/profile/dir") def index(self): self.p.run(self._index) |
|---|
| | 409 | index.exposed = True def _index(self): return "Hello, world!" cherrypy.root = |
|---|
| | 410 | Root()</code> |
|---|
| | 411 | |
|---|
| | 412 | </para> |
|---|
| | 413 | </example> |
|---|
| | 414 | <para>Set the config entry: "profiling.on = True" if you'd rather turn on profiling for |
|---|
| | 415 | all requests. Then, use the serve() function to browse the results in a web browser. If |
|---|
| | 416 | you run this module as a script (i.e., from the command line), it will call serve() for |
|---|
| | 417 | you.</para> |
|---|
| | 418 | <para>Developers: this module should be used whenever you make significant changes to |
|---|
| | 419 | CherryPy, to get a quick sanity-check on the performance of the request process. Basic |
|---|
| | 420 | requests should complete in about 5 milliseconds on a reasonably-fast machine running |
|---|
| | 421 | Python 2.4 (Python 2.3 will be much slower due to threadlocal being implemented in |
|---|
| | 422 | Python, not C). You can profile the test suite by supplying the --profile option to |
|---|
| | 423 | test.py.</para> |
|---|