diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2011-02-21 17:11:56 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2011-02-21 17:11:56 -0500 |
commit | 384c5cd07b027b1a53d59d81fd3dc7661cbc2ab1 (patch) | |
tree | 3de877db036706e3f11981a4d33968dea4a020e1 /beautifulsoup/dammit.py | |
parent | 274d94dc13ffeb80c587f68bbad267f4f5199b9e (diff) |
Switched Tag.decode to use EntitySubstitution.substitute_xml.
Diffstat (limited to 'beautifulsoup/dammit.py')
-rw-r--r-- | beautifulsoup/dammit.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/beautifulsoup/dammit.py b/beautifulsoup/dammit.py index 06e142e..f0690c1 100644 --- a/beautifulsoup/dammit.py +++ b/beautifulsoup/dammit.py @@ -37,8 +37,20 @@ from htmlentitydefs import codepoint2name import re class EntitySubstitution(object): - CHARACTER_TO_HTML_ENTITY = None - CHARACTER_TO_HTML_ENTITY_RE = None + + def _populate_class_variables(): + lookup = {} + characters = [] + for codepoint, name in codepoint2name.items(): + character = unichr(codepoint) + characters.append(character) + lookup[character] = name + re_definition = "[%s]" % "".join(characters) + return lookup, re.compile(re_definition) + + CHARACTER_TO_HTML_ENTITY, CHARACTER_TO_HTML_ENTITY_RE = ( + _populate_class_variables()) + CHARACTER_TO_XML_ENTITY = { "'" : "apos", @@ -56,15 +68,6 @@ class EntitySubstitution(object): def _initialize_lookup(cls): if cls.CHARACTER_TO_HTML_ENTITY is not None: return - lookup = {} - characters = [] - for codepoint, name in codepoint2name.items(): - character = unichr(codepoint) - characters.append(character) - lookup[character] = name - re_definition = "[%s]" % "".join(characters) - cls.CHARACTER_TO_HTML_ENTITY = lookup - cls.CHARACTER_TO_HTML_ENTITY_RE = re.compile(re_definition) def __init__(self): # Initialize the class variables if not already initialized |