Modify

Ticket #149 (new defect)

Opened 4 years ago

Throws wrong ValueError exception on bad time stamps

Reported by: f_d_c_-alquiler@… Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords: ValueError, YAMLError
Cc:

Description

If a timestamp is badly formatted construct_yaml_timestamp() throws an uncaught ValueError? instead of yaml.YAMLError:

>>> yaml.safe_load("2009-13-11")
Traceback (most recent call last):
  File "<pyshell#4>", line 2, in <module>
    yaml.safe_load("2009-13-11")
  File "C:\Python26\lib\site-packages\yaml\__init__.py", line 75, in safe_load
    return load(stream, SafeLoader)
  File "C:\Python26\lib\site-packages\yaml\__init__.py", line 58, in load
    return loader.get_single_data()
  File "C:\Python26\lib\site-packages\yaml\constructor.py", line 44, in get_single_data
    return self.construct_document(node)
  File "C:\Python26\lib\site-packages\yaml\constructor.py", line 48, in construct_document
    data = self.construct_object(node)
  File "C:\Python26\lib\site-packages\yaml\constructor.py", line 93, in construct_object
    data = constructor(self, node)
  File "C:\Python26\lib\site-packages\yaml\constructor.py", line 318, in construct_yaml_timestamp
    return datetime.date(year, month, day)
ValueError: month must be in 1..12

Environment:

  • Python 2.6.4 on Windows XP
  • PyYAML-3.09-py2.5.exe

I think the function should include something like this:

try:
    return datetime.date(year, month, day)
except ValueError:
    raise ConstructorError(None,None,"inappropriate date value",node.start_mark)

Thank you.

Attachments

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
The owner will be changed from xi to anonymous. Next status will be 'assigned'
Author


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

 
Note: See TracTickets for help on using tickets.