Skip to content

Commit

Permalink
Fixed merge of old code.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspatzke committed Jun 16, 2016
1 parent e27e61b commit 2806e5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
39 changes: 24 additions & 15 deletions WASEHTMLParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
def add_attrs(attrNames, attrList):
return [a[1] for a in filter(lambda attr: attr[0] in attrNames, attrList)]

def has_attr(attrs, attr):
return attr in map(lambda kv: kv[0], attrs)

def attr_val_is(attrs, attr, val):
try:
return filter(lambda kv: kv[0] == attr, attrs)[0][1] == val
except:
return False

class WASEHTMLParser(HTMLParser, object):
def reset(self):
self.doctype = set()
Expand All @@ -28,33 +37,33 @@ def handle_decl(self, decl):

def handle_starttag(self, tag, attrs):
if tag == "iframe":
self.frames = self.frames.union(add_attrs(["src"], attrs))
self.frames.update(add_attrs(["src"], attrs))
elif tag == "base":
self.base = self.base.union(add_attrs(["href"], attrs))
elif tag == "link" and "rel" in attrs and attrs["rel"] == "stylesheet":
self.stylesheets = self.stylesheets.union(add_attrs(["href"], attrs))
self.base.update(add_attrs(["href"], attrs))
elif tag == "link" and attr_val_is(attrs, "rel", "stylesheet"):
self.stylesheets.update(add_attrs(["href"], attrs))
elif tag == "script":
self.scripts = self.scripts.union(add_attrs(["src"], attrs))
self.scripts.update(add_attrs(["src"], attrs))
elif tag == "a" or tag == "area":
self.links = self.links.union(add_attrs(["href"], attrs))
self.links.update(add_attrs(["href"], attrs))
elif tag == "img" or tag == "input":
self.images = self.images.union(add_attrs(["src"], attrs))
self.images.update(add_attrs(["src"], attrs))
elif tag == "svg" or tag == "image":
self.images = self.images.union(add_attrs(["href", "xlink:href"], attrs))
self.images.update(add_attrs(["href", "xlink:href"], attrs))
elif tag == "audio":
self.audio = self.audio.union(add_attrs(["src"], attrs))
self.audio.update(add_attrs(["src"], attrs))
elif tag == "video":
self.video = self.video.union(add_attrs(["src"], attrs))
self.video.update(add_attrs(["src"], attrs))
elif tag == "object":
self.objects = self.objects.union(add_attrs(["data"], attrs))
self.objects.update(add_attrs(["data"], attrs))
elif tag == "embed":
self.objects = self.objects.union(add_attrs(["src"], attrs))
self.objects.update(add_attrs(["src"], attrs))
elif tag == "applet":
self.objects = self.objects.union(add_attrs(["code"], attrs))
self.objects.update(add_attrs(["code"], attrs))
elif tag == "form":
self.formactions = self.formactions.union(add_attrs(["action"], attrs))
self.formactions.update(add_attrs(["action"], attrs))
elif tag == "input" or tag == "button":
self.formactions = self.formactions.union(add_attrs(["formaction"], attrs))
self.formactions.update(add_attrs(["formaction"], attrs))
else:
return

Expand Down

0 comments on commit 2806e5f

Please sign in to comment.