This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author patrick.vrijlandt
Recipients eli.bendersky, flox, patrick.vrijlandt
Date 2013-01-22.18:43:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1358880238.63.0.0440119609646.issue12323@psf.upfronthosting.co.za>
In-reply-to
Content
Dear Eli,

According to the XPath spec, the 'position' as can be used in xpath expressions, should be positive. However, the current implementation (example below from 3.3.0) accepts some values that should not be ok.

Therefore, I do not agree that it behaves correctly. Garbage positions should return [] or an exception, not a value. And if you accept one value before the first position, you should accept them all.

DATA = '''<?xml version="1.0"?>
<data>
    <country name="Liechtenstein">
        <rank updated="yes">2</rank>
        <year>2008</year>
        <gdppc>141100</gdppc>
        <neighbor name="Austria" direction="E"/>
        <neighbor name="Switzerland" direction="W"/>
    </country>
    <country name="Singapore">
        <rank updated="yes">5</rank>
        <year>2011</year>
        <gdppc>59900</gdppc>
        <neighbor name="Malaysia" direction="N"/>
    </country>
    <country name="Panama">
        <rank updated="yes">69</rank>
        <year>2011</year>
        <gdppc>13600</gdppc>
        <neighbor name="Costa Rica" direction="W"/>
        <neighbor name="Colombia" direction="E"/>
    </country>
</data>
'''

import xml.etree.ElementTree as ET

root = ET.XML(DATA)
print(root)
for XP in (['./country'] +
           ['./country[%d]' % i for i in range(-1, 5)] +
           ['./country[last()%+d]' % i for i in range(-3, 5)]):
    print('{:20}'.format(XP), [elem.get('name') for elem in root.findall(XP)])

##  OUTPUT:
##    <Element 'data' at 0x03CD9BD0>
##    ./country            ['Liechtenstein', 'Singapore', 'Panama']
##    ./country[-1]        []
##    ./country[0]         ['Panama']
##    ./country[1]         ['Liechtenstein']
##    ./country[2]         ['Singapore']
##    ./country[3]         ['Panama']
##    ./country[4]         []
##    ./country[last()-3]  []
##    ./country[last()-2]  ['Liechtenstein']
##    ./country[last()-1]  ['Singapore']
##    ./country[last()+0]  ['Panama']
##    ./country[last()+1]  ['Liechtenstein']
##    ./country[last()+2]  ['Singapore']
##    ./country[last()+3]  ['Panama']
##    ./country[last()+4]  []
History
Date User Action Args
2013-01-22 18:43:58patrick.vrijlandtsetrecipients: + patrick.vrijlandt, eli.bendersky, flox
2013-01-22 18:43:58patrick.vrijlandtsetmessageid: <1358880238.63.0.0440119609646.issue12323@psf.upfronthosting.co.za>
2013-01-22 18:43:58patrick.vrijlandtlinkissue12323 messages
2013-01-22 18:43:58patrick.vrijlandtcreate