Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml.etree.register_namespace dictionary changed size during iteration #54986

Closed
peterjc mannequin opened this issue Dec 27, 2010 · 2 comments
Closed

xml.etree.register_namespace dictionary changed size during iteration #54986

peterjc mannequin opened this issue Dec 27, 2010 · 2 comments
Labels
topic-XML type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@peterjc
Copy link
Mannequin

peterjc mannequin commented Dec 27, 2010

BPO 10777
Nosy @birkenfeld, @peterjc

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2010-12-28.10:38:45.452>
created_at = <Date 2010-12-27.00:11:54.358>
labels = ['expert-XML', 'type-crash']
title = 'xml.etree.register_namespace dictionary changed size during iteration'
updated_at = <Date 2010-12-28.10:38:45.450>
user = 'https://github.com/peterjc'

bugs.python.org fields:

activity = <Date 2010-12-28.10:38:45.450>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = <Date 2010-12-28.10:38:45.452>
closer = 'georg.brandl'
components = ['XML']
creation = <Date 2010-12-27.00:11:54.358>
creator = 'maubp'
dependencies = []
files = []
hgrepos = []
issue_num = 10777
keywords = []
message_count = 2.0
messages = ['124688', '124781']
nosy_count = 2.0
nosy_names = ['georg.brandl', 'maubp']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'crash'
url = 'https://bugs.python.org/issue10777'
versions = ['Python 3.2']

@peterjc
Copy link
Mannequin Author

peterjc mannequin commented Dec 27, 2010

The following was found testing the Biopython unit tests (latest code from git) against Python 3.2 beta 2 (compiled from source on 64 bit Linux Ubuntu). Reduced test case:

$ python3.2
Python 3.2b2 (r32b2:87398, Dec 26 2010, 19:01:30) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from xml.etree import ElementTree
>>> ElementTree.register_namespace("xs", "http://www.w3.org/2001/XMLSchema")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/peterjc/lib/python3.2/xml/etree/ElementTree.py", line 1071, in register_namespace
    for k, v in _namespace_map.items():
RuntimeError: dictionary changed size during iteration

Suggested fix, replace this:

def register_namespace(prefix, uri):
    if re.match("ns\d+$", prefix):
        raise ValueError("Prefix format reserved for internal use")
    for k, v in _namespace_map.items():
        if k == uri or v == prefix:
            del _namespace_map[k]
    _namespace_map[uri] = prefix


with something like this:

def register_namespace(prefix, uri):
    if re.match("ns\d+$", prefix):
        raise ValueError("Prefix format reserved for internal use")
    for k, v in list(_namespace_map.items()):
        if k == uri or v == prefix:
            del _namespace_map[k]
    _namespace_map[uri] = prefix

Note that cElementTree seems to be OK.

Note that Python 3.1 was not affected as it didn't even have register_namespace,

$ python3
Python 3.1.2 (r312:79147, Sep 27 2010, 09:57:50) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from xml.etree import ElementTree
>>> ElementTree.register_namespace("xs", "http://www.w3.org/2001/XMLSchema")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'register_namespace'

@peterjc peterjc mannequin added topic-XML type-crash A hard crash of the interpreter, possibly with a core dump labels Dec 27, 2010
@birkenfeld
Copy link
Member

Thanks, this should be fixed in r87526.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-XML type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

1 participant