Changeset 316:8b6a594b3761
- Timestamp:
- 2007-09-02 16:36:05
(1 year ago)
- Author:
- Stefan Schwarzer <sschwarzer@sschwarzer.net>
- branch:
- default
- Message:
Added some code to test the effect on render time when
syntax-highlighted pages rendered by Pygments are cached.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r298 |
r316 |
|
| 30 | 30 | import os |
|---|
| 31 | 31 | import sys |
|---|
| | 32 | import time |
|---|
| 32 | 33 | import urllib |
|---|
| 33 | 34 | import urlparse |
|---|
| … | … | |
| 103 | 104 | self.emit_data(data=self.get_file(source_path, raw=True), |
|---|
| 104 | 105 | content_type=content_type) |
|---|
| | 106 | |
|---|
| 105 | 107 | # |
|---|
| 106 | 108 | # HTTP-specific processing |
|---|
| … | … | |
| 171 | 173 | Handle HTTP GET request. |
|---|
| 172 | 174 | """ |
|---|
| | 175 | start_time = time.time() |
|---|
| | 176 | self._time = None |
|---|
| 173 | 177 | # reject forbidden clients |
|---|
| 174 | 178 | if config.allowed_clients is not config.ALL_CLIENTS and \ |
|---|
| … | … | |
| 231 | 235 | h1_class=h1_class, |
|---|
| 232 | 236 | use_header_and_footer=use_header_and_footer) |
|---|
| | 237 | print "Render time:", time.time() - start_time, "s" |
|---|
| 233 | 238 | |
|---|
| 234 | 239 | # |
|---|
| r315 |
r316 |
|
| 199 | 199 | return u"\n".join(('<pre>', cgi.escape(text), '</pre>')) |
|---|
| 200 | 200 | |
|---|
| 201 | | def text_to_html(text, path): |
|---|
| | 201 | def text_to_html(text, path, _cache={}): |
|---|
| 202 | 202 | """ |
|---|
| 203 | 203 | Convert the unicode string `text` to HTML and return the HTML |
|---|
| … | … | |
| 207 | 207 | if not pygmentsfinder.found_pygments: |
|---|
| 208 | 208 | return dumb_text_to_html(text) |
|---|
| | 209 | #TODO make cache handling threadsafe when Websourcebrowser |
|---|
| | 210 | # works multithreaded |
|---|
| | 211 | if (text, path) in _cache: |
|---|
| | 212 | return _cache[text, path] |
|---|
| 209 | 213 | try: |
|---|
| 210 | 214 | # assume the link doesn't point to a link or at least has |
|---|
| … | … | |
| 222 | 226 | formatter = pygmentsfinder.formatters.HtmlFormatter( |
|---|
| 223 | 227 | linenos=config.line_numbers) |
|---|
| 224 | | return pygmentsfinder.pygments.highlight(text, lexer, formatter) |
|---|
| | 228 | html = pygmentsfinder.pygments.highlight(text, lexer, formatter) |
|---|
| | 229 | _cache[text, path] = html |
|---|
| | 230 | return html |
|---|
| 225 | 231 | |
|---|
| 226 | 232 | def image_to_html(url): |
|---|