@@ -561,20 +561,15 @@ def __init__(self):
561561 self .errors = list ()
562562
563563
564- class _LineParser :
564+ class _Line (str ):
565+ __slots__ = 'clean' , 'has_comments'
565566
566- def __init__ ( self , comments ):
567- self . comments = comments
567+ def __new__ ( cls , val , * args , ** kwargs ):
568+ return super (). __new__ ( cls , val )
568569
569- @property
570- def value (self ):
571- return self ._value
572-
573- @value .setter
574- def value (self , text ):
575- self ._value = text
576- trimmed = text .strip ()
577- self .clean = self .comments .strip (trimmed )
570+ def __init__ (self , val , comments ):
571+ trimmed = val .strip ()
572+ self .clean = comments .strip (trimmed )
578573 self .has_comments = trimmed != self .clean
579574
580575
@@ -595,6 +590,9 @@ def __init__(self, full_prefixes, inline_prefixes):
595590 def strip (self , text ):
596591 return self .pattern .sub ('' , text ).rstrip ()
597592
593+ def load (self , text ):
594+ return _Line (text , self )
595+
598596
599597class RawConfigParser (MutableMapping ):
600598 """ConfigParser that does not do interpolation."""
@@ -1064,9 +1062,8 @@ def _read(self, fp, fpname):
10641062
10651063 def _read_inner (self , fp , fpname ):
10661064 st = _ReadState ()
1067- line = _LineParser (self ._comments )
10681065
1069- for st .lineno , line . value in enumerate (fp , start = 1 ):
1066+ for st .lineno , line in enumerate (map ( self . _comments . load , fp ) , start = 1 ):
10701067 if not line .clean :
10711068 if self ._empty_lines_in_values :
10721069 # add empty line to the value, but only if there was no
@@ -1081,7 +1078,7 @@ def _read_inner(self, fp, fpname):
10811078 st .indent_level = sys .maxsize
10821079 continue
10831080
1084- first_nonspace = self .NONSPACECRE .search (line . value )
1081+ first_nonspace = self .NONSPACECRE .search (line )
10851082 st .cur_indent_level = first_nonspace .start () if first_nonspace else 0
10861083
10871084 if self ._handle_continuation_line (st , line , fpname ):
@@ -1097,7 +1094,7 @@ def _handle_continuation_line(self, st, line, fpname):
10971094 st .cur_indent_level > st .indent_level )
10981095 if is_continue :
10991096 if st .cursect [st .optname ] is None :
1100- raise MultilineContinuationError (fpname , st .lineno , line . value )
1097+ raise MultilineContinuationError (fpname , st .lineno , line )
11011098 st .cursect [st .optname ].append (line .clean )
11021099 return is_continue
11031100
@@ -1111,7 +1108,7 @@ def _handle_rest(self, st, line, fpname):
11111108 mo = self .SECTCRE .match (line .clean )
11121109
11131110 if not mo and st .cursect is None :
1114- raise MissingSectionHeaderError (fpname , st .lineno , line . value )
1111+ raise MissingSectionHeaderError (fpname , st .lineno , line )
11151112
11161113 self ._handle_header (st , mo .group ('header' ), fpname ) if mo else self ._handle_option (st , line , fpname )
11171114
@@ -1143,12 +1140,12 @@ def _handle_option(self, st, line, fpname):
11431140 # exception but keep going. the exception will be
11441141 # raised at the end of the file and will contain a
11451142 # list of all bogus lines
1146- st .errors .append (ParsingError (fpname , st .lineno , line . value ))
1143+ st .errors .append (ParsingError (fpname , st .lineno , line ))
11471144 return
11481145
11491146 st .optname , vi , optval = mo .group ('option' , 'vi' , 'value' )
11501147 if not st .optname :
1151- st .errors .append (ParsingError (fpname , st .lineno , line . value ))
1148+ st .errors .append (ParsingError (fpname , st .lineno , line ))
11521149 st .optname = self .optionxform (st .optname .rstrip ())
11531150 if (self ._strict and
11541151 (st .sectname , st .optname ) in st .elements_added ):
0 commit comments