summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bottle.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/bottle.py b/bottle.py
index 0894d57..a5c16c1 100644
--- a/bottle.py
+++ b/bottle.py
@@ -3340,7 +3340,10 @@ class SimpleTemplate(BaseTemplate):
@cached_property
def code(self):
- source = self.source or open(self.filename, 'rb').read()
+ source = self.source
+ if not source:
+ with open(self.filename, 'rb') as f:
+ source = f.read()
try:
source, encoding = touni(source), 'utf8'
except UnicodeError: