@@ -1023,6 +1023,14 @@ def restore_defaults(self):
10231023 self [section ].restore_defaults ()
10241024
10251025
1026+ def _get_triple_quote (value ):
1027+ """Helper for triple-quoting round-trips."""
1028+ if ('"""' in value ) and ("'''" in value ):
1029+ raise ConfigObjError ('Value cannot be safely quoted: {0!r}' .format (value ))
1030+
1031+ return tsquot if "'''" in value else tdquot
1032+
1033+
10261034class ConfigObj (Section ):
10271035 """An object to read, create, and write config files."""
10281036
@@ -1773,7 +1781,7 @@ def _quote(self, value, multiline=True):
17731781 # for normal values either single or double quotes will do
17741782 elif '\n ' in value :
17751783 # will only happen if multiline is off - e.g. '\n' in key
1776- raise ConfigObjError ('Value "%s" cannot be safely quoted.' % value )
1784+ raise ConfigObjError ('Value cannot be safely quoted: {0!r}' . format ( value ) )
17771785 elif ((value [0 ] not in wspace_plus ) and
17781786 (value [- 1 ] not in wspace_plus ) and
17791787 (',' not in value )):
@@ -1782,7 +1790,7 @@ def _quote(self, value, multiline=True):
17821790 quot = self ._get_single_quote (value )
17831791 else :
17841792 # if value has '\n' or "'" *and* '"', it will need triple quotes
1785- quot = self . _get_triple_quote (value )
1793+ quot = _get_triple_quote (value )
17861794
17871795 if quot == noquot and '#' in value and self .list_values :
17881796 quot = self ._get_single_quote (value )
@@ -1792,25 +1800,14 @@ def _quote(self, value, multiline=True):
17921800
17931801 def _get_single_quote (self , value ):
17941802 if ("'" in value ) and ('"' in value ):
1795- raise ConfigObjError ('Value "%s" cannot be safely quoted.' % value )
1803+ raise ConfigObjError ('Value cannot be safely quoted: {0!r}' . format ( value ) )
17961804 elif '"' in value :
17971805 quot = squot
17981806 else :
17991807 quot = dquot
18001808 return quot
18011809
18021810
1803- @staticmethod
1804- def _get_triple_quote (value ):
1805- if (value .find ('"""' ) != - 1 ) and (value .find ("'''" ) != - 1 ):
1806- raise ConfigObjError ('Value "%s" cannot be safely quoted.' % value )
1807- if value .find ("'''" ) == - 1 :
1808- quot = tdquot
1809- else :
1810- quot = tsquot
1811- return quot
1812-
1813-
18141811 def _handle_value (self , value ):
18151812 """
18161813 Given a value string, unquote, remove comment,
0 commit comments