Skip to content

Commit a4b5234

Browse files
committed
fixup! Only initialize the method dispatcher once
1 parent 5220d03 commit a4b5234

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

html5lib/_tokenizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class HTMLTokenizer(object):
3636
* self.stream
3737
Points to HTMLInputStream object.
3838
"""
39-
39+
4040
def __init__(self, stream, parser=None, **kwargs):
4141

4242
self.stream = HTMLInputStream(stream, **kwargs)

html5lib/_utils.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,17 @@ def __init__(self, items=()):
6969
def __getitem__(self, key):
7070
return dict.get(self, key, self.default)
7171

72+
def __get__(self, instance, owner=None):
73+
return BoundMethodDispatcher(instance, self)
74+
7275

7376
class BoundMethodDispatcher(Mapping):
7477
def __init__(self, instance, dispatcher):
7578
self.instance = instance
7679
self.dispatcher = dispatcher
77-
self.cache = {}
7880

7981
def __getitem__(self, key):
80-
if key in self.cache:
81-
return self.cache[key]
82-
83-
try:
84-
item = self.dispatcher[key]
85-
except KeyError:
86-
item = self.default
87-
88-
r = item.__get__(self.instance)
89-
self.cache[key] = r
90-
return r
82+
return self.dispatcher[key].__get__(self.instance)
9183

9284
def get(self, key, default):
9385
if key in self.dispatcher:

html5lib/html5parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def processStartTag(self, token):
456456
try:
457457
func = self.__startTagCache[name]
458458
except KeyError:
459-
func = self.__startTagCache[name] = self.startTagHandler[name].__get__(self)
459+
func = self.__startTagCache[name] = self.startTagHandler[name]
460460
return func(token)
461461

462462
def startTagHtml(self, token):
@@ -474,7 +474,7 @@ def processEndTag(self, token):
474474
try:
475475
func = self.__endTagCache[name]
476476
except KeyError:
477-
func = self.__endTagCache[name] = self.endTagHandler[name].__get__(self)
477+
func = self.__endTagCache[name] = self.endTagHandler[name]
478478
return func(token)
479479

480480
class InitialPhase(Phase):

0 commit comments

Comments
 (0)