Commits

Ronny Pfannschmidt  committed 5367bea

update iniconfig

  • Participants
  • Parent commits 577b599

Comments (0)

Files changed (2)

File py/_iniconfig.py

         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 = {}
 
     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:
                 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:

File testing/test_iniconfig.py

     # 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)