From 77d0680b34cc5bd44aa59372811e50dfa696c056 Mon Sep 17 00:00:00 2001 From: noah morrison Date: Wed, 5 Nov 2014 21:47:05 -0500 Subject: [PATCH] Removed peek Peek had a lot of file-object calls that were not needed, and was an easy removal. --- entei.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/entei.py b/entei.py index ae11452..6753967 100755 --- a/entei.py +++ b/entei.py @@ -41,15 +41,6 @@ def tokenize(template): return data - def peek(ahead=0, amount=1): - current = template.tell() - template.seek(current + ahead) - data = template.read(amount) - template.seek(current) - if len(data) != amount: - raise EOFError() - return data - def grab_literal(until=None): until = until or l_del literal = get() @@ -87,16 +78,18 @@ def tokenize(template): if template.closed: break - tag_type = tag_types.get(peek(0, 1), 'variable') + tag_key = get(1) + tag_type = tag_types.get(tag_key, 'variable') if tag_type != 'variable': - template.seek(template.tell() + 1) + tag_key = '' - tag_key = grab_literal(r_del).strip() + tag_key += grab_literal(r_del).strip() if tag_type == 'no escape?': - if peek(0, 1) == '}': + if get(1) == '}': tag_type = 'no escape' - get(1) + else: + template.seek(template.tell() - 1) elif tag_type == 'set delimiter?': if tag_key[-1] == '=': -- 2.47.3