Ticket #61 (new defect)

Opened 4 years ago

Last modified 4 years ago

Raise ValueError on bad time stamps

Reported by: miki@… Owned by: xi
Priority: normal Component: pysyck
Severity: normal Keywords:
Cc:

Description

Currently if a timestamp is badly formatted, syck raises:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    yaml = syck.load(open("/var/spool/articles/20070917/9a45fab335a148a5999d8d000a3c23fe/article.yaml").read())
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 408, in load
    return loader.load()
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 50, in load
    return self._convert(node, {})
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 67, in _convert
    node_to_object)
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 84, in _convert
    object = self.construct(node)
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 174, in construct
    return constructor(node)
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 242, in construct_timestamp
    values = match.groupdict()
AttributeError: 'NoneType' object has no attribute 'groupdict'

which is cryptic.

construct_timestamp should check the if the value was matched:

    def construct_timestamp(self, node):
        match = self.timestamp_expr.match(node.value)

        if not match:
            raise ValueError, "bad time stamp: %s" % node.value

Attachments

Change History

Changed 4 years ago by xi

Could you post the part of the input yaml file that breaks syck?

Changed 4 years ago by anonymous

>>> from datetime import datetime
>>> t = syck.dump(datetime.now())
>>> t
'--- !timestamp 2007-09-19T09:48:46.485859\n'
>>> n = t[:14] + " == " + t[14:]
>>> n
'--- !timestamp ==  2007-09-19T09:48:46.485859\n'
>>> syck.load(n)

Traceback (most recent call last):
  File "<pyshell#33>", line 1, in <module>
    syck.load(n)
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 408, in load
    return loader.load()
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 50, in load
    return self._convert(node, {})
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 84, in _convert
    object = self.construct(node)
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 174, in construct
    return constructor(node)
  File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 242, in construct_timestamp
    values = match.groupdict()
AttributeError: 'NoneType' object has no attribute 'groupdict'
>>> 

(There is some noise on my network protocol, so I sometime get these errors)

Add/Change #61 (Raise ValueError on bad time stamps)

Author


E-mail address and user name can be saved in the Preferences.


Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change from xi. Next status will be 'new'
The owner will change from xi to anonymous. Next status will be 'assigned'
 
Note: See TracTickets for help on using tickets.