Mercurial > piecrust2
comparison piecrust/templating/jinjaengine.py @ 738:b91fe30ae7aa
internal: Remove threading stuff we don't need anymore.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 02 Jun 2016 13:00:36 -0700 |
parents | f0a3af3fbea2 |
children | f6f9a284a5f3 |
comparison
equal
deleted
inserted
replaced
737:8b3dfd91cbf6 | 738:b91fe30ae7aa |
---|---|
1 import re | 1 import re |
2 import time | 2 import time |
3 import os.path | 3 import os.path |
4 import hashlib | 4 import hashlib |
5 import logging | 5 import logging |
6 import threading | |
7 import email.utils | 6 import email.utils |
8 import strict_rfc3339 | 7 import strict_rfc3339 |
9 from jinja2 import Environment, FileSystemLoader, TemplateNotFound | 8 from jinja2 import Environment, FileSystemLoader, TemplateNotFound |
10 from jinja2.exceptions import TemplateSyntaxError | 9 from jinja2.exceptions import TemplateSyntaxError |
11 from jinja2.ext import Extension, Markup | 10 from jinja2.ext import Extension, Markup |
446 class PieCrustCacheExtension(Extension): | 445 class PieCrustCacheExtension(Extension): |
447 tags = set(['pccache', 'cache']) | 446 tags = set(['pccache', 'cache']) |
448 | 447 |
449 def __init__(self, environment): | 448 def __init__(self, environment): |
450 super(PieCrustCacheExtension, self).__init__(environment) | 449 super(PieCrustCacheExtension, self).__init__(environment) |
451 self._lock = threading.RLock() | |
452 | |
453 environment.extend( | 450 environment.extend( |
454 piecrust_cache_prefix='', | 451 piecrust_cache_prefix='', |
455 piecrust_cache={} | 452 piecrust_cache={} |
456 ) | 453 ) |
457 | 454 |
488 pair = self.environment.piecrust_cache.get(key) | 485 pair = self.environment.piecrust_cache.get(key) |
489 if pair is not None: | 486 if pair is not None: |
490 rdr_pass.used_source_names.update(pair[1]) | 487 rdr_pass.used_source_names.update(pair[1]) |
491 return pair[0] | 488 return pair[0] |
492 | 489 |
493 with self._lock: | 490 pair = self.environment.piecrust_cache.get(key) |
494 pair = self.environment.piecrust_cache.get(key) | 491 if pair is not None: |
495 if pair is not None: | 492 rdr_pass.used_source_names.update(pair[1]) |
496 rdr_pass.used_source_names.update(pair[1]) | 493 return pair[0] |
497 return pair[0] | 494 |
498 | 495 prev_used = rdr_pass.used_source_names.copy() |
499 prev_used = rdr_pass.used_source_names.copy() | 496 rv = caller() |
500 rv = caller() | 497 after_used = rdr_pass.used_source_names.copy() |
501 after_used = rdr_pass.used_source_names.copy() | 498 used_delta = after_used.difference(prev_used) |
502 used_delta = after_used.difference(prev_used) | 499 self.environment.piecrust_cache[key] = (rv, used_delta) |
503 self.environment.piecrust_cache[key] = (rv, used_delta) | 500 return rv |
504 return rv | |
505 | 501 |
506 | 502 |
507 class PieCrustSpacelessExtension(HtmlCompressor): | 503 class PieCrustSpacelessExtension(HtmlCompressor): |
508 """ A re-implementation of `SelectiveHtmlCompressor` so that we can | 504 """ A re-implementation of `SelectiveHtmlCompressor` so that we can |
509 both use `strip` or `spaceless` in templates. | 505 both use `strip` or `spaceless` in templates. |