| 1 |
|
| 2 |
""" |
| 3 |
Simple transfomer: handle OpenID elements. Ie: an openid namespace is added and the usual |
| 4 |
'link' elements for openid are exchanged against a namespaced version. |
| 5 |
|
| 6 |
@summary: OpenID transformer module. |
| 7 |
@requires: U{RDFLib package<http://rdflib.net>} |
| 8 |
@organization: U{World Wide Web Consortium<http://www.w3.org>} |
| 9 |
@author: U{Ivan Herman<a href="http://www.w3.org/People/Ivan/">} |
| 10 |
@license: This software is available for use under the |
| 11 |
U{W3C® SOFTWARE NOTICE AND LICENSE<href="http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231">} |
| 12 |
@contact: Ivan Herman, [email protected] |
| 13 |
@var OPENID_NS: the OpenID URI used in the package |
| 14 |
""" |
| 15 |
|
| 16 |
""" |
| 17 |
$Id: OpenID.py,v 1.4 2012-01-18 14:16:44 ivan Exp $ |
| 18 |
$Date: 2012-01-18 14:16:44 $ |
| 19 |
""" |
| 20 |
|
| 21 |
OPENID_NS = "http://xmlns.openid.net/auth#" |
| 22 |
|
| 23 |
|
| 24 |
def OpenID_transform(html, options, _state): |
| 25 |
""" |
| 26 |
Replace C{openid.XXX} type C{@rel} attribute values in C{<link>} elements by C{openid:XXX}. The openid URI is also |
| 27 |
added to the top level namespaces with the C{openid:} local name. |
| 28 |
|
| 29 |
@param html: a DOM node for the top level html element |
| 30 |
@param options: invocation options |
| 31 |
@type options: L{Options<pyRdfa.options>} |
| 32 |
@param state: top level execution state |
| 33 |
@type state: L{State<pyRdfa.state>} |
| 34 |
""" |
| 35 |
from ..host import HostLanguage |
| 36 |
if not(options.host_language in [HostLanguage.xhtml, HostLanguage.html5, HostLanguage.xhtml5]): |
| 37 |
return |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
head = None |
| 42 |
try: |
| 43 |
head = html.getElementsByTagName("head")[0] |
| 44 |
except: |
| 45 |
|
| 46 |
return |
| 47 |
|
| 48 |
foundOpenId = False |
| 49 |
for link in html.getElementsByTagName("link"): |
| 50 |
if link.hasAttribute("rel"): |
| 51 |
rel = link.getAttribute("rel") |
| 52 |
newProp = "" |
| 53 |
for n in rel.strip().split(): |
| 54 |
if n.startswith("openid."): |
| 55 |
newProp += " " + n.replace("openid.", "openid:") |
| 56 |
foundOpenId = True |
| 57 |
else: |
| 58 |
newProp += " " + n |
| 59 |
link.setAttribute("rel",newProp.strip()) |
| 60 |
|
| 61 |
|
| 62 |
if foundOpenId and not head.hasAttribute("xmlns:openid"): |
| 63 |
head.setAttributeNS("", "xmlns:openid", OPENID_NS) |
| 64 |
|