Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion extruct/rdfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
from xml.dom import Node
from xml.dom.minidom import Attr, NamedNodeMap

from lxml.etree import ElementBase, _ElementStringResult, _ElementUnicodeResult, XPath
from lxml.etree import ElementBase, _ElementStringResult, _ElementUnicodeResult, XPath, tostring
from lxml.html import fromstring, HTMLParser, HtmlElementClassLookup
from rdflib import Graph, logger as rdflib_logger
from rdflib.plugins.parsers.pyRdfa import pyRdfa as PyRdfa, Options, logger as pyrdfa_logger
from rdflib.plugins.parsers.pyRdfa.initialcontext import initial_context

from copy import deepcopy, copy

# silence rdflib/PyRdfa INFO logs
rdflib_logger.setLevel(logging.ERROR)
pyrdfa_logger.setLevel(logging.ERROR)
Expand Down Expand Up @@ -71,6 +73,7 @@ class DomHtmlMixin(object):
TEXT_NODE = Node.TEXT_NODE

_xp_childrennodes = XPath('child::node()')

@property
def documentElement(self):
return self.getroottree().getroot()
Expand Down Expand Up @@ -101,6 +104,9 @@ def getAttribute(self, name):
def setAttribute(self, name, value):
self.set(name, value)

def cloneNode(self, deep):
return deepcopy(self) if deep else copy(self)

@property
def attributes(self):
attrs = {}
Expand Down Expand Up @@ -152,6 +158,10 @@ def data(self):
else:
raise RuntimeError

def toxml(self, encoding=None):
return tostring(self, encoding=encoding)



class DomHtmlElementClassLookup(HtmlElementClassLookup):
_lookups = {}
Expand Down