[py-svn] commit/py: hpk42: change iniconfig behaviour to only recognise comment chars if they start the line

Bitbucket commits-noreply at bitbucket.org
Fri Jun 8 16:55:11 CEST 2012


1 new commit in py:


https://bitbucket.org/hpk42/py/changeset/8af99f47795c/
changeset:   8af99f47795c
user:        hpk42
date:        2012-06-08 16:55:05
summary:     change iniconfig behaviour to only recognise comment chars if they start the line
affected #:  5 files

diff -r 6be37b7cb55c6ac1da9e9afa4dbbae6c1f499fd2 -r 8af99f47795c5549af4f83f525904c778a036a04 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,9 @@
+Changes between 1.4.8 and 1.4.9.DEV
+==================================================
+
+- changed iniconfig parsing to better conform, now the chars ";"
+  and "#" only mark a comment at the stripped start of a line
+
 Changes between 1.4.7 and 1.4.8
 ==================================================
 


diff -r 6be37b7cb55c6ac1da9e9afa4dbbae6c1f499fd2 -r 8af99f47795c5549af4f83f525904c778a036a04 py/__init__.py
--- a/py/__init__.py
+++ b/py/__init__.py
@@ -8,7 +8,7 @@
 
 (c) Holger Krekel and others, 2004-2010
 """
-__version__ = '1.4.8'
+__version__ = '1.4.9.dev1'
 
 from py import _apipkg
 


diff -r 6be37b7cb55c6ac1da9e9afa4dbbae6c1f499fd2 -r 8af99f47795c5549af4f83f525904c778a036a04 py/_iniconfig.py
--- a/py/_iniconfig.py
+++ b/py/_iniconfig.py
@@ -5,6 +5,8 @@
 
 __all__ = ['IniConfig', 'ParseError']
 
+COMMENTCHARS = "#;"
+
 class ParseError(Exception):
     def __init__(self, path, lineno, msg):
         Exception.__init__(self, path, lineno, msg)
@@ -101,15 +103,21 @@
         return result
 
     def _parseline(self, line, lineno):
-        # comments
-        line = line.split('#')[0].rstrip()
-        line = line.split(';')[0].rstrip()
         # blank lines
+        if iscommentline(line):
+            line = ""
+        else:
+            line = line.rstrip()
         if not line:
             return None, None
         # section
-        if line[0] == '[' and line[-1] == ']':
-            return line[1:-1], None
+        if line[0] == '[':
+            realline = line
+            for c in COMMENTCHARS:
+                line = line.split(c)[0].rstrip()
+            if line[-1] == "]":
+                return line[1:-1], None
+            return None, realline.strip()
         # value
         elif not line[0].isspace():
             try:
@@ -148,3 +156,7 @@
 
     def __contains__(self, arg):
         return arg in self.sections
+
+def iscommentline(line):
+    c = line.lstrip()[:1]
+    return c in COMMENTCHARS


diff -r 6be37b7cb55c6ac1da9e9afa4dbbae6c1f499fd2 -r 8af99f47795c5549af4f83f525904c778a036a04 setup.py
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@
         name='py',
         description='library with cross-python path, ini-parsing, io, code, log facilities',
         long_description = open('README.txt').read(),
-        version='1.4.8',
+        version='1.4.9.dev1',
         url='http://pylib.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],


diff -r 6be37b7cb55c6ac1da9e9afa4dbbae6c1f499fd2 -r 8af99f47795c5549af4f83f525904c778a036a04 testing/test_iniconfig.py
--- a/testing/test_iniconfig.py
+++ b/testing/test_iniconfig.py
@@ -1,5 +1,7 @@
 import py
+import pytest
 from py._iniconfig import IniConfig, ParseError, __all__ as ALL
+from py._iniconfig import iscommentline
 from textwrap import dedent
 
 def pytest_generate_tests(metafunc):
@@ -57,7 +59,7 @@
         []
     ),
     'comment on value': (
-        'value = 1 # comment',
+        'value = 1',
         [(0, None, 'value', '1')]
     ),
 
@@ -69,10 +71,6 @@
         '; comment',
         []
     ),
-    'comment2 on value': (
-        'value = 1 ; comment',
-        [(0, None, 'value', '1')]
-    ),
 
     'comment2 on section': (
         '[section] ;comment',
@@ -100,7 +98,7 @@
     ),
 
 }
-   
+
 def parse(input):
     # only for testing purposes - _parse() does not use state except path
     ini = object.__new__(IniConfig)
@@ -184,7 +182,7 @@
     assert config.lineof('section2') == 3
     assert config.lineof('section', 'value') == 2
     assert config.lineof('section2','value') == 5
-    
+
     assert config['section'].lineof('value') == 2
     assert config['section2'].lineof('value') == 5
 
@@ -288,3 +286,14 @@
 
 def test_api_import():
     assert ALL == ['IniConfig', 'ParseError']
+
+ at pytest.mark.parametrize("line", [
+    "#qwe",
+    "  #qwe",
+    ";qwe",
+    " ;qwe",
+])
+def test_iscommentline_true(line):
+    assert iscommentline(line)
+
+

Repository URL: https://bitbucket.org/hpk42/py/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list