|
From: David H. <neg...@gm...> - 2009-01-28 23:13:32
|
I'm having a devil of a time getting validate to allow for the default value
of a string check to consist of a string that includes a newline character
('\n'). I've tried several syntactic variants, and nothing is working - the
validation fails everytime.
E.g.:
spec = { u'val': u"string(default='%s')" % ('\n') }
cfgdict = {}
vtor = validate.Validator()
cfg = configobj.ConfigObj(cfgdict, configspec=spec)
results = cfg.validate(vtor, preserve_errors=True)
In addition to the spec as shown above, I've tried:
spec = { u'val': u"string(default='\n')" }
spec = { u'val': u""""string(default='
')""" }
I even tried putting the spec into a text block and using splitlines() and
giving that as the configspec argument (where the text block used the
'''<value>''' syntax for multi-line values).
No joy.
The validation parser seems to treat any newline as the end of the spec
definition for that particular value, and either bombs out with a parse
error, or returns False upon validation.
Any tips? Bug?
thanks,
- David Hostetler
|
|
From: Michael F. <fuz...@vo...> - 2009-01-28 23:17:43
|
David Hostetler wrote:
> I'm having a devil of a time getting validate to allow for the default
> value of a string check to consist of a string that includes a newline
> character ('\n'). I've tried several syntactic variants, and nothing
> is working - the validation fails everytime.
>
> E.g.:
>
> spec = { u'val': u"string(default='%s')" % ('\n') }
> cfgdict = {}
>
> vtor = validate.Validator()
> cfg = configobj.ConfigObj(cfgdict, configspec=spec)
>
> results = cfg.validate(vtor, preserve_errors=True)
>
> In addition to the spec as shown above, I've tried:
>
> spec = { u'val': u"string(default='\n')" }
>
> spec = { u'val': u""""string(default='
> ')""" }
>
>
> I even tried putting the spec into a text block and using splitlines()
> and giving that as the configspec argument (where the text block used
> the '''<value>''' syntax for multi-line values).
>
> No joy.
>
> The validation parser seems to treat any newline as the end of the
> spec definition for that particular value, and either bombs out with a
> parse error, or returns False upon validation.
>
> Any tips? Bug?
Hmm... probably the regular expression matching used in validation can't
handle the newlines. Hopefully adding re.DOTALL to some of the regular
expressions in validate.py will fix it.
I'm unlikely to be able to get to it for a few weeks - so patches
(including tests!) welcomed. :-)
All the best,
Michael Foord
>
> thanks,
>
> - David Hostetler
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> ------------------------------------------------------------------------
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
|
|
From: David H. <neg...@gm...> - 2009-01-28 23:21:56
|
> Hmm... probably the regular expression matching used in validation can't > handle the newlines. Hopefully adding re.DOTALL to some of the regular > expressions in validate.py will fix it. > > I'm unlikely to be able to get to it for a few weeks - so patches > (including tests!) welcomed. :-) > > All the best, > > > Michael Foord Roger that. Thanks for the quick reply. - David |
|
From: David H. <neg...@gm...> - 2009-02-19 19:51:39
|
I have the newline support implemented (with tests).
Would you prefer a diff, or just the validate.py?
cheers,
-hoss
On Wed, Jan 28, 2009 at 18:17, Michael Foord <fuz...@vo...>wrote:
> David Hostetler wrote:
> > I'm having a devil of a time getting validate to allow for the default
> > value of a string check to consist of a string that includes a newline
> > character ('\n'). I've tried several syntactic variants, and nothing
> > is working - the validation fails everytime.
> >
> > E.g.:
> >
> > spec = { u'val': u"string(default='%s')" % ('\n') }
> > cfgdict = {}
> >
> > vtor = validate.Validator()
> > cfg = configobj.ConfigObj(cfgdict, configspec=spec)
> >
> > results = cfg.validate(vtor, preserve_errors=True)
> >
> > In addition to the spec as shown above, I've tried:
> >
> > spec = { u'val': u"string(default='\n')" }
> >
> > spec = { u'val': u""""string(default='
> > ')""" }
> >
> >
> > I even tried putting the spec into a text block and using splitlines()
> > and giving that as the configspec argument (where the text block used
> > the '''<value>''' syntax for multi-line values).
> >
> > No joy.
> >
> > The validation parser seems to treat any newline as the end of the
> > spec definition for that particular value, and either bombs out with a
> > parse error, or returns False upon validation.
> >
> > Any tips? Bug?
>
> Hmm... probably the regular expression matching used in validation can't
> handle the newlines. Hopefully adding re.DOTALL to some of the regular
> expressions in validate.py will fix it.
>
> I'm unlikely to be able to get to it for a few weeks - so patches
> (including tests!) welcomed. :-)
>
> All the best,
>
>
> Michael Foord
>
>
|
|
From: Michael F. <fuz...@vo...> - 2009-02-19 20:11:49
|
David Hostetler wrote:
> I have the newline support implemented (with tests).
>
> Would you prefer a diff, or just the validate.py?
Diff against svn head is perfect.
Michael
>
> cheers,
>
> -hoss
>
> On Wed, Jan 28, 2009 at 18:17, Michael Foord
> <fuz...@vo... <mailto:fuz...@vo...>> wrote:
>
> David Hostetler wrote:
> > I'm having a devil of a time getting validate to allow for the
> default
> > value of a string check to consist of a string that includes a
> newline
> > character ('\n'). I've tried several syntactic variants, and
> nothing
> > is working - the validation fails everytime.
> >
> > E.g.:
> >
> > spec = { u'val': u"string(default='%s')" % ('\n') }
> > cfgdict = {}
> >
> > vtor = validate.Validator()
> > cfg = configobj.ConfigObj(cfgdict, configspec=spec)
> >
> > results = cfg.validate(vtor, preserve_errors=True)
> >
> > In addition to the spec as shown above, I've tried:
> >
> > spec = { u'val': u"string(default='\n')" }
> >
> > spec = { u'val': u""""string(default='
> > ')""" }
> >
> >
> > I even tried putting the spec into a text block and using
> splitlines()
> > and giving that as the configspec argument (where the text block
> used
> > the '''<value>''' syntax for multi-line values).
> >
> > No joy.
> >
> > The validation parser seems to treat any newline as the end of the
> > spec definition for that particular value, and either bombs out
> with a
> > parse error, or returns False upon validation.
> >
> > Any tips? Bug?
>
> Hmm... probably the regular expression matching used in validation
> can't
> handle the newlines. Hopefully adding re.DOTALL to some of the regular
> expressions in validate.py will fix it.
>
> I'm unlikely to be able to get to it for a few weeks - so patches
> (including tests!) welcomed. :-)
>
> All the best,
>
>
> Michael Foord
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> ------------------------------------------------------------------------
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
|
|
From: David H. <neg...@gm...> - 2009-02-19 20:26:09
|
Index: validate.py
===================================================================
--- validate.py (revision 106)
+++ validate.py (working copy)
@@ -130,7 +130,7 @@
__docformat__ = "restructuredtext en"
-__version__ = '0.3.2'
+__version__ = '0.3.3'
__revision__ = '$Id: validate.py 123 2005-09-08 08:54:28Z fuzzyman $'
@@ -183,15 +183,15 @@
(?:
\s*
(?:
- (?:".*?")| # double quotes
- (?:'.*?')| # single quotes
+ (?s)(?:".*?")| # double quotes
+ (?s)(?:'.*?')| # single quotes
(?:[^'",\s\)][^,\)]*?) # unquoted
)
\s*,\s*
)*
(?:
- (?:".*?")| # double quotes
- (?:'.*?')| # single quotes
+ (?s)(?:".*?")| # double quotes
+ (?s)(?:'.*?')| # single quotes
(?:[^'",\s\)][^,\)]*?) # unquoted
)? # last one
)
@@ -201,8 +201,8 @@
_list_members = re.compile(r'''
(
- (?:".*?")| # double quotes
- (?:'.*?')| # single quotes
+ (?s)(?:".*?")| # double quotes
+ (?s)(?:'.*?')| # single quotes
(?:[^'",\s=][^,=]*?) # unquoted
)
(?:
@@ -218,28 +218,28 @@
(?:
\s*
(?:
- (?:".*?")| # double quotes
- (?:'.*?')| # single quotes
- (?:[^'",\s\)][^,\)]*?) # unquoted
+ (?s)(?:".*?")| # double quotes
+ (?s)(?:'.*?')| # single quotes
+ (?:[^'",\s\)][^,\)]*?) # unquoted
)
\s*,\s*
)*
(?:
- (?:".*?")| # double quotes
- (?:'.*?')| # single quotes
- (?:[^'",\s\)][^,\)]*?) # unquoted
+ (?s)(?:".*?")| # double quotes
+ (?s)(?:'.*?')| # single quotes
+ (?:[^'",\s\)][^,\)]*?) # unquoted
)? # last one
\)
)|
(?:
- (?:".*?")| # double quotes
- (?:'.*?')| # single quotes
+ (?s)(?:".*?")| # double quotes
+ (?s)(?:'.*?')| # single quotes
(?:[^'",\s=][^,=]*?)| # unquoted
(?: # keyword argument
[a-zA-Z_][a-zA-Z0-9_]*\s*=\s*
(?:
- (?:".*?")| # double quotes
- (?:'.*?')| # single quotes
+ (?s)(?:".*?")| # double quotes
+ (?s)(?:'.*?')| # single quotes
(?:[^'",\s=][^,=]*?) # unquoted
)
)
@@ -278,7 +278,8 @@
>>> int(dottedQuadToNum('1.2.3.4'))
16909060
>>> dottedQuadToNum('1.2.3. 4')
- 16909060
+ Traceback (most recent call last):
+ ValueError: Not a good dotted-quad IP: 1.2.3. 4
>>> dottedQuadToNum('255.255.255.255')
4294967295L
>>> dottedQuadToNum('255.255.255.256')
@@ -525,10 +526,10 @@
"""
# this regex does the initial parsing of the checks
- _func_re = re.compile(r'(.+?)\((.*)\)')
+ _func_re = re.compile(r'(.+?)\((?s)(.*)\)')
# this regex takes apart keyword arguments
- _key_arg = re.compile(r'^([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(.*)$')
+ _key_arg = re.compile(r'^([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(?s)(.*)$')
# this regex finds keyword=list(....) type values
@@ -573,7 +574,7 @@
def check(self, check, value, missing=False):
- """
+ r"""
Usage: check(check, value)
Arguments:
@@ -592,6 +593,27 @@
>>> vtor.check('string(default="")', '', missing=True)
''
+ >>> vtor.check('string(default="\n")', '', missing=True)
+ '\n'
+ >>> print vtor.check('string(default="\n")', '', missing=True),
+ <BLANKLINE>
+ >>> vtor.check('string()', '\n')
+ '\n'
+ >>> vtor.check('string(default="\n\n\n")', '', missing=True)
+ '\n\n\n'
+ >>> vtor.check('string()', 'random \n text goes here\n\n')
+ 'random \n text goes here\n\n'
+ >>> vtor.check('string(default=" \nrandom text\ngoes \n here\n\n ")',
+ ... '', missing=True)
+ ' \nrandom text\ngoes \n here\n\n '
+ >>> vtor.check("string(default='\n\n\n')", '', missing=True)
+ '\n\n\n'
+ >>> vtor.check("option('\n','a','b',default='\n')", '', missing=True)
+ '\n'
+ >>> vtor.check("string_list()", ['foo', '\n', 'bar'])
+ ['foo', '\n', 'bar']
+ >>> vtor.check("string_list(default=list('\n'))", '', missing=True)
+ ['\n']
"""
fun_name, fun_args, fun_kwargs, default = self._parse_with_caching(check)
|
|
From: Michael F. <fuz...@vo...> - 2009-02-19 20:40:51
|
Hello David,
Great - I'll integrate this ASAP. ConfigObj is due a new release so I
can do them together.
I agree that doctest is a pain for unit testing, but unless someone
volunteers to port all the existing tests...
Michael
David Hostetler wrote:
> See attached.
>
> Note that the version bump to '0.3.3' was just because I'm using this
> in the context of systems that do module version checking and I
> needed/wanted to distinguish the updated version from both the
> published version and the svn tip.
>
> Note also that I updated one of the dottedQuadToNum() tests - not sure
> if this was a platform/python version idiosyncrasy or what, but I had
> to fix it to get a clean doctest run.
>
> Let me know if there are any issues.
>
> p.s. -- using doctest for this kind of thing was cumbersome. Are you
> considering unittest for actual tests, and just leaving doctest for
> validating docstring examples?
>
>
> regards,
>
> -hoss
>
> David Hostetler
> neg...@gm... <mailto:neg...@gm...>
>
>
> On Thu, Feb 19, 2009 at 15:11, Michael Foord
> <fuz...@vo... <mailto:fuz...@vo...>> wrote:
>
> David Hostetler wrote:
> > I have the newline support implemented (with tests).
> >
> > Would you prefer a diff, or just the validate.py?
>
> Diff against svn head is perfect.
>
> Michael
>
> >
> > cheers,
> >
> > -hoss
> >
> > On Wed, Jan 28, 2009 at 18:17, Michael Foord
> > <fuz...@vo... <mailto:fuz...@vo...>
> <mailto:fuz...@vo...
> <mailto:fuz...@vo...>>> wrote:
> >
> > David Hostetler wrote:
> > > I'm having a devil of a time getting validate to allow for the
> > default
> > > value of a string check to consist of a string that includes a
> > newline
> > > character ('\n'). I've tried several syntactic variants, and
> > nothing
> > > is working - the validation fails everytime.
> > >
> > > E.g.:
> > >
> > > spec = { u'val': u"string(default='%s')" % ('\n') }
> > > cfgdict = {}
> > >
> > > vtor = validate.Validator()
> > > cfg = configobj.ConfigObj(cfgdict, configspec=spec)
> > >
> > > results = cfg.validate(vtor, preserve_errors=True)
> > >
> > > In addition to the spec as shown above, I've tried:
> > >
> > > spec = { u'val': u"string(default='\n')" }
> > >
> > > spec = { u'val': u""""string(default='
> > > ')""" }
> > >
> > >
> > > I even tried putting the spec into a text block and using
> > splitlines()
> > > and giving that as the configspec argument (where the text
> block
> > used
> > > the '''<value>''' syntax for multi-line values).
> > >
> > > No joy.
> > >
> > > The validation parser seems to treat any newline as the
> end of the
> > > spec definition for that particular value, and either
> bombs out
> > with a
> > > parse error, or returns False upon validation.
> > >
> > > Any tips? Bug?
> >
> > Hmm... probably the regular expression matching used in
> validation
> > can't
> > handle the newlines. Hopefully adding re.DOTALL to some of
> the regular
> > expressions in validate.py will fix it.
> >
> > I'm unlikely to be able to get to it for a few weeks - so
> patches
> > (including tests!) welcomed. :-)
> >
> > All the best,
> >
> >
> > Michael Foord
> >
> >
> >
> ------------------------------------------------------------------------
> >
> >
> ------------------------------------------------------------------------------
> > Open Source Business Conference (OSBC), March 24-25, 2009, San
> Francisco, CA
> > -OSBC tackles the biggest issue in open source: Open Sourcing
> the Enterprise
> > -Strategies to boost innovation and cut costs with open source
> participation
> > -Receive a $600 discount off the registration fee with the
> source code: SFAD
> > http://p.sf.net/sfu/XcvMzF8H
> >
> ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Configobj-develop mailing list
> > Con...@li...
> <mailto:Con...@li...>
> > https://lists.sourceforge.net/lists/listinfo/configobj-develop
> >
>
>
> --
> http://www.ironpythoninaction.com/
> http://www.voidspace.org.uk/blog
>
>
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San
> Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the
> Enterprise
> -Strategies to boost innovation and cut costs with open source
> participation
> -Receive a $600 discount off the registration fee with the source
> code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> <mailto:Con...@li...>
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> ------------------------------------------------------------------------
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
|