diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2011-02-26 23:42:54 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2011-02-26 23:42:54 -0500 |
commit | 6a8fa5523c6783fc407a9f49f7b446d8f4327e8e (patch) | |
tree | 3867bd5618536c3acd69e759e383a042dda1eda4 /beautifulsoup/dammit.py | |
parent | 8a6e1b5e15368c9dd66b6b407b7328c2bd0360ad (diff) |
Made EntitySubstitution a utility class, not the kind of class you subclass.
Diffstat (limited to 'beautifulsoup/dammit.py')
-rw-r--r-- | beautifulsoup/dammit.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/beautifulsoup/dammit.py b/beautifulsoup/dammit.py index 31dfa95..bff87c6 100644 --- a/beautifulsoup/dammit.py +++ b/beautifulsoup/dammit.py @@ -61,17 +61,20 @@ class EntitySubstitution(object): "&(?!#\d+;|#x[0-9a-fA-F]+;|\w+;)" ")") - def _substitute_html_entity(self, matchobj): - entity = self.CHARACTER_TO_HTML_ENTITY.get(matchobj.group(0)) + @classmethod + def _substitute_html_entity(cls, matchobj): + entity = cls.CHARACTER_TO_HTML_ENTITY.get(matchobj.group(0)) return "&%s;" % entity - def _substitute_xml_entity(self, matchobj): + @classmethod + def _substitute_xml_entity(cls, matchobj): """Used with a regular expression to substitute the appropriate XML entity for an XML special character.""" - entity = self.CHARACTER_TO_XML_ENTITY[matchobj.group(0)] + entity = cls.CHARACTER_TO_XML_ENTITY[matchobj.group(0)] return "&%s;" % entity - def substitute_xml(self, value, make_quoted_attribute=False): + @classmethod + def substitute_xml(cls, value, make_quoted_attribute=False): """Substitute XML entities for special XML characters. :param value: A string to be substituted. The less-than sign will @@ -117,14 +120,15 @@ class EntitySubstitution(object): # Escape angle brackets, and ampersands that aren't part of # entities. - value = self.BARE_AMPERSAND_OR_BRACKET.sub( - self._substitute_xml_entity, value) + value = cls.BARE_AMPERSAND_OR_BRACKET.sub( + cls._substitute_xml_entity, value) if make_quoted_attribute: return quote_with + value + quote_with else: return value - def substitute_html(self, s): + @classmethod + def substitute_html(cls, s): """Replace certain Unicode characters with named HTML entities. This differs from data.encode(encoding, 'xmlcharrefreplace') @@ -135,8 +139,8 @@ class EntitySubstitution(object): character with "é" will make it more readable to some people. """ - return self.CHARACTER_TO_HTML_ENTITY_RE.sub( - self._substitute_html_entity, s) + return cls.CHARACTER_TO_HTML_ENTITY_RE.sub( + cls._substitute_html_entity, s) class UnicodeDammit: |