Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a7eac1

Browse files
committed
Remove a lot of old 2.3/2.4 support code
1 parent93365ea commit9a7eac1

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
importstring,gettext
33
_=gettext.gettext
44

5-
try:
6-
frozenset
7-
exceptNameError:
8-
# Import from the sets module for python 2.3
9-
fromsetsimportSetasset
10-
fromsetsimportImmutableSetasfrozenset
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__importabsolute_import
2-
try:
3-
frozenset
4-
exceptNameError:
5-
# Import from the sets module for python 2.3
6-
fromsetsimportImmutableSetasfrozenset
7-
82
importre
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__importabsolute_import
2-
fromitertoolsimportizip
3-
try:
4-
frozenset
5-
exceptNameError:
6-
# Import from the sets module for python 2.3
7-
fromsetsimportSetasset
8-
fromsetsimportImmutableSetasfrozenset
9-
10-
try:
11-
any
12-
except:
13-
# Implement 'any' for python 2.4 and previous
14-
defany(iterable):
15-
forelementiniterable:
16-
ifelement:
17-
returnTrue
18-
returnFalse
19-
any.func_annotations= {}
20-
21-
try:
22-
u"abc".startswith((u"a",u"b"))
23-
defstartswithany(unicode,prefixes):
24-
returnunicode.startswith(prefixes)
25-
startswithany.func_annotations= {}
26-
except:
27-
# Python 2.4 doesn't accept a tuple as argument to string startswith
28-
defstartswithany(unicode,prefixes):
29-
forprefixinprefixes:
30-
ifunicode.startswith(prefix):
31-
returnTrue
32-
returnFalse
33-
startswithany.func_annotations= {}
34-
352
importsys
363
importtypes
374

@@ -50,6 +17,7 @@ def startswithany(unicode, prefixes):
5017
from .constantsimportcdataElements,rcdataElements,voidElements
5118
from .constantsimporttokenTypes,ReparseException,namespaces,spaceCharacters
5219
from .constantsimporthtmlIntegrationPointElements,mathmlTextIntegrationPointElements
20+
fromitertoolsimportizip
5321

