[py-svn] pylib commit 5367bea2f477: update iniconfig

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sat Nov 6 00:46:34 CET 2010


# HG changeset patch -- Bitbucket.org
# Project pylib
# URL http://bitbucket.org/hpk42/pylib/overview
# User Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
# Date 1288999101 -3600
# Node ID 5367bea2f47738bdefa9eb55752e5a2a4b0e841b
# Parent  577b5991dbceffe0887001c8597fd9a2f4d50023
update iniconfig

--- a/testing/test_iniconfig.py
+++ b/testing/test_iniconfig.py
@@ -92,7 +92,7 @@ def parse(input):
     # only for testing purposes - _parse() does not use state except path
     ini = object.__new__(IniConfig)
     ini.path = "sample"
-    return ini._parse(input)
+    return ini._parse(input.splitlines(True))
 
 def parse_a_error(input):
     return py.test.raises(ParseError, parse, input)

--- a/py/_iniconfig.py
+++ b/py/_iniconfig.py
@@ -46,10 +46,13 @@ class IniConfig(object):
         self.path = str(path) # convenience
         if data is None:
             f = open(self.path)
-            data = f.read()
-            f.close()
-        tokens = self._parse(data)
-        
+            try:
+                tokens = self._parse(iter(f))
+            finally:
+                f.close()
+        else:
+            tokens = self._parse(data.splitlines(True))
+
         self._sources = {}
         self.sections = {}
 
@@ -69,10 +72,10 @@ class IniConfig(object):
     def _raise(self, lineno, msg):
         raise ParseError(self.path, lineno, msg)
 
-    def _parse(self, data):
+    def _parse(self, line_iter):
         result = []
         section = None
-        for lineno, line in enumerate(data.splitlines(True)):
+        for lineno, line in enumerate(line_iter):
             name, data = self._parseline(line, lineno)
             # new value
             if name is not None and data is not None:
@@ -116,7 +119,7 @@ class IniConfig(object):
                 try:
                     name, value = line.split(": ", 1)
                 except ValueError:
-                    self._raise(lineno, 'unexpected line: %s')
+                    self._raise(lineno, 'unexpected line: %r' % line)
             return name.strip(), value.strip()
         # continuation
         else:



More information about the pytest-commit mailing list