From 5527f61b6639e6ed299a38c67c8ca0d59d2c7f97 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 24 Sep 2018 22:12:55 +0200 Subject: [PATCH] properly handle binary when checking for template #58 --- dotdrop/templategen.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dotdrop/templategen.py b/dotdrop/templategen.py index af422bc..06138d3 100644 --- a/dotdrop/templategen.py +++ b/dotdrop/templategen.py @@ -114,8 +114,12 @@ class Templategen: """test if file pointed by path is a template""" if not os.path.isfile(path): return False - with open(path, 'r') as f: - data = f.read() + try: + with open(path, 'r') as f: + data = f.read() + except UnicodeDecodeError: + # is binary so surely no template + return False markers = [BLOCK_START, VAR_START, COMMENT_START] for marker in markers: if marker in data: