Skip to content

Commit 84b1710

Browse files
committed
Remove a lot of old 2.3/2.4 support code
1 parent 97b25e3 commit 84b1710

File tree

7 files changed

+7
-196
lines changed

7 files changed

+7
-196
lines changed

html5lib/constants.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import string, gettext
22
_ = gettext.gettext
33

4-
try:
5-
frozenset
6-
except NameError:
7-
# Import from the sets module for python 2.3
8-
from sets import Set as set
9-
from sets import ImmutableSet as frozenset
10-
114
EOF = None
125

136
E = {

html5lib/filters/whitespace.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
try:
2-
frozenset
3-
except NameError:
4-
# Import from the sets module for python 2.3
5-
from sets import ImmutableSet as frozenset
6-
71
import re
82

93
from . import _base

html5lib/html5parser.py

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
try:
2-
frozenset
3-
except NameError:
4-
# Import from the sets module for python 2.3
5-
from sets import Set as set
6-
from sets import ImmutableSet as frozenset
7-
8-
try:
9-
any
10-
except:
11-
# Implement 'any' for python 2.4 and previous
12-
def any(iterable):
13-
for element in iterable:
14-
if element:
15-
return True
16-
return False
17-
18-
try:
19-
"abc".startswith(("a", "b"))
20-
def startswithany(str, prefixes):
21-
return str.startswith(prefixes)
22-
except:
23-
# Python 2.4 doesn't accept a tuple as argument to string startswith
24-
def startswithany(str, prefixes):
25-
for prefix in prefixes:
26-
if str.startswith(prefix):
27-
return True
28-
return False
29-
301
import sys
312
import types
323

@@ -540,7 +511,7 @@ def processDoctype(self, token):
540511
publicId = publicId.translate(asciiUpper2Lower)
541512

542513
if (not correct or token["name"] != "html"
543-
or startswithany(publicId,
514+
or publicId.startswith(
544515
("+//silmaril//dtd html pro v0r11 19970101//",
545516
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
546517
"-//as//dtd html 3.0 aswedit + extensions//",
@@ -600,16 +571,16 @@ def processDoctype(self, token):
600571
("-//w3o//dtd w3 html strict 3.0//en//",
601572
"-/w3c/dtd html 4.0 transitional/en",
602573
"html")
603-
or startswithany(publicId,
574+
or publicId.startswith(
604575
("-//w3c//dtd html 4.01 frameset//",
605576
"-//w3c//dtd html 4.01 transitional//")) and
606577
systemId == None
607578
or systemId and systemId.lower() == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd"):
608579
self.parser.compatMode = "quirks"
609-
elif (startswithany(publicId,
580+
elif (publicId.startswith(
610581
("-//w3c//dtd xhtml 1.0 frameset//",
611582
"-//w3c//dtd xhtml 1.0 transitional//"))
612-
or startswithany(publicId,
583+
or publicId.startswith(
613584
("-//w3c//dtd html 4.01 frameset//",
614585
"-//w3c//dtd html 4.01 transitional//")) and
615586
systemId != None):

html5lib/serializer/htmlserializer.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
try:
2-
frozenset
3-
except NameError:
4-
# Import from the sets module for python 2.3
5-
from sets import ImmutableSet as frozenset
1+
import gettext
2+
_ = gettext.gettext
63

74
try:
85
from functools import reduce
96
pass # no-op statement to avoid 3to2 introducing parse error
107
except ImportError:
118
pass
129

13-
import gettext
14-
_ = gettext.gettext
15-
1610
from html5lib.constants import voidElements, booleanAttributes, spaceCharacters
1711
from html5lib.constants import rcdataElements, entities, xmlEntities
1812
from html5lib import utils

html5lib/tokenizer.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
try:
2-
frozenset
3-
except NameError:
4-
# Import from the sets module for python 2.3
5-
from sets import Set as set
6-
from sets import ImmutableSet as frozenset
7-
try:
8-
from collections import deque
9-
except ImportError:
10-
from .utils import deque
1+
from collections import deque
112

123
from .constants import spaceCharacters
134
from .constants import entitiesWindows1252, entities

html5lib/treebuilders/_base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
from html5lib.constants import scopingElements, tableInsertModeElements, namespaces
2-
try:
3-
frozenset
4-
except NameError:
5-
# Import from the sets module for python 2.3
6-
from sets import Set as set
7-
from sets import ImmutableSet as frozenset
82

93
# The scope markers are inserted when entering object elements,
104
# marquees, table cells, and table captions, and are used to prevent formatting

html5lib/utils.py

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
try:
2-
frozenset
3-
except NameError:
4-
#Import from the sets module for python 2.3
5-
from sets import Set as set
6-
from sets import ImmutableSet as frozenset
7-
81
from types import ModuleType
92

103

@@ -38,125 +31,6 @@ def __init__(self, items=()):
3831
def __getitem__(self, key):
3932
return dict.get(self, key, self.default)
4033

41-
#Pure python implementation of deque taken from the ASPN Python Cookbook
42-
#Original code by Raymond Hettinger
43-
44-
class deque(object):
45-
46-
def __init__(self, iterable=(), maxsize=-1):
47-
if not hasattr(self, 'data'):
48-
self.left = self.right = 0
49-
self.data = {}
50-
self.maxsize = maxsize
51-
self.extend(iterable)
52-
53-
def append(self, x):
54-
self.data[self.right] = x
55-
self.right += 1
56-
if self.maxsize != -1 and len(self) > self.maxsize:
57-
self.popleft()
58-
59-
def appendleft(self, x):
60-
self.left -= 1
61-
self.data[self.left] = x
62-
if self.maxsize != -1 and len(self) > self.maxsize:
63-
self.pop()
64-
65-
def pop(self):
66-
if self.left == self.right:
67-
raise IndexError('cannot pop from empty deque')
68-
self.right -= 1
69-
elem = self.data[self.right]
70-
del self.data[self.right]
71-
return elem
72-
73-
def popleft(self):
74-
if self.left == self.right:
75-
raise IndexError('cannot pop from empty deque')
76-
elem = self.data[self.left]
77-
del self.data[self.left]
78-
self.left += 1
79-
return elem
80-
81-
def clear(self):
82-
self.data.clear()
83-
self.left = self.right = 0
84-
85-
def extend(self, iterable):
86-
for elem in iterable:
87-
self.append(elem)
88-
89-
def extendleft(self, iterable):
90-
for elem in iterable:
91-
self.appendleft(elem)
92-
93-
def rotate(self, n=1):
94-
if self:
95-
n %= len(self)
96-
for i in range(n):
97-
self.appendleft(self.pop())
98-
99-
def __getitem__(self, i):
100-
if i < 0:
101-
i += len(self)
102-
try:
103-
return self.data[i + self.left]
104-
except KeyError:
105-
raise IndexError
106-
107-
def __setitem__(self, i, value):
108-
if i < 0:
109-
i += len(self)
110-
try:
111-
self.data[i + self.left] = value
112-
except KeyError:
113-
raise IndexError
114-
115-
def __delitem__(self, i):
116-
size = len(self)
117-
if not (-size <= i < size):
118-
raise IndexError
119-
data = self.data
120-
if i < 0:
121-
i += size
122-
for j in range(self.left+i, self.right-1):
123-
data[j] = data[j+1]
124-
self.pop()
125-
126-
def __len__(self):
127-
return self.right - self.left
128-
129-
def __cmp__(self, other):
130-
if type(self) != type(other):
131-
return cmp(type(self), type(other))
132-
return cmp(list(self), list(other))
133-
134-
def __repr__(self, _track=[]):
135-
if id(self) in _track:
136-
return '...'
137-
_track.append(id(self))
138-
r = 'deque(%r)' % (list(self),)
139-
_track.remove(id(self))
140-
return r
141-
142-
def __getstate__(self):
143-
return (tuple(self),)
144-
145-
def __setstate__(self, s):
146-
self.__init__(s[0])
147-
148-
def __hash__(self):
149-
raise TypeError
150-
151-
def __copy__(self):
152-
return self.__class__(self)
153-
154-
def __deepcopy__(self, memo={}):
155-
from copy import deepcopy
156-
result = self.__class__()
157-
memo[id(self)] = result
158-
result.__init__(deepcopy(tuple(self), memo))
159-
return result
16034

16135
#Some utility functions to dal with weirdness around UCS2 vs UCS4
16236
#python builds

0 commit comments

Comments
 (0)