Skip to content

Commit

Permalink
Merge pull request gstein#17 from sebbASF/lint
Browse files Browse the repository at this point in the history
Linting
  • Loading branch information
gstein authored Apr 6, 2023
2 parents ca48025 + 5474d9a commit 943d7b2
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions ezt.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def readtext(fname):
# replace the relevant pieces, and then put it all back together. splitting
# will produce a list of: TEXT ( splitter TEXT )*. splitter will be '%' or
# an integer.
_re_subst = re.compile('%(%|[0-9]+)')
_re_subst = re.compile(r'%(%|\d+)')

class Template:

Expand Down Expand Up @@ -237,7 +237,7 @@ def _parse(self, reader, for_names=None, file_args=(), base_printer=None):
if cmd == 'format':
printers.pop()
else:
func = getattr(self, '_cmd_' + re.sub('-', '_', cmd))
func = getattr(self, '_cmd_' + cmd.replace('-', '_'))
program[idx:] = [ (func, (args, true_section, else_section),
filename, line_number) ]
if cmd == 'for':
Expand Down Expand Up @@ -390,17 +390,17 @@ def _cmd_if_any(self, args, fp, ctx, filename, line_number):
break
self._do_if(value, t_section, f_section, fp, ctx)

def _cmd_if_index(self, args, fp, ctx, filename, line_number):
def _cmd_if_index(self, args, fp, ctx, _filename, _line_number):
((valref, value), t_section, f_section) = args
list, idx = ctx.for_index[valref[0]]
items, idx = ctx.for_index[valref[0]]
if value == 'even':
value = idx % 2 == 0
elif value == 'odd':
value = idx % 2 == 1
elif value == 'first':
value = idx == 0
elif value == 'last':
value = idx == len(list)-1
value = idx == len(items)-1
else:
value = idx == int(value)
self._do_if(value, t_section, f_section, fp, ctx)
Expand All @@ -425,17 +425,17 @@ def _do_if(self, value, t_section, f_section, fp, ctx):

def _cmd_for(self, args, fp, ctx, filename, line_number):
((valref,), unused, section) = args
list = _get_value(valref, ctx, filename, line_number)
items = _get_value(valref, ctx, filename, line_number)
refname = valref[0]
if isinstance(list, basestring):
if isinstance(items, basestring):
raise NeedSequenceError(refname, filename, line_number)
ctx.for_index[refname] = idx = [ list, 0 ]
for item in list:
ctx.for_index[refname] = idx = [ items, 0 ]
for _item in items:
self._execute(section, fp, ctx)
idx[1] = idx[1] + 1
del ctx.for_index[refname]

def _cmd_define(self, args, fp, ctx, filename, line_number):
def _cmd_define(self, args, _fp, ctx, _filename, _line_number):
((name,), unused, section) = args
valfp = StringIO()
if section is not None:
Expand Down Expand Up @@ -512,8 +512,8 @@ def _get_value(refname_start_rest, ctx, filename, line_number):

# get the starting object
if start in ctx.for_index:
list, idx = ctx.for_index[start]
ob = list[idx]
items, idx = ctx.for_index[start]
ob = items[idx]
elif start in ctx.defines:
ob = ctx.defines[start]
elif hasattr(ctx.data, start):
Expand Down

0 comments on commit 943d7b2

Please sign in to comment.