Custom Query (132 matches)
Results (25 - 27 of 132)
|#74||fixed||porting yaml to python 3000||xi||idadesub@…|
I've started to play around with porting code over to python 3, and since I use yaml, I had to port it over as well. So, here's the patch :) It's pretty heavyweight, though, because of the change of "str" to be unicode. Since there are many incompatible changes, I'd recommend creating a branch for this.
Here's some other notes that you ought to be aware of:
try: set except NameError: from sets import Set as set
Finally, in case it wasn't clear in the patch, I've removed the following tests:
D tests/data/construct-python-unicode-utf8.data D tests/data/construct-python-unicode-ascii.data D tests/data/construct-python-unicode-utf8.code D tests/data/construct-python-unicode-ascii.code
A tests/data/construct-python-bytes-utf8.data A tests/data/construct-python-bytes-ascii.data A tests/data/construct-python-bytes-utf8.code A tests/data/construct-python-bytes-ascii.code
Please consider integrating libyaml with pkgconfig.
|#43||fixed||path resolver has bug||xi||jstroud@…|
Path resolving does not work for Nodes within Sequence Nodes
[This is current for pyyaml 3.04.]
yaml.add_path_resolver(u'!MyObject', (u'myobjs', [list, False]))
should match all of the items in the myobjs sequence in this yaml:
""" --- !MyConfig myobjs : - name: x root: z - name: p root: q ... """
The problem is here in resolver.py (line 210):
elif isinstance(index_check, int): if index_check != current_index: return
If I'm infering the intent of the code correctly
(u'myobjs', (list, False))
should match all elements of the sequence keyed by "myobjs". However,
always returns True because bool is a subclass of int, so index_check will only equal current_index for the first element when False is specified as the index_check.
Additionally, I believe another bug exists in resolver.py. According to the code in add_path_resolver(), index_check defaults to True when not specified (resolver.py, line 39):
if isinstance(element, (list, tuple)): if len(element) == 2: node_check, index_check = element elif len(element) == 1: node_check = element index_check = True
The intendend meaning of True here is not clear because True causes every element in the sequence to fail the match. The relevant test is in check_resolver_prefix() (resolver.py, line 116):
if index_check is True and current_index is not None: return
Thus, any path not specifying an index_check will never match. Most insidious to the user is that this case is never reported nor an exception thrown. If index_check is True, this code will only continue to test if current_index is None, which should never happen for any node of any sequence, because any node of a sequence must, by virtue of its existence, have an index.
To fix these problems, I propose the following patch to resolver.py:
44c44 < index_check = True --- > index_check = False 122c122 < elif isinstance(index_check, int): --- > elif isinstance(index_check, int) and index_check is not False:
This will set the default value of index_check to match all elements of a sequence if no index_check is given and will not attempt to compare False to the value of index_check.
At the bare minimum, the following patch should be strongly considered if a good reason exists to leave the defalut of index_check to True.
122c122 < elif isinstance(index_check, int): --- > elif isinstance(index_check, int) and index_check is not False:
Moreover, the code should provide some indication for what an index_check value of True actually means.
In fact, I propose re-writing the code to use None to match all elements, because
will always evaluate to False. This will also remove the question as to what the "other" bool value means because bools will not be used. I can provide a patch if this latter proposal sounds good to the developers.