From 9a5ef0f23953f89b2eec60f0554c94cba355fc28 Mon Sep 17 00:00:00 2001 From: Alec Warner Date: Sun, 1 Apr 2007 04:32:13 +0000 Subject: [PATCH] I consulted the python oracle and it told me enumerate was better, so go team enumerate svn path=/main/trunk/; revision=6330 --- pym/portage/env/loaders.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pym/portage/env/loaders.py b/pym/portage/env/loaders.py index b38670816..6bfcce77b 100644 --- a/pym/portage/env/loaders.py +++ b/pym/portage/env/loaders.py @@ -4,7 +4,6 @@ # $Id$ import os -from itertools import izip, count class LoaderError(Exception): @@ -91,19 +90,19 @@ class ItemFileLoader(DataLoader): errors = {} for file in RecursiveFileLoader(self.fname): f = open(file, 'rb') - for line_num, line in izip(count(1),f): + for line_num, line in enumerate(f): if line.startswith('#'): continue split = line.strip().split() if not len(split): errors.setdefault(self.fname,[]).append( "Malformed data at line: %s, data: %s" - % (line_num, split)) + % (line_num + 1, split)) key = split[0] if not self._validator.validate(key): errors.setdefault(self.fname,[]).append( "Validation failed at line: %s, data %s" - % (line_num, split)) + % (line_num + 1, split)) continue data[key] = None return (data,errors) @@ -128,21 +127,21 @@ class KeyListFileLoader(DataLoader): errors = {} for file in RecursiveFileLoader(self.fname): f = open(file, 'rb') - for line_num, line in izip(count(1),f): + for line_num, line in enumerate(f): if line.startswith('#'): continue split = line.strip().split() if len(split) < 2: errors.setdefault(self.fname,[]).append( "Malformed data at line: %s, data: %s" - % (line_num, split)) + % (line_num + 1, split)) continue key = split[0] value = split[1:] if not self._validator.validate(key): errors.setdefault(self.fname,[]).append( "Validation failed at line: %s, data %s" - % (line_num, split)) + % (line_num + 1, split)) continue if key in data: data[key].append(value) @@ -185,21 +184,20 @@ class KeyValuePairFileLoader(DataLoader): errors = {} for file in RecursiveFileLoader(self.fname): f = open(file, 'rb') - for line_num, line in izip(count(1),f): - line_count = line_count + 1 # Increment line count + for line_num, line in enumerate(f): if line.startswith('#'): continue split = line.strip().split('=') if len(split) < 2: errors.setdefault(self.fname,[]).append( "Malformed data at line: %s, data %s" - % (line_count, split)) + % (line_num + 1, split)) key = split[0] value = split[1:] if not self._validator.validate(key): errors.setdefault(self.fname,[]).append( "Validation failed at line: %s, data %s" - % (line_count, split)) + % (line_num + 1, split)) continue if key in data: data[key].append(value) -- 2.26.2