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.
Created on 2012年03月01日 17:21 by vinay.sajip, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (7) | |||
|---|---|---|---|
| msg154705 - (view) | Author: Vinay Sajip (vinay.sajip) * (Python committer) | Date: 2012年03月01日 17:21 | |
The following script, minidom_test.py, from xml.dom import minidom data = b''' <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"> <channel> <link>https://example.com/blog/</link> <atom:link href="https://example.com/rss2/" rel="self"></atom:link> <item> <link>https://example.com/blog/1/</link> </item> </channel> </rss>''' doc = minidom.parseString(data) for link in doc.getElementsByTagName('link'): print(link._attrs) produces different results in Python 3.2 and 3.3: vinay@eta-oneiric64:~/projects/scratch$ python3.2 minidom_test.py {} {} vinay@eta-oneiric64:~/projects/scratch$ python3.3 minidom_test.py None None |
|||
| msg154722 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2012年03月02日 03:34 | |
That would be caused by Martin’s change in 5d27a32ebbcc. I don’t see the docs marking _attrs public, so I think this is not a bug. |
|||
| msg154751 - (view) | Author: Vinay Sajip (vinay.sajip) * (Python committer) | Date: 2012年03月02日 08:34 | |
The error which prompted this issue was not caused by external code peeking into the internals - it was just my toy test script which did that. The error came up in Django testing:
======================================================================
ERROR: test_secure_urls (regressiontests.syndication.tests.SyndicationFeedTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/vinay/projects/django3/tests/regressiontests/syndication/tests.py", line 255, in test_secure_urls
if link.getAttribute('rel') == 'self':
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/xml/dom/minidom.py", line 727, in getAttribute
return self._attrs[attname].value
TypeError: 'NoneType' object is not subscriptable
So, perhaps there is a missing _ensure_attributes() call somewhere.
|
|||
| msg154752 - (view) | Author: Vinay Sajip (vinay.sajip) * (Python committer) | Date: 2012年03月02日 08:54 | |
Upon inspection, _ensure_attributes() is only called in _get_attributes(), setAttributeNode() and _set_attribute_node(). The last of these is only called by setAttributeNode(), and it would appear that setAttributeNode() is only called if there *are* attributes. _get_attributes() is only called by writexml(). So, calls to public methods getAttribute(), getAttributeNS() and a few others are likely to fail because, if there are no attributes in the XML being processed, _ensure_attributes() wouldn't get called. It looks like a bug to me! ;-) |
|||
| msg154753 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2012年03月02日 09:05 | |
Agreed :) Needs unit tests that use the public attributes. |
|||
| msg154911 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2012年03月04日 20:51 | |
Instead of calling _ensure_attributes (which creates the attribute dictionaries), getAttribute should return "" immediately if there are no attributes at all, to avoid creating those dictionaries. I'll do a patch shortly, unless somebody beats me. |
|||
| msg154927 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年03月05日 06:01 | |
New changeset 73c76466cf44 by Martin v. Löwis in branch 'default': Issue #14168: Check for presence of _attrs before accessing it. http://hg.python.org/cpython/rev/73c76466cf44 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:27 | admin | set | github: 58376 |
| 2012年03月05日 06:02:34 | loewis | set | status: open -> closed resolution: fixed |
| 2012年03月05日 06:01:57 | python-dev | set | nosy:
+ python-dev messages: + msg154927 |
| 2012年03月04日 20:51:30 | loewis | set | messages: + msg154911 |
| 2012年03月02日 09:05:30 | eric.araujo | set | keywords:
+ easy, - 3.2regression title: minidom behaves differently in 3.3 compared to 3.2 -> Bug in minidom 3.3 after optimization patch messages: + msg154753 stage: needs patch |
| 2012年03月02日 08:54:11 | vinay.sajip | set | messages: + msg154752 |
| 2012年03月02日 08:34:42 | vinay.sajip | set | messages: + msg154751 |
| 2012年03月02日 03:34:07 | eric.araujo | set | nosy:
+ eric.araujo messages: + msg154722 |
| 2012年03月01日 17:21:38 | vinay.sajip | create | |