summaryrefslogtreecommitdiff
path: root/bs4/dammit.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2011-02-27 18:08:59 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2011-02-27 18:08:59 -0500
commit3156a689a566966079bba7fb19497314e9184b94 (patch)
tree463a004e531b553f9cfb1ab58507392b99fe5efa /bs4/dammit.py
parent8c7a895ff8cfc357543966137a7f71e48a9ea02d (diff)
downloadbeautifulsoup4-3156a689a566966079bba7fb19497314e9184b94.tar.gz
Added a tree builder for the built-in HTMLParser, and tests.
Diffstat (limited to 'bs4/dammit.py')
-rw-r--r--bs4/dammit.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/bs4/dammit.py b/bs4/dammit.py
index 4483118..75d445e 100644
--- a/bs4/dammit.py
+++ b/bs4/dammit.py
@@ -35,6 +35,7 @@ class EntitySubstitution(object):
def _populate_class_variables():
lookup = {}
+ reverse_lookup = {}
characters = []
for codepoint, name in codepoint2name.items():
if codepoint == 34:
@@ -45,10 +46,11 @@ class EntitySubstitution(object):
character = unichr(codepoint)
characters.append(character)
lookup[character] = name
+ reverse_lookup[name] = character
re_definition = "[%s]" % "".join(characters)
- return lookup, re.compile(re_definition)
- CHARACTER_TO_HTML_ENTITY, CHARACTER_TO_HTML_ENTITY_RE = (
- _populate_class_variables())
+ return lookup, reverse_lookup, re.compile(re_definition)
+ (CHARACTER_TO_HTML_ENTITY, HTML_ENTITY_TO_CHARACTER,
+ CHARACTER_TO_HTML_ENTITY_RE) = _populate_class_variables()
CHARACTER_TO_XML_ENTITY = {