summaryrefslogtreecommitdiff
path: root/bs4/dammit.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2011-05-21 11:23:05 -0400
committerLeonard Richardson <leonard.richardson@canonical.com>2011-05-21 11:23:05 -0400
commit5cf4c589827a66e6be8b8c0e9e016b782f9f81ea (patch)
treeab00ce4f941fbeb79acd592032b364cebf910852 /bs4/dammit.py
parent0beb500a501cfc9a98d0aed5c929ce78bd54058f (diff)
downloadbeautifulsoup4-5cf4c589827a66e6be8b8c0e9e016b782f9f81ea.tar.gz
Changed dammit.py to require fewer changes to be Python 3 compatible.
Diffstat (limited to 'bs4/dammit.py')
-rw-r--r--bs4/dammit.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/bs4/dammit.py b/bs4/dammit.py
index 75d445e..4aafe81 100644
--- a/bs4/dammit.py
+++ b/bs4/dammit.py
@@ -9,7 +9,6 @@ encoding; that's the tree builder's job.
import codecs
from htmlentitydefs import codepoint2name
import re
-import types
# Autodetects character encodings. Very useful.
# Download from http://chardet.feedparser.org/
@@ -37,7 +36,7 @@ class EntitySubstitution(object):
lookup = {}
reverse_lookup = {}
characters = []
- for codepoint, name in codepoint2name.items():
+ for codepoint, name in list(codepoint2name.items()):
if codepoint == 34:
# There's no point in turning the quotation mark into
# &quot;, unless it happens within an attribute value, which
@@ -175,7 +174,7 @@ class UnicodeDammit:
self.tried_encodings = []
if markup == '' or isinstance(markup, unicode):
self.original_encoding = None
- self.unicode = unicode(markup)
+ self.unicode_markup = unicode(markup)
return
u = None
@@ -197,7 +196,7 @@ class UnicodeDammit:
if u:
break
- self.unicode = u
+ self.unicode_markup = u
if not u: self.original_encoding = None
def _sub_ms_char(self, match):
@@ -205,7 +204,7 @@ class UnicodeDammit:
entity."""
orig = match.group(1)
sub = self.MS_CHARS.get(orig)
- if type(sub) == types.TupleType:
+ if type(sub) == tuple:
if self.smart_quotes_to == 'xml':
sub = '&#x'.encode() + sub[1].encode() + ';'.encode()
else:
@@ -234,7 +233,7 @@ class UnicodeDammit:
u = self._to_unicode(markup, proposed)
self.markup = u
self.original_encoding = proposed
- except Exception, e:
+ except Exception as e:
# print "That didn't work!"
# print e
return None
@@ -375,7 +374,7 @@ class UnicodeDammit:
250,251,252,253,254,255)
import string
c.EBCDIC_TO_ASCII_MAP = string.maketrans( \
- ''.join(map(chr, range(256))), ''.join(map(chr, emap)))
+ ''.join(map(chr, list(range(256)))), ''.join(map(chr, emap)))
return s.translate(c.EBCDIC_TO_ASCII_MAP)
MS_CHARS = { '\x80' : ('euro', '20AC'),