/usr/share/pyshared/sx/w3c/cssDOMElementInterface.py is in python-pisa 3.0.32-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | #!/usr/bin/env python
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##~ Copyright (C) 2002-2004 TechGame Networks, LLC.
##~
##~ This library is free software; you can redistribute it and/or
##~ modify it under the terms of the BSD style License as found in the
##~ LICENSE file included with this distribution.
##
## Modified by Dirk Holtwick <holtwick@web.de>, 2007-2008
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Imports
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import css
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Definitions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class CSSDOMElementInterface(css.CSSElementInterfaceAbstract):
"""An implementation of css.CSSElementInterfaceAbstract for xml.dom Element Nodes"""
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Constants / Variables / Etc.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
style = None
_pseudoStateHandlerLookup = {
'first-child':
lambda self: not bool(self.getPreviousSibling()),
'not-first-child':
lambda self: bool(self.getPreviousSibling()),
'last-child':
lambda self: not bool(self.getNextSibling()),
'not-last-child':
lambda self: bool(self.getNextSibling()),
'middle-child':
lambda self: not bool(self.getPreviousSibling()) and not bool(self.getNextSibling()),
'not-middle-child':
lambda self: bool(self.getPreviousSibling()) or bool(self.getNextSibling()),
# XXX 'first-line':
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Definitions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def __init__(self, domElement, cssParser=None):
self.domElement = domElement
# print self.domElement.attributes
if cssParser is not None:
self.onCSSParserVisit(cssParser)
def onCSSParserVisit(self, cssParser):
styleSrc = self.getStyleAttr()
if styleSrc:
style = cssParser.parseInline(styleSrc)
self.setInlineStyle(style)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def matchesNode(self, (namespace, tagName)):
if tagName not in ('*', self.domElement.tagName):
return False
if namespace in (None, '', '*'):
# matches any namespace
return True
else: # full compare
return namespace == self.domElement.namespaceURI
def getAttr(self, name, default=NotImplemented):
attrValue = self.domElement.attributes.get(name)
if attrValue is not None:
return attrValue.value
else:
return default
def getIdAttr(self):
return self.getAttr('id', '')
def getClassAttr(self):
return self.getAttr('class', '')
def getStyleAttr(self):
return self.getAttr('style', None)
def inPseudoState(self, name, params=()):
handler = self._pseudoStateHandlerLookup.get(name, lambda self: False)
return handler(self)
def iterXMLParents(self, includeSelf=False):
klass = self.__class__
current = self.domElement
if not includeSelf:
current = current.parentNode
while (current is not None) and (current.nodeType == current.ELEMENT_NODE):
yield klass(current)
current = current.parentNode
def getPreviousSibling(self):
sibling = self.domElement.previousSibling
while sibling:
if sibling.nodeType == sibling.ELEMENT_NODE:
return sibling
else:
sibling = sibling.previousSibling
return None
def getNextSibling(self):
sibling = self.domElement.nextSibling
while sibling:
if sibling.nodeType == sibling.ELEMENT_NODE:
return sibling
else:
sibling = sibling.nextSibling
return None
def getInlineStyle(self):
return self.style
def setInlineStyle(self, style):
self.style = style
|