Skip to content

Commit 9a7eac1

Browse files
committed
Remove a lot of old 2.3/2.4 support code
1 parent 93365ea commit 9a7eac1

File tree

8 files changed

+9
-220
lines changed

8 files changed

+9
-220
lines changed

html5lib/constants.py

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

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

147
E = {

html5lib/filters/whitespace.py

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

104
from . import _base

html5lib/html5parser.py

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

@@ -50,6 +17,7 @@ def startswithany(unicode, prefixes):
5017
from .constants import cdataElements, rcdataElements, voidElements
5118
from .constants import tokenTypes, ReparseException, namespaces, spaceCharacters
5219
from .constants import htmlIntegrationPointElements, mathmlTextIntegrationPointElements
20+
from itertools import izip
5321

5422
def parse(doc, treebuilder=u"simpletree", encoding=None,
5523
namespaceHTMLElements=True):
@@ -581,7 +549,7 @@ def processDoctype(self, token):
581549
publicId = publicId.translate(asciiUpper2Lower)
582550

583551
if (not correct or token[u"name"] != u"html"
584-
or startswithany(publicId,
552+
or publicId.startswith(
585553
(u"+//silmaril//dtd html pro v0r11 19970101//",
586554
u"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
587555
u"-//as//dtd html 3.0 aswedit + extensions//",
@@ -641,16 +609,16 @@ def processDoctype(self, token):
641609
(u"-//w3o//dtd w3 html strict 3.0//en//",
642610
u"-/w3c/dtd html 4.0 transitional/en",
643611
u"html")
644-
or startswithany(publicId,
612+
or publicId.startswith(
645613
(u"-//w3c//dtd html 4.01 frameset//",
646614
u"-//w3c//dtd html 4.01 transitional//")) and
647615
systemId == None
648616
or systemId and systemId.lower() == u"http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd"):
649617
self.parser.compatMode = u"quirks"
650-
elif (startswithany(publicId,
618+
elif (publicId.startswith(
651619
(u"-//w3c//dtd xhtml 1.0 frameset//",
652620
u"-//w3c//dtd xhtml 1.0 transitional//"))
653-
or startswithany(publicId,
621+
or publicId.startswith(
654622
(u"-//w3c//dtd html 4.01 frameset//",
655623
u"-//w3c//dtd html 4.01 transitional//")) and
656624
systemId != None):

html5lib/inputstream.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def HTMLInputStream(source, encoding=None, parseMeta=True, chardet=True):
133133
if isUnicode:
134134
if encoding is not None:
135135
raise TypeError(u"Cannot explicitly set an encoding with a unicode string")
136+
136137
return HTMLUnicodeInputStream(source)
137138
else:
138139
return HTMLBinaryInputStream(source, encoding, parseMeta, chardet)

html5lib/serializer/htmlserializer.py

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

85
try:
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,14 +1,5 @@
11
from __future__ import absolute_import
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
8-
try:
9-
from collections import deque
10-
except ImportError:
11-
from .utils import deque
2+
from collections import deque
123

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

html5lib/treebuilders/_base.py

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

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

html5lib/utils.py

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
from __future__ import absolute_import
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
8-
92
from types import ModuleType
103

114

@@ -41,145 +34,6 @@ def __getitem__(self, key):
4134
return dict.get(self, key, self.default)
4235
__getitem__.func_annotations = {}
4336

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

18438
#Some utility functions to dal with weirdness around UCS2 vs UCS4
18539
#python builds

0 commit comments

Comments
 (0)