Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refined the RDFa warnings by treating the @rel/<link> combination sep…

…arately.
  • Loading branch information...
commit c2eb7feb591007d2a90d1c6dd3625ecd0d2b75ae 1 parent 5556347
@iherman iherman authored
View
10 pyRdfa/__init__.py
@@ -155,7 +155,7 @@
"""
"""
- $Id: __init__.py,v 1.87 2012-12-26 12:30:39 ivan Exp $
+ $Id: __init__.py,v 1.88 2013-01-07 12:46:43 ivan Exp $
"""
__version__ = "3.4.3"
@@ -488,7 +488,6 @@ def copyGraph(tog, fromg) :
# Create the initial state. This takes care of things
# like base, top level namespace settings, etc.
state = ExecutionContext(topElement, default_graph, base=self.required_base if self.required_base != None else "", options=self.options, rdfa_version=self.rdfa_version)
- #state = ExecutionContext(topElement, default_graph, base=self.base, options=self.options, rdfa_version=self.rdfa_version)
# Perform the built-in and external transformations on the HTML tree.
for trans in self.options.transformers + builtInTransformers :
@@ -771,9 +770,7 @@ def _get_option(param, compare_value, default) :
transformers = []
- if "rdfa_lite" in list(form.keys()) and form.getfirst("rdfa_lite").lower() == "true" :
- from .transform.lite import lite_prune
- transformers.append(lite_prune)
+ check_lite = "rdfa_lite" in list(form.keys()) and form.getfirst("rdfa_lite").lower() == "true"
# The code below is left for backward compatibility only. In fact, these options are not exposed any more,
# they are not really in use
@@ -829,7 +826,8 @@ def _get_option(param, compare_value, default) :
vocab_cache_report = vocab_cache_report,
refresh_vocab_cache = refresh_vocab_cache,
vocab_expansion = vocab_expansion,
- embedded_rdf = embedded_rdf
+ embedded_rdf = embedded_rdf,
+ check_lite = check_lite
)
processor = pyRdfa(options = options, base = base, media_type = media_type, rdfa_version = rdfa_version)
View
6 pyRdfa/host/__init__.py
@@ -30,8 +30,8 @@
"""
"""
-$Id: __init__.py,v 1.19 2012/06/28 11:58:14 ivan Exp $
-$Date: 2012/06/28 11:58:14 $
+$Id: __init__.py,v 1.20 2013-01-07 13:03:16 ivan Exp $
+$Date: 2013-01-07 13:03:16 $
"""
__version__ = "3.0"
@@ -84,7 +84,7 @@ class HostLanguage :
# ie, it cannot be turned down by an option
require_embedded_rdf = [ HostLanguage.svg ]
-warn_xmlns_usage = [ HostLanguage.html5, HostLanguage.xhtml5, HostLanguage.xhtml]
+warn_xmlns_usage = [ HostLanguage.html5, HostLanguage.xhtml5, HostLanguage.xhtml ]
host_dom_transforms = {
HostLanguage.atom : [atom_add_entry_type],
View
4 pyRdfa/initialcontext.py
@@ -13,8 +13,8 @@
"""
"""
-$Id: initialcontext.py,v 1.9 2012/09/27 18:10:44 ivan Exp $
-$Date: 2012/09/27 18:10:44 $
+$Id: initialcontext.py,v 1.10 2013-01-07 12:46:43 ivan Exp $
+$Date: 2013-01-07 12:46:43 $
"""
class Wrapper :
View
13 pyRdfa/options.py
@@ -11,7 +11,7 @@
"""
"""
-$Id: options.py,v 1.18 2012-12-26 12:28:57 ivan Exp $ $Date: 2012-12-26 12:28:57 $
+$Id: options.py,v 1.19 2013-01-07 12:46:43 ivan Exp $ $Date: 2013-01-07 12:46:43 $
"""
import sys, datetime
@@ -33,6 +33,7 @@
from .host import HostLanguage, MediaTypes, content_to_host_language, predefined_1_0_rel, require_embedded_rdf
from . import ns_xsd, ns_distill, ns_rdfa
from . import RDFA_Error, RDFA_Warning, RDFA_Info
+from .transform.lite import lite_prune
ns_dc = Namespace("http://purl.org/dc/terms/")
ns_ht = Namespace("http://www.w3.org/2006/http#")
@@ -149,6 +150,9 @@ class Options :
@type content_type: string (logically: an enumeration)
@ivar add_informational_messages: whether informational messages should also be added to the processor graph, or only errors and warnings
+
+ @ivar experimental_features: whether experimental features should be activated; that is a developer's option...
+ @ivar check_lite: whether RDFa Lite should be checked, to generate warnings.
"""
def __init__(self, output_default_graph = True,
output_processor_graph = False,
@@ -160,7 +164,9 @@ def __init__(self, output_default_graph = True,
vocab_cache_report = False,
refresh_vocab_cache = False,
add_informational_messages = False,
- experimental_features = False) :
+ check_lite = False,
+ experimental_features = False
+ ) :
self.space_preserve = space_preserve
self.transformers = transformers
self.processor_graph = ProcessorGraph()
@@ -173,6 +179,9 @@ def __init__(self, output_default_graph = True,
self.vocab_expansion = vocab_expansion
self.vocab_cache = vocab_cache
self.add_informational_messages = add_informational_messages
+ self.check_lite = check_lite
+ if check_lite :
+ self.transformers.append(lite_prune)
self.experimental_features = experimental_features
def set_host_language(self, content_type) :
View
15 pyRdfa/parse.py
@@ -15,15 +15,15 @@
"""
"""
-$Id: parse.py,v 1.18 2012/11/16 17:51:53 ivan Exp $
-$Date: 2012/11/16 17:51:53 $
+$Id: parse.py,v 1.19 2013-01-07 12:46:43 ivan Exp $
+$Date: 2013-01-07 12:46:43 $
"""
import sys
from .state import ExecutionContext
from .property import ProcessProperty
-from .embeddedRDF import handle_embeddedRDF
+from .embeddedRDF import handle_embeddedRDF
from .host import HostLanguage, host_dom_transforms
import rdflib
@@ -95,10 +95,19 @@ def header_check(p_obj) :
else :
return None
+ def lite_check() :
+ if state.options.check_lite and state.options.host_language in [ HostLanguage.html5, HostLanguage.xhtml5, HostLanguage.xhtml ] :
+ if node.tagName == "link" and node.hasAttribute("rel") and state.term_or_curie.CURIE_to_URI(node.getAttribute("rel")) != None :
+ state.options.add_warning("In RDFa Lite, attribute @rel in <link> is only used in non-RDFa way (consider using @property)", node=node)
+
# Update the state. This means, for example, the possible local settings of
# namespaces and lang
state = None
state = ExecutionContext(node, graph, inherited_state=incoming_state)
+
+ #---------------------------------------------------------------------------------
+ # Extra warning check on RDFa Lite
+ lite_check()
#---------------------------------------------------------------------------------
# Handling the role attribute is pretty much orthogonal to everything else...
View
29 pyRdfa/transform/lite.py
@@ -5,11 +5,13 @@
@license: This software is available for use under the
U{W3C® SOFTWARE NOTICE AND LICENSE<href="http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231">}
@contact: Ivan Herman, ivan@w3.org
-@version: $Id: lite.py,v 1.9 2012/06/26 13:29:58 ivan Exp $
-$Date: 2012/06/26 13:29:58 $
+@version: $Id: lite.py,v 1.10 2013-01-07 12:46:31 ivan Exp $
+$Date: 2013-01-07 12:46:31 $
"""
-non_lite_attributes = ["about","inlist","datatype","rev","rel"]
+from ..host import HostLanguage
+non_lite_attributes = ["about","inlist","datatype","rev","rel","content"]
+non_lite_attributes_html = ["about","inlist","datatype","rev"]
def lite_prune(top, options, state) :
"""
@@ -26,18 +28,27 @@ def lite_prune(top, options, state) :
"""
def generate_warning(node, attr) :
if attr == "rel" :
- msg = "Attribute @rel is not used in RDFa Lite, ignored (consider using @property)"
+ msg = "Attribute @rel should not be used in RDFa Lite (consider using @property)"
elif attr == "about" :
- msg = "Attribute @about is not used in RDFa Lite, ignored (consider using a <link> element with @href or @resource)"
+ msg = "Attribute @about should not be used in RDFa Lite (consider using a <link> element with @href or @resource)"
else :
- msg = "Attribute @%s is not used in RDFa Lite, ignored" % attr
+ msg = "Attribute @%s should not be used in RDFa Lite" % attr
options.add_warning(msg, node=node)
def remove_attrs(node) :
# first the @content; this has a special treatment
- if node.tagName != "meta" and node.hasAttribute("content") :
- generate_warning(node, "content")
- # node.removeAttribute("content")
+ # there are some extras to check for HTML dialects
+ if options.host_language in [ HostLanguage.html5, HostLanguage.xhtml5, HostLanguage.xhtml ] :
+ if node.tagName != "meta" and node.hasAttribute("content") :
+ generate_warning(node, "content")
+ # node.removeAttribute("content")
+ if node.tagName != "link" and node.hasAttribute("rel") :
+ # Unfortunately, this has to be checked separately and run-time for <link> where @rel is allowed for non-RDFa purposes...
+ generate_warning(node, "rel")
+ for attr in non_lite_attributes_html :
+ if node.hasAttribute(attr) :
+ generate_warning(node, attr)
+ # node.removeAttribute(attr)
else :
for attr in non_lite_attributes :
if node.hasAttribute(attr) :
View
5 scripts/localRDFa.py
@@ -13,7 +13,6 @@
from pyRdfa.transform.metaname import meta_transform
from pyRdfa.transform.OpenID import OpenID_transform
from pyRdfa.transform.DublinCore import DC_transform
-from pyRdfa.transform.lite import lite_prune
from pyRdfa.options import Options
extraTransformers = [
@@ -64,6 +63,7 @@ def usage() :
vocab_expansion = False
vocab_cache = True
embedded_rdf = True
+check_lite = False
try :
opts, value = getopt.getopt(sys.argv[1:],"vxetjnpzsb:g:ryl",['graph='])
@@ -85,7 +85,7 @@ def usage() :
elif o == "-s" :
space_preserve = False
elif o == "-l" :
- extras.append(lite_prune)
+ check_lite = True
elif o == "-r" :
vocab_cache_report = True
elif o == "-v" :
@@ -117,6 +117,7 @@ def usage() :
vocab_cache = vocab_cache,
vocab_cache_report = vocab_cache_report,
refresh_vocab_cache = refresh_vocab_cache,
+ check_lite = check_lite,
experimental_features = True
)
Please sign in to comment.
Something went wrong with that request. Please try again.