id
int64 0
458k
| file_name
stringlengths 4
119
| file_path
stringlengths 14
227
| content
stringlengths 24
9.96M
| size
int64 24
9.96M
| language
stringclasses 1
value | extension
stringclasses 14
values | total_lines
int64 1
219k
| avg_line_length
float64 2.52
4.63M
| max_line_length
int64 5
9.91M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 7
101
| repo_stars
int64 100
139k
| repo_forks
int64 0
26.4k
| repo_open_issues
int64 0
2.27k
| repo_license
stringclasses 12
values | repo_extraction_date
stringclasses 433
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
12,800
|
NodeType.py
|
buffer_thug/thug/DOM/W3C/Core/NodeType.py
|
#!/usr/bin/env python
class NodeType:
ELEMENT_NODE = 1
ATTRIBUTE_NODE = 2
TEXT_NODE = 3
CDATA_SECTION_NODE = 4
ENTITY_REFERENCE_NODE = 5
ENTITY_NODE = 6
PROCESSING_INSTRUCTION_NODE = 7
COMMENT_NODE = 8
DOCUMENT_NODE = 9
DOCUMENT_TYPE_NODE = 10
DOCUMENT_FRAGMENT_NODE = 11
NOTATION_NODE = 12
| 341
|
Python
|
.py
| 14
| 19.785714
| 35
| 0.664615
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,801
|
Node.py
|
buffer_thug/thug/DOM/W3C/Core/Node.py
|
#!/usr/bin/env python
import copy
import logging
from thug.DOM.JSClass import JSClass
from thug.DOM.W3C.Events.EventTarget import EventTarget
from .abstractmethod import abstractmethod
from .DOMException import DOMException
from .NodeType import NodeType
log = logging.getLogger("Thug")
class Node(JSClass, EventTarget):
# NodeType
ELEMENT_NODE = NodeType.ELEMENT_NODE
ATTRIBUTE_NODE = NodeType.ATTRIBUTE_NODE
TEXT_NODE = NodeType.TEXT_NODE
CDATA_SECTION_NODE = NodeType.CDATA_SECTION_NODE
ENTITY_REFERENCE_NODE = NodeType.ENTITY_REFERENCE_NODE
ENTITY_NODE = NodeType.ENTITY_NODE
PROCESSING_INSTRUCTION_NODE = NodeType.PROCESSING_INSTRUCTION_NODE
COMMENT_NODE = NodeType.COMMENT_NODE
DOCUMENT_NODE = NodeType.DOCUMENT_NODE
DOCUMENT_TYPE_NODE = NodeType.DOCUMENT_TYPE_NODE
DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT_NODE
NOTATION_NODE = NodeType.NOTATION_NODE
def __init__(self, doc, tag):
self._doc = doc
self._tag = tag
EventTarget.__init__(self, doc, tag)
self.__init_node_personality()
def __eq__(self, other): # pragma: no cover
return hasattr(other, "doc") and self.doc == other.doc
def __ne__(self, other): # pragma: no cover
return not self == other
def __hash__(self):
return id(self)
def __init_node_personality(self):
if log.ThugOpts.Personality.isIE():
self.__init_node_personality_IE()
return
if log.ThugOpts.Personality.isFirefox():
self.__init_node_personality_Firefox()
return
if log.ThugOpts.Personality.isChrome():
self.__init_node_personality_Chrome()
return
if log.ThugOpts.Personality.isSafari():
self.__init_node_personality_Safari()
return
def __init_node_personality_IE(self):
self.applyElement = self._applyElement
# Internet Explorer < 9 does not implement compareDocumentPosition
if log.ThugOpts.Personality.browserMajorVersion >= 9:
self.compareDocumentPosition = self._compareDocumentPosition
def __init_node_personality_Firefox(self):
self.compareDocumentPosition = self._compareDocumentPosition
def __init_node_personality_Chrome(self):
self.compareDocumentPosition = self._compareDocumentPosition
def __init_node_personality_Safari(self):
self.compareDocumentPosition = self._compareDocumentPosition
def get_tag(self):
return self._tag
def set_tag(self, tag):
self._tag = tag
tag = property(get_tag, set_tag)
def get_doc(self):
return self._doc
def set_doc(self, doc):
self._doc = doc
doc = property(get_doc, set_doc)
@property
@abstractmethod
def nodeType(self): # pragma: no cover
pass
@property
@abstractmethod
def nodeName(self): # pragma: no cover
pass
@abstractmethod
def getNodeValue(self): # pragma: no cover
pass
@abstractmethod
def setNodeValue(self, value): # pragma: no cover
pass
nodeValue = property(getNodeValue, setNodeValue)
def getTextContent(self):
return self.tag.string
def setTextContent(self, value):
self.tag.string = str(value)
# Introduced in DOM Level 3
textContent = property(getTextContent, setTextContent)
@property
def attributes(self):
from .NamedNodeMap import NamedNodeMap
return NamedNodeMap(self.doc, self.tag)
@property
def childNodes(self):
from .NodeList import NodeList
return NodeList(self.doc, self.tag.contents)
@property
def firstChild(self):
return (
log.DOMImplementation.wrap(self.doc, self.tag.contents[0])
if self.tag.contents
else None
)
@property
def lastChild(self):
return (
log.DOMImplementation.wrap(self.doc, self.tag.contents[-1])
if self.tag.contents
else None
)
@property
def nextSibling(self):
return log.DOMImplementation.wrap(self.doc, self.tag.next_sibling)
@property
def previousSibling(self):
return log.DOMImplementation.wrap(self.doc, self.tag.previous_sibling)
@property
def parentNode(self):
return (
log.DOMImplementation.wrap(self.doc, self.tag.parent)
if self.tag.parent
else None
)
# Introduced in DOM Level 2
@property
def namespaceURI(self):
return None
# Introduced in DOM Level 2
@property
def prefix(self):
return None
# Introduced in DOM Level 2
@property
def localName(self):
return None
# Modified in DOM Level 2
@property
def ownerDocument(self):
return log.DFT.window.doc
def findChild(self, child):
if getattr(child, "tag", None) and child.tag in self.tag.contents:
childHash = hash(child.tag._node)
for p in self.tag.contents:
if getattr(p, "_node", None) is None:
continue
if childHash == hash(p._node):
return self.tag.contents.index(p)
return -1
@property
def innerText(self):
return str(self.tag.string)
def is_readonly(self, node):
return node.nodeType in (
Node.DOCUMENT_TYPE_NODE,
Node.NOTATION_NODE,
Node.ENTITY_REFERENCE_NODE,
Node.ENTITY_NODE,
)
def is_text(self, node):
return node.nodeType in (
Node.TEXT_NODE,
Node.PROCESSING_INSTRUCTION_NODE,
Node.CDATA_SECTION_NODE,
)
def insertBefore(self, newChild, refChild):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_insertbefore_count()
if not newChild:
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
if not isinstance(newChild, Node):
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
# If refChild is null, insert newChild at the end of the list
# of children
if not refChild:
return self.appendChild(newChild)
if not isinstance(refChild, Node):
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
# If the newChild is already in the tree, it is first removed
if getattr(newChild, "tag", None) and newChild.tag in self.tag.contents:
newChildHash = hash(newChild.tag._node)
for p in self.tag.contents:
if getattr(p, "_node", None) is None:
continue
if newChildHash in (hash(p._node),):
p.extract()
index = self.findChild(refChild)
if index < 0 and not self.is_text(refChild):
raise DOMException(DOMException.NOT_FOUND_ERR)
if self.is_text(newChild):
self.tag.insert(index, newChild.data.output_ready(formatter=lambda x: x))
return newChild
if newChild.nodeType in (Node.COMMENT_NODE,):
return newChild
if newChild.nodeType in (Node.DOCUMENT_FRAGMENT_NODE,):
node = None
for p in newChild.tag.find_all_next():
if node is None:
self.tag.insert(index, p)
else:
node.append(p)
node = p
return newChild
self.tag.insert(index, newChild.tag)
return newChild
def replaceChild(self, newChild, oldChild):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_replacechild_count()
# NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of
# the new node is readonly.
if self.is_readonly(self):
raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
parent = getattr(newChild, "parentNode", None)
if parent:
if self.is_readonly(parent): # pragma: no cover
raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
if not newChild or not oldChild:
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
if not isinstance(newChild, Node) or not isinstance(oldChild, Node):
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
index = self.findChild(oldChild)
if index < 0:
raise DOMException(DOMException.NOT_FOUND_ERR)
if self.is_text(newChild):
self.tag.contents[index].replace_with(
newChild.data.output_ready(formatter=lambda x: x)
)
return oldChild
if newChild.nodeType in (Node.COMMENT_NODE,):
self.tag.contents[index].replace_with(newChild.data)
return oldChild
if newChild.nodeType in (Node.DOCUMENT_FRAGMENT_NODE,):
node = None
for p in newChild.tag.find_all_next():
if node is None:
self.tag.contents[index].replace_with(p)
else:
node.append(p)
node = p
return oldChild
self.tag.contents[index].replace_with(newChild.tag)
return oldChild
def removeChild(self, oldChild):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_removechild_count()
# NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly
if self.is_readonly(self):
raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
if not oldChild:
raise DOMException(DOMException.NOT_FOUND_ERR)
if not isinstance(oldChild, Node):
raise DOMException(DOMException.NOT_FOUND_ERR)
index = self.findChild(oldChild)
if index < 0 and not self.is_text(oldChild):
raise DOMException(DOMException.NOT_FOUND_ERR)
if getattr(oldChild, "tag", None) and oldChild.tag in self.tag.contents:
oldChildHash = hash(oldChild.tag._node)
for p in self.tag.contents:
if getattr(p, "_node", None) is None:
continue
if oldChildHash == hash(p._node):
p.extract()
return oldChild
def appendChild(self, newChild):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_appendchild_count()
# NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly
if self.is_readonly(self):
raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
if self.is_text(self):
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
if not newChild:
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
if not isinstance(newChild, Node):
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
# If the newChild is already in the tree, it is first removed
if getattr(newChild, "tag", None) and newChild.tag in self.tag.contents:
newChildHash = hash(newChild.tag._node)
for p in self.tag.contents:
if getattr(p, "_node", None) is None:
continue
if newChildHash == hash(p._node):
p.extract()
if self.is_text(newChild):
self.tag.append(newChild.data.output_ready(formatter=lambda x: x))
return newChild
if newChild.nodeType in (Node.COMMENT_NODE,):
self.tag.append(newChild.data)
return newChild
if newChild.nodeType in (Node.DOCUMENT_FRAGMENT_NODE,):
node = self.tag
for p in newChild.tag.find_all_next():
node.append(p)
node = p
return newChild
self.tag.append(newChild.tag)
return newChild
def hasChildNodes(self):
return len(self.tag.contents) > 0
def _applyElement(self, element, where="outside"):
where = where.lower()
if where in ("inside",):
self.appendChild(element)
if where in ("outside",):
self.tag.wrap(element.tag)
# Modified in DOM Level 2
def normalize(self):
index = 0
max_index = self.childNodes.length
while index < max_index:
child = self.childNodes[index]
if child is None or child.nodeType not in (Node.TEXT_NODE,):
index += 1
continue
sibling = child.nextSibling
if sibling is None or sibling.nodeType not in (Node.TEXT_NODE,):
index += 1
continue
child.tag.string = child.innerText + sibling.innerText
self.removeChild(sibling)
# Introduced in DOM Level 2
def isSupported(self, feature, version): # pragma: no cover
return log.DOMImplementation.hasFeature(feature, version)
# Introduced in DOM Level 2
def hasAttributes(self):
return self.attributes.length > 0
# Introduced in DOM Level 3
def _compareDocumentPosition(self, node): # pylint:disable=unused-argument
return None
# @abstractmethod
def cloneNode(self, deep=False):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_clonenode_count()
# Returns a duplicate of this node
cloned = copy.copy(self)
# The duplicate node has no parent (parentNode is null)
cloned.tag.parent = None
# Cloning an Element copies all attributes and their values but
# this method does not copy any text it contains unless it is a
# deep clone, since the Text is contained in a child Text node.
if cloned.nodeType in (Node.ELEMENT_NODE,) and deep is False:
cloned.tag.string = ""
return cloned
# @staticmethod
# def wrap(doc, obj):
# from .Element import Element
#
# if obj is None:
# return None
#
# if isinstance(obj, bs4.CData): # pragma: no cover
# from .CDATASection import CDATASection
# return CDATASection(doc, obj)
#
# if isinstance(obj, bs4.NavigableString):
# from .Text import Text
# return Text(doc, obj)
#
# return Element(doc, obj)
| 14,383
|
Python
|
.py
| 359
| 30.454039
| 85
| 0.629451
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,802
|
Element.py
|
buffer_thug/thug/DOM/W3C/Core/Element.py
|
#!/usr/bin/env python
import logging
import random
from urllib.parse import urlsplit
from thug.DOM.W3C.Style.CSS.ElementCSSInlineStyle import ElementCSSInlineStyle
from .DOMException import DOMException
from .Node import Node
from .ClassList import ClassList
log = logging.getLogger("Thug")
FF_STYLES = (
(27, "cursor"),
(19, "font-size"),
)
FF_INPUTS = ((23, "range"),)
class Element(Node, ElementCSSInlineStyle):
def __init__(self, doc, tag):
tag._node = self
Node.__init__(self, doc, tag)
ElementCSSInlineStyle.__init__(self, doc, tag)
self.__init_element_personality()
def __init_element_personality(self):
if log.ThugOpts.Personality.isIE():
self.__init_element_personality_IE()
return
if log.ThugOpts.Personality.isFirefox():
self.__init_element_personality_Firefox()
return
if log.ThugOpts.Personality.isChrome():
self.__init_element_personality_Chrome()
return
if log.ThugOpts.Personality.isSafari():
self.__init_element_personality_Safari()
return
def __init_element_personality_IE(self):
self.clearAttributes = self._clearAttributes
if log.ThugOpts.Personality.browserMajorVersion > 7:
self.querySelectorAll = self._querySelectorAll
self.querySelector = self._querySelector
if log.ThugOpts.Personality.browserMajorVersion > 8:
self.getElementsByClassName = self._getElementsByClassName
self.msMatchesSelector = self._matches
self.classList = ClassList(self.tag)
def __init_element_personality_Firefox(self):
self.querySelectorAll = self._querySelectorAll
self.querySelector = self._querySelector
self.mozMatchesSelector = self._matches
self.getElementsByClassName = self._getElementsByClassName
self.classList = ClassList(self.tag)
if log.ThugOpts.Personality.browserMajorVersion > 33:
self.matches = self._matches
def __init_element_personality_Chrome(self):
self.querySelectorAll = self._querySelectorAll
self.querySelector = self._querySelector
self.webkitMatchesSelector = self._matches
self.getElementsByClassName = self._getElementsByClassName
self.classList = ClassList(self.tag)
if log.ThugOpts.Personality.browserMajorVersion > 33:
self.matches = self._matches
def __init_element_personality_Safari(self):
self.querySelectorAll = self._querySelectorAll
self.querySelector = self._querySelector
self.getElementsByClassName = self._getElementsByClassName
self.classList = ClassList(self.tag)
if log.ThugOpts.Personality.browserMajorVersion > 6:
self.matches = self._matches
if log.ThugOpts.Personality.browserMajorVersion > 4:
self.webkitMatchesSelector = self._matches
def _querySelectorAll(self, selectors):
from .NodeList import NodeList
try:
s = self.tag.select(selectors)
except Exception: # pragma: no cover,pylint:disable=broad-except
return NodeList(self.doc, [])
return NodeList(self.doc, s)
def _querySelector(self, selectors):
try:
s = self.tag.select(selectors)
except Exception: # pragma: no cover,pylint:disable=broad-except
return None
return (
log.DOMImplementation.createHTMLElement(self, s[0]) if s and s[0] else None
)
def _matches(self, selector):
try:
s = self.tag.select(selector)
except Exception as e:
raise DOMException(DOMException.SYNTAX_ERR) from e
return bool(s)
def __eq__(self, other): # pragma: no cover
return (
Node.__eq__(self, other) and hasattr(other, "tag") and self.tag == other.tag
)
def __ne__(self, other): # pragma: no cover
return not self == other
def __hash__(self):
return id(self)
@property
def nodeType(self):
return Node.ELEMENT_NODE
@property
def nodeName(self):
return self.tagName
@property
def nodeValue(self):
return None
@property
def clientWidth(self):
return 800
@property
def clientHeight(self):
return 600
@property
def scrollTop(self):
return random.randint(0, 100)
@property
def scrollHeight(self):
return random.randint(10, 100)
# Introduced in DOM Level 2
def hasAttribute(self, name):
return self.tag.has_attr(name)
@property
def tagName(self):
return self.tag.name.upper()
def getAttribute(self, name, flags=0):
if not isinstance(name, str): # pragma: no cover
name = str(name)
return_as_url = False
if log.ThugOpts.Personality.isIE():
if log.ThugOpts.Personality.browserMajorVersion < 8:
# flags parameter is only supported in Internet Explorer earlier
# than version 8.
#
# A value of 0 means that the search is case-insensitive and the
# returned value does not need to be converted. Other values can
# be any combination of the following integer constants with the
# bitwise OR operator:
#
# 1 Case-sensitive search
# 2 Returns the value as a string
# 4 Returns the value as an URL
if not flags & 1:
name = name.lower()
if flags & 4:
return_as_url = True
value = self.tag.attrs[name] if name in self.tag.attrs else None
if isinstance(value, list):
value = " ".join(value)
if return_as_url:
value = log.HTTPSession.normalize_url(self.doc.window, value)
return value
def setAttribute(self, name, value):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_setattribute_count()
if not isinstance(name, str): # pragma: no cover
name = str(name)
if log.ThugOpts.Personality.isFirefox():
if name in ("style",):
svalue = value.split("-")
_value = svalue[0]
if len(svalue) > 1:
_value = f"{_value}{''.join([s.capitalize() for s in svalue[1:]])}"
for css in [
p
for p in FF_STYLES
if log.ThugOpts.Personality.browserMajorVersion >= p[0]
]:
if css[1] in value:
self.tag.attrs[name] = _value
return
if name in ("type",):
for _input in [
p
for p in FF_INPUTS
if log.ThugOpts.Personality.browserMajorVersion > p[0]
]:
if _input[1] in value:
self.tag.attrs[name] = value
return
self.tag.attrs[name] = value
if name.lower() in ("src", "archive"):
s = urlsplit(value)
handler = getattr(log.SchemeHandler, f"handle_{s.scheme}", None)
if handler:
handler(self.doc.window, value)
return
try:
response = self.doc.window._navigator.fetch(
value, redirect_type="element workaround"
)
except Exception: # pylint:disable=broad-except
return
if response is None or not response.ok:
return
if getattr(response, "thug_mimehandler_hit", False): # pragma: no cover
return
ctype = response.headers.get("content-type", None)
if ctype and ctype.startswith(("text/html",)):
window_open = getattr(log.DFT, "window_open", None)
if window_open:
window_open(response.url, response.content) # pylint:disable=not-callable
def removeAttribute(self, name):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_removeattribute_count()
if name in self.tag.attrs:
del self.tag.attrs[name]
def _clearAttributes(self):
from thug.DOM.W3C.Events.HTMLEvent import HTMLEvent
from thug.DOM.W3C.Events.MouseEvent import MouseEvent
no_clear = {
"id",
"name",
"style",
"value",
}
for events in (
HTMLEvent.EventTypes,
MouseEvent.EventTypes,
):
for e in events:
no_clear.add(f"on{e}")
names = [name for name in self.tag.attrs if name not in no_clear]
for name in names:
self.removeAttribute(name)
def getAttributeNode(self, name):
from .Attr import Attr
return Attr(self.doc, self, name) if name in self.tag.attrs else None
def setAttributeNode(self, attr):
self.tag.attrs[attr.name] = attr.value
def removeAttributeNode(self, attr):
if attr.name in self.tag.attrs:
del self.tag.attrs[attr.name]
def getElementsByTagName(self, tagname):
from .NodeList import NodeList
return NodeList(self.doc, self.tag.find_all(tagname))
def _getElementsByClassName(self, classname):
from .NodeList import NodeList
return NodeList(self.doc, self.tag.find_all(class_=classname))
| 9,703
|
Python
|
.py
| 237
| 29.970464
| 94
| 0.599446
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,803
|
CharacterData.py
|
buffer_thug/thug/DOM/W3C/Core/CharacterData.py
|
#!/usr/bin/env python
from .Node import Node
from .DOMException import DOMException
class CharacterData(Node):
def __init__(self, doc, tag):
tag._node = self
Node.__init__(self, doc, tag)
def getData(self):
return self._data
def setData(self, data):
self._data = data
data = property(getData, setData)
@property
def length(self):
return len(self.data)
def substringData(self, offset, count):
return self.data[offset : offset + count]
def appendData(self, arg):
self.data += arg
def insertData(self, offset, arg):
if offset > len(self.data):
raise DOMException(DOMException.INDEX_SIZE_ERR)
self.data = self.data[:offset] + arg + self.data[offset:]
def deleteData(self, offset, count):
length = len(self.data)
if offset > length:
raise DOMException(DOMException.INDEX_SIZE_ERR)
if offset + count > length:
self.data = self.data[:offset]
else:
self.data = self.data[:offset] + self.data[offset + count :]
def replaceData(self, offset, count, arg):
s = self.data[:offset] + arg + self.data[offset + count :]
self.data = s
| 1,245
|
Python
|
.py
| 34
| 28.941176
| 72
| 0.617893
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,804
|
DocumentType.py
|
buffer_thug/thug/DOM/W3C/Core/DocumentType.py
|
#!/usr/bin/env python
import logging
import re
from .Node import Node
from .NamedNodeMap import NamedNodeMap
log = logging.getLogger("Thug")
class DocumentType(Node):
RE_DOCTYPE = re.compile(r"^(\w+)", re.M + re.S)
def __init__(self, doc, tag):
Node.__init__(self, doc, tag)
self.__init_documenttype_personality()
def __init_documenttype_personality(self):
if log.ThugOpts.Personality.isIE():
self.__init_node_personality_IE()
def __init_node_personality_IE(self):
if log.ThugOpts.Personality.browserMajorVersion in (9,):
self.entities = NamedNodeMap(self.doc, self.tag)
self.notations = NamedNodeMap(self.doc, self.tag)
@property
def name(self):
m = self.RE_DOCTYPE.match(self.tag)
return m.group(1) if m else ""
@property
def nodeName(self):
return self.name
@property
def nodeType(self):
return Node.DOCUMENT_TYPE_NODE
@property
def nodeValue(self):
return None
# Modified in DOM Level 2
@property
def ownerDocument(self):
return log.DFT.window.doc
# Introduced in DOM Level 2
@property
def publicId(self):
return " "
# Introduced in DOM Level 2
@property
def systemId(self):
return " "
# Introduced in DOM Level 2
@property
def internalSubset(self):
return None
# Introduced in DOM Level 3
@property
def textContent(self):
return None
| 1,512
|
Python
|
.py
| 51
| 23.294118
| 64
| 0.645429
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,805
|
Comment.py
|
buffer_thug/thug/DOM/W3C/Core/Comment.py
|
#!/usr/bin/env python
from .CharacterData import CharacterData
class Comment(CharacterData):
def __init__(self, doc, tag):
self.setNodeValue(tag)
CharacterData.__init__(self, doc, tag)
@property
def nodeName(self):
return "#comment"
@property
def nodeType(self):
from .NodeType import NodeType
return NodeType.COMMENT_NODE
def getNodeValue(self):
return str(self.data)
def setNodeValue(self, value):
self._data = value
nodeValue = property(getNodeValue, setNodeValue)
| 565
|
Python
|
.py
| 18
| 25
| 52
| 0.674721
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,806
|
Entity.py
|
buffer_thug/thug/DOM/W3C/Core/Entity.py
|
#!/usr/bin/env python
from .Node import Node
class Entity(Node): # pragma: no cover
@property
def publicId(self):
return None
@property
def systemId(self):
return None
@property
def notationName(self):
return None
@property
def nodeName(self):
return None
@property
def nodeType(self):
return Node.ENTITY_NODE
@property
def nodeValue(self):
return None
| 458
|
Python
|
.py
| 21
| 15.857143
| 39
| 0.638695
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,807
|
abstractmethod.py
|
buffer_thug/thug/DOM/W3C/Core/abstractmethod.py
|
#!/usr/bin/env python
import sys
class abstractmethod:
def __init__(self, func):
self.func = func
def __call__(self, *args, **kwds): # pragma: no cover
func_name = (
self.func.__name__ if sys.version_info.major >= 3 else self.func.func_name
)
raise NotImplementedError(f"Method {func_name} is abstract.")
| 362
|
Python
|
.py
| 10
| 29.6
| 86
| 0.612069
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,808
|
EntityReference.py
|
buffer_thug/thug/DOM/W3C/Core/EntityReference.py
|
#!/usr/bin/env python
import bs4
from .Node import Node
class EntityReference(Node):
def __init__(self, doc, name):
tag = bs4.BeautifulSoup(f"&{name};", "lxml")
Node.__init__(self, doc, tag)
@property
def name(self):
return self.tag.string.encode("utf8")
@property
def nodeName(self):
return self.name
@property
def nodeType(self):
return Node.ENTITY_REFERENCE_NODE
@property
def nodeValue(self):
return None
| 501
|
Python
|
.py
| 19
| 20.526316
| 52
| 0.635021
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,809
|
CDATASection.py
|
buffer_thug/thug/DOM/W3C/Core/CDATASection.py
|
#!/usr/bin/env python
from .Text import Text
class CDATASection(Text):
@property
def nodeName(self):
return "#cdata-section"
@property
def nodeType(self):
from .NodeType import NodeType
return NodeType.CDATA_SECTION_NODE
| 266
|
Python
|
.py
| 10
| 21.1
| 42
| 0.693227
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,810
|
__init__.py
|
buffer_thug/thug/DOM/W3C/Core/__init__.py
|
__all__ = [
"Attr",
"CDATASection",
"CharacterData",
"Comment",
"DOMException",
"DOMImplementation",
"Document",
"DocumentFragment",
"DocumentType",
"Element",
"Entity",
"EntityReference",
"NamedNodeMap",
"Node",
"NodeList",
"Notation",
"ProcessingInstruction",
"Text",
]
from .Attr import Attr
from .CDATASection import CDATASection
from .CharacterData import CharacterData
from .Comment import Comment
from .DOMException import DOMException
from .Document import Document
from .DocumentFragment import DocumentFragment
from .DocumentType import DocumentType
from .Element import Element
from .Entity import Entity
from .EntityReference import EntityReference
from .NamedNodeMap import NamedNodeMap
from .Node import Node
from .NodeList import NodeList
from .Notation import Notation
from .ProcessingInstruction import ProcessingInstruction
from .Text import Text
| 939
|
Python
|
.py
| 37
| 22.378378
| 56
| 0.774444
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,811
|
Text.py
|
buffer_thug/thug/DOM/W3C/Core/Text.py
|
#!/usr/bin/env python
from .CharacterData import CharacterData
class Text(CharacterData):
def __init__(self, doc, tag):
self.data = tag
CharacterData.__init__(self, doc, tag)
def splitText(self, offset):
newNode = self.doc.createTextNode(self.data[offset:])
self.data = self.data[:offset]
if self.parentNode:
self.parentNode.insertBefore(newNode, self.nextSibling)
return newNode
def getNodeValue(self):
return str(self.data)
def setNodeValue(self, value):
self.data = value
nodeValue = property(getNodeValue, setNodeValue)
@property
def nodeName(self):
return "#text"
@property
def nodeType(self):
from .NodeType import NodeType
return NodeType.TEXT_NODE
| 804
|
Python
|
.py
| 24
| 26.333333
| 67
| 0.66276
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,812
|
NamedNodeMap.py
|
buffer_thug/thug/DOM/W3C/Core/NamedNodeMap.py
|
#!/usr/bin/env python
from thug.DOM.JSClass import JSClass
class NamedNodeMap(JSClass):
def __init__(self, doc, tag):
self.doc = doc
self.tag = tag
def __len__(self):
return self.length
def __getattr__(self, key):
return self.getNamedItem(key)
def __getitem__(self, key):
return self.item(int(key))
def getNamedItem(self, name):
if name not in self.tag.attrs:
return None
from .Attr import Attr
attr = Attr(self.doc, None, name)
attr.nodeValue = self.tag.attrs[name]
return attr
def setNamedItem(self, attr):
oldvalue = self.tag.attrs.get(attr.name, None)
self.tag.attrs[attr.name] = attr.value
if oldvalue is None:
return None
from .Attr import Attr
oldattr = Attr(self.doc, None, attr.name)
oldattr.value = oldvalue
return oldattr
def removeNamedItem(self, name):
if name in self.tag.attrs:
del self.tag.attrs[name]
def item(self, index):
names = list(self.tag.attrs)
if index < 0 or index >= len(names):
return None
return self.getNamedItem(names[index])
@property
def length(self):
return len(self.tag.attrs)
| 1,295
|
Python
|
.py
| 39
| 24.974359
| 54
| 0.606624
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,813
|
ClassList.py
|
buffer_thug/thug/DOM/W3C/Core/ClassList.py
|
#!/usr/bin/env python
import logging
from thug.DOM.JSClass import JSClass
log = logging.getLogger("Thug")
class ClassList(JSClass):
def __init__(self, tag):
self.tag = tag
self.__init_classlist_personality()
self.__init_class_list()
def __init_classlist_personality(self):
if log.ThugOpts.Personality.isIE():
self.__init_classlist_personality_IE()
return
if log.ThugOpts.Personality.isFirefox():
self.__init_classlist_personality_Firefox()
return
if log.ThugOpts.Personality.isChrome():
self.__init_classlist_personality_Chrome()
return
if log.ThugOpts.Personality.isSafari():
self.__init_classlist_personality_Safari()
return
def __init_classlist_personality_IE(self):
self.add = self.__add_ie
self.remove = self.__remove_ie
self.toggle = self.__toggle_ie
def __init_classlist_personality_Firefox(self):
self.add = self.__add
self.remove = self.__remove
self.toggle = self.__toggle
self.replace = self.__replace
def __init_classlist_personality_Chrome(self):
self.add = self.__add
self.remove = self.__remove
self.toggle = self.__toggle
self.replace = self.__replace
def __init_classlist_personality_Safari(self):
self.add = self.__add
self.remove = self.__remove
self.toggle = self.__toggle
def __init_class_list(self):
self._class_list = []
if "class" not in self.tag.attrs:
return
attrs = self.tag.attrs["class"]
attrs = (
[
attrs,
]
if isinstance(attrs, str)
else attrs
)
for c in attrs:
if c not in self._class_list:
self._class_list.append(c)
def __do_add(self, c):
if c not in self._class_list:
self._class_list.append(c)
if "class" not in self.tag.attrs:
self.tag.attrs["class"] = []
attrs = self.tag.attrs["class"]
attrs = (
[
attrs,
]
if isinstance(attrs, str)
else attrs
)
if c in attrs:
return
attrs.append(c)
self.tag.attrs["class"] = attrs
def __add(self, *args):
for c in args:
self.__do_add(c)
def __add_ie(self, c):
self.__do_add(c)
def __do_remove(self, c):
if c in self._class_list:
self._class_list.remove(c)
if "class" not in self.tag.attrs:
return
attrs = self.tag.attrs["class"]
attrs = (
[
attrs,
]
if isinstance(attrs, str)
else attrs
)
if c not in attrs:
return
attrs.remove(c)
self.tag.attrs["class"] = attrs
def __remove(self, *args):
for c in args:
self.__do_remove(c)
def __remove_ie(self, c):
self.__do_remove(c)
def item(self, index):
if index < 0 or index > len(self._class_list) - 1:
return None
return self._class_list[index]
def __toggle(self, c, force=None):
if force is False or c in self._class_list:
self.remove(c)
return False
self.add(c)
return True
def __toggle_ie(self, c):
return self.__toggle(c)
def contains(self, c):
return c in self._class_list
def __replace(self, oldClass, newClass):
if oldClass not in self._class_list:
return
self.remove(oldClass)
self.add(newClass)
| 3,760
|
Python
|
.py
| 118
| 22.059322
| 58
| 0.540383
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,814
|
ProcessingInstruction.py
|
buffer_thug/thug/DOM/W3C/Core/ProcessingInstruction.py
|
#!/usr/bin/env python
from .Node import Node
class ProcessingInstruction(Node):
def __init__(self, doc, target, tag):
self._target = target
self.data = str(tag)
Node.__init__(self, doc, tag)
@property
def target(self):
return self._target
@property
def nodeName(self):
return self._target
@property
def nodeType(self):
return Node.PROCESSING_INSTRUCTION_NODE
@property
def nodeValue(self):
return self.data
| 507
|
Python
|
.py
| 19
| 20.421053
| 47
| 0.6375
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,815
|
Attr.py
|
buffer_thug/thug/DOM/W3C/Core/Attr.py
|
#!/usr/bin/env python
import bs4
from .Node import Node
class Attr(Node):
_value = ""
def __init__(self, doc, parent, attr):
self.doc = doc
self.parent = parent
self.attr = attr
tag = bs4.Tag(parser=self.doc, name="attr")
Node.__init__(self, doc, tag)
self._specified = False
self._value = self.getValue()
def __hash__(self): # pragma: no cover
return id(self)
def __eq__(self, other): # pragma: no cover
return (
hasattr(other, "parent")
and self.parent == other.parent
and hasattr(other, "attr")
and self.attr == other.attr
)
def __ne__(self, other): # pragma: no cover
return not self == other
@property
def nodeType(self):
return Node.ATTRIBUTE_NODE
@property
def nodeName(self):
return self.attr
def getNodeValue(self):
return self.getValue()
def setNodeValue(self, value):
self.setValue(value)
nodeValue = property(getNodeValue, setNodeValue)
@property
def childNodes(self):
from .NodeList import NodeList
return NodeList(self.doc, [])
@property
def parentNode(self):
return self.parent
# Introduced in DOM Level 2
@property
def ownerElement(self):
if self.parent:
if self.parent.nodeType == Node.ELEMENT_NODE:
return self.parent
return None
@property
def ownerDocument(self):
return self.doc
@property
def name(self):
return self.attr
@property
def specified(self):
if self.ownerElement is None:
return True
return self._specified
def getValue(self):
if self.parent:
if self.parent.tag.has_attr(self.attr):
self._specified = True
return self.parent.tag[self.attr]
return self._value
def setValue(self, value):
self._value = value
if self.parent:
self._specified = True
self.parent.tag[self.attr] = value
value = property(getValue, setValue)
| 2,172
|
Python
|
.py
| 72
| 21.930556
| 57
| 0.591502
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,816
|
DOMException.py
|
buffer_thug/thug/DOM/W3C/Core/DOMException.py
|
#!/usr/bin/env python
from thug.DOM.JSClass import JSClass
class DOMException(RuntimeError, JSClass):
# ExceptionCode
INDEX_SIZE_ERR = (
1 # If index or size is negative, or greater than the allowed value
)
DOMSTRING_SIZE_ERR = (
2 # If the specified range of text does not fit into a DOMString
)
HIERARCHY_REQUEST_ERR = 3 # If any node is inserted somewhere it doesn't belong
WRONG_DOCUMENT_ERR = 4 # If a node is used in a different document than the one that created it (that doesn't support it)
INVALID_CHARACTER_ERR = (
5 # If an invalid or illegal character is specified, such as in a name.
)
NO_DATA_ALLOWED_ERR = (
6 # If data is specified for a node which does not support data
)
NO_MODIFICATION_ALLOWED_ERR = 7 # If an attempt is made to modify an object where modifications are not allowed
NOT_FOUND_ERR = 8 # If an attempt is made to reference a node in a context where it does not exist
NOT_SUPPORTED_ERR = (
9 # If the implementation does not support the type of object requested
)
INUSE_ATTRIBUTE_ERR = (
10 # If an attempt is made to add an attribute that is already in use elsewhere
)
# Introduced in Level 2
INVALID_STATE_ERR = 11 # If an attempt is made to use an object that is not, or is no longer, usable
SYNTAX_ERR = 12 # If an invalid or illegal string is specified
INVALID_MODIFICATION_ERR = (
13 # If an attempt is made to modify the type of the underlying object
)
NAMESPACE_ERR = 14 # If an attempt is made to create or change an object in a way which is incorrect with regards to namespaces
INVALID_ACCESS_ERR = (
15 # If a parameter or an operation is not supported by the underlying object
)
def __init__(self, code):
super().__init__(code)
self.code = code
| 1,893
|
Python
|
.py
| 39
| 42.692308
| 132
| 0.685235
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,817
|
NodeList.py
|
buffer_thug/thug/DOM/W3C/Core/NodeList.py
|
#!/usr/bin/env python
import logging
from thug.DOM.JSClass import JSClass
log = logging.getLogger("Thug")
class NodeList(JSClass):
def __init__(self, doc, nodes):
self.doc = doc
self.nodes = nodes
def __len__(self):
return self.length
def __getitem__(self, key):
return self.item(int(key))
def item(self, index):
return (
log.DOMImplementation.createHTMLElement(self.doc, self.nodes[index])
if index in range(0, len(self.nodes))
else None
)
@property
def length(self):
return len(self.nodes)
| 617
|
Python
|
.py
| 21
| 22.428571
| 80
| 0.616695
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,818
|
DOMImplementation.py
|
buffer_thug/thug/DOM/W3C/Core/DOMImplementation.py
|
#!/usr/bin/env python
import logging
import bs4
from lxml.html import builder as E
from lxml.html import tostring
from thug.DOM.W3C import HTML
log = logging.getLogger("Thug")
class DOMImplementation(HTML.HTMLDocument):
features = (
("core", "1.0"),
("core", "2.0"),
("core", None),
("html", "1.0"),
("html", "2.0"),
("html", None),
("events", "2.0"),
("events", None),
("uievents", "2.0"),
("uievents", None),
("mouseevents", "2.0"),
("mouseevents", None),
("htmlevents", "2.0"),
("htmlevents", None),
("views", "2.0"),
("views", None),
("stylesheets", "2.0"),
("stylesheets", None),
)
@staticmethod
def hasFeature(feature, version):
if version == "":
version = None
return (feature.lower(), version) in DOMImplementation.features
TAGS = {
"html": HTML.HTMLHtmlElement,
"head": HTML.HTMLHeadElement,
"link": HTML.HTMLLinkElement,
"title": HTML.HTMLTitleElement,
"meta": HTML.HTMLMetaElement,
"base": HTML.HTMLBaseElement,
"isindex": HTML.HTMLIsIndexElement,
"style": HTML.HTMLStyleElement,
"body": HTML.HTMLBodyElement,
"form": HTML.HTMLFormElement,
"select": HTML.HTMLSelectElement,
"optgroup": HTML.HTMLOptGroupElement,
"option": HTML.HTMLOptionElement,
"input": HTML.HTMLInputElement,
"textarea": HTML.HTMLTextAreaElement,
"button": HTML.HTMLButtonElement,
"label": HTML.HTMLLabelElement,
"fieldset": HTML.HTMLFieldSetElement,
"legend": HTML.HTMLLegendElement,
"ul": HTML.HTMLUListElement,
"ol": HTML.HTMLOListElement,
"dl": HTML.HTMLDListElement,
"dir": HTML.HTMLDirectoryElement,
"menu": HTML.HTMLMenuElement,
"li": HTML.HTMLLIElement,
"div": HTML.HTMLDivElement,
"p": HTML.HTMLParagraphElement,
"h1": HTML.HTMLHeadingElement,
"h2": HTML.HTMLHeadingElement,
"h3": HTML.HTMLHeadingElement,
"h4": HTML.HTMLHeadingElement,
"h5": HTML.HTMLHeadingElement,
"h6": HTML.HTMLHeadingElement,
"q": HTML.HTMLQuoteElement,
"blockquote": HTML.HTMLQuoteElement,
"span": HTML.HTMLSpanElement,
"pre": HTML.HTMLPreElement,
"br": HTML.HTMLBRElement,
"basefont": HTML.HTMLBaseFontElement,
"font": HTML.HTMLFontElement,
"hr": HTML.HTMLHRElement,
"ins": HTML.HTMLModElement,
"del": HTML.HTMLModElement,
"a": HTML.HTMLAnchorElement,
"object": HTML.HTMLObjectElement,
"param": HTML.HTMLParamElement,
"img": HTML.HTMLImageElement,
"applet": HTML.HTMLAppletElement,
"script": HTML.HTMLScriptElement,
"frameset": HTML.HTMLFrameSetElement,
"frame": HTML.HTMLFrameElement,
"iframe": HTML.HTMLIFrameElement,
"table": HTML.HTMLTableElement,
"caption": HTML.HTMLTableCaptionElement,
"col": HTML.HTMLTableColElement,
"colgroup": HTML.HTMLTableColElement,
"thead": HTML.HTMLTableSectionElement,
"tbody": HTML.HTMLTableSectionElement,
"tfoot": HTML.HTMLTableSectionElement,
"tr": HTML.HTMLTableRowElement,
"th": HTML.HTMLTableCellElement,
"td": HTML.HTMLTableCellElement,
"media": HTML.HTMLMediaElement,
"audio": HTML.HTMLAudioElement,
"video": HTML.HTMLVideoElement,
}
@staticmethod
def createHTMLElement(doc, tag):
if isinstance(tag, bs4.NavigableString):
return DOMImplementation.wrap(doc, tag)
if log.ThugOpts.Personality.isIE():
if tag.name.lower() in ("t:animatecolor",):
return HTML.TAnimateColor(doc, tag)
if (
tag.name.lower() in ("audio",)
and log.ThugOpts.Personality.browserMajorVersion < 9
):
return HTML.HTMLElement(doc, tag)
if tag.name.lower() in DOMImplementation.TAGS:
return DOMImplementation.TAGS[tag.name.lower()](doc, tag)
return HTML.HTMLElement(doc, tag)
def _createHTMLDocument(self, title=None):
body = E.BODY()
title = E.TITLE(title) if title else ""
head = E.HEAD(title)
html = E.HTML(head, body)
soup = bs4.BeautifulSoup(tostring(html, doctype="<!doctype html>"), "lxml")
return DOMImplementation(soup)
@staticmethod
def wrap(doc, obj):
from .Element import Element
if obj is None:
return None
if isinstance(obj, bs4.CData): # pragma: no cover
from .CDATASection import CDATASection
return CDATASection(doc, obj)
if isinstance(obj, bs4.NavigableString):
from .Text import Text
return Text(doc, obj)
return Element(doc, obj)
| 4,988
|
Python
|
.py
| 134
| 28.291045
| 83
| 0.609398
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,819
|
HTMLOListElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLOListElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
class HTMLOListElement(HTMLElement):
compact = bool_property("compact")
start = attr_property("start", int)
type = attr_property("type")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 373
|
Python
|
.py
| 10
| 33.5
| 44
| 0.724234
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,820
|
HTMLBaseFontElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLBaseFontElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLBaseFontElement(HTMLElement):
color = attr_property("color")
face = attr_property("face")
size = attr_property("size", int)
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 329
|
Python
|
.py
| 9
| 32.444444
| 44
| 0.705696
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,821
|
HTMLLabelElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLLabelElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .form_property import form_property
class HTMLLabelElement(HTMLElement):
accessKey = attr_property("accesskey")
form = form_property()
htmlFor = attr_property("for")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 366
|
Python
|
.py
| 10
| 32.8
| 44
| 0.730114
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,822
|
HTMLObjectElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLObjectElement.py
|
#!/usr/bin/env python
import logging
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
from .form_property import form_property
log = logging.getLogger("Thug")
class HTMLObjectElement(HTMLElement):
code = attr_property("code")
align = attr_property("align")
archive = attr_property("archive")
border = attr_property("border")
classid = attr_property("classid")
codeBase = attr_property("codebase")
codeType = attr_property("codetype")
data = attr_property("data")
declare = bool_property("declare")
form = form_property()
height = attr_property("height")
hspace = attr_property("hspace", int)
name = attr_property("name")
standBy = attr_property("standby")
tabIndex = attr_property("tabindex", int, default=0)
type = attr_property("type")
useMap = attr_property("usemap")
vspace = attr_property("vspace", int)
width = attr_property("width")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
self._window = self.doc.window
def __getattr__(self, name):
for key, value in self.tag.attrs.items():
if key.lower() not in ("id",):
continue
obj = getattr(self.doc.window, value, None)
if obj:
attr = getattr(obj, name, None)
if attr:
return attr
log.info("HTMLObjectElement attribute not found: %s", (name,))
raise AttributeError
def __setattr__(self, name, value):
if name == "classid":
self.setAttribute(name, value)
return
self.__dict__[name] = value
if "funcattrs" not in self.__dict__:
return
if name in self.__dict__["funcattrs"]:
self.__dict__["funcattrs"][name](value)
# Introduced in DOM Level 2
@property
def contentDocument(self):
return self.doc if self.doc else None
def setAttribute(self, name, value):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_setattribute_count()
# ActiveX registration
if name == "classid":
from thug.ActiveX.ActiveX import register_object
try:
register_object(self, value)
except TypeError:
return
self.tag[name] = value
@property
def object(self):
return self
def definition(self, value):
pass # pragma: no cover
| 2,550
|
Python
|
.py
| 70
| 28.342857
| 70
| 0.616667
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,823
|
HTMLHeadingElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLHeadingElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLHeadingElement(HTMLElement):
align = attr_property("align")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 257
|
Python
|
.py
| 7
| 32.857143
| 44
| 0.727642
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,824
|
HTMLLIElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLLIElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLLIElement(HTMLElement):
type = attr_property("type")
value = attr_property("value", int)
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 290
|
Python
|
.py
| 8
| 32.25
| 44
| 0.708633
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,825
|
HTMLAudioElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLAudioElement.py
|
#!/usr/bin/env python
import logging
from .HTMLMediaElement import HTMLMediaElement
log = logging.getLogger("Thug")
class HTMLAudioElement(HTMLMediaElement):
def __init__(self, doc, tag):
HTMLMediaElement.__init__(self, doc, tag)
| 247
|
Python
|
.py
| 7
| 31.857143
| 49
| 0.753191
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,826
|
HTMLFormElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLFormElement.py
|
#!/usr/bin/env python
import logging
from .HTMLElement import HTMLElement
from .HTMLFormControlsCollection import HTMLFormControlsCollection
from .attr_property import attr_property
log = logging.getLogger("Thug")
class HTMLFormElement(HTMLElement):
name = attr_property("name")
acceptCharset = attr_property("accept-charset", default="")
action = attr_property("action")
enctype = attr_property("enctype", default="application/x-www-form-urlencoded")
encoding = attr_property("enctype", default="application/x-www-form-urlencoded")
method = attr_property("method", default="get")
target = attr_property("target", default="")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
def __getattr__(self, key):
for tag in self.tag.children:
if tag.name not in ("input",):
continue
if "name" in tag.attrs and tag.attrs["name"] in (key,):
return log.DOMImplementation.createHTMLElement(self.doc, tag)
raise AttributeError
@property
def elements(self):
nodes = []
for tag in self.tag.children:
if getattr(tag, "name", None) and tag.name not in ("br",):
nodes.append(log.DOMImplementation.createHTMLElement(self.doc, tag))
return HTMLFormControlsCollection(self.doc, nodes)
@property
def length(self):
return len(self.elements)
def submit(self):
handler = getattr(log.DFT, "do_handle_form", None)
if handler:
handler(self.tag) # pylint:disable=not-callable
def reset(self):
log.warning("[HTMLFormElement] reset method not defined")
| 1,689
|
Python
|
.py
| 39
| 35.897436
| 84
| 0.667482
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,827
|
HTMLScriptElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLScriptElement.py
|
#!/usr/bin/env python
import logging
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
from .text_property import text_property
log = logging.getLogger("Thug")
class HTMLScriptElement(HTMLElement):
_async = bool_property("async", readonly=True, novalue=True)
text = text_property()
htmlFor = None
event = None
charset = attr_property("charset", default="")
defer = bool_property("defer", novalue=True)
_src = attr_property("src", default="")
type = attr_property("type")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
def __getattr__(self, name):
if name in ("async",):
return self._async
raise AttributeError
def get_src(self):
return self._src
def set_src(self, src):
self._src = src
log.DFT.handle_script(self.tag)
src = property(get_src, set_src)
| 963
|
Python
|
.py
| 28
| 29
| 64
| 0.667749
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,828
|
AudioTrackList.py
|
buffer_thug/thug/DOM/W3C/HTML/AudioTrackList.py
|
#!/usr/bin/env python
from .HTMLCollection import HTMLCollection
class AudioTrackList(HTMLCollection):
def __init__(self, doc, tracks):
HTMLCollection.__init__(self, doc, tracks)
| 194
|
Python
|
.py
| 5
| 34.8
| 50
| 0.736559
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,829
|
HTMLModElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLModElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLModElement(HTMLElement):
cite = attr_property("cite")
dateTime = attr_property("datetime")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 292
|
Python
|
.py
| 8
| 32.5
| 44
| 0.717857
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,830
|
HTMLAnchorElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLAnchorElement.py
|
#!/usr/bin/env python
import logging
import time
import datetime
from urllib.parse import urlparse
from .HTMLElement import HTMLElement
from .attr_property import attr_property
log = logging.getLogger("Thug")
class HTMLAnchorElement(HTMLElement):
accessKey = attr_property("accesskey")
charset = attr_property("charset", default="")
coords = attr_property("coords")
download = attr_property("download")
href = attr_property("href")
hreflang = attr_property("hreflang")
name = attr_property("name")
rel = attr_property("rel")
rev = attr_property("rev")
shape = attr_property("shape")
tabIndex = attr_property("tabindex", int)
target = attr_property("target")
type = attr_property("type")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
@property
def protocol(self):
if not self.href:
return ":"
o = urlparse(self.href)
return f"{o.scheme}:" if o.scheme else ":"
@property
def host(self):
if not self.href:
return ""
o = urlparse(self.href)
return o.netloc if o.netloc else ""
@property
def hostname(self):
if not self.href:
return ""
return self.host.split(":")[0]
@property
def port(self):
if not self.host:
return ""
if ":" not in self.host:
return ""
return self.host.split(":")[1]
@property
def pathname(self):
if not self.href:
return ""
o = urlparse(self.href)
return o.path if o.path else "/"
def blur(self):
pass
def focus(self):
pass
def click(self):
now = datetime.datetime.now()
self.tag["_clicked"] = time.mktime(now.timetuple())
if self.href:
log.DFT.follow_href(self.href)
| 1,878
|
Python
|
.py
| 63
| 22.888889
| 59
| 0.604794
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,831
|
HTMLTableCellElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLTableCellElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
class HTMLTableCellElement(HTMLElement):
abbr = attr_property("abbr")
align = attr_property("align")
axis = attr_property("axis")
bgColor = attr_property("bgcolor")
ch = attr_property("char")
chOff = attr_property("charoff")
colSpan = attr_property("colspan", int)
headers = attr_property("headers")
height = attr_property("height")
noWrap = bool_property("nowrap")
rowSpan = attr_property("rowspan", int)
scope = attr_property("scope")
vAlign = attr_property("valign")
width = attr_property("width")
def __init__(self, doc, tag, index=0):
HTMLElement.__init__(self, doc, tag)
self._cellIndex = index
@property
def cellIndex(self):
return self._cellIndex
| 893
|
Python
|
.py
| 25
| 30.84
| 44
| 0.683662
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,832
|
HTMLIFrameElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLIFrameElement.py
|
#!/usr/bin/env python
import logging
from thug.DOM import W3C
from .HTMLElement import HTMLElement
from .attr_property import attr_property
log = logging.getLogger("Thug")
class HTMLIFrameElement(HTMLElement):
align = attr_property("align")
frameBorder = attr_property("frameborder")
height = attr_property("height")
longDesc = attr_property("longdesc")
marginHeight = attr_property("marginheight")
marginWidth = attr_property("marginwidth")
name = attr_property("name")
referrerpolicy = attr_property("referrerpolicy")
sandbox = attr_property("sandbox")
scrolling = attr_property("scrolling")
src = attr_property("src")
srcdoc = attr_property("srcdoc")
width = attr_property("width")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
self.document = W3C.w3c.getDOMImplementation()
# Introduced in DOM Level 2
@property
def contentDocument(self):
return self.doc if self.doc else None
@property
def contentWindow(self):
# if self.id in log.ThugLogging.windows:
# return log.ThugLogging.windows[self.id]
return getattr(self.doc, "window", None) if self.doc else None
| 1,219
|
Python
|
.py
| 32
| 32.9375
| 70
| 0.702886
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,833
|
HTMLTextAreaElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLTextAreaElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
from .text_property import text_property
from .form_property import form_property
class HTMLTextAreaElement(HTMLElement):
accessKey = attr_property("accesskey")
cols = attr_property("cols", int)
disabled = bool_property("disabled")
form = form_property()
name = attr_property("name")
readOnly = bool_property("readonly")
rows = attr_property("rows", int)
tabIndex = attr_property("tabindex", int)
value = text_property()
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
@property
def defaultValue(self):
return self.value
@defaultValue.setter
def defaultValue(self, value):
self.value = value
@property
def type(self):
return "textarea"
def focus(self):
pass
def blur(self):
pass
def select(self):
pass
| 1,004
|
Python
|
.py
| 33
| 25.121212
| 45
| 0.681582
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,834
|
HTMLTitleElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLTitleElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .text_property import text_property
class HTMLTitleElement(HTMLElement):
text = text_property()
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 247
|
Python
|
.py
| 7
| 31.428571
| 44
| 0.724576
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,835
|
HTMLFormControlsCollection.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLFormControlsCollection.py
|
#!/usr/bin/env python
from .HTMLCollection import HTMLCollection
class HTMLFormControlsCollection(HTMLCollection):
def __init__(self, doc, nodes):
HTMLCollection.__init__(self, doc, nodes)
| 204
|
Python
|
.py
| 5
| 36.8
| 49
| 0.75
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,836
|
HTMLElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLElement.py
|
#!/usr/bin/env python
import logging
import random
import io
import bs4
from thug.DOM.W3C.Core.DOMException import DOMException
from thug.DOM.W3C.Core.Element import Element
from .Dataset import Dataset
from .attr_property import attr_property
log = logging.getLogger("Thug")
class HTMLElement(Element):
className = attr_property("class", default="")
dir = attr_property("dir")
id = attr_property("id")
lang = attr_property("lang")
title = attr_property("title")
lang = attr_property("lang")
def __init__(self, doc, tag):
Element.__init__(self, doc, tag)
self.__init_htmlelement_personality()
def __init_htmlelement_personality(self):
if log.ThugOpts.Personality.isIE():
self.__init_htmlelement_personality_IE()
return
if log.ThugOpts.Personality.isFirefox():
self.__init_htmlelement_personality_Firefox()
return
if log.ThugOpts.Personality.isChrome():
self.__init_htmlelement_personality_Chrome()
return
if log.ThugOpts.Personality.isSafari():
self.__init_htmlelement_personality_Safari()
return
def __init_htmlelement_personality_IE(self):
if log.ThugOpts.Personality.browserMajorVersion > 10:
self.dataset = Dataset(self.tag.attrs)
def __init_htmlelement_personality_Firefox(self):
if log.ThugOpts.Personality.browserMajorVersion > 5:
self.dataset = Dataset(self.tag.attrs)
def __init_htmlelement_personality_Chrome(self):
if log.ThugOpts.Personality.browserMajorVersion > 7:
self.dataset = Dataset(self.tag.attrs)
def __init_htmlelement_personality_Safari(self):
if log.ThugOpts.Personality.browserMajorVersion > 4:
self.dataset = Dataset(self.tag.attrs)
def __getattr__(self, key):
if key in log.DFT.handled_on_events:
return None
if key in log.DFT._on_events:
return None
log.info("[HTMLElement] Undefined: %s", key)
raise AttributeError
def getInnerHTML(self):
if not self.hasChildNodes():
return ""
html = io.StringIO()
for tag in self.tag.contents:
html.write(str(tag))
return html.getvalue()
def setInnerHTML(self, html):
log.HTMLClassifier.classify(
log.ThugLogging.url if log.ThugOpts.local else log.last_url, html
)
self.tag.clear()
for node in bs4.BeautifulSoup(html, "html.parser").contents:
self.tag.append(node)
name = getattr(node, "name", None)
if name is None:
continue
handler = getattr(log.DFT, f"handle_{name}", None)
if handler:
handler(node)
def getOuterHTML(self):
return str(self.tag)
innerHTML = property(getInnerHTML, setInnerHTML)
outerHTML = property(getOuterHTML, setInnerHTML)
# WARNING: NOT DEFINED IN W3C SPECS!
def focus(self):
pass
@property
def sourceIndex(self):
return None
@property
def offsetParent(self):
return None
@property
def offsetTop(self):
return random.randint(1, 10)
@property
def offsetLeft(self):
return random.randint(10, 100)
@property
def offsetWidth(self):
return random.randint(10, 100)
@property
def offsetHeight(self):
return random.randint(10, 100)
def insertAdjacentHTML(self, position, text):
if position not in (
"beforebegin",
"afterbegin",
"beforeend",
"afterend",
):
raise DOMException(DOMException.NOT_SUPPORTED_ERR)
if position in ("beforebegin",):
target = self.tag.parent if self.tag.parent else self.doc.find("body")
pos = target.index(self.tag) - 1
if position in ("afterbegin",):
target = self.tag
pos = 0
if position in ("beforeend",):
target = self.tag
pos = len(list(self.tag.children))
if position in ("afterend",):
target = self.tag.parent if self.tag.parent else self.doc.find("body")
pos = target.index(self.tag) + 1
for node in bs4.BeautifulSoup(text, "html.parser").contents:
target.insert(pos, node)
pos += 1
| 4,438
|
Python
|
.py
| 120
| 28.125
| 82
| 0.623744
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,837
|
HTMLBaseElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLBaseElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLBaseElement(HTMLElement):
href = attr_property("href")
target = attr_property("target")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 289
|
Python
|
.py
| 8
| 32.125
| 44
| 0.714801
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,838
|
HTMLOptionElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLOptionElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
from .form_property import form_property
class HTMLOptionElement(HTMLElement):
defaultSelected = bool_property("selected")
index = attr_property("index", int, readonly=True)
disabled = bool_property("disabled")
form = form_property()
label = attr_property("label")
selected = False
value = attr_property("value")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
@property
def text(self):
return str(self.tag.string) if self.tag.string else ""
| 663
|
Python
|
.py
| 18
| 32.444444
| 62
| 0.714063
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,839
|
HTMLHeadElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLHeadElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLHeadElement(HTMLElement):
profile = attr_property("profile")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 258
|
Python
|
.py
| 7
| 33
| 44
| 0.728745
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,840
|
HTMLLinkElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLLinkElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLLinkElement(HTMLElement):
charset = attr_property("charset", default="")
disabled = False
href = attr_property("href")
hreflang = attr_property("hreflang")
media = attr_property("media")
rel = attr_property("rel")
rev = attr_property("rev")
target = attr_property("target")
type = attr_property("type")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 532
|
Python
|
.py
| 15
| 31
| 50
| 0.682261
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,841
|
HTMLCollection.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLCollection.py
|
#!/usr/bin/env python
import logging
import bs4
from thug.DOM.JSClass import JSClass
log = logging.getLogger("Thug")
class HTMLCollection(JSClass):
def __init__(self, doc, nodes):
self.doc = doc
self.nodes = nodes
def __len__(self):
return self.length
def __getitem__(self, key):
return self.item(int(key))
def __delitem__(self, key): # pragma: no cover
self.nodes.__delitem__(key)
def __getattr__(self, key):
return self.namedItem(key)
@property
def length(self):
return len(self.nodes)
def item(self, index):
if index < 0 or index >= self.length:
return None
if isinstance(self.nodes[index], bs4.element.Tag):
return log.DOMImplementation.createHTMLElement(self.doc, self.nodes[index])
return self.nodes[index]
def namedItem(self, name):
for node in self.nodes:
if "id" in node.attrs and node.attrs["id"] in (name,):
return log.DOMImplementation.createHTMLElement(self.doc, node)
for node in self.nodes:
if "name" in node.attrs and node.attrs["name"] in (name,):
return log.DOMImplementation.createHTMLElement(self.doc, node)
return None
| 1,278
|
Python
|
.py
| 34
| 29.617647
| 87
| 0.629177
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,842
|
HTMLStyleElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLStyleElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLStyleElement(HTMLElement):
disabled = False
media = attr_property("media")
type = attr_property("type")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 309
|
Python
|
.py
| 9
| 30.222222
| 44
| 0.709459
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,843
|
HTMLIsIndexElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLIsIndexElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLIsIndexElement(HTMLElement):
form = None
prompt = attr_property("prompt")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 275
|
Python
|
.py
| 8
| 30.375
| 44
| 0.718631
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,844
|
HTMLHRElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLHRElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
class HTMLHRElement(HTMLElement):
align = attr_property("align")
noShade = bool_property("noshade")
size = attr_property("size")
width = attr_property("width")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 400
|
Python
|
.py
| 11
| 32.454545
| 44
| 0.716883
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,845
|
HTMLFieldSetElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLFieldSetElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .bool_property import bool_property
from .form_property import form_property
class HTMLFieldSetElement(HTMLElement):
disabled = bool_property("disabled")
form = form_property()
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 332
|
Python
|
.py
| 9
| 33.222222
| 44
| 0.739812
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,846
|
text_property.py
|
buffer_thug/thug/DOM/W3C/HTML/text_property.py
|
#!/usr/bin/env python
import logging
log = logging.getLogger("Thug")
def text_property(readonly=False):
def getter(self):
return str(self.tag.string) if self.tag.string else ""
def setter(self, text):
self.tag.string = text
if self.tagName.lower() in ("script",):
if log.ThugOpts.code_logging:
log.ThugLogging.add_code_snippet(text, "Javascript", "Contained_Inside")
script_type = self.tag.attrs.get("type", None)
if script_type and "vbscript" in script_type.lower():
log.VBSClassifier.classify(
log.ThugLogging.url if log.ThugOpts.local else log.last_url, text
)
self.doc.window.evalScript(text, self.tag.string)
return property(getter) if readonly else property(getter, setter)
| 841
|
Python
|
.py
| 18
| 36.777778
| 88
| 0.636364
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,847
|
HTMLAllCollection.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLAllCollection.py
|
#!/usr/bin/env python
from .HTMLCollection import HTMLCollection
class HTMLAllCollection(HTMLCollection):
def __init__(self, doc, nodes):
HTMLCollection.__init__(self, doc, nodes)
def tags(self, name):
from thug.DOM.W3C.Core.NodeList import NodeList
nodes = list(self.doc.find_all(name.lower()))
return NodeList(self.doc, nodes)
| 374
|
Python
|
.py
| 9
| 35.555556
| 55
| 0.697222
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,848
|
HTMLAppletElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLAppletElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLAppletElement(HTMLElement):
align = attr_property("align")
alt = attr_property("alt")
archive = attr_property("archive")
code = attr_property("code")
codeBase = attr_property("codebase")
height = attr_property("height")
hspace = attr_property("hspace", int)
name = attr_property("name")
object = attr_property("object")
vspace = attr_property("vspace", int)
width = attr_property("width")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 626
|
Python
|
.py
| 17
| 32.294118
| 44
| 0.684298
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,849
|
HTMLSpanElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLSpanElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
class HTMLSpanElement(HTMLElement):
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 177
|
Python
|
.py
| 5
| 31.4
| 44
| 0.710059
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,850
|
HTMLParamElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLParamElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLParamElement(HTMLElement):
name = attr_property("name")
type = attr_property("type")
value = attr_property("value")
valueType = attr_property("valuetype")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 364
|
Python
|
.py
| 10
| 32.2
| 44
| 0.705714
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,851
|
form_property.py
|
buffer_thug/thug/DOM/W3C/HTML/form_property.py
|
#!/usr/bin/env python
import logging
log = logging.getLogger("Thug")
def form_property(default=None):
def getter(self):
if self.tag.parent.name.lower() not in ("form",):
return default
_form = getattr(self, "_form", None)
if _form is None:
self._form = log.DOMImplementation.createHTMLElement(
self.doc, self.tag.parent
)
return self._form
return property(getter)
| 463
|
Python
|
.py
| 14
| 25
| 65
| 0.61086
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,852
|
HTMLTableRowElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLTableRowElement.py
|
#!/usr/bin/env python
import logging
from thug.DOM.W3C.Core.DOMException import DOMException
from .HTMLElement import HTMLElement
from .HTMLCollection import HTMLCollection
from .HTMLTableCellElement import HTMLTableCellElement
from .attr_property import attr_property
log = logging.getLogger("Thug")
class HTMLTableRowElement(HTMLElement):
align = attr_property("align")
bgColor = attr_property("bgcolor")
ch = attr_property("char")
chOff = attr_property("charoff")
vAlign = attr_property("valign")
def __init__(self, doc, tag, table=None, section=None):
HTMLElement.__init__(self, doc, tag)
self._table = table
self._section = section
self._cells = HTMLCollection(doc, [])
# Modified in DOM Level 2
@property
def rowIndex(self):
if not self._table:
return None # pragma: no cover
index = 0
while index < len(self._table.rows):
if id(self._table.rows.item(index)) == id(self):
return index
index += 1
return None # pragma: no cover
# Modified in DOM Level 2
@property
def sectionRowIndex(self):
if not self._section:
return 0 # pragma: no cover
index = 0
while index < len(self._section.rows):
if id(self._section.rows.item(index)) == id(self):
return index
index += 1
return None # pragma: no cover
# Modified in DOM Level 2
@property
def cells(self):
return self._cells
# Modified in DOM Level 2
def insertCell(self, index=None):
# `index' specifies the position of the row to insert (starts at 0).
# The value of -1 can also be used; which result in that the new row
# will be inserted at the last position. This parameter is required
# in Firefox and Opera, but optional in Internet Explorer, Chrome and
# Safari. If this parameter is omitted, insertRow() inserts a new row
# at the last position in IE and at the first position in Chrome and
# Safari.
if index is None:
if log.ThugOpts.Personality.isIE():
index = -1
if (
log.ThugOpts.Personality.isChrome()
or log.ThugOpts.Personality.isSafari()
):
index = 0
cell = HTMLTableCellElement(self.doc, self.tag, index)
if index in (
-1,
len(self._cells),
):
self.cells.nodes.append(cell)
else:
self.cells.nodes.insert(index, cell)
return cell
# Modified in DOM Level 2
def deleteCell(self, index):
if index < -1 or index >= len(self.cells.nodes):
raise DOMException(DOMException.INDEX_SIZE_ERR)
del self.cells.nodes[index]
| 2,865
|
Python
|
.py
| 76
| 28.986842
| 77
| 0.615468
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,853
|
TimeRanges.py
|
buffer_thug/thug/DOM/W3C/HTML/TimeRanges.py
|
#!/usr/bin/env python
from thug.DOM.JSClass import JSClass
from thug.DOM.W3C.Core.DOMException import DOMException
class TimeRanges(JSClass):
def __init__(self, doc, ranges):
self.doc = doc
self.ranges = ranges
@property
def length(self):
return len(self.ranges)
def start(self, index):
if index in range(0, len(self.ranges)):
return self.ranges[0][0] # pragma: no cover
raise DOMException(DOMException.INDEX_SIZE_ERR)
def end(self, index):
if index in range(0, len(self.ranges)):
return self.ranges[0][1] # pragma: no cover
raise DOMException(DOMException.INDEX_SIZE_ERR)
| 683
|
Python
|
.py
| 18
| 30.944444
| 56
| 0.660578
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,854
|
HTMLOptionsCollection.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLOptionsCollection.py
|
#!/usr/bin/env python
from .HTMLCollection import HTMLCollection
# Introduced in DOM Level 2
class HTMLOptionsCollection(HTMLCollection):
def __init__(self, doc, nodes):
HTMLCollection.__init__(self, doc, nodes)
| 227
|
Python
|
.py
| 6
| 34.333333
| 49
| 0.747706
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,855
|
HTMLImageElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLImageElement.py
|
#!/usr/bin/env python
import logging
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
log = logging.getLogger("Thug")
class HTMLImageElement(HTMLElement):
align = attr_property("align")
alt = attr_property("alt")
border = attr_property("border")
height = attr_property("height", int)
hspace = attr_property("hspace", int)
isMap = bool_property("ismap")
longDesc = attr_property("longdesc")
name = attr_property("name")
useMap = attr_property("usemap")
vspace = attr_property("vspace", int)
width = attr_property("width", int)
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
@property
def complete(self):
return True
def getSrc(self):
return str(self.tag.attrs["src"]) if "src" in self.tag.attrs else None
def setSrc(self, value):
self.tag.attrs["src"] = str(value)
if value.lower().startswith("res://"):
onerror = getattr(self, "onerror", None)
if log.JSEngine.isJSFunction(onerror):
with self.doc.window.context:
onerror.__call__()
src = property(getSrc, setSrc)
| 1,233
|
Python
|
.py
| 33
| 30.909091
| 78
| 0.64899
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,856
|
HTMLInputElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLInputElement.py
|
#!/usr/bin/env python
import sys
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
from .form_property import form_property
class HTMLInputElement(HTMLElement):
accept = attr_property("accept")
accessKey = attr_property("accesskey")
align = attr_property("align")
alt = attr_property("alt")
checked = bool_property("checked")
defaultChecked = bool_property("checked")
defaultValue = bool_property("value")
disabled = bool_property("disabled")
form = form_property()
maxLength = attr_property("maxlength", int, default=sys.maxsize)
name = attr_property("name")
readOnly = bool_property("readonly")
size = attr_property("size", int)
src = attr_property("src")
tabIndex = attr_property("tabindex", int)
type = attr_property("type", default="text")
useMap = attr_property("usermap")
_value = attr_property("value")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
def getValue(self):
return self._value
def setValue(self, value):
self._value = value
value = property(getValue, setValue)
def blur(self):
pass
def focus(self):
pass
def select(self):
pass
def click(self):
pass
| 1,330
|
Python
|
.py
| 40
| 27.95
| 68
| 0.675274
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,857
|
HTMLBodyElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLBodyElement.py
|
#!/usr/bin/env python
import logging
import io
import bs4
from .HTMLElement import HTMLElement
from .attr_property import attr_property
log = logging.getLogger("Thug")
class HTMLBodyElement(HTMLElement):
aLink = attr_property("alink")
background = attr_property("background")
bgColor = attr_property("bgcolor")
link = attr_property("link")
text = attr_property("text")
vLink = attr_property("vlink")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag if tag else doc)
def __str__(self):
return "[object HTMLBodyElement]"
def getInnerHTML(self):
html = io.StringIO()
for tag in self.tag.contents:
try:
html.write(str(tag))
except Exception as e: # pylint:disable=broad-except
log.warning("[HTMLBodyElement] innerHTML warning: %s", str(e))
return html.getvalue()
def setInnerHTML(self, html):
log.HTMLClassifier.classify(
log.ThugLogging.url if log.ThugOpts.local else log.last_url, html
)
self.tag.clear()
for node in bs4.BeautifulSoup(html, "html.parser").contents:
self.tag.append(node)
name = getattr(node, "name", None)
if name is None:
continue
handler = getattr(log.DFT, f"handle_{name}", None)
if handler:
handler(node)
innerHTML = property(getInnerHTML, setInnerHTML)
| 1,484
|
Python
|
.py
| 40
| 28.775
| 78
| 0.626489
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,858
|
HTMLTableSectionElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLTableSectionElement.py
|
#!/usr/bin/env python
import logging
import bs4
from thug.DOM.W3C.Core.DOMException import DOMException
from .HTMLElement import HTMLElement
from .HTMLCollection import HTMLCollection
from .HTMLTableRowElement import HTMLTableRowElement
from .attr_property import attr_property
log = logging.getLogger("Thug")
class HTMLTableSectionElement(HTMLElement):
align = attr_property("align")
ch = attr_property("char")
chOff = attr_property("charoff")
vAlign = attr_property("valign")
def __init__(self, doc, tag, table=None):
HTMLElement.__init__(self, doc, tag)
self._table = table
self._rows = HTMLCollection(doc, [])
@property
def rows(self):
return self._rows
# Modified in DOM Level 2
def insertRow(self, index=None):
# `index' specifies the position of the row to insert (starts at 0). The value of
# -1 can also be used; which result in that the new row will be inserted at the
# last position. This parameter is required in Firefox and Opera, but optional in
# Internet Explorer, Chrome and Safari. If this parameter is omitted, insertRow()
# inserts a new row at the last position in IE and at the first position in Chrome
# and Safari.
if index is None:
if log.ThugOpts.Personality.isIE():
index = -1
if (
log.ThugOpts.Personality.isChrome()
or log.ThugOpts.Personality.isSafari()
):
index = 0
row = HTMLTableRowElement(
self.doc, bs4.Tag(self.doc, name="tr"), table=self._table, section=self
)
if index in (
-1,
len(self._rows),
):
self.rows.nodes.append(row)
else:
self.rows.nodes.insert(index, row)
return row
# Modified in DOM Level 2
def deleteRow(self, index):
if index < -1 or index >= len(self.rows.nodes):
raise DOMException(DOMException.INDEX_SIZE_ERR)
del self.rows.nodes[index]
| 2,075
|
Python
|
.py
| 53
| 30.962264
| 90
| 0.637631
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,859
|
HTMLDListElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLDListElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLDListElement(HTMLElement):
compact = attr_property("compact", bool)
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 265
|
Python
|
.py
| 7
| 34
| 44
| 0.728346
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,860
|
HTMLTableColElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLTableColElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLTableColElement(HTMLElement):
align = attr_property("align")
ch = attr_property("char")
chOff = attr_property("charoff")
span = attr_property("span", int)
vAlign = attr_property("valign")
width = attr_property("width")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 436
|
Python
|
.py
| 12
| 32
| 44
| 0.692857
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,861
|
__init__.py
|
buffer_thug/thug/DOM/W3C/HTML/__init__.py
|
__all__ = [
"AudioTrackList",
"HTMLAllCollection",
"HTMLAnchorElement",
"HTMLAppletElement",
"HTMLAudioElement",
"HTMLBRElement",
"HTMLBaseElement",
"HTMLBaseFontElement",
"HTMLBodyElement",
"HTMLButtonElement",
"HTMLCollection",
"HTMLDirectoryElement",
"HTMLDivElement",
"HTMLDListElement",
"HTMLDocument",
"HTMLDocumentCompatibleInfo",
"HTMLDocumentCompatibleInfoCollection",
"HTMLElement",
"HTMLFieldSetElement",
"HTMLFontElement",
"HTMLFormElement",
"HTMLFrameElement",
"HTMLFrameSetElement",
"HTMLHRElement",
"HTMLHeadElement",
"HTMLHeadingElement",
"HTMLHtmlElement",
"HTMLIFrameElement",
"HTMLImageElement",
"HTMLInputElement",
"HTMLIsIndexElement",
"HTMLLIElement",
"HTMLLabelElement",
"HTMLLegendElement",
"HTMLLinkElement",
"HTMLMediaElement",
"HTMLMenuElement",
"HTMLMetaElement",
"HTMLModElement",
"HTMLOListElement",
"HTMLObjectElement",
"HTMLOptGroupElement",
"HTMLOptionElement",
"HTMLOptionsCollection",
"HTMLParagraphElement",
"HTMLParamElement",
"HTMLPreElement",
"HTMLQuoteElement",
"HTMLScriptElement",
"HTMLSelectElement",
"HTMLSpanElement",
"HTMLStyleElement",
"HTMLTableCaptionElement",
"HTMLTableCellElement",
"HTMLTableColElement",
"HTMLTableElement",
"HTMLTableRowElement",
"HTMLTableSectionElement",
"HTMLTextAreaElement",
"HTMLTitleElement",
"HTMLUListElement",
"HTMLVideoElement",
"TAnimateColor",
"TextTrackList",
"TimeRanges",
]
from .AudioTrackList import AudioTrackList
from .HTMLAllCollection import HTMLAllCollection
from .HTMLAnchorElement import HTMLAnchorElement
from .HTMLAppletElement import HTMLAppletElement
from .HTMLAudioElement import HTMLAudioElement
from .HTMLBRElement import HTMLBRElement
from .HTMLBaseElement import HTMLBaseElement
from .HTMLBaseFontElement import HTMLBaseFontElement
from .HTMLBodyElement import HTMLBodyElement
from .HTMLButtonElement import HTMLButtonElement
from .HTMLCollection import HTMLCollection
from .HTMLDListElement import HTMLDListElement
from .HTMLDirectoryElement import HTMLDirectoryElement
from .HTMLDivElement import HTMLDivElement
from .HTMLDocument import HTMLDocument
from .HTMLDocumentCompatibleInfo import HTMLDocumentCompatibleInfo
from .HTMLDocumentCompatibleInfoCollection import HTMLDocumentCompatibleInfoCollection
from .HTMLElement import HTMLElement
from .HTMLFieldSetElement import HTMLFieldSetElement
from .HTMLFontElement import HTMLFontElement
from .HTMLFormElement import HTMLFormElement
from .HTMLFrameElement import HTMLFrameElement
from .HTMLFrameSetElement import HTMLFrameSetElement
from .HTMLHRElement import HTMLHRElement
from .HTMLHeadElement import HTMLHeadElement
from .HTMLHeadingElement import HTMLHeadingElement
from .HTMLHtmlElement import HTMLHtmlElement
from .HTMLIFrameElement import HTMLIFrameElement
from .HTMLImageElement import HTMLImageElement
from .HTMLInputElement import HTMLInputElement
from .HTMLIsIndexElement import HTMLIsIndexElement
from .HTMLLIElement import HTMLLIElement
from .HTMLLabelElement import HTMLLabelElement
from .HTMLLegendElement import HTMLLegendElement
from .HTMLLinkElement import HTMLLinkElement
from .HTMLMediaElement import HTMLMediaElement
from .HTMLMenuElement import HTMLMenuElement
from .HTMLMetaElement import HTMLMetaElement
from .HTMLModElement import HTMLModElement
from .HTMLOListElement import HTMLOListElement
from .HTMLObjectElement import HTMLObjectElement
from .HTMLOptGroupElement import HTMLOptGroupElement
from .HTMLOptionElement import HTMLOptionElement
from .HTMLOptionsCollection import HTMLOptionsCollection
from .HTMLParagraphElement import HTMLParagraphElement
from .HTMLParamElement import HTMLParamElement
from .HTMLPreElement import HTMLPreElement
from .HTMLQuoteElement import HTMLQuoteElement
from .HTMLScriptElement import HTMLScriptElement
from .HTMLSelectElement import HTMLSelectElement
from .HTMLSpanElement import HTMLSpanElement
from .HTMLStyleElement import HTMLStyleElement
from .HTMLTableCaptionElement import HTMLTableCaptionElement
from .HTMLTableCellElement import HTMLTableCellElement
from .HTMLTableColElement import HTMLTableColElement
from .HTMLTableElement import HTMLTableElement
from .HTMLTableRowElement import HTMLTableRowElement
from .HTMLTableSectionElement import HTMLTableSectionElement
from .HTMLTextAreaElement import HTMLTextAreaElement
from .HTMLTitleElement import HTMLTitleElement
from .HTMLUListElement import HTMLUListElement
from .HTMLVideoElement import HTMLVideoElement
from .TAnimateColor import TAnimateColor
from .TextTrackList import TextTrackList
from .TimeRanges import TimeRanges
| 4,769
|
Python
|
.py
| 132
| 33.143939
| 86
| 0.843797
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,862
|
HTMLHtmlElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLHtmlElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLHtmlElement(HTMLElement):
version = attr_property("version")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 258
|
Python
|
.py
| 7
| 33
| 44
| 0.728745
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,863
|
HTMLFrameElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLFrameElement.py
|
#!/usr/bin/env python
import logging
from .HTMLElement import HTMLElement
from .attr_property import attr_property
log = logging.getLogger("Thug")
class HTMLFrameElement(HTMLElement):
frameBorder = attr_property("frameborder")
longDesc = attr_property("longdesc")
marginHeight = attr_property("marginheight")
marginWidth = attr_property("marginwidth")
name = attr_property("name")
noResize = attr_property("noresize", bool)
scrolling = attr_property("scrolling")
src = attr_property("src")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
# Introduced in DOM Level 2
@property
def contentDocument(self):
return self.doc if self.doc else None
@property
def contentWindow(self):
# if self.id in log.ThugLogging.windows:
# return log.ThugLogging.windows[self.id]
return getattr(self.doc, "window", None) if self.doc else None
| 948
|
Python
|
.py
| 25
| 32.76
| 70
| 0.702732
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,864
|
bool_property.py
|
buffer_thug/thug/DOM/W3C/HTML/bool_property.py
|
#!/usr/bin/env python
def bool_property(name, attrtype=bool, readonly=False, default=False, novalue=False):
def getter(self):
if novalue:
return self.tag.has_attr(name)
return attrtype(self.tag[name]) if self.tag.has_attr(name) else default
def setter(self, value):
self.tag[name] = attrtype(value)
return property(getter) if readonly else property(getter, setter)
| 418
|
Python
|
.py
| 9
| 39.555556
| 85
| 0.695545
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,865
|
TextTrackList.py
|
buffer_thug/thug/DOM/W3C/HTML/TextTrackList.py
|
#!/usr/bin/env python
from .HTMLCollection import HTMLCollection
class TextTrackList(HTMLCollection):
def __init__(self, doc, tracks):
HTMLCollection.__init__(self, doc, tracks)
def getTrackById(self, id_): # pylint:disable=unused-argument
return None
| 281
|
Python
|
.py
| 7
| 35.142857
| 66
| 0.718519
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,866
|
HTMLTableCaptionElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLTableCaptionElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLTableCaptionElement(HTMLElement):
align = attr_property("align")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 262
|
Python
|
.py
| 7
| 33.571429
| 44
| 0.733068
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,867
|
HTMLLegendElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLLegendElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .form_property import form_property
class HTMLLegendElement(HTMLElement):
accessKey = attr_property("accesskey")
align = attr_property("align")
form = form_property()
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 367
|
Python
|
.py
| 10
| 32.9
| 44
| 0.730878
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,868
|
HTMLMediaElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLMediaElement.py
|
#!/usr/bin/env python
import logging
from thug.DOM.W3C.DOMTokenList import DOMTokenList
from .HTMLElement import HTMLElement
from .AudioTrackList import AudioTrackList
from .TextTrackList import TextTrackList
from .TimeRanges import TimeRanges
from .attr_property import attr_property
log = logging.getLogger("Thug")
# HTMLMediaElement.networkState possible values
NETWORK_EMPTY = 0 # There is no data yet. Also, readyState is HAVE_NOTHING.
NETWORK_IDLE = 1 # HTMLMediaElement is active and has selected a resource, but is not using the network.
NETWORK_LOADING = 2 # The browser is downloading HTMLMediaElement data.
NETWORK_NO_SOURCE = 3 # No HTMLMediaElement src found.
# HTMLMediaElement.readyState possible values
HAVE_NOTHING = 0 # No information is available about the media resource.
HAVE_METADATA = 1 # Enough of the media resource has been retrieved that the metadata attributes are
# initialized. Seeking will no longer raise an exception.
HAVE_CURRENT_DATA = (
2 # Data is available for the current playback position, but not enough to actually
)
# play more than one frame.
HAVE_FUTURE_DATA = 3 # Data for the current playback position as well as for at least a little bit of time
# into the future is available (in other words, at least two frames of video, for example).
HAVE_ENOUGH_DATA = 4 # Enough data is available - and the download rate is high enough - that the media can be
# played through to the end without interruption.
class HTMLMediaElement(HTMLElement):
autoplay = attr_property("autoplay", bool)
controls = attr_property("console", bool, readonly=True, default=False)
loop = attr_property("loop", bool, default=False)
mediaGroup = attr_property("mediagroup")
_src = attr_property("src", default="")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
self._audioTracks = AudioTrackList(doc, [])
self._textTracks = TextTrackList(doc, [])
self._buffered = TimeRanges(doc, [])
self._paused = False
if (
log.ThugOpts.Personality.isChrome()
and log.ThugOpts.Personality.browserMajorVersion >= 58
):
self.controlsList = DOMTokenList(
["download", "fullscreen", "remoteplayback"]
) # pragma: no cover
def get_src(self):
return self._src
def set_src(self, src):
self._src = src
try:
self.doc.window._navigator.fetch(src)
except Exception: # pragma: no cover,pylint:disable=broad-except
return
src = property(get_src, set_src)
@property
def audioTracks(self):
return self._audioTracks
@property
def buffered(self):
return self._buffered
@property
def controller(self):
return None
def canPlayType(self, mimetype): # pylint:disable=unused-argument
return "maybe"
@property
def crossOrigin(self):
return None
@property
def currentSrc(self):
return self._src
@property
def currentTime(self):
return 0
@property
def defaultMuted(self):
return False
@property
def defaultPlaybackRate(self):
return 1
@property
def disableRemotePlayback(self):
return False
@property
def duration(self):
return 0
@property
def ended(self):
return False
@property
def error(self):
return None
@property
def initialTime(self):
return 0
@property
def mediaKeys(self):
return None
@property
def muted(self):
return False
@property
def networkState(self):
return NETWORK_IDLE
@property
def paused(self):
return self._paused
@property
def playbackRate(self):
return 1
@property
def readyState(self):
return HAVE_ENOUGH_DATA
@property
def sinkId(self):
return ""
@property
def srcObject(self):
return None
@property
def textTracks(self):
return self._textTracks
def load(self):
pass
def pause(self):
self._paused = True
def play(self):
self._paused = False
| 4,236
|
Python
|
.py
| 128
| 26.9375
| 111
| 0.679134
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,869
|
HTMLDivElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLDivElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLDivElement(HTMLElement):
align = attr_property("align")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 253
|
Python
|
.py
| 7
| 32.285714
| 44
| 0.72314
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,870
|
HTMLMetaElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLMetaElement.py
|
#!/usr/bin/env python
import logging
from .HTMLElement import HTMLElement
from .attr_property import attr_property
log = logging.getLogger("Thug")
class HTMLMetaElement(HTMLElement):
content = attr_property("content")
httpEquiv = attr_property("http-equiv")
name = attr_property("name", default="")
scheme = attr_property("scheme")
_charset = attr_property("charset", default="")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
def __getattr__(self, name):
if name in ("charset",) and log.ThugOpts.Personality.isIE():
return self._charset
raise AttributeError
| 651
|
Python
|
.py
| 17
| 33.058824
| 68
| 0.683706
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,871
|
HTMLDocument.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLDocument.py
|
#!/usr/bin/env python
import logging
from urllib.parse import urlparse
import bs4
from lxml.html import builder as E
from lxml.html import tostring
from thug.DOM.W3C.Core.Document import Document
from .HTMLBodyElement import HTMLBodyElement
from .text_property import text_property
log = logging.getLogger("Thug")
class HTMLDocument(Document):
innerHTML = text_property()
def __str__(self):
return "[object HTMLDocument]"
def __init__(self, doc, win=None, referer=None, lastModified=None, cookie=""):
Document.__init__(self, doc, self)
self._win = win
self.body = HTMLBodyElement(self.doc, self.doc.find("body"))
self._referer = referer
self._lastModified = lastModified
self._cookie = cookie
self._html = None
self._head = None
self._currentScript = None
self._readyState = "loading"
self._domain = urlparse(self._win.url).hostname if self._win else ""
self.current = None
self.__init_htmldocument_personality()
def __init_htmldocument_personality(self):
if log.ThugOpts.Personality.isIE():
self.__init_htmldocument_personality_IE()
return
if log.ThugOpts.Personality.isFirefox():
self.__init_htmldocument_personality_Firefox()
return
if log.ThugOpts.Personality.isChrome():
self.__init_htmldocument_personality_Chrome()
return
if log.ThugOpts.Personality.isSafari():
self.__init_htmldocument_personality_Safari()
return
def __init_htmldocument_personality_IE(self):
from .HTMLDocumentCompatibleInfoCollection import (
HTMLDocumentCompatibleInfoCollection,
)
if log.ThugOpts.Personality.browserMajorVersion < 8:
self._compatible = None
else:
self._compatible = HTMLDocumentCompatibleInfoCollection(self.doc, [])
if log.ThugOpts.Personality.browserMajorVersion > 7:
self.implementation.createHTMLDocument = (
self.implementation._createHTMLDocument
)
if log.ThugOpts.Personality.browserMajorVersion < 11:
self.all = self._all
self.createStyleSheet = self._createStyleSheet
self.msHidden = self.hidden
self.msVisibilityState = self.visibilityState
def __init_htmldocument_personality_Firefox(self):
self.implementation.createHTMLDocument = self.implementation._createHTMLDocument
self.mozHidden = self.hidden
self.mozVisibilityState = self.visibilityState
def __init_htmldocument_personality_Chrome(self):
self.all = self._all
self.implementation.createHTMLDocument = self.implementation._createHTMLDocument
self.webkitHidden = self.hidden
self.webkitVisibilityState = self.visibilityState
def __init_htmldocument_personality_Safari(self):
self.all = self._all
self.implementation.createHTMLDocument = self.implementation._createHTMLDocument
def __getattr__(self, attr):
if attr in ("_listeners",):
return self.tag._listeners # pragma: no cover
if attr in ("getBoxObjectFor",) and not log.ThugOpts.Personality.isFirefox():
raise AttributeError
if self._win and getattr(self._win, "doc", None):
if attr in self._win.doc.DFT.handled_on_events:
return None
if attr in self._win.doc.DFT._on_events:
return None
_attr = self.getElementById(attr)
if _attr:
return _attr
_attr = self.getElementsByName(attr)
if _attr:
tag = getattr(_attr[0], "tag", None)
if tag:
return log.DOMImplementation.createHTMLElement(self.doc, tag)
log.info("[HTMLDocument] Undefined: %s", attr)
raise AttributeError
def getWindow(self):
return self._win
def setWindow(self, win):
self._win = win
window = property(getWindow, setWindow)
@property
def _node(self):
return self # pragma: no cover
@property
def visibilityState(self):
return "visible"
@property
def hidden(self):
return False
@property
def parentNode(self):
return None
@property
def referrer(self):
last_url = getattr(log, "last_url", None)
if last_url:
return last_url
if self._referer:
return str(self._referer) # pragma: no cover
return ""
@property
def anchors(self):
from .HTMLCollection import HTMLCollection
nodes = [
f for f in self.doc.find_all("a") if "name" in f.attrs and f.attrs["name"]
]
return HTMLCollection(self.doc, nodes)
@property
def applets(self):
from .HTMLCollection import HTMLCollection
applets = list(self.doc.find_all("applet"))
objects = [
f
for f in self.doc.find_all("object")
if "type" in f.attrs and "applet" in f.attrs["type"]
]
return HTMLCollection(self.doc, applets + objects)
@property
def forms(self):
from .HTMLCollection import HTMLCollection
nodes = list(self.doc.find_all("form"))
return HTMLCollection(self.doc, nodes)
@property
def images(self):
from .HTMLCollection import HTMLCollection
nodes = list(self.doc.find_all("img"))
return HTMLCollection(self.doc, nodes)
@property
def links(self):
from .HTMLCollection import HTMLCollection
nodes = [
f
for f in self.doc.find_all(["a", "area"])
if "href" in f.attrs and f.attrs["href"]
]
return HTMLCollection(self.doc, nodes)
@property
def styleSheets(self):
from .HTMLCollection import HTMLCollection
nodes = list(self.doc.find_all("style"))
return HTMLCollection(self.doc, nodes)
def getTitle(self):
title = self.head.tag.find("title")
return str(title.string) if title else ""
def setTitle(self, value):
title = self.head.tag.find("title")
if title:
title.string = value
return
title = E.TITLE(value)
tag = bs4.BeautifulSoup(tostring(title), "html.parser")
self.head.tag.append(tag)
title = property(getTitle, setTitle)
@property
def lastModified(self):
return self._lastModified
def getCookie(self):
if not log.HTTPSession or not log.HTTPSession.cookies:
return self._cookie
items = [f"{n}={v}" for n, v in log.HTTPSession.cookies.items()]
return "; ".join(items)
def setCookie(self, value):
item = value.split(";")[0].strip()
k, v = item.split("=")
log.HTTPSession.set_cookies(k, v)
cookie = property(getCookie, setCookie)
def getDomain(self):
return self._domain
def setDomain(self, domain):
self._domain = domain
domain = property(getDomain, setDomain)
@property
def URL(self):
return self._win.url if self._win else ""
@property
def documentElement(self):
from .HTMLHtmlElement import HTMLHtmlElement
html = self.doc.find("html")
return HTMLHtmlElement(self, html if html else self.doc)
@property
def readyState(self):
return self._readyState
@property
def compatMode(self):
return "CSS1Compat"
def getHead(self):
from .HTMLHeadElement import HTMLHeadElement
if self._head:
return self._head
tag = self.doc.find("head")
if not tag:
head = E.HEAD()
tag = bs4.BeautifulSoup(tostring(head), "html.parser")
self._head = HTMLHeadElement(self.doc, tag)
return self._head
def setHead(self, head):
pass
head = property(getHead, setHead)
def getCompatible(self):
return self._compatible
def setCompatible(self, compatible):
from .HTMLDocumentCompatibleInfo import HTMLDocumentCompatibleInfo
from .HTMLDocumentCompatibleInfoCollection import (
HTMLDocumentCompatibleInfoCollection,
)
_compatibles = []
if (
log.ThugOpts.Personality.isIE()
and log.ThugOpts.Personality.browserMajorVersion >= 8
):
for s in compatible.split(";"):
try:
(useragent, version) = s.split("=")
except ValueError: # pragma: no cover
# Ignore the http-equiv X-UA-Compatible content if its
# format is not correct
return
for v in version.split(","):
p = HTMLDocumentCompatibleInfo(useragent, v)
_compatibles.append(p)
self._compatible = HTMLDocumentCompatibleInfoCollection(
self.doc, _compatibles
)
compatible = property(getCompatible, setCompatible)
@property
def documentMode(self):
major = log.ThugOpts.Personality.browserMajorVersion
if major < 8:
return 7 if self.compatMode in ("CSS1Compat",) else 5
self.window.doc.DFT.force_handle_meta_x_ua_compatible()
engine = 0
for index in range(self.compatible.length):
item = self.compatible.item(index)
if item.userAgent.lower() not in ("ie",):
continue
_version = item.version.lower()
if _version in ("edge",):
engine = major
break
mode_version = _version
if _version.startswith("emulateie"):
mode_version = _version.split("emulateie")[1]
try:
mode_version = int(mode_version)
except ValueError: # pragma: no cover
continue
if mode_version not in (5, 7, 8, 9, 10): # pragma: no cover
continue
if engine <= mode_version <= major:
engine = mode_version
if not engine:
engine = min(major, 10)
return engine
def open(self, mimetype="text/html", historyPosition="replace"): # pylint:disable=unused-argument
self.doc = bs4.BeautifulSoup("", "html5lib")
return self
def close(self):
if self._html is None:
return
html = "".join(self._html)
self._html = None
self.doc = log.HTMLInspector.run(html, "html5lib")
def write(self, html):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_document_write_count()
if isinstance(html, int):
html = str(html)
log.HTMLClassifier.classify(
log.ThugLogging.url if log.ThugOpts.local else self.URL, html
)
if self._html is None:
self._html = []
self._html.append(html)
if self._html.count(html) > 20:
log.warning("[WARNING] document.write loop detected")
return
tag = self.current
body = self.doc.find("body")
if tag is None or tag.parent is None:
parent = body # pragma: no cover
else:
parent = body if body and tag.parent.name in ("html",) else tag.parent
html_write = False
soup = log.HTMLInspector.run(html, "html.parser")
for tag in list(soup.contents):
if isinstance(tag, bs4.NavigableString):
if not tag.string.rstrip():
continue
child = list(parent.children)[-1]
if isinstance(child, bs4.NavigableString):
child.string.replace_with(child.string + tag)
if isinstance(child, bs4.Tag):
child.append(tag)
if isinstance(tag, bs4.Tag):
parent.append(tag)
name = getattr(tag, "name", None)
if name in (None,):
continue
if name in ("html",):
html_write = True
try:
handler = getattr(self._win.doc.DFT, f"handle_{name}", None)
except Exception: # pragma: no cover,pylint:disable=broad-except
handler = getattr(log.DFT, f"handle_{name}", None)
if handler:
handler(tag)
log.HTMLClassifier.classify(
log.ThugLogging.url if log.ThugOpts.local else self.URL, str(self.tag)
)
_html = "".join(self._html)
if not html_write and html == _html:
return
soup = log.HTMLInspector.run(html, "html.parser")
for tag in list(soup.contents):
name = getattr(tag, "name", None)
if name in (
"script",
None,
):
continue
try:
handler = getattr(self._win.doc.DFT, f"handle_{name}", None)
except Exception: # pragma: no cover,pylint:disable=broad-except
handler = getattr(log.DFT, f"handle_{name}", None)
if handler:
handler(tag)
def writeln(self, text):
self.write(text + "\n")
def getElementsByName(self, elementName):
from .HTMLCollection import HTMLCollection
tags = self.doc.find_all(attrs={"name": elementName})
return HTMLCollection(self.doc, tags)
@property
def _all(self):
from .HTMLAllCollection import HTMLAllCollection
s = list(self.doc.find_all(string=False))
return HTMLAllCollection(self.doc, s)
@property
def scripts(self):
from .HTMLAllCollection import HTMLAllCollection
s = list(self.current.find_all_previous("script"))
s.append(self.current)
return HTMLAllCollection(self.doc, s)
@property
def currentScript(self):
if self._currentScript:
return self._currentScript # pragma: no cover
return (
log.DOMImplementation.createHTMLElement(self.doc, self.current)
if self.current
else None
)
def _createStyleSheet(self, URL=None, index=None):
# Creates a styleSheet object and inserts it into the current document.
# The createStyleSheet method is only supported by Internet Explorer.
# In other browsers, use the createElement method to create a new link
# or style element, and the insertBefore or appendChild method to insert
# it into the document.
#
# URL Optional. String that specifies the URL of a style file. If an
# URL is specified, a new link element is inserted into the current
# document that imports the style file. If this parameter is not specified
# or an empty string is set, then an empty style element is inserted into
# the current document.
#
# index Optional. Integer that specifies the position of the new styleSheet
# object in the styleSheets collection of the document. This parameter
# also has effect on the source position of the inserted link or style
# element. If this parameter is not specified, the new styleSheet object
# is inserted at the end of the styleSheets collection and the new link or
# style element is inserted after the other link and style elements in
# source order.
_type = "style" if not URL else "link"
obj = self.createElement(_type)
if _type in ("link",):
obj.href = URL
obj.rel = "stylesheet"
head = self.getElementsByTagName("head")[0]
if head is None:
return obj
if index is None:
head.appendChild(obj)
return obj
length = len(head.childNodes)
matches = 0
pos = 0
while pos < length:
if head.childNodes[pos].tagName.lower() in (_type,):
matches += 1
if matches > index:
head.insertBefore(obj, head.childNodes[pos])
break
pos += 1
if matches <= index:
head.appendChild(obj)
return obj
| 16,355
|
Python
|
.py
| 411
| 29.506083
| 102
| 0.605508
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,872
|
HTMLFrameSetElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLFrameSetElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLFrameSetElement(HTMLElement):
cols = attr_property("cols")
rows = attr_property("rows")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 289
|
Python
|
.py
| 8
| 32.125
| 44
| 0.714801
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,873
|
TAnimateColor.py
|
buffer_thug/thug/DOM/W3C/HTML/TAnimateColor.py
|
#!/usr/bin/env python
import string
import logging
from .HTMLElement import HTMLElement
log = logging.getLogger("Thug")
class TAnimateColor(HTMLElement):
def __init__(self, doc, tag):
self.doc = doc
self.tag = tag
HTMLElement.__init__(self, doc, tag)
self._values = ""
def get_values(self):
return self._values
def set_values(self, values):
if all(c in string.printable for c in values) is False:
log.ThugLogging.log_exploit_event(
self.doc.window.url,
"Microsoft Internet Explorer",
"Microsoft Internet Explorer CButton Object Use-After-Free Vulnerability (CVE-2012-4792)",
cve="CVE-2012-4792",
forward=True,
)
log.ThugLogging.log_classifier(
"exploit", log.ThugLogging.url, "CVE-2012-4792"
)
log.ThugLogging.Shellcode.check_shellcode(values)
self._values = values
values = property(get_values, set_values)
| 1,042
|
Python
|
.py
| 28
| 27.857143
| 106
| 0.611554
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,874
|
HTMLDocumentCompatibleInfoCollection.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLDocumentCompatibleInfoCollection.py
|
#!/usr/bin/env python
from .HTMLCollection import HTMLCollection
class HTMLDocumentCompatibleInfoCollection(HTMLCollection):
"""
http://msdn.microsoft.com/en-us/library/hh826015(v=vs.85).aspx
There are no standards that apply here.
"""
def __init__(self, doc, nodes):
HTMLCollection.__init__(self, doc, nodes)
def __call__(self, item):
return self.__getitem__(item)
| 412
|
Python
|
.py
| 11
| 32.272727
| 66
| 0.691139
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,875
|
HTMLButtonElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLButtonElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
from .form_property import form_property
class HTMLButtonElement(HTMLElement):
accessKey = attr_property("accesskey")
disabled = bool_property("disabled")
form = form_property()
name = attr_property("name")
tabIndex = attr_property("tabindex", int)
type = attr_property("type")
value = attr_property("value")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 561
|
Python
|
.py
| 15
| 33.466667
| 45
| 0.721402
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,876
|
HTMLOptGroupElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLOptGroupElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
class HTMLOptGroupElement(HTMLElement):
disabled = bool_property("disabled")
label = attr_property("label")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 340
|
Python
|
.py
| 9
| 34.111111
| 44
| 0.740061
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,877
|
HTMLVideoElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLVideoElement.py
|
#!/usr/bin/env python
import logging
from .HTMLMediaElement import HTMLMediaElement
from .attr_property import attr_property
from .bool_property import bool_property
log = logging.getLogger("Thug")
class HTMLVideoElement(HTMLMediaElement):
width = attr_property("width", int, default=0)
height = attr_property("height", int, default=0)
videoWidth = attr_property("videoWidth", int, default=0)
videoHeight = attr_property("videoHeight", int, default=0)
poster = attr_property("poster", default="")
playsInline = bool_property("playsInline")
def __init__(self, doc, tag):
HTMLMediaElement.__init__(self, doc, tag)
| 654
|
Python
|
.py
| 15
| 39.8
| 62
| 0.736177
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,878
|
HTMLTableElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLTableElement.py
|
#!/usr/bin/env python
import logging
import bs4
from thug.DOM.W3C.Core.DOMException import DOMException
from .HTMLElement import HTMLElement
from .HTMLCollection import HTMLCollection
from .HTMLTableRowElement import HTMLTableRowElement
from .HTMLTableSectionElement import HTMLTableSectionElement
from .HTMLTableCaptionElement import HTMLTableCaptionElement
from .attr_property import attr_property
log = logging.getLogger("Thug")
class HTMLTableElement(HTMLElement):
align = attr_property("align")
bgColor = attr_property("bgcolor")
border = attr_property("border")
cellPadding = attr_property("cellpadding")
cellSpacing = attr_property("cellspacing")
frame = attr_property("frame")
rules = attr_property("rules")
summary = attr_property("summary")
width = attr_property("width")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
self._caption = None
self._tHead = None
self._tFoot = None
self._rows = HTMLCollection(doc, [])
self._tBodies = HTMLCollection(doc, [])
@property
def caption(self):
return self._caption
@property
def tHead(self):
return self._tHead
@property
def tFoot(self):
return self._tFoot
@property
def rows(self):
return self._rows
@property
def tBodies(self):
return self._tBodies
def createTHead(self):
if self._tHead:
return self._tHead
self._tHead = HTMLTableSectionElement(
self.doc, bs4.Tag(self.doc, name="thead"), table=self
)
self.rows.nodes.insert(0, self._tHead)
return self._tHead
def deleteTHead(self):
if self.tHead:
self._tHead = None
del self.rows.nodes[0]
def createTFoot(self):
if self._tFoot:
return self._tFoot
self._tFoot = HTMLTableSectionElement(
self.doc, bs4.Tag(self.doc, name="tfoot"), table=self
)
self.rows.nodes.append(self._tFoot)
return self._tFoot
def deleteTFoot(self):
if self._tFoot:
self._tFoot = None
del self.rows.nodes[-1]
def createCaption(self):
if self._caption:
return self._caption
self._caption = HTMLTableCaptionElement(
self.doc, bs4.Tag(self.doc, name="caption")
)
return self._caption
def deleteCaption(self):
if self.caption:
self._caption = None
# Modified in DOM Level 2
def insertRow(self, index=None):
# Insert a new empty row in the table. The new row is inserted immediately before
# and in the same section as the current indexth row in the table. If index is -1
# or equal to the number of rows, the new row is appended. In addition, when the
# table is empty the row is inserted into a TBODY which is created and inserted
# into the table.
# `index' specifies the position of the row to insert (starts at 0). The value of
# -1 can also be used; which result in that the new row will be inserted at the
# last position. This parameter is required in Firefox and Opera, but optional in
# Internet Explorer, Chrome and Safari. If this parameter is omitted, insertRow()
# inserts a new row at the last position in IE and at the first position in Chrome
# and Safari.
if index is None:
if log.ThugOpts.Personality.isIE():
index = -1
if (
log.ThugOpts.Personality.isChrome()
or log.ThugOpts.Personality.isSafari()
):
index = 0
row = HTMLTableRowElement(
self.doc, bs4.Tag(self.doc, name="tr"), table=self, section=self
)
self.rows.nodes.insert(index, row)
return row
def deleteRow(self, index):
if index < -1 or index >= len(self.rows.nodes):
raise DOMException(DOMException.INDEX_SIZE_ERR)
del self.rows.nodes[index]
def appendChild(self, newChild):
if newChild.tagName.lower() in ("tbody",):
self._tBodies.nodes.append(newChild)
return super().appendChild(newChild)
def removeChild(self, oldChild):
if oldChild.tagName.lower() in ("tbody",):
self._tBodies.nodes.remove(oldChild)
return super().removeChild(oldChild)
| 4,449
|
Python
|
.py
| 115
| 30.4
| 90
| 0.64093
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,879
|
HTMLUListElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLUListElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
from .bool_property import bool_property
class HTMLUListElement(HTMLElement):
compact = bool_property("compact")
type = attr_property("type")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 333
|
Python
|
.py
| 9
| 33.333333
| 44
| 0.734375
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,880
|
HTMLDirectoryElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLDirectoryElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .bool_property import bool_property
class HTMLDirectoryElement(HTMLElement):
compact = bool_property("compact")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 263
|
Python
|
.py
| 7
| 33.714286
| 44
| 0.734127
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,881
|
HTMLDocumentCompatibleInfo.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLDocumentCompatibleInfo.py
|
#!/usr/bin/env python
class HTMLDocumentCompatibleInfo:
"""
IHTMLDocumentCompatibleInfo provides information about the
compatibility mode specified by the web page. If the web page
specifies multiple compatibility modes, they can be retrieved
using IHTMLDocumentCompatibleInfoCollection.
http://msdn.microsoft.com/en-us/library/cc288659(v=vs.85).aspx
There are no standards that apply here.
"""
def __init__(self, useragent="", version=""):
self._userAgent = useragent
self._version = version
def getUserAgent(self):
return self._userAgent
def setUserAgent(self, useragent): # pragma: no cover
self._userAgent = useragent
userAgent = property(getUserAgent, setUserAgent)
def getVersion(self):
return self._version
def setVersion(self, version): # pragma: no cover
self._version = version
version = property(getVersion, setVersion)
| 952
|
Python
|
.py
| 23
| 35.217391
| 66
| 0.716776
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,882
|
HTMLParagraphElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLParagraphElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLParagraphElement(HTMLElement):
align = attr_property("align")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 259
|
Python
|
.py
| 7
| 33.142857
| 44
| 0.729839
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,883
|
HTMLQuoteElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLQuoteElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLQuoteElement(HTMLElement):
cite = attr_property("cite")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 253
|
Python
|
.py
| 7
| 32.285714
| 44
| 0.72314
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,884
|
HTMLBRElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLBRElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLBRElement(HTMLElement):
clear = attr_property("clear")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 252
|
Python
|
.py
| 7
| 32.142857
| 44
| 0.721992
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,885
|
HTMLSelectElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLSelectElement.py
|
#!/usr/bin/env python
from thug.DOM.W3C.Core.DOMException import DOMException
from .HTMLElement import HTMLElement
from .HTMLOptionsCollection import HTMLOptionsCollection
from .attr_property import attr_property
from .bool_property import bool_property
class HTMLSelectElement(HTMLElement):
selectedIndex = 0
value = None
disabled = bool_property("disabled")
multiple = bool_property("multiple")
name = attr_property("name")
size = attr_property("size", int)
tabIndex = attr_property("tabindex", int)
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
self._options = list(self.tag.find_all("option"))
@property
def type(self):
return "select-multiple" if self.multiple else "select-one"
@property
def length(self):
return len(self.options)
@property
def form(self):
return None
@property
def options(self):
return HTMLOptionsCollection(self.doc, self._options)
def add(self, element, before):
if not before:
self._options.append(element)
return
index = None
for opt in self._options:
if before.value in (opt.value,):
index = self._options.index(opt)
if index is None:
raise DOMException(DOMException.NOT_FOUND_ERR)
self._options.insert(index, element)
def remove(self, index):
if index > len(self._options):
return
del self._options[index]
def blur(self):
pass
def focus(self):
pass
| 1,594
|
Python
|
.py
| 48
| 26.104167
| 67
| 0.65206
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,886
|
HTMLMenuElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLMenuElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLMenuElement(HTMLElement):
compact = attr_property("compact", bool)
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 264
|
Python
|
.py
| 7
| 33.857143
| 44
| 0.727273
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,887
|
HTMLFontElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLFontElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLFontElement(HTMLElement):
color = attr_property("color")
face = attr_property("face")
size = attr_property("size")
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 320
|
Python
|
.py
| 9
| 31.444444
| 44
| 0.703583
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,888
|
Dataset.py
|
buffer_thug/thug/DOM/W3C/HTML/Dataset.py
|
#!/usr/bin/env python
import re
class Dataset:
def __init__(self, attrs):
self.__dict__["attrs"] = attrs
def __getattr__(self, attr):
data_attr = re.sub("([A-Z])", r"-\1", attr).lower()
return self.__dict__["attrs"].get(f"data-{data_attr}", "")
def __setattr__(self, attr, value):
data_attr = re.sub("([A-Z])", r"-\1", attr).lower()
self.__dict__["attrs"].__setitem__(f"data-{data_attr}", value)
def __delattr__(self, attr):
data_attr = re.sub("([A-Z])", r"-\1", attr).lower()
self.__dict__["attrs"].__delitem__(f"data-{data_attr}")
| 611
|
Python
|
.py
| 14
| 37.071429
| 70
| 0.527919
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,889
|
HTMLPreElement.py
|
buffer_thug/thug/DOM/W3C/HTML/HTMLPreElement.py
|
#!/usr/bin/env python
from .HTMLElement import HTMLElement
from .attr_property import attr_property
class HTMLPreElement(HTMLElement):
width = attr_property("width", int)
def __init__(self, doc, tag):
HTMLElement.__init__(self, doc, tag)
| 258
|
Python
|
.py
| 7
| 33
| 44
| 0.720648
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,890
|
attr_property.py
|
buffer_thug/thug/DOM/W3C/HTML/attr_property.py
|
#!/usr/bin/env python
def attr_property(name, attrtype=str, readonly=False, default=None):
def getter(self):
return attrtype(self.tag[name]) if self.tag.has_attr(name) else default
def setter(self, value):
if attrtype in (int,) and str(value).endswith("px"):
value = int(str(value).split("px", maxsplit=1)[0])
self.tag[name] = attrtype(value)
return property(getter) if readonly else property(getter, setter)
| 462
|
Python
|
.py
| 9
| 44.444444
| 79
| 0.676339
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,891
|
__init__.py
|
buffer_thug/thug/DOM/W3C/URL/__init__.py
|
__all__ = ["URL", "URLSearchParams"]
from .URL import URL
from .URLSearchParams import URLSearchParams
| 104
|
Python
|
.py
| 3
| 33.333333
| 44
| 0.77
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,892
|
URL.py
|
buffer_thug/thug/DOM/W3C/URL/URL.py
|
#!/usr/bin/env python
#
# URL.py
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# URL Standard
# https://url.spec.whatwg.org/
import logging
import urllib.parse
import uuid
from thug.DOM.JSClass import JSClass
from .URLSearchParams import URLSearchParams
log = logging.getLogger("Thug")
class URL(JSClass):
protocols = (
"http",
"https",
"ftp",
)
def __init__(self, url, base=None):
self.init_url(url if base is None else urllib.parse.urljoin(base, url))
def init_url(self, url):
self.b_url = url if url else "about:blank"
self.p_url = urllib.parse.urlparse(url)
self.p_url = self.p_url._replace(path=urllib.parse.quote(self.p_url.path))
def __get_port(self, port):
if isinstance(port, str):
if not port.isnumeric():
return None
port = int(port)
return port if port in range(1, 65536) else None
def get_hash(self):
return f"#{self.p_url.fragment}"
def set_hash(self, fragment):
self.p_url = self.p_url._replace(fragment=fragment)
hash = property(get_hash, set_hash)
def get_host(self):
return self.p_url.netloc
def set_host(self, host):
s_host = host.split(":")
if len(s_host) > 1 and self.__get_port(s_host[1]) is None:
return
self.p_url = self.p_url._replace(netloc=host)
host = property(get_host, set_host)
def get_hostname(self):
s_netloc = self.p_url.netloc.split(":")
return s_netloc[0] if len(s_netloc) > 0 else ""
def set_hostname(self, hostname):
if ":" in hostname:
return
self.set_host(hostname)
hostname = property(get_hostname, set_hostname)
def get_href(self):
return urllib.parse.urlunparse(self.p_url)
def set_href(self, href):
self.init_url(href)
href = property(get_href, set_href)
@property
def origin(self):
return f"{self.p_url.scheme}://{self.p_url.netloc}"
def get_password(self):
return self.p_url.password
def set_password(self, password):
s_netloc = self.p_url.netloc.split("@")
if len(s_netloc) < 2:
_netloc = f":{password}@{self.p_url.netloc}"
self.p_url = self.p_url._replace(netloc=_netloc)
return
if ":" not in s_netloc[0]:
s_netloc[0] = f"{s_netloc[0]}:{password}"
else:
s_netloc[0] = f"{s_netloc[0].split(':')[0]}:{password}"
self.p_url = self.p_url._replace(netloc="@".join(s_netloc))
password = property(get_password, set_password)
def get_pathname(self):
return self.p_url.path
def set_pathname(self, pathname):
self.p_url = self.p_url._replace(path=pathname)
pathname = property(get_pathname, set_pathname)
def get_port(self):
return self.p_url.port
def set_port(self, port):
_port = self.__get_port(port)
if _port is None:
return
_netloc = self.p_url.netloc.split(":")[0]
self.p_url = self.p_url._replace(netloc=f"{_netloc}:{_port}")
port = property(get_port, set_port)
def get_protocol(self):
return f"{self.p_url.scheme}:"
def set_protocol(self, protocol):
if protocol in self.protocols:
self.p_url = self.p_url._replace(scheme=protocol)
protocol = property(get_protocol, set_protocol)
def get_search(self):
return self.p_url.query
def set_search(self, search):
self.p_url = self.p_url._replace(query=search)
search = property(get_search, set_search)
@property
def searchParams(self):
return URLSearchParams(self.p_url.query)
def get_username(self):
return self.p_url.username
def set_username(self, username):
s_netloc = self.p_url.netloc.split("@")
if len(s_netloc) < 2:
_netloc = f"{username}@{self.p_url.netloc}"
self.p_url = self.p_url._replace(netloc=_netloc)
return
if ":" not in s_netloc[0]:
s_netloc[0] = username
else:
s_netloc[0] = f"{username}:{s_netloc[0].split(':')[1]}"
self.p_url = self.p_url._replace(netloc="@".join(s_netloc))
username = property(get_username, set_username)
def createObjectURL(self, obj):
objurl = f"blob://{self.b_url}/{str(uuid.uuid4())}"
log.UrlObjects[objurl] = obj
return objurl
def revokeObjectURL(self, urlobj):
log.UrlObjects.pop(urlobj, None)
| 5,148
|
Python
|
.py
| 134
| 31.246269
| 82
| 0.629361
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,893
|
URLSearchParams.py
|
buffer_thug/thug/DOM/W3C/URL/URLSearchParams.py
|
#!/usr/bin/env python
#
# URLSearchParams.py
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# URL Standard
# https://url.spec.whatwg.org/
import logging
from thug.DOM.JSClass import JSClass
log = logging.getLogger("Thug")
class URLSearchParams(JSClass):
def __init__(self, params=None):
self.search_params = {}
if params is None:
return
if not isinstance(params, str):
for name in params.keys():
if name not in self.search_params:
self.search_params[name] = []
self.search_params[name].append(params[name])
return
if params.startswith("?"):
params = params[1:]
for item in params.split("&"):
sitem = item.split("=")
name = sitem[0].strip()
value = "" if len(sitem) < 2 else sitem[1].strip()
if name not in self.search_params:
self.search_params[name] = []
self.search_params[name].append(value)
def toString(self):
items = []
for key, values in self.search_params.items():
items.append("&".join(f"{key}={value}" for value in values))
return "&".join(items)
def append(self, name, value):
if name not in self.search_params:
self.search_params[name] = []
self.search_params[name].append(value)
def delete(self, name):
if name not in self.search_params:
return
del self.search_params[name]
def get(self, name):
if name not in self.search_params or len(self.search_params[name]) < 1:
return None
return self.search_params[name][0]
def getAll(self, name):
if name not in self.search_params or len(self.search_params[name]) < 1:
return []
return self.search_params[name]
def has(self, name):
return name in self.search_params
def set(self, name, value):
self.search_params[name] = [
value,
]
def sort(self):
self.search_params = dict(sorted(self.search_params.items()))
| 2,728
|
Python
|
.py
| 71
| 30.788732
| 79
| 0.631179
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,894
|
HTMLEvent.py
|
buffer_thug/thug/DOM/W3C/Events/HTMLEvent.py
|
#!/usr/bin/env python
from .Event import Event
# Introduced in DOM Level 2
class HTMLEvent(Event):
EventTypes = (
"load",
"unload",
"abort",
"error",
"select",
"change",
"submit",
"reset",
"focus",
"blur",
"resize",
"scroll",
)
def __init__(self):
Event.__init__(self)
| 389
|
Python
|
.py
| 20
| 12.45
| 28
| 0.473973
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,895
|
MouseEvent.py
|
buffer_thug/thug/DOM/W3C/Events/MouseEvent.py
|
#!/usr/bin/env python
from .UIEvent import UIEvent
# Introduced in DOM Level 2
class MouseEvent(UIEvent):
EventTypes = ("click", "mousedown", "mouseup", "mouseover", "mousemove", "mouseout")
def __init__(self):
UIEvent.__init__(self)
self._screenX = None
self._screenY = None
self._clientX = None
self._clientY = None
self._ctrlKey = None
self._altKey = None
self._shiftKey = None
self._metaKey = None
self._button = None
self._relatedTarget = None
@property
def altKey(self):
return self._altKey
@property
def button(self):
return self._button
@property
def clientX(self):
return self._clientX
@property
def clientY(self):
return self._clientY
@property
def ctrlKey(self):
return self._ctrlKey
@property
def metaKey(self):
return self._metaKey
@property
def relatedTarget(self):
return self._relatedTarget
@property
def screenX(self):
return self._screenX
@property
def screenY(self):
return self._screenY
@property
def shiftKey(self):
return self._shiftKey
def initMouseEvent(
self,
typeArg,
canBubbleArg,
cancelableArg,
viewArg=None,
detailArg=0,
screenXArg=0,
screenYArg=0,
clientXArg=0,
clientYArg=0,
ctrlKeyArg=False,
altKeyArg=False,
shiftKeyArg=False,
metaKeyArg=False,
buttonArg=0,
relatedTargetArg=None,
):
self.initUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg)
self._screenX = screenXArg
self._screenY = screenYArg
self._clientX = clientXArg
self._clientY = clientYArg
self._ctrlKey = ctrlKeyArg
self._altKey = altKeyArg
self._shiftKey = shiftKeyArg
self._metaKey = metaKeyArg
self._button = buttonArg
self._relatedTarget = relatedTargetArg
| 2,068
|
Python
|
.py
| 76
| 19.684211
| 88
| 0.612854
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,896
|
Event.py
|
buffer_thug/thug/DOM/W3C/Events/Event.py
|
#!/usr/bin/env python
import logging
from thug.DOM.JSClass import JSClass
log = logging.getLogger("Thug")
# Introduced in DOM Level 2
class Event(JSClass):
CAPTURING_PHASE = 1 # The current event phase is the capturing phase.
AT_TARGET = 2 # The event is currently being evaluated at the target EventTarget
BUBBLING_PHASE = 3 # The current event phase is the bubbling phase.
def __init__(self):
self._type = None
self._target = None
self.currentTarget = None
self.eventPhase = self.AT_TARGET
self._stoppedPropagation = False
self._defaultPrevented = False
self._canBubble = False
self._cancelable = False
self.__init_event_personality()
def __init_event_personality(self):
if log.ThugOpts.Personality.isIE():
self.__init_event_personality_IE()
return
if log.ThugOpts.Personality.isFirefox():
self.__init_event_personality_Firefox()
return
if log.ThugOpts.Personality.isChrome():
self.__init_event_personality_Chrome()
return
if log.ThugOpts.Personality.isSafari():
self.__init_event_personality_Safari()
return
def __init_event_personality_IE(self):
# Prior to IE9, IE does not support the stopPropagation() method. Instead,
# the IE Event object has a property named `cancelBubble'. Setting this
# property to true prevents any further propagation (IE8 and before do not
# support the capturing phase of event propagation so bubbling is the only
# kind of propagation to be canceled)
if log.ThugOpts.Personality.browserMajorVersion < 9:
self.cancelBubble = property(
self._getPropagationStatus, self._setPropagationStatus
)
else:
self.stopPropagation = self._stopPropagation
# In IE prior to IE9 the default action can be canceled by setting the
# `returnValue' of the Event object to false
if log.ThugOpts.Personality.browserMajorVersion < 9:
self.returnValue = property(
self._getDefaultPrevented, self._setDefaultPrevented
)
else:
self.preventDefault = self._preventDefault
# Introduced in DOM Events Level 3
if log.ThugOpts.Personality.browserMajorVersion > 8:
self.defaultPrevented = self._defaultPrevented
def __init_event_personality_Firefox(self):
# Introduced in DOM Events Level 3
if log.ThugOpts.Personality.browserMajorVersion > 5:
self.defaultPrevented = self._defaultPrevented
def __init_event_personality_Chrome(self):
# Introduced in DOM Events Level 3
if log.ThugOpts.Personality.browserMajorVersion > 17:
self.defaultPrevented = self._defaultPrevented
def __init_event_personality_Safari(self):
# Introduced in DOM Events Level 3
if log.ThugOpts.Personality.browserMajorVersion > 4:
self.defaultPrevented = self._defaultPrevented
def _getPropagationStatus(self):
return self._stoppedPropagation
def _setPropagationStatus(self, value):
self._stoppedPropagation = bool(value)
def _stopPropagation(self):
self._stoppedPropagation = True
def _getDefaultPrevented(self):
return self._defaultPrevented
def _setDefaultPrevented(self, value):
self._defaultPrevented = bool(value)
def _preventDefault(self):
self._defaultPrevented = True
@property
def type(self):
return self._type
@property
def target(self):
return self._target
@property
def bubbles(self):
return self._canBubble
@property
def cancelable(self):
return self._cancelable
@property
def timeStamp(self):
return 0
def initEvent(self, eventTypeArg, canBubbleArg, cancelableArg):
self._type = eventTypeArg
self._canBubble = canBubbleArg
self._cancelable = cancelableArg
| 4,094
|
Python
|
.py
| 98
| 33.132653
| 85
| 0.668515
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,897
|
EventTarget.py
|
buffer_thug/thug/DOM/W3C/Events/EventTarget.py
|
#!/usr/bin/env python
import logging
from .Event import Event
from .EventException import EventException
log = logging.getLogger("Thug")
# Introduced in DOM Level 2
class EventTarget:
def __init__(self, doc, tag):
self.__init_eventtarget_personality()
self.doc = doc
self.tag = tag
self.tag._listeners = []
def __init_eventtarget_personality(self):
if log.ThugOpts.Personality.isIE():
self.__init_eventtarget_personality_IE()
return
if log.ThugOpts.Personality.isFirefox():
self.__init_eventtarget_personality_Firefox()
return
if log.ThugOpts.Personality.isChrome():
self.__init_eventtarget_personality_Chrome()
return
if log.ThugOpts.Personality.isSafari():
self.__init_eventtarget_personality_Safari()
return
def __init_eventtarget_personality_IE(self):
if log.ThugOpts.Personality.browserMajorVersion < 11:
self.__init_proprietary_ie_event_methods()
if log.ThugOpts.Personality.browserMajorVersion >= 8:
self.__init_event_methods()
def __init_eventtarget_personality_Firefox(self):
self.__init_event_methods()
def __init_eventtarget_personality_Chrome(self):
self.__init_event_methods()
def __init_eventtarget_personality_Safari(self):
self.__init_event_methods()
def __init_proprietary_ie_event_methods(self):
self.detachEvent = self._detachEvent
def attachEvent(self, eventType, handler, prio=False):
return self._attachEvent(eventType, handler, prio)
setattr(self.__class__, "attachEvent", attachEvent)
def __init_event_methods(self):
self.removeEventListener = self._removeEventListener
def addEventListener(self, eventType, listener, capture=False):
return self._addEventListener(eventType, listener, capture)
setattr(self.__class__, "addEventListener", addEventListener)
def __insert_listener(self, eventType, listener, capture, prio):
# A document element or other object may have more than one event
# handler registered for a particular type of event. When an appropriate
# event occurs, the browser must invoke all of the handlers, following
# these rules of invocation order:
#
# - Handlers registered by setting an object property or HTML attribute,
# if any, are always invoked first
#
# - Handlers registered with addEventListener() are invoked in the order
# in which they were registered
#
# - Handlers registered with attachEvent() may be invoked in any order
# and your code should not depend on sequential invocation
#
# The `prio' parameter is used for deciding if the handler has to be
# appended at the end of the _listener list (addEventListener and
# attachEvent) or at the beginning (setting an object property or HTML
# attribute)
if prio:
self.tag._listeners.insert(0, (eventType, listener, capture))
else:
self.tag._listeners.append((eventType, listener, capture))
def _addEventListener(self, eventType, listener, capture=False, prio=False):
if not isinstance(capture, bool): # pragma: no cover
capture = False
log.debug("_addEventListener(%s, \n%r, \n%s)", eventType, listener, capture)
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_addeventlistener_count()
if getattr(self.tag, "_listeners", None) is None: # pragma: no cover
self.tag._listeners = []
if (eventType, listener, capture) not in self.tag._listeners:
self.__insert_listener(eventType, listener, capture, prio)
return
# attachEvent() allows the same event handler to be registered more than
# once. When the event of the specified type occurs, the registered
# function will be invoked as many times as it was registered
if (
log.ThugOpts.Personality.isIE()
and log.ThugOpts.Personality.browserMajorVersion < 9
):
self.__insert_listener(eventType, listener, capture, prio)
def _removeEventListener(self, eventType, listener, capture=False):
log.debug("_removeEventListener(%s, \n%r, \n%s)", eventType, listener, capture)
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_removeeventlistener_count()
try:
self.tag._listeners.remove((eventType, listener, capture))
except Exception: # pylint:disable=broad-except
pass
def _attachEvent(self, eventType, handler, prio=False):
log.debug("_attachEvent(%s, \n%r)", eventType, handler)
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_attachevent_count()
if not eventType.startswith("on"): # pragma: no cover
log.warning("[WARNING] attachEvent eventType: %s", eventType)
self._addEventListener(eventType[2:], handler, False, prio)
def _detachEvent(self, eventType, handler):
log.debug("_detachEvent(%s, \n%r)", eventType, handler)
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_detachevent_count()
if not eventType.startswith("on"): # pragma: no cover
log.warning("[WARNING] detachEvent eventType: %s", eventType)
self._removeEventListener(eventType[2:], handler)
def _get_listeners(self, tag, evtType):
_listeners = [
(eventType, listener, capture)
for (eventType, listener, capture) in tag._listeners
if eventType == evtType
]
capture_listeners = [
(eventType, listener, capture)
for (eventType, listener, capture) in _listeners
if capture is True
]
bubbling_listeners = [
(eventType, listener, capture)
for (eventType, listener, capture) in _listeners
if capture is False
]
return capture_listeners, bubbling_listeners
def _do_dispatch(self, c, evtObject):
eventType, listener, capture = c # pylint:disable=unused-variable
self.doc.window.event = evtObject
with self.doc.window.context:
if (
log.ThugOpts.Personality.isIE()
and log.ThugOpts.Personality.browserMajorVersion < 9
):
listener()
else:
listener.apply(evtObject.currentTarget)
def do_dispatch(self, c, evtObject):
try:
self._do_dispatch(c, evtObject)
except Exception as e: # pylint:disable=broad-except
eventType, listener, capture = c # pylint:disable=unused-variable
log.warning(
"[WARNING] Error while dispatching %s event (%s)", eventType, str(e)
)
def _dispatchCaptureEvent(self, tag, evtType, evtObject):
if tag.parent is None:
return
self._dispatchCaptureEvent(tag.parent, evtType, evtObject)
if not tag.parent._listeners:
return
if evtObject._stoppedPropagation: # pragma: no cover
return
capture_listeners, bubbling_listeners = self._get_listeners(tag.parent, evtType) # pylint:disable=unused-variable
for c in capture_listeners:
evtObject.currentTarget = tag.parent._node
self.do_dispatch(c, evtObject)
def _dispatchBubblingEvent(self, tag, evtType, evtObject):
for node in tag.parents:
if node is None: # pragma: no cover
break
if not node._listeners:
continue
if evtObject._stoppedPropagation: # pragma: no cover
continue
capture_listeners, bubbling_listeners = self._get_listeners(node, evtType) # pylint:disable=unused-variable
for c in bubbling_listeners:
evtObject.currentTarget = node._node
self.do_dispatch(c, evtObject)
def dispatchEvent(self, evtObject):
evtType = evtObject.type
if not evtType:
raise EventException(EventException.UNSPECIFIED_EVENT_TYPE_ERR)
log.info("dispatchEvent(%s)", evtType)
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_dispatchevent_count()
capture_listeners, bubbling_listeners = self._get_listeners(self.tag, evtType)
if capture_listeners:
evtObject.eventPhase = Event.CAPTURING_PHASE
self._dispatchCaptureEvent(self.tag, evtType, evtObject)
evtObject._target = self
evtObject.eventPhase = Event.AT_TARGET
evtObject.currentTarget = self
if not evtObject._stoppedPropagation:
for c in capture_listeners:
self.do_dispatch(c, evtObject)
for c in bubbling_listeners:
self.do_dispatch(c, evtObject)
if bubbling_listeners:
evtObject.eventPhase = Event.BUBBLING_PHASE
self._dispatchBubblingEvent(self.tag, evtType, evtObject)
evtObject.eventPhase = Event.AT_TARGET
return True
| 9,365
|
Python
|
.py
| 194
| 37.829897
| 122
| 0.644779
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,898
|
__init__.py
|
buffer_thug/thug/DOM/W3C/Events/__init__.py
|
__all__ = [
"DocumentEvent",
"Event",
"EventException",
"EventListener",
"EventTarget",
"HTMLEvent",
"MessageEvent",
"MouseEvent",
"MutationEvent",
"StorageEvent",
"UIEvent",
]
# from .DocumentEvent import DocumentEvent
from .Event import Event
from .EventException import EventException
from .EventListener import EventListener
from .EventTarget import EventTarget
from .HTMLEvent import HTMLEvent
from .MessageEvent import MessageEvent
from .MouseEvent import MouseEvent
from .MutationEvent import MutationEvent
from .StorageEvent import StorageEvent
from .UIEvent import UIEvent
| 628
|
Python
|
.py
| 24
| 23.25
| 42
| 0.780731
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|
12,899
|
StorageEvent.py
|
buffer_thug/thug/DOM/W3C/Events/StorageEvent.py
|
#!/usr/bin/env python
from .Event import Event
# Introduced in DOM Level 2
class StorageEvent(Event):
EventTypes = ("storage",)
def __init__(self):
Event.__init__(self)
self._key = None
self._oldValue = None
self._newValue = None
self._url = None
self._storageArea = None
@property
def key(self):
return self._key
@property
def oldValue(self):
return self._oldValue
@property
def newValue(self):
return self._newValue
@property
def url(self):
return self._url
@property
def storageArea(self):
return self._storageArea
def initStorageEvent(
self,
eventTypeArg,
canBubbleArg,
cancelableArg,
keyArg,
oldValueArg,
newValueArg,
urlArg,
storageAreaArg,
):
self.initEvent(eventTypeArg, canBubbleArg, cancelableArg)
self._key = keyArg
self._oldValue = oldValueArg
self._newValue = newValueArg
self._url = urlArg
self._storageArea = storageAreaArg
| 1,113
|
Python
|
.py
| 44
| 18.068182
| 65
| 0.606232
|
buffer/thug
| 978
| 204
| 0
|
GPL-2.0
|
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
|