Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def createElement(self, tagname, tagvalue = None):
from .DOMImplementation import DOMImplementation
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_createelement_count()
# Internet Explorer 8 and below also support the syntax
# document.createElement('<p>')
if log.ThugOpts.Personality.isIE() and log.ThugOpts.Personality.browserMajorVersion < 9:
if tagname.startswith('<') and '>' in tagname:
tagname = tagname[1:].split('>')[0]
return DOMImplementation.createHTMLElement(self, bs4.Tag(parser = self.doc, name = tagname))
</p>
def _querySelector(self, selectors):
from .DOMImplementation import DOMImplementation
try:
s = self.tag.select(selectors)
except Exception: # pragma: no cover
return None
return DOMImplementation.createHTMLElement(self, s[0]) if s and s[0] else None
def elements(self):
from thug.DOM.W3C.Core.DOMImplementation import DOMImplementation
nodes = []
for tag in self.tag.children:
if getattr(tag, 'name', None) and tag.name not in ('br', ):
nodes.append(DOMImplementation.createHTMLElement(self.doc, tag))
return HTMLFormControlsCollection(self.doc, nodes)
def frames(self):
"""an array of all the frames (including iframes) in the current window"""
from thug.DOM.W3C.HTML.HTMLCollection import HTMLCollection
frames = set()
for frame in self._findAll(['frame', 'iframe']):
if not getattr(frame, '_node', None):
from thug.DOM.W3C.Core.DOMImplementation import DOMImplementation
DOMImplementation.createHTMLElement(self.window.doc, frame)
frames.add(frame._node)
return HTMLCollection(self.doc, list(frames))
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, ):
from thug.DOM.W3C.Core.DOMImplementation import DOMImplementation
return DOMImplementation.createHTMLElement(self.doc, tag)
raise AttributeError
def _querySelector(self, selectors):
from .DOMImplementation import DOMImplementation
try:
s = self.tag.select(selectors)
except Exception: # pragma: no cover
return None
return DOMImplementation.createHTMLElement(self, s[0]) if s and s[0] else None
def hasFeature(feature, version):
if version == "":
version = None
return (feature.lower(), version) in DOMImplementation.features
def _querySelector(self, selectors):
from .DOMImplementation import DOMImplementation
try:
s = self.doc.select(selectors)
except Exception: # pragma: no cover
return None
return DOMImplementation.createHTMLElement(self, s[0]) if s and s[0] else None
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:
from thug.DOM.W3C.Core.DOMImplementation import DOMImplementation
return DOMImplementation.createHTMLElement(self.doc, _attr[0])
log.info("[HTMLDocument] Undefined: %s", attr)
raise AttributeError
def getDOMImplementation(dom = None, **kwds):
from thug.DOM.W3C.Core.DOMImplementation import DOMImplementation
return DOMImplementation(dom if dom else bs4.BeautifulSoup('', 'lxml'), **kwds)