5422
defparse(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 (notcorrectortoken[u"name"]!=u"html"
584-
orstartswithany(publicId,
552+
orpublicId.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-
orstartswithany(publicId,
612+
orpublicId.startswith(
645613
(u"-//w3c//dtd html 4.01 frameset//",
646614
u"-//w3c//dtd html 4.01 transitional//"))and
647615
systemId==None
648616
orsystemIdandsystemId.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-
orstartswithany(publicId,
621+
orpublicId.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
ifisUnicode:
134134
ifencodingisnotNone:
135135
raiseTypeError(u"Cannot explicitly set an encoding with a unicode string")
136+
136137
returnHTMLUnicodeInputStream(source)
137138
else:
138139
returnHTMLBinaryInputStream(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__importabsolute_import
2-
try:
3-
frozenset
4-
exceptNameError:
5-
# Import from the sets module for python 2.3
6-
fromsetsimportImmutableSetasfrozenset
2+
importgettext
3+
_=gettext.gettext
74

85
try:
96
pass# no-op statement to avoid 3to2 introducing parse error
107
exceptImportError:
118
pass
129

13-
importgettext
14-
_=gettext.gettext
15-
1610
fromhtml5lib.constantsimportvoidElements,booleanAttributes,spaceCharacters
1711
fromhtml5lib.constantsimportrcdataElements,entities,xmlEntities
1812
fromhtml5libimportutils

‎html5lib/tokenizer.py‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
from __future__importabsolute_import
2-
try:
3-
frozenset
4-
exceptNameError:
5-
# Import from the sets module for python 2.3
6-
fromsetsimportSetasset
7-
fromsetsimportImmutableSetasfrozenset
8-
try:
9-
fromcollectionsimportdeque
10-
exceptImportError:
11-
from .utilsimportdeque
2+
fromcollectionsimportdeque
123

134
from .constantsimportspaceCharacters
145
from .constantsimportentitiesWindows1252,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__importabsolute_import
22
fromhtml5lib.constantsimportscopingElements,tableInsertModeElements,namespaces
3-
try:
4-
frozenset
5-
exceptNameError:
6-
# Import from the sets module for python 2.3
7-
fromsetsimportSetasset
8-
fromsetsimportImmutableSetasfrozenset
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__importabsolute_import
2-
try:
3-
frozenset
4-
exceptNameError:
5-
#Import from the sets module for python 2.3
6-
fromsetsimportSetasset
7-
fromsetsimportImmutableSetasfrozenset
8-
92
fromtypesimportModuleType
103

114

@@ -41,145 +34,6 @@ def __getitem__(self, key):
4134
returndict.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-
classdeque(object):
48-
49-
def__init__(self,iterable=(),maxsize=-1):
50-
ifnothasattr(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-
defappend(self,x):
58-
self.data[self.right]=x
59-
self.right+=1
60-
ifself.maxsize!=-1andlen(self)>self.maxsize:
61-
self.popleft()
62-
append.func_annotations= {}
63-
64-
defappendleft(self,x):
65-
self.left-=1
66-
self.data[self.left]=x
67-
ifself.maxsize!=-1andlen(self)>self.maxsize:
68-
self.pop()
69-
appendleft.func_annotations= {}
70-
71-
defpop(self):
72-
ifself.left==self.right:
73-
raiseIndexError(u'cannot pop from empty deque')
74-
self.right-=1
75-
elem=self.data[self.right]
76-
delself.data[self.right]
77-
returnelem
78-
pop.func_annotations= {}
79-
80-
defpopleft(self):
81-
ifself.left==self.right:
82-
raiseIndexError(u'cannot pop from empty deque')
83-
elem=self.data[self.left]
84-
delself.data[self.left]
85-
self.left+=1
86-
returnelem
87-
popleft.func_annotations= {}
88-
89-
defclear(self):
90-
self.data.clear()
91-
self.left=self.right=0
92-
clear.func_annotations= {}
93-
94-
defextend(self,iterable):
95-
foreleminiterable:
96-
self.append(elem)
97-
extend.func_annotations= {}
98-
99-
defextendleft(self,iterable):
100-
foreleminiterable:
101-
self.appendleft(elem)
102-
extendleft.func_annotations= {}
103-
104-
defrotate(self,n=1):
105-
ifself:
106-
n%=len(self)
107-
foriinxrange(n):
108-
self.appendleft(self.pop())
109-
rotate.func_annotations= {}
110-
111-
def__getitem__(self,i):
112-
ifi<0:
113-
i+=len(self)
114-
try:
115-
returnself.data[i+self.left]
116-
exceptKeyError:
117-
raiseIndexError
118-
__getitem__.func_annotations= {}
119-
120-
def__setitem__(self,i,value):
121-
ifi<0:
122-
i+=len(self)
123-
try:
124-
self.data[i+self.left]=value
125-
exceptKeyError:
126-
raiseIndexError
127-
__setitem__.func_annotations= {}
128-
129-
def__delitem__(self,i):
130-
size=len(self)
131-
ifnot (-size<=i<size):
132-
raiseIndexError
133-
data=self.data
134-
ifi<0:
135-
i+=size
136-
forjinxrange(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-
returnself.right-self.left
143-
__len__.func_annotations= {}
144-
145-
def__cmp__(self,other):
146-
iftype(self)!=type(other):
147-
returncmp(type(self),type(other))
148-
returncmp(list(self),list(other))
149-
__cmp__.func_annotations= {}
150-
151-
def__repr__(self,_track=[]):
152-
ifid(self)in_track:
153-
returnu'...'
154-
_track.append(id(self))
155-
r=u'deque(%r)'% (list(self),)
156-
_track.remove(id(self))
157-
returnr
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-
raiseTypeError
170-
__hash__.func_annotations= {}
171-
172-
def__copy__(self):
173-
returnself.__class__(self)
174-
__copy__.func_annotations= {}
175-
176-
def__deepcopy__(self,memo={}):
177-
fromcopyimportdeepcopy
178-
result=self.__class__()
179-
memo[id(self)]=result
180-
result.__init__(deepcopy(tuple(self),memo))
181-
returnresult
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)

[8]ページ先頭

©2009-2025 Movatter.jp