summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Aastrand Grimnes <gromgull@gmail.com>2015-11-22 14:13:38 +0100
committerGunnar Aastrand Grimnes <gromgull@gmail.com>2015-11-22 14:13:38 +0100
commit227b41fb1f1de15f1f4c126aae008444e0e6b0a9 (patch)
tree25fd39e794e3c3e7e97ff7432573026837d1b951
parentea043ead8fd51acca7d2d3f4562aab7b05b2baa1 (diff)
downloadrdflib-227b41fb1f1de15f1f4c126aae008444e0e6b0a9.tar.gz
cleaned up trailing whitespace
-rw-r--r--rdflib/plugins/parsers/pyMicrodata/__init__.py44
-rw-r--r--rdflib/plugins/parsers/pyMicrodata/microdata.py132
-rw-r--r--rdflib/plugins/parsers/pyMicrodata/registry.py2
-rw-r--r--rdflib/plugins/parsers/pyMicrodata/utils.py26
-rw-r--r--rdflib/plugins/parsers/pyRdfa/__init__.py104
-rw-r--r--rdflib/plugins/parsers/pyRdfa/embeddedRDF.py12
-rw-r--r--rdflib/plugins/parsers/pyRdfa/extras/__init__.py2
-rw-r--r--rdflib/plugins/parsers/pyRdfa/extras/httpheader.py40
-rwxr-xr-xrdflib/plugins/parsers/pyRdfa/host/__init__.py22
-rw-r--r--rdflib/plugins/parsers/pyRdfa/host/atom.py4
-rw-r--r--rdflib/plugins/parsers/pyRdfa/host/html5.py48
-rw-r--r--rdflib/plugins/parsers/pyRdfa/initialcontext.py4
-rw-r--r--rdflib/plugins/parsers/pyRdfa/options.py56
-rw-r--r--rdflib/plugins/parsers/pyRdfa/parse.py80
-rw-r--r--rdflib/plugins/parsers/pyRdfa/property.py82
-rw-r--r--rdflib/plugins/parsers/pyRdfa/rdfs/cache.py62
-rw-r--r--rdflib/plugins/parsers/pyRdfa/rdfs/process.py52
-rw-r--r--rdflib/plugins/parsers/pyRdfa/state.py118
-rw-r--r--rdflib/plugins/parsers/pyRdfa/termorcurie.py96
-rwxr-xr-xrdflib/plugins/parsers/pyRdfa/transform/DublinCore.py2
-rwxr-xr-xrdflib/plugins/parsers/pyRdfa/transform/__init__.py18
-rwxr-xr-xrdflib/plugins/parsers/pyRdfa/transform/lite.py4
-rw-r--r--rdflib/plugins/parsers/pyRdfa/transform/prototype.py2
-rw-r--r--rdflib/plugins/parsers/pyRdfa/utils.py36
-rw-r--r--rdflib/plugins/parsers/structureddata.py10
-rw-r--r--rdflib/plugins/sleepycat.py4
-rw-r--r--rdflib/plugins/sparql/__init__.py2
-rw-r--r--rdflib/plugins/sparql/algebra.py16
-rw-r--r--rdflib/plugins/sparql/evaluate.py6
-rw-r--r--rdflib/plugins/sparql/processor.py2
-rw-r--r--rdflib/plugins/sparql/results/txtresults.py14
-rw-r--r--rdflib/plugins/stores/regexmatching.py2
32 files changed, 552 insertions, 552 deletions
diff --git a/rdflib/plugins/parsers/pyMicrodata/__init__.py b/rdflib/plugins/parsers/pyMicrodata/__init__.py
index 7137b60d..7b943f98 100644
--- a/rdflib/plugins/parsers/pyMicrodata/__init__.py
+++ b/rdflib/plugins/parsers/pyMicrodata/__init__.py
@@ -98,7 +98,7 @@ class MicrodataError(Exception) :
def __init__(self, msg) :
self.msg = msg
Exception.__init__(self)
-
+
class HTTPError(MicrodataError) :
"""Raised when HTTP problems are detected. It does not add any new functionality to the
Exception class."""
@@ -144,11 +144,11 @@ class pyMicrodata :
self.base = base
self.vocab_expansion = vocab_expansion
self.vocab_cache = vocab_cache
-
+
def _generate_error_graph(self, pgraph, full_msg, uri = None) :
"""
Generate an error message into the graph. This method is usually used reacting on exceptions.
-
+
Later versions of pyMicrodata may have more detailed error conditions on which it wishes to react. At the moment, this
is fairly crude...
"""
@@ -156,7 +156,7 @@ class pyMicrodata :
retval = Graph()
else :
retval = pgraph
-
+
pgraph.bind( "dc","http://purl.org/dc/terms/" )
pgraph.bind( "xsd",'http://www.w3.org/2001/XMLSchema#' )
pgraph.bind( "ht",'http://www.w3.org/2006/http#' )
@@ -166,13 +166,13 @@ class pyMicrodata :
retval.add((bnode, ns_rdf["type"], ns_micro["Error"]))
retval.add((bnode, ns_dc["description"], Literal(full_msg)))
retval.add((bnode, ns_dc["date"], Literal(datetime.datetime.utcnow().isoformat(),datatype=ns_xsd["dateTime"])))
-
+
if uri != None :
htbnode = BNode()
retval.add( (bnode, ns_micro["context"],htbnode) )
retval.add( (htbnode, ns_rdf["type"], ns_ht["Request"]) )
retval.add( (htbnode, ns_ht["requestURI"], Literal(uri)) )
-
+
if self.http_status != None and self.http_status != 200:
htbnode = BNode()
retval.add( (bnode, ns_micro["context"],htbnode) )
@@ -180,7 +180,7 @@ class pyMicrodata :
retval.add( (htbnode, ns_ht["responseCode"], URIRef("http://www.w3.org/2006/http#%s" % self.http_status)) )
return retval
-
+
def _get_input(self, name) :
"""
Trying to guess whether "name" is a URI, a string; it then tries to open these as such accordingly,
@@ -209,7 +209,7 @@ class pyMicrodata :
return open(name, 'rb')
else :
return name
-
+
####################################################################################################################
# Externally used methods
#
@@ -226,20 +226,20 @@ class pyMicrodata :
if graph == None :
# Create the RDF Graph, that will contain the return triples...
graph = Graph()
-
- conversion = MicrodataConversion(dom.documentElement,
- graph,
- base = self.base,
- vocab_expansion = self.vocab_expansion,
+
+ conversion = MicrodataConversion(dom.documentElement,
+ graph,
+ base = self.base,
+ vocab_expansion = self.vocab_expansion,
vocab_cache = self.vocab_cache)
conversion.convert()
return graph
-
+
def graph_from_source(self, name, graph = None, rdfOutput = False) :
"""
Extract an RDF graph from an microdata source. The source is parsed, the RDF extracted, and the RDF Graph is
returned. This is a front-end to the L{pyMicrodata.graph_from_DOM} method.
-
+
@param name: a URI, a file name, or a file-like object
@return: an RDF Graph
@rtype: rdflib Graph instance
@@ -261,7 +261,7 @@ class pyMicrodata :
self.http_status = 500
if not rdfOutput : raise e
return self._generate_error_graph(graph, str(e), uri=name)
-
+
dom = None
try :
import warnings
@@ -278,7 +278,7 @@ class pyMicrodata :
e = sys.exc_info()[1]
self.http_status = 400
if not rdfOutput : raise e
- return self._generate_error_graph(graph, str(e), uri=name)
+ return self._generate_error_graph(graph, str(e), uri=name)
except Exception :
# Something nasty happened:-(
@@ -289,7 +289,7 @@ class pyMicrodata :
self.http_status = 500
if not rdfOutput : raise e
return self._generate_error_graph(graph, str(e), uri=name)
-
+
def rdf_from_sources(self, names, outputFormat = "pretty-xml", rdfOutput = False) :
"""
Extract and RDF graph from a list of RDFa sources and serialize them in one graph. The sources are parsed, the RDF
@@ -329,7 +329,7 @@ def processURI(uri, outputFormat, form) :
"""The standard processing of a microdata uri options in a form, ie, as an entry point from a CGI call.
The call accepts extra form options (eg, HTTP GET options) as follows:
-
+
@param uri: URI to access. Note that the "text:" and "uploaded:" values are treated separately; the former is for textual intput (in which case a StringIO is used to get the data) and the latter is for uploaded file, where the form gives access to the file directly.
@param outputFormat: serialization formats, as understood by RDFLib. Note that though "turtle" is
a possible parameter value, some versions of the RDFLib turtle generation does funny (though legal) things with
@@ -370,7 +370,7 @@ def processURI(uri, outputFormat, form) :
# Decide the output format; the issue is what should happen in case of a top level error like an inaccessibility of
# the html source: should a graph be returned or an HTML page with an error message?
- # decide whether HTML or RDF should be sent.
+ # decide whether HTML or RDF should be sent.
htmlOutput = False
#if 'HTTP_ACCEPT' in os.environ :
# acc = os.environ['HTTP_ACCEPT']
@@ -404,7 +404,7 @@ def processURI(uri, outputFormat, form) :
import cgi
h = sys.exc_info()[1]
retval = 'Content-type: text/html; charset=utf-8\nStatus: %s \n\n' % h.http_code
- retval += "<html>\n"
+ retval += "<html>\n"
retval += "<head>\n"
retval += "<title>HTTP Error in Microdata processing</title>\n"
retval += "</head><body>\n"
@@ -422,7 +422,7 @@ def processURI(uri, outputFormat, form) :
import traceback, cgi
retval = 'Content-type: text/html; charset=utf-8\nStatus: %s\n\n' % processor.http_status
- retval += "<html>\n"
+ retval += "<html>\n"
retval += "<head>\n"
retval += "<title>Exception in Microdata processing</title>\n"
retval += "</head><body>\n"
diff --git a/rdflib/plugins/parsers/pyMicrodata/microdata.py b/rdflib/plugins/parsers/pyMicrodata/microdata.py
index a783839c..b7079351 100644
--- a/rdflib/plugins/parsers/pyMicrodata/microdata.py
+++ b/rdflib/plugins/parsers/pyMicrodata/microdata.py
@@ -23,7 +23,7 @@ is stopped (on the whole subtree)
import sys
if sys.version_info[0] >= 3 :
from urllib.parse import urlsplit, urlunsplit
-else :
+else :
from urlparse import urlsplit, urlunsplit
from types import *
@@ -43,7 +43,7 @@ else :
from rdflib.RDFS import RDFSNS as ns_rdfs
from rdflib.Literal import _XSD_NS as ns_xsd
from rdflib.RDF import RDFNS as ns_rdf
-
+
ns_owl = Namespace("http://www.w3.org/2002/07/owl#")
from .registry import registry, vocab_names
@@ -59,7 +59,7 @@ from . import debug
class PropertySchemes :
vocabulary = "vocabulary"
contextual = "contextual"
-
+
class ValueMethod :
unordered = "unordered"
list = "list"
@@ -69,7 +69,7 @@ class ValueMethod :
class Evaluation_Context :
"""
Evaluation context structure. See Section 4.1 of the U{W3C IG Note<http://www.w3.org/TR/microdata-rdf/>}for the details.
-
+
@ivar current_type : an absolute URL for the current type, used when an item does not contain an item type
@ivar memory: mapping from items to RDF subjects
@type memory: dictionary
@@ -81,7 +81,7 @@ class Evaluation_Context :
self.memory = {}
self.current_name = None
self.current_vocabulary = None
-
+
def get_memory( self, item ) :
"""
Get the memory content (ie, RDF subject) for 'item', or None if not stored yet
@@ -93,7 +93,7 @@ class Evaluation_Context :
return self.memory[item]
else :
return None
-
+
def set_memory( self, item, subject ) :
"""
Set the memory content, ie, the subject, for 'item'.
@@ -103,11 +103,11 @@ class Evaluation_Context :
@type subject: URIRef or Blank Node
"""
self.memory[item] = subject
-
+
def new_copy(self, itype) :
"""
During the generation algorithm a new copy of the current context has to be done with a new current type.
-
+
At the moment, the content of memory is copied, ie, a fresh dictionary is created and the content copied over.
Not clear whether that is necessary, though, maybe a simple reference is enough...
@param itype : an absolute URL for the current type
@@ -117,11 +117,11 @@ class Evaluation_Context :
for k in self.memory :
retval.memory[k] = self.memory[k]
- retval.current_type = itype
+ retval.current_type = itype
retval.current_name = self.current_name
retval.current_vocabulary = self.current_vocabulary
return retval
-
+
def __str__(self) :
retval = "Evaluation context:\n"
retval += " current type: %s\n" % self.current_type
@@ -130,12 +130,12 @@ class Evaluation_Context :
retval += " memory: %s\n" % self.memory
retval += "----\n"
return retval
-
+
class Microdata :
"""
This class encapsulates methods that are defined by the U{microdata spec<http://dev.w3.org/html5/md/Overview.html>},
as opposed to the RDF conversion note.
-
+
@ivar document: top of the DOM tree, as returned by the HTML5 parser
@ivar base: the base URI of the Dom tree, either set from the outside or via a @base element
"""
@@ -145,7 +145,7 @@ class Microdata :
@param base: the base URI of the Dom tree, either set from the outside or via a @base element
"""
self.document = document
-
+
#-----------------------------------------------------------------
# set the document base, will be used to generate top level URIs
self.base = None
@@ -156,13 +156,13 @@ class Microdata :
self.base = set_base.getAttribute("href")
return
# If got here, ie, if no local setting for base occurs, the input argument has it
- self.base = base
+ self.base = base
def get_top_level_items( self ) :
"""
A top level item is and element that has the @itemscope set, but no @itemtype. They have to
be collected in pre-order and depth-first fashion.
-
+
@return: list of items (ie, DOM Nodes)
"""
def collect_items( node ) :
@@ -170,20 +170,20 @@ class Microdata :
for child in node.childNodes :
if child.nodeType == node.ELEMENT_NODE :
items += collect_items( child )
-
+
if node.hasAttribute("itemscope") and not node.hasAttribute("itemprop") :
# This is also a top level item
items.append(node)
-
+
return items
-
+
return collect_items( self.document )
-
+
def get_item_properties( self, item ) :
"""
Collect the item's properties, ie, all DOM descendent nodes with @itemprop until the subtree hits another
@itemscope. @itemrefs are also added at this point.
-
+
@param item: current item
@type item: DOM Node
@return: array of items, ie, DOM Nodes
@@ -193,14 +193,14 @@ class Microdata :
# returns a series of element nodes.
# Is it worth filtering the ones with itemprop at that level???
results = []
- memory = [ item ]
+ memory = [ item ]
pending = [ child for child in item.childNodes if child.nodeType == item.ELEMENT_NODE ]
-
+
if item.hasAttribute("itemref") :
for id in item.getAttribute("itemref").strip().split() :
obj = self.getElementById(id)
if obj != None : pending.append(obj)
-
+
while len(pending) > 0 :
current = pending.pop(0)
if current in memory :
@@ -210,16 +210,16 @@ class Microdata :
else :
# this for the check above
memory.append(current)
-
+
# @itemscope is the barrier...
if not current.hasAttribute("itemscope") :
pending = [ child for child in current.childNodes if child.nodeType == child.ELEMENT_NODE ] + pending
if current.hasAttribute("itemprop") and current.getAttribute("itemprop").strip() != "" :
results.append(current)
-
+
return results
-
+
def getElementById(self, id) :
"""This is a method defined for DOM 2 HTML, but the HTML5 parser does not seem to define it. Oh well...
@param id: value of an @id attribute to look for
@@ -230,23 +230,23 @@ class Microdata :
for child in node.childNodes :
if child.nodeType == node.ELEMENT_NODE :
ids += collect_ids( child )
-
+
if node.hasAttribute("id") and node.getAttribute("id") == id :
# This is also a top level item
ids.append(node)
-
+
return ids
-
+
ids = collect_ids(self.document)
if len(ids) > 0 :
return ids[0]
else :
return None
-
+
class MicrodataConversion(Microdata) :
"""
Top level class encapsulating the conversion algorithms as described in the W3C note.
-
+
@ivar graph: an RDF graph; an RDFLib Graph
@type graph: RDFLib Graph
@ivar document: top of the DOM tree, as returned by the HTML5 parser
@@ -282,10 +282,10 @@ class MicrodataConversion(Microdata) :
retval = {}
vocabs = initial_context["http://www.w3.org/2011/rdfa-context/rdfa-1.1"].ns
for prefix in list(vocabs.keys()) :
- uri = vocabs[prefix]
+ uri = vocabs[prefix]
if uri not in vocab_names and uri not in registry : retval[uri] = prefix
return retval
-
+
for vocab in registry :
if vocab in vocab_names :
self.graph.bind( vocab_names[vocab],vocab )
@@ -293,7 +293,7 @@ class MicrodataConversion(Microdata) :
hvocab = vocab + '#'
if hvocab in vocab_names :
self.graph.bind( vocab_names[hvocab],hvocab )
-
+
# Add the prefixes defined in the RDFa initial context to improve the outlook of the output
# I put this into a try: except: in case the pyRdfa package is not available...
try :
@@ -309,7 +309,7 @@ class MicrodataConversion(Microdata) :
self.graph.bind( prefix,uri )
except :
pass
-
+
def convert( self ) :
"""
Top level entry to convert and generate all the triples. It finds the top level items,
@@ -321,7 +321,7 @@ class MicrodataConversion(Microdata) :
item_list.append( self.generate_triples(top_level_item, Evaluation_Context()) )
list = generate_RDF_collection( self.graph, item_list )
self.graph.add( (URIRef(self.base),self.ns_md["item"],list) )
-
+
# If the vocab expansion is also switched on, this is the time to do it.
# This is the version with my current proposal: the basic expansion is always there;
@@ -348,7 +348,7 @@ class MicrodataConversion(Microdata) :
def generate_triples( self, item, context ) :
"""
Generate the triples for a specific item. See the W3C Note for the details.
-
+
@param item: the DOM Node for the specific item
@type item: DOM Node
@param context: an instance of an evaluation context
@@ -364,7 +364,7 @@ class MicrodataConversion(Microdata) :
else :
subject = BNode()
context.set_memory( item, subject )
-
+
# Step 3: set the type triples if any
types = []
if item.hasAttribute("itemtype") :
@@ -372,7 +372,7 @@ class MicrodataConversion(Microdata) :
for t in types :
if is_absolute_URI( t ) :
self.graph.add( (subject, ns_rdf["type"], URIRef(t)) )
-
+
# Step 4, 5 and 6 to set the typing variable
if len(types) == 0 :
itype = None
@@ -400,13 +400,13 @@ class MicrodataConversion(Microdata) :
if vocab == None :
parsed = urlsplit(itype)
if parsed.fragment != "" :
- vocab = urlunsplit( (parsed.scheme,parsed.netloc,parsed.path,parsed.query,"") ) + '#'
+ vocab = urlunsplit( (parsed.scheme,parsed.netloc,parsed.path,parsed.query,"") ) + '#'
elif parsed.path == "" and parsed.query == "" :
vocab = itype
if vocab[-1] != '/' : vocab += '/'
else :
vocab = itype.rsplit('/',1)[0] + '/'
-
+
# Step 9: update vocab in the context
if vocab != None :
context.current_vocabulary = vocab
@@ -416,7 +416,7 @@ class MicrodataConversion(Microdata) :
# Step 10: set up a property list; this will be used to generate triples later.
# each entry in the dictionary is an array of RDF objects
property_list = {}
-
+
# Step 11: Get the item properties and run a cycle on those
for prop in self.get_item_properties(item) :
for name in prop.getAttribute("itemprop").strip().split() :
@@ -434,28 +434,28 @@ class MicrodataConversion(Microdata) :
property_list[predicate].append(value)
else :
property_list[predicate] = [ value ]
-
+
# step 12: generate the triples
for property in list(property_list.keys()) :
self.generate_property_values( subject, URIRef(property), property_list[property], context )
-
+
# Step 13: return the subject to the caller
return subject
-
+
def generate_predicate_URI( self, name, context ) :
"""
Generate a full URI for a predicate, using the type, the vocabulary, etc.
-
+
For details of this entry, see Section 4.4
@param name: name of the property, ie, what appears in @itemprop
@param context: an instance of an evaluation context
@type context: L{Evaluation_Context}
"""
if debug: print( "name: %s, %s" % (name,context) )
-
+
# Step 1: absolute URI-s are fine, take them as they are
if is_absolute_URI(name) : return name
-
+
# Step 2: if type is none, that this is just used as a fragment
# if not context.current_type :
if context.current_type == None and context.current_vocabulary == None :
@@ -467,7 +467,7 @@ class MicrodataConversion(Microdata) :
#if context.current_type == None :
# return generate_URI( self.base, name )
-
+
# Step 3: set the scheme
try :
if context.current_vocabulary in registry and "propertyURI" in registry[context.current_vocabulary] :
@@ -477,7 +477,7 @@ class MicrodataConversion(Microdata) :
except :
# This is when the structure of the registry is broken
scheme = PropertySchemes.vocabulary
-
+
name = fragment_escape( name )
if scheme == PropertySchemes.contextual :
# Step 5.1
@@ -530,17 +530,17 @@ class MicrodataConversion(Microdata) :
return expandedURI
-
+
def get_property_value(self, node, context) :
"""
Generate an RDF object, ie, the value of a property. Note that if this element contains
an @itemscope, then a recursive call to L{MicrodataConversion.generate_triples} is done and the
return value of that method (ie, the subject for the corresponding item) is return as an
object.
-
+
Otherwise, either URIRefs are created for <a>, <img>, etc, elements, or a Literal; the latter
gets a time-related type for the <time> element.
-
+
@param node: the DOM Node for which the property values should be generated
@type node: DOM Node
@param context: an instance of an evaluation context
@@ -558,18 +558,18 @@ class MicrodataConversion(Microdata) :
"data" : "src",
"a" : "href",
"area" : "href",
- "link" : "href",
- "object" : "data"
+ "link" : "href",
+ "object" : "data"
}
lang = get_lang_from_hierarchy( self.document, node )
if node.hasAttribute("itemscope") :
# THIS IS A RECURSION ENTRY POINT!
return self.generate_triples( node, context )
-
+
elif node.tagName in URI_attrs and node.hasAttribute(URI_attrs[node.tagName]) :
return URIRef( generate_URI( self.base, node.getAttribute(URI_attrs[node.tagName]).strip() ) )
-
+
elif node.tagName == "meta" and node.hasAttribute("content") :
if lang :
return Literal( node.getAttribute("content"), lang = lang )
@@ -612,12 +612,12 @@ class MicrodataConversion(Microdata) :
return Literal( get_Literal(node), lang = lang )
else :
return Literal( get_Literal(node) )
-
+
def generate_property_values( self, subject, predicate, objects, context) :
"""
Generate the property values for a specific subject and predicate. The context should specify whether
the objects should be added in an RDF list or each triples individually.
-
+
@param subject: RDF subject
@type subject: RDFLib Node (URIRef or blank node)
@param predicate: RDF predicate
@@ -631,7 +631,7 @@ class MicrodataConversion(Microdata) :
# The biggest complication is to find the method...
method = ValueMethod.unordered
superproperties = None
-
+
# This is necessary because predicate is a URIRef, and I am not sure the comparisons would work well
# to be tested, in fact...
pred_key = "%s" % predicate
@@ -649,15 +649,15 @@ class MicrodataConversion(Microdata) :
pass
except :
pass
-
+
if method == ValueMethod.unordered :
for object in objects :
self.graph.add( (subject, predicate, object) )
else :
self.graph.add( (subject,predicate,generate_RDF_collection( self.graph, objects )) )
-
-
-
-
-
+
+
+
+
+
diff --git a/rdflib/plugins/parsers/pyMicrodata/registry.py b/rdflib/plugins/parsers/pyMicrodata/registry.py
index 22cec0ac..aa777a6c 100644
--- a/rdflib/plugins/parsers/pyMicrodata/registry.py
+++ b/rdflib/plugins/parsers/pyMicrodata/registry.py
@@ -116,7 +116,7 @@ _myRegistry = """
"http://n.whatwg.org/work": {
"propertyURI" : "contextual",
"multipleValues" : "list"
- }
+ }
}
"""
diff --git a/rdflib/plugins/parsers/pyMicrodata/utils.py b/rdflib/plugins/parsers/pyMicrodata/utils.py
index 9ac25835..ae7cc6a1 100644
--- a/rdflib/plugins/parsers/pyMicrodata/utils.py
+++ b/rdflib/plugins/parsers/pyMicrodata/utils.py
@@ -45,7 +45,7 @@ def is_absolute_URI( uri ) :
def fragment_escape( name ) :
return quote(name, '/~:-.')
-
+
#################################################################################
def generate_URI(base, v) :
@@ -57,12 +57,12 @@ def generate_URI(base, v) :
"""
if is_absolute_URI( v ) :
return v
- else :
+ else :
# UGLY!!! There is a bug for a corner case in python version <= 2.5.X
if len(v) > 0 and v[0] == '?' and (py_v_major < 3 and py_v_minor <= 5) :
return base+val
####
-
+
# Trust the python library...
# Well, not quite:-) there is what is, in my view, a bug in the urljoin; in some cases it
# swallows the '#' or '?' character at the end. This is clearly a problem with
@@ -75,7 +75,7 @@ def generate_URI(base, v) :
else :
return joined
except :
- return joined
+ return joined
#################################################################################
def generate_RDF_collection( graph, vals ) :
@@ -108,11 +108,11 @@ def get_Literal(Pnode):
rc = rc + node.data
elif node.nodeType == node.ELEMENT_NODE :
rc = rc + get_Literal(node)
-
+
# This presupposes that all spaces and such should be stripped. I am not sure it is true in the spec,
# but this is what the examples show
# return re.sub(r'(\r| |\n|\t)+'," ",rc).strip()
-
+
# at present, the agreement seems to say that white spaces are maintained:
return rc
@@ -139,7 +139,7 @@ def get_lang_from_hierarchy(document, node) :
return get_lang(document)
else :
return lang
-
+
#################################################################################
datetime_type = "http://www.w3.org/2001/XMLSchema#dateTime"
time_type = "http://www.w3.org/2001/XMLSchema#time"
@@ -156,7 +156,7 @@ _formats = {
date_type : [ "%Y-%m-%d", "%Y-%m-%dZ" ],
time_type : [ "%H:%M",
"%H:%M:%S",
- "%H:%M:%SZ",
+ "%H:%M:%SZ",
"%H:%M:%S.%f" ],
datetime_type : [ "%Y-%m-%dT%H:%M",
"%Y-%m-%dT%H:%M:%S",
@@ -234,7 +234,7 @@ def get_time_type(string) :
except ValueError :
pass
# something went wrong...
- return None
+ return None
else :
# Well, no more tricks, this is a plain type
return None
@@ -273,7 +273,7 @@ class URIOpener :
sets the content location.
The class also adds an accept header to the outgoing request, namely
text/html and application/xhtml+xml (unless set explicitly by the caller).
-
+
@ivar data: the real data, ie, a file-like object
@ivar headers: the return headers as sent back by the server
@ivar location: the real location of the data (ie, after possible redirection and content negotiation)
@@ -283,13 +283,13 @@ class URIOpener :
"""
@param name: URL to be opened
@keyword additional_headers: additional HTTP request headers to be added to the call
- """
+ """
try :
# Note the removal of the fragment ID. This is necessary, per the HTTP spec
req = Request(url=name.split('#')[0])
req.add_header('Accept', 'text/html, application/xhtml+xml')
-
+
self.data = urlopen(req)
self.headers = self.data.info()
@@ -297,7 +297,7 @@ class URIOpener :
self.location = urlparse.urljoin(self.data.geturl(),self.headers[URIOpener.CONTENT_LOCATION])
else :
self.location = name
-
+
except urllib_HTTPError :
e = sys.exc_info()[1]
from pyMicrodata import HTTPError
diff --git a/rdflib/plugins/parsers/pyRdfa/__init__.py b/rdflib/plugins/parsers/pyRdfa/__init__.py
index 1a75163e..a9223698 100644
--- a/rdflib/plugins/parsers/pyRdfa/__init__.py
+++ b/rdflib/plugins/parsers/pyRdfa/__init__.py
@@ -42,12 +42,12 @@ The package also implements some optional features that are not part of the RDFa
- possibility for plain literals to be normalized in terms of white spaces. Default: false. (The RDFa specification requires keeping the white spaces and leave applications to normalize them, if needed)
- inclusion of embedded RDF: Turtle content may be enclosed in a C{script} element and typed as C{text/turtle}, U{defined by the RDF Working Group<http://www.w3.org/TR/turtle/>}. Alternatively, some XML dialects (e.g., SVG) allows the usage of RDF/XML as part of their core content to define metadata in RDF. For both of these cases pyRdfa parses these serialized RDF content and adds the resulting triples to the output Graph. Default: true.
- extra, built-in transformers are executed on the DOM tree prior to RDFa processing (see below). These transformers can be provided by the end user.
-
+
Options are collected in an instance of the L{Options} class and may be passed to the processing functions as an extra argument. E.g., to allow the inclusion of embedded content::
from pyRdfa.options import Options
options = Options(embedded_rdf=True)
print pyRdfa(options=options).rdf_from_source('filename')
-
+
See the description of the L{Options} class for the details.
@@ -88,16 +88,16 @@ The triples in the vocabulary files themselves (i.e., the small ontology in RDF
Vocabulary caching
------------------
-By default, pyRdfa uses a caching mechanism instead of fetching the vocabulary files each time their URI is met as a C{@vocab} attribute value. (This behavior can be switched off setting the C{vocab_cache} option to false.)
+By default, pyRdfa uses a caching mechanism instead of fetching the vocabulary files each time their URI is met as a C{@vocab} attribute value. (This behavior can be switched off setting the C{vocab_cache} option to false.)
Caching happens in a file system directory. The directory itself is determined by the platform the tool is used on, namely:
- On Windows, it is the C{pyRdfa-cache} subdirectory of the C{%APPDATA%} environment variable
- On MacOS, it is the C{~/Library/Application Support/pyRdfa-cache}
- Otherwise, it is the C{~/.pyRdfa-cache}
-
-This automatic choice can be overridden by the C{PyRdfaCacheDir} environment variable.
-Caching can be set to be read-only, i.e., the setup might generate the cache files off-line instead of letting the tool writing its own cache when operating, e.g., as a service on the Web. This can be achieved by making the cache directory read only.
+This automatic choice can be overridden by the C{PyRdfaCacheDir} environment variable.
+
+Caching can be set to be read-only, i.e., the setup might generate the cache files off-line instead of letting the tool writing its own cache when operating, e.g., as a service on the Web. This can be achieved by making the cache directory read only.
If the directories are neither readable nor writable, the vocabulary files are retrieved via HTTP every time they are hit. This may slow down processing, it is advised to avoid such a setup for the package.
@@ -136,7 +136,7 @@ The user of the package may refer add these transformers to L{Options} instance.
from pyRdfa.transform.OpenID import OpenID_transform
options = Options(transformers=[OpenID_transform])
print pyRdfa(options=options).rdf_from_source('filename')
-
+
@summary: RDFa parser (distiller)
@requires: Python version 2.5 or up; 2.7 is preferred
@@ -150,7 +150,7 @@ U{W3C® SOFTWARE NOTICE AND LICENSE<href="http://www.w3.org/Consortium/Legal/200
@copyright: W3C
@var builtInTransformers: List of built-in transformers that are to be run regardless, because they are part of the RDFa spec
-@var CACHE_DIR_VAR: Environment variable used to define cache directories for RDFa vocabularies in case the default setting does not work or is not appropriate.
+@var CACHE_DIR_VAR: Environment variable used to define cache directories for RDFa vocabularies in case the default setting does not work or is not appropriate.
@var rdfa_current_version: Current "official" version of RDFa that this package implements by default. This can be changed at the invocation of the package
@var uri_schemes: List of registered (or widely used) URI schemes; used for warnings...
"""
@@ -233,7 +233,7 @@ class FailedSource(RDFaError) :
self.msg = msg
self.http_code = http_code
RDFaError.__init__(self, msg)
-
+
class HTTPError(RDFaError) :
"""Raised when HTTP problems are detected. It does not add any new functionality to the
Exception class."""
@@ -280,9 +280,9 @@ err_invalid_prefix = "Invalid prefix declaration '%s' (in '%s')
err_no_default_prefix = "Default prefix cannot be changed (in '%s')"
err_prefix_and_xmlns = "@prefix setting for '%s' overrides the 'xmlns:%s' setting; may be a source of problem if same file is run through RDFa 1.0"
err_non_ncname_prefix = "Non NCNAME '%s' in prefix definition (in '%s'); ignored"
-err_absolute_reference = "CURIE Reference part contains an authority part: %s (in '%s'); ignored"
-err_query_reference = "CURIE Reference query part contains an unauthorized character: %s (in '%s'); ignored"
-err_fragment_reference = "CURIE Reference fragment part contains an unauthorized character: %s (in '%s'); ignored"
+err_absolute_reference = "CURIE Reference part contains an authority part: %s (in '%s'); ignored"
+err_query_reference = "CURIE Reference query part contains an unauthorized character: %s (in '%s'); ignored"
+err_fragment_reference = "CURIE Reference fragment part contains an unauthorized character: %s (in '%s'); ignored"
err_lang = "There is a problem with language setting; either both xml:lang and lang used on an element with different values, or, for (X)HTML5, only xml:lang is used."
err_URI_scheme = "Unusual URI scheme used in <%s>; may that be a mistake, e.g., resulting from using an undefined CURIE prefix or an incorrect CURIE?"
err_illegal_safe_CURIE = "Illegal safe CURIE: %s; ignored"
@@ -303,7 +303,7 @@ from .transform import top_about, empty_safe_curie, vocab_for_role
from .utils import URIOpener
from .host import HostLanguage, MediaTypes, preferred_suffixes, content_to_host_language
-# Environment variable used to characterize cache directories for RDFa vocabulary files.
+# Environment variable used to characterize cache directories for RDFa vocabulary files.
CACHE_DIR_VAR = "PyRdfaCacheDir"
# current "official" version of RDFa that this package implements. This can be changed at the invocation of the package
@@ -341,11 +341,11 @@ historical_iana_schemes = [
]
provisional_iana_schemes = [
- "afs", "dtn", "dvb", "icon", "ipn", "jms", "oid", "rsync", "ni"
+ "afs", "dtn", "dvb", "icon", "ipn", "jms", "oid", "rsync", "ni"
]
other_used_schemes = [
- "hdl", "isbn", "issn", "mstp", "rtmp", "rtspu", "stp"
+ "hdl", "isbn", "issn", "mstp", "rtmp", "rtspu", "stp"
]
uri_schemes = registered_iana_schemes + unofficial_common + historical_iana_schemes + provisional_iana_schemes + other_used_schemes
@@ -354,11 +354,11 @@ uri_schemes = registered_iana_schemes + unofficial_common + historical_iana_sche
builtInTransformers = [
empty_safe_curie, top_about, vocab_for_role
]
-
+
#########################################################################################################
class pyRdfa :
"""Main processing class for the distiller
-
+
@ivar options: an instance of the L{Options} class
@ivar media_type: the preferred default media type, possibly set at initialization
@ivar base: the base value, possibly set at initialization
@@ -373,7 +373,7 @@ class pyRdfa :
@keyword rdfa_version: the RDFa version that should be used. If not set, the value of the global L{rdfa_current_version} variable is used
"""
self.http_status = 200
-
+
self.base = base
if base == "" :
self.required_base = None
@@ -391,22 +391,22 @@ class pyRdfa :
if media_type != "" :
self.options.set_host_language(self.media_type)
-
+
if rdfa_version is not None :
self.rdfa_version = rdfa_version
else :
self.rdfa_version = None
-
+
def _get_input(self, name) :
"""
Trying to guess whether "name" is a URI or a string (for a file); it then tries to open this source accordingly,
returning a file-like object. If name is none of these, it returns the input argument (that should
be, supposedly, a file-like object already).
-
+
If the media type has not been set explicitly at initialization of this instance,
the method also sets the media_type based on the HTTP GET response or the suffix of the file. See
- L{host.preferred_suffixes} for the suffix to media type mapping.
-
+ L{host.preferred_suffixes} for the suffix to media type mapping.
+
@param name: identifier of the input source
@type name: string or a file-like object
@return: a file like object if opening "name" is possible and successful, "name" otherwise
@@ -456,7 +456,7 @@ class pyRdfa :
except :
(type, value, traceback) = sys.exc_info()
raise FailedSource(value)
-
+
####################################################################################################################
# Externally used methods
#
@@ -481,22 +481,22 @@ class pyRdfa :
if graph == None :
# Create the RDF Graph, that will contain the return triples...
graph = Graph()
-
+
# this will collect the content, the 'default graph', as called in the RDFa spec
default_graph = Graph()
-
+
# get the DOM tree
topElement = dom.documentElement
-
+
# 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)
- # Perform the built-in and external transformations on the HTML tree.
+ # Perform the built-in and external transformations on the HTML tree.
logger.info(self.options)
for trans in self.options.transformers + builtInTransformers :
trans(topElement, self.options, state)
-
+
# This may have changed if the state setting detected an explicit version information:
self.rdfa_version = state.rdfa_version
@@ -507,7 +507,7 @@ class pyRdfa :
# Massage the output graph in term of rdfa:Pattern and rdfa:copy
handle_prototypes(default_graph)
-
+
# If the RDFS expansion has to be made, here is the place...
if self.options.vocab_expansion :
from .rdfs.process import process_rdfa_sem
@@ -516,14 +516,14 @@ class pyRdfa :
# Experimental feature: nothing for now, this is kept as a placeholder
if self.options.experimental_features :
pass
-
+
# What should be returned depends on the way the options have been set up
if self.options.output_default_graph :
copyGraph(graph, default_graph)
if self.options.output_processor_graph :
if pgraph != None :
copyGraph(pgraph, self.options.processor_graph.graph)
- else :
+ else :
copyGraph(graph, self.options.processor_graph.graph)
elif self.options.output_processor_graph :
if pgraph != None :
@@ -535,12 +535,12 @@ class pyRdfa :
self.options.reset_processor_graph()
return graph
-
+
def graph_from_source(self, name, graph = None, rdfOutput = False, pgraph = None) :
"""
Extract an RDF graph from an RDFa source. The source is parsed, the RDF extracted, and the RDFa Graph is
returned. This is a front-end to the L{pyRdfa.graph_from_DOM} method.
-
+
@param name: a URI, a file name, or a file-like object
@param graph: rdflib Graph instance. If None, a new one is created.
@param pgraph: rdflib Graph instance for the processor graph. If None, and the error/warning triples are to be generated, they will be added to the returned graph. Otherwise they are stored in this graph.
@@ -559,7 +559,7 @@ class pyRdfa :
tog.bind(k,ns)
if pgraph != None : pgraph.bind(k,ns)
options.reset_processor_graph()
- return tog
+ return tog
# Separating this for a forward Python 3 compatibility
try :
@@ -568,7 +568,7 @@ class pyRdfa :
except :
# Python 3 branch
isstring = isinstance(name, str)
-
+
try :
# First, open the source... Possible HTTP errors are returned as error triples
input = None
@@ -615,7 +615,7 @@ class pyRdfa :
# the file to find a meta header for the charset; if that
# works, fine, otherwise it falls back on window-...
dom = parser.parse(input)
-
+
try :
if isstring :
input.close()
@@ -627,7 +627,7 @@ class pyRdfa :
except :
# if anyting goes wrong, it is not really important; rdfa version stays what it was...
pass
-
+
else :
# in other cases an XML parser has to be used
from .host import adjust_xhtml_and_version
@@ -649,7 +649,7 @@ class pyRdfa :
self.options.processor_graph.add_http_context(err, 400)
return copyErrors(graph, self.options)
- # If we got here, we have a DOM tree to operate on...
+ # If we got here, we have a DOM tree to operate on...
return self.graph_from_DOM(dom, graph, pgraph)
except Exception :
# Something nasty happened during the generation of the graph...
@@ -663,7 +663,7 @@ class pyRdfa :
err = self.options.add_error(str(b), context = name)
self.options.processor_graph.add_http_context(err, 500)
return copyErrors(graph, self.options)
-
+
def rdf_from_sources(self, names, outputFormat = "turtle", rdfOutput = False) :
"""
Extract and RDF graph from a list of RDFa sources and serialize them in one graph. The sources are parsed, the RDF
@@ -709,7 +709,7 @@ def processURI(uri, outputFormat, form={}) :
"""The standard processing of an RDFa uri options in a form; used as an entry point from a CGI call.
The call accepts extra form options (i.e., HTTP GET options) as follows:
-
+
- C{graph=[output|processor|output,processor|processor,output]} specifying which graphs are returned. Default: C{output}
- C{space_preserve=[true|false]} means that plain literals are normalized in terms of white spaces. Default: C{false}
- C{rfa_version} provides the RDFa version that should be used for distilling. The string should be of the form "1.0" or "1.1". Default is the highest version the current package implements, currently "1.1"
@@ -721,7 +721,7 @@ def processURI(uri, outputFormat, form={}) :
- C{vocab_cache_bypass=[true|false]} : whether vocab caches have to be regenerated every time. Default: C{false}
- C{rdfa_lite=[true|false]} : whether warnings should be generated for non RDFa Lite attribute usage. Default: C{false}
- @param uri: URI to access. Note that the C{text:} and C{uploaded:} fake URI values are treated separately; the former is for textual intput (in which case a StringIO is used to get the data) and the latter is for uploaded file, where the form gives access to the file directly.
+ @param uri: URI to access. Note that the C{text:} and C{uploaded:} fake URI values are treated separately; the former is for textual intput (in which case a StringIO is used to get the data) and the latter is for uploaded file, where the form gives access to the file directly.
@param outputFormat: serialization format, as defined by the package. Currently "xml", "turtle", "nt", or "json". Default is "turtle", also used if any other string is given.
@param form: extra call options (from the CGI call) to set up the local options
@type form: cgi FieldStorage instance
@@ -750,12 +750,12 @@ def processURI(uri, outputFormat, form={}) :
else :
input = uri
base = uri
-
+
if "rdfa_version" in list(form.keys()) :
rdfa_version = form.getfirst("rdfa_version")
else :
rdfa_version = None
-
+
# working through the possible options
# Host language: HTML, XHTML, or XML
# Note that these options should be used for the upload and inline version only in case of a form
@@ -773,9 +773,9 @@ def processURI(uri, outputFormat, form={}) :
media_type = MediaTypes.xml
else :
media_type = ""
-
+
transformers = []
-
+
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,
@@ -815,7 +815,7 @@ def processURI(uri, outputFormat, form={}) :
output_processor_graph = True
elif a == "processor,output" or a == "output,processor" :
output_processor_graph = True
-
+
embedded_rdf = _get_option( "embedded_rdf", "true", False)
space_preserve = _get_option( "space_preserve", "true", True)
vocab_cache = _get_option( "vocab_cache", "true", True)
@@ -840,7 +840,7 @@ def processURI(uri, outputFormat, form={}) :
# Decide the output format; the issue is what should happen in case of a top level error like an inaccessibility of
# the html source: should a graph be returned or an HTML page with an error message?
- # decide whether HTML or RDF should be sent.
+ # decide whether HTML or RDF should be sent.
htmlOutput = False
#if 'HTTP_ACCEPT' in os.environ :
# acc = os.environ['HTTP_ACCEPT']
@@ -855,7 +855,7 @@ def processURI(uri, outputFormat, form={}) :
# sg = acceptable_content_type(acc, possibilities)
# htmlOutput = (sg != None and sg[0] == content_type('text/html'))
# os.environ['rdfaerror'] = 'true'
-
+
# This is really for testing purposes only, it is an unpublished flag to force RDF output no
# matter what
try :
@@ -874,9 +874,9 @@ def processURI(uri, outputFormat, form={}) :
except HTTPError :
(type,h,traceback) = sys.exc_info()
import cgi
-
+
retval = 'Content-type: text/html; charset=utf-8\nStatus: %s \n\n' % h.http_code
- retval += "<html>\n"
+ retval += "<html>\n"
retval += "<head>\n"
retval += "<title>HTTP Error in distilling RDFa content</title>\n"
retval += "</head><body>\n"
@@ -894,7 +894,7 @@ def processURI(uri, outputFormat, form={}) :
import traceback, cgi
retval = 'Content-type: text/html; charset=utf-8\nStatus: %s\n\n' % processor.http_status
- retval += "<html>\n"
+ retval += "<html>\n"
retval += "<head>\n"
retval += "<title>Exception in RDFa processing</title>\n"
retval += "</head><body>\n"
diff --git a/rdflib/plugins/parsers/pyRdfa/embeddedRDF.py b/rdflib/plugins/parsers/pyRdfa/embeddedRDF.py
index d5f3cb15..1ea644f6 100644
--- a/rdflib/plugins/parsers/pyRdfa/embeddedRDF.py
+++ b/rdflib/plugins/parsers/pyRdfa/embeddedRDF.py
@@ -23,16 +23,16 @@ import re, sys
def handle_embeddedRDF(node, graph, state) :
"""
Handles embedded RDF. There are two possibilities:
-
- - the file is one of the XML dialects that allows for an embedded RDF/XML portion. See the L{host.accept_embedded_rdf_xml} for those (a typical example is SVG).
- - the file is HTML and there is a turtle portion in the C{<script>} element with type text/turtle.
-
+
+ - the file is one of the XML dialects that allows for an embedded RDF/XML portion. See the L{host.accept_embedded_rdf_xml} for those (a typical example is SVG).
+ - the file is HTML and there is a turtle portion in the C{<script>} element with type text/turtle.
+
@param node: a DOM node for the top level element
@param graph: target rdf graph
@type graph: RDFLib's Graph object instance
@param state: the inherited state (namespaces, lang, etc)
@type state: L{state.ExecutionContext}
- @return: whether an RDF/XML or turtle content has been detected or not. If TRUE, the RDFa processing should not occur on the node and its descendents.
+ @return: whether an RDF/XML or turtle content has been detected or not. If TRUE, the RDFa processing should not occur on the node and its descendents.
@rtype: Boolean
"""
#def _get_prefixes_in_turtle() :
@@ -41,7 +41,7 @@ def handle_embeddedRDF(node, graph, state) :
# retval += "@prefix %s: <%s> .\n" % (key, state.term_or_curie.ns[key])
# retval += '\n'
# return retval
-
+
# This feature is optional!
def _get_literal(Pnode):
"""
diff --git a/rdflib/plugins/parsers/pyRdfa/extras/__init__.py b/rdflib/plugins/parsers/pyRdfa/extras/__init__.py
index 51124777..0cc1a144 100644
--- a/rdflib/plugins/parsers/pyRdfa/extras/__init__.py
+++ b/rdflib/plugins/parsers/pyRdfa/extras/__init__.py
@@ -1,4 +1,4 @@
"""
-Collection of external modules that are used by pyRdfa and are added for an easier
+Collection of external modules that are used by pyRdfa and are added for an easier
distribution
"""
diff --git a/rdflib/plugins/parsers/pyRdfa/extras/httpheader.py b/rdflib/plugins/parsers/pyRdfa/extras/httpheader.py
index b923b470..b228a682 100644
--- a/rdflib/plugins/parsers/pyRdfa/extras/httpheader.py
+++ b/rdflib/plugins/parsers/pyRdfa/extras/httpheader.py
@@ -32,7 +32,7 @@
* parse_accept_header()
* parse_accept_language_header()
* parse_range_header()
-
+
* Date and time...
* http_datetime()
* parse_http_datetime()
@@ -70,12 +70,12 @@
<http://www.ietf.org/rfc/rfc2046.txt>
* RFC 3066, "Tags for the Identification of Languages", January 2001.
<http://www.ietf.org/rfc/rfc3066.txt>
-
-
- Note: I have made a small modification on the regexp for internet date,
+
+
+ Note: I have made a small modification on the regexp for internet date,
to make it more liberal (ie, accept a time zone string of the form +0000)
Ivan Herman <http://www.ivan-herman.net>, March 2011.
-
+
Have added statements to make it (hopefully) Python 3 compatible.
Ivan Herman <http://www.ivan-herman.net>, August 2012.
"""
@@ -151,7 +151,7 @@ def http_datetime( dt=None ):
If no datetime is provided (or None) then the current
time is used.
-
+
ABOUT TIMEZONES: If the passed in datetime object is naive it is
assumed to be in UTC already. But if it has a tzinfo component,
the returned timestamp string will have been converted to UTC
@@ -186,7 +186,7 @@ def parse_http_datetime( datestring, utc_tzinfo=None, strict=False ):
If you set 'strict' to True, then only the RFC 1123 format
is recognized. Otherwise the backwards-compatible RFC 1036
and Unix asctime(3) formats are also recognized.
-
+
Please note that the day-of-the-week is not validated.
Also two-digit years, although not HTTP 1.1 compliant, are
treated according to recommended Y2K rules.
@@ -546,7 +546,7 @@ def parse_comment(s, start=0):
or Via, allow ()-style comments within the header value.
A comment is defined by RFC 2616 section 2.2 as:
-
+
comment = "(" *( ctext | quoted-pair | comment ) ")"
ctext = <any TEXT excluding "(" and ")">
"""
@@ -591,7 +591,7 @@ def parse_comment(s, start=0):
while len(s2) and s2[-1] in LWS:
s2 = s2[:-1]
return s2, (pos - start)
-
+
class range_spec(object):
"""A single contiguous (byte) range.
@@ -676,7 +676,7 @@ class range_spec(object):
def __ge__(self, other):
""">= operator is not defined"""
raise NotImplementedError('Ranges can not be relationally compared')
-
+
def copy(self):
"""Makes a copy of this range object."""
return self.__class__( self.first, self.last )
@@ -1123,7 +1123,7 @@ def parse_accept_header( header_value ):
The value of the header as a string should be passed in; without
the header name itself.
-
+
This will parse the value of any of the HTTP headers "Accept",
"Accept-Charset", "Accept-Encoding", or "Accept-Language". These
headers are similarly formatted, in that they are a list of items
@@ -1197,7 +1197,7 @@ def parse_media_type(media_type, start=0, with_parameters=True):
where parmlist is a list of tuples of (parm_name, parm_value).
Quoted-values are appropriately unquoted and unescaped.
-
+
If 'with_parameters' is False, then parsing will stop immediately
after the minor media type; and will not proceed to parse any
of the semicolon-separated paramters.
@@ -1325,7 +1325,7 @@ class content_type(object):
self._set_major( major )
self._set_minor( minor )
self.parmdict = dict(pdict)
-
+
def _get_major(self):
return self._major
def _set_major(self, s):
@@ -1408,7 +1408,7 @@ class content_type(object):
def __ne__(self, other):
"""Inequality test."""
return not self.__eq__(other)
-
+
def _get_media_type(self):
"""Returns the media 'type/subtype' string, without parameters."""
return '%s/%s' % (self.major, self.minor)
@@ -1645,7 +1645,7 @@ def canonical_charset( charset ):
altering the character_set_aliases dictionary in this module.
Charsets which are not recognized are simply converted to
upper-case (as charset names are always case-insensitive).
-
+
See <http://www.iana.org/assignments/character-sets>.
"""
@@ -1678,7 +1678,7 @@ def acceptable_charset( accept_charset_header, charsets, ignore_wildcard=True, d
This function returns the charset identifier string which is the
most prefered and is acceptable to both the user agent and the
caller. It will return the default value if no charset is negotiable.
-
+
Note that the wildcarded charset "*" will be ignored. To override
this, call with ignore_wildcard=False.
@@ -1730,7 +1730,7 @@ class language_tag(object):
Initialize objects of this class with a single string representing
the language tag, such as "en-US".
-
+
Case is insensitive. Wildcarded subtags are ignored or stripped as
they have no significance, so that "en-*" is the same as "en".
However the universal wildcard "*" language tag is kept as-is.
@@ -1813,7 +1813,7 @@ class language_tag(object):
continue
langlist.append(l)
return langlist
-
+
def is_universal_wildcard(self):
"""Returns True if this language tag represents all possible
languages, by using the reserved tag of "*".
@@ -1940,7 +1940,7 @@ def acceptable_language( accept_header, server_languages, ignore_wildcard=True,
See also: RFC 3066 <http://www.ietf.org/rfc/rfc3066.txt>, and
ISO 639, links at <http://en.wikipedia.org/wiki/ISO_639>, and
<http://www.iana.org/assignments/language-tags>.
-
+
"""
# Note special instructions from RFC 2616 sect. 14.1:
# "The language quality factor assigned to a language-tag by the
@@ -1979,7 +1979,7 @@ def acceptable_language( accept_header, server_languages, ignore_wildcard=True,
# Select the best one
best = None # tuple (langtag, qvalue, matchlen)
-
+
for langtag, qvalue, aargs in accept_list:
# aargs is ignored for Accept-Language
if qvalue <= 0:
diff --git a/rdflib/plugins/parsers/pyRdfa/host/__init__.py b/rdflib/plugins/parsers/pyRdfa/host/__init__.py
index 93d908f9..325bc4e4 100755
--- a/rdflib/plugins/parsers/pyRdfa/host/__init__.py
+++ b/rdflib/plugins/parsers/pyRdfa/host/__init__.py
@@ -46,7 +46,7 @@ class HostLanguage :
html5 = "HTML5+RDFa"
atom = "Atom+RDFa"
svg = "SVG+RDFa"
-
+
# initial contexts for host languages
initial_contexts = {
HostLanguage.xhtml : ["http://www.w3.org/2011/rdfa-context/rdfa-1.1",
@@ -64,7 +64,7 @@ beautifying_prefixes = {
},
# HostLanguage.html5 : {
# "xhv" : "http://www.w3.org/1999/xhtml/vocab#"
- # },
+ # },
# HostLanguage.xhtml5 : {
# "xhv" : "http://www.w3.org/1999/xhtml/vocab#"
# },
@@ -97,11 +97,11 @@ default_vocabulary = {
}
predefined_1_0_rel = ['alternate', 'appendix', 'cite', 'bookmark', 'chapter', 'contents',
-'copyright', 'glossary', 'help', 'icon', 'index', 'meta', 'next', 'p3pv1', 'prev', 'previous',
+'copyright', 'glossary', 'help', 'icon', 'index', 'meta', 'next', 'p3pv1', 'prev', 'previous',
'role', 'section', 'subsection', 'start', 'license', 'up', 'last', 'stylesheet', 'first', 'top']
# ----------------------------------------------------------------------------------------------------------
-
+
class MediaTypes :
"""An enumeration style class: some common media types (better have them at one place to avoid misstyping...)"""
rdfxml = 'application/rdf+xml'
@@ -115,7 +115,7 @@ class MediaTypes :
xml = 'application/xml'
xmlt = 'text/xml'
nt = 'text/plain'
-
+
# mapping from (some) content types to RDFa host languages. This may control the exact processing or at least the initial context (see below)...
content_to_host_language = {
MediaTypes.html : HostLanguage.html5,
@@ -143,7 +143,7 @@ preferred_suffixes = {
".nt" : MediaTypes.nt,
".atom" : MediaTypes.atom
}
-
+
# DTD combinations that may determine the host language and the rdfa version
_XHTML_1_0 = [
("-//W3C//DTD XHTML+RDFa 1.0//EN", "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd")
@@ -151,13 +151,13 @@ _XHTML_1_0 = [
_XHTML_1_1 = [
("-//W3C//DTD XHTML+RDFa 1.1//EN", "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd"),
- ("-//W3C//DTD HTML 4.01+RDFa 1.1//EN", "http://www.w3.org/MarkUp/DTD/html401-rdfa11-1.dtd")
+ ("-//W3C//DTD HTML 4.01+RDFa 1.1//EN", "http://www.w3.org/MarkUp/DTD/html401-rdfa11-1.dtd")
]
_XHTML = [
("-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"),
("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"),
- ("-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd")
+ ("-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd")
]
def adjust_html_version(input, rdfa_version) :
@@ -170,16 +170,16 @@ def adjust_html_version(input, rdfa_version) :
import xml.dom.minidom
parse = xml.dom.minidom.parse
dom = parse(input)
-
+
(hl,version) = adjust_xhtml_and_version(dom, HostLanguage.xhtml, rdfa_version)
return version
-
+
def adjust_xhtml_and_version(dom, incoming_language, rdfa_version) :
"""
Check if the xhtml+RDFa is really XHTML 0 or 1 or whether it should be considered as XHTML5. This is done
by looking at the DTD. Furthermore, checks whether whether the system id signals an rdfa 1.0, in which case the
version is also set.
-
+
@param dom: top level DOM node
@param incoming_language: host language to be checked; the whole check is relevant for xhtml only.
@param rdfa_version: rdfa_version as known by the caller
diff --git a/rdflib/plugins/parsers/pyRdfa/host/atom.py b/rdflib/plugins/parsers/pyRdfa/host/atom.py
index 38277cd1..52e5329e 100644
--- a/rdflib/plugins/parsers/pyRdfa/host/atom.py
+++ b/rdflib/plugins/parsers/pyRdfa/host/atom.py
@@ -22,8 +22,8 @@ def atom_add_entry_type(node, state) :
@param state: current state
@type state: L{Execution context<pyRdfa.state.ExecutionContext>}
"""
- def res_set(node) :
+ def res_set(node) :
return True in [ node.hasAttribute(a) for a in ["resource", "about", "href", "src"] ]
-
+
if node.tagName == "entry" and not res_set(node) and node.hasAttribute("typeof") == False :
node.setAttribute("typeof","")
diff --git a/rdflib/plugins/parsers/pyRdfa/host/html5.py b/rdflib/plugins/parsers/pyRdfa/host/html5.py
index 9f08d8bc..b7420aad 100644
--- a/rdflib/plugins/parsers/pyRdfa/host/html5.py
+++ b/rdflib/plugins/parsers/pyRdfa/host/html5.py
@@ -43,7 +43,7 @@ _formats = {
date_type : [ "%Y-%m-%d", "%Y-%m-%dZ" ],
time_type : [ "%H:%M",
"%H:%M:%S",
- "%H:%M:%SZ",
+ "%H:%M:%SZ",
"%H:%M:%S.%f" ],
datetime_type : [ "%Y-%m-%dT%H:%M",
"%Y-%m-%dT%H:%M:%S",
@@ -79,7 +79,7 @@ def _format_test(string) :
return key
except ValueError :
pass
-
+
# Now come the special cases:-(
# Check first for the duration stuff, that is the nastiest.
if len(string) > 2 and (string[0] == 'P' or (string[0] == '-' and string[1] == 'P')) :
@@ -122,12 +122,12 @@ def _format_test(string) :
except ValueError :
pass
# something went wrong...
- return plain
+ return plain
else :
# Well, no more tricks, this is a plain type
return plain
-
-
+
+
# If we got here, we should check the time zone
# there is a discrepancy betwen the python and the HTML5/XSD lexical string,
# which means that this has to handled separately for the date and the timezone portion
@@ -141,7 +141,7 @@ def _format_test(string) :
except ValueError :
# Bummer, this is not a correct time
return plain
- # The time-zone is fine, the datetime portion has to be checked
+ # The time-zone is fine, the datetime portion has to be checked
for format in _formats[datetime_type] :
try :
# try to check if it is fine
@@ -163,7 +163,7 @@ def html5_extra_attributes(node, state) :
def _get_literal(Pnode):
"""
Get (recursively) the full text from a DOM Node.
-
+
@param Pnode: DOM Node
@return: string
"""
@@ -181,7 +181,7 @@ def html5_extra_attributes(node, state) :
# end _getLiteral
def _set_time(value) :
- if not node.hasAttribute("datatype") :
+ if not node.hasAttribute("datatype") :
# Check the datatype:
dt = _format_test(value)
if dt != plain :
@@ -199,11 +199,11 @@ def html5_extra_attributes(node, state) :
elif node.tagName == "time" :
# Note that a possible @datetime value has already been taken care of
_set_time( _get_literal(node) )
-
+
def remove_rel(node, state):
"""
If @property and @rel/@rev are on the same element, then only CURIE and URI can appear as a rel/rev value.
-
+
@param node: the current node that could be modified
@param state: current state
@type state: L{Execution context<pyRdfa.state.ExecutionContext>}
@@ -219,19 +219,19 @@ def remove_rel(node, state):
node.removeAttribute(attr)
else :
node.setAttribute(attr, reduce(lambda x,y: x+' '+y,final_vals))
-
+
_massage_node(node, "rev")
_massage_node(node, "rel")
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rdflib/plugins/parsers/pyRdfa/initialcontext.py b/rdflib/plugins/parsers/pyRdfa/initialcontext.py
index 93e50fb6..98d1aaab 100644
--- a/rdflib/plugins/parsers/pyRdfa/initialcontext.py
+++ b/rdflib/plugins/parsers/pyRdfa/initialcontext.py
@@ -14,7 +14,7 @@ U{W3C® SOFTWARE NOTICE AND LICENSE<href="http://www.w3.org/Consortium/Legal/200
class Wrapper :
pass
-
+
initial_context = {
"http://www.w3.org/2011/rdfa-context/rdfa-1.1" : Wrapper(),
"http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1" : Wrapper(),
@@ -39,7 +39,7 @@ initial_context["http://www.w3.org/2011/rdfa-context/rdfa-1.1"].ns = {
'rdfa' : 'http://www.w3.org/ns/rdfa#',
'dc' : 'http://purl.org/dc/terms/',
'dcterms' : 'http://purl.org/dc/terms/',
- 'dc11' : 'http://purl.org/dc/elements/1.1/',
+ 'dc11' : 'http://purl.org/dc/elements/1.1/',
'foaf' : 'http://xmlns.com/foaf/0.1/',
'void' : 'http://rdfs.org/ns/void#',
'ical' : 'http://www.w3.org/2002/12/cal/icaltzd#',
diff --git a/rdflib/plugins/parsers/pyRdfa/options.py b/rdflib/plugins/parsers/pyRdfa/options.py
index da58cbb3..d11a00a0 100644
--- a/rdflib/plugins/parsers/pyRdfa/options.py
+++ b/rdflib/plugins/parsers/pyRdfa/options.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
-L{Options} class: collect the possible options that govern the parsing possibilities. The module also includes the L{ProcessorGraph} class that handles the processor graph, per RDFa 1.1 (i.e., the graph containing errors and warnings).
+L{Options} class: collect the possible options that govern the parsing possibilities. The module also includes the L{ProcessorGraph} class that handles the processor graph, per RDFa 1.1 (i.e., the graph containing errors and warnings).
@summary: RDFa parser (distiller)
@requires: U{RDFLib<http://rdflib.net>}
@@ -44,13 +44,13 @@ class ProcessorGraph :
"""
def __init__(self) :
self.graph = Graph()
-
+
def add_triples(self, msg, top_class, info_class, context, node) :
"""
Add an error structure to the processor graph: a bnode with a number of predicates. The structure
follows U{the processor graph vocabulary<http://www.w3.org/2010/02/rdfa/wiki/Processor_Graph_Vocabulary>} as described
on the RDFa WG Wiki page.
-
+
@param msg: the core error message, added as an object to a dc:description
@param top_class: Error, Warning, or Info; an explicit rdf:type added to the bnode
@type top_class: URIRef
@@ -75,9 +75,9 @@ class ProcessorGraph :
is_context_string = isinstance(context, basestring)
except :
is_context_string = isinstance(context, str)
-
+
bnode = BNode()
-
+
if node != None:
try :
full_msg = "[In element '%s'] %s" % (node.nodeName, msg)
@@ -85,7 +85,7 @@ class ProcessorGraph :
full_msg = "[In element '%s'] %s" % (node, msg)
else :
full_msg = msg
-
+
self.graph.add((bnode, ns_rdf["type"], top_class))
if info_class :
self.graph.add((bnode, ns_rdf["type"], info_class))
@@ -97,12 +97,12 @@ class ProcessorGraph :
self.graph.add( (htbnode, ns_rdf["type"], ns_ht["Request"]) )
self.graph.add( (htbnode, ns_ht["requestURI"], Literal("%s" % context)) )
return bnode
-
+
def add_http_context(self, subj, http_code) :
"""
Add an additional HTTP context to a message with subject in C{subj}, using the U{<http://www.w3.org/2006/http#>}
vocabulary. Typically used to extend an error structure, as created by L{add_triples}.
-
+
@param subj: an RDFLib resource, typically a blank node
@param http_code: HTTP status code
"""
@@ -117,40 +117,40 @@ class Options :
@ivar space_preserve: whether plain literals should preserve spaces at output or not
@type space_preserve: Boolean
-
+
@ivar output_default_graph: whether the 'default' graph should be returned to the user
@type output_default_graph: Boolean
-
+
@ivar output_processor_graph: whether the 'processor' graph should be returned to the user
@type output_processor_graph: Boolean
-
+
@ivar processor_graph: the 'processor' Graph
@type processor_graph: L{ProcessorGraph}
-
+
@ivar transformers: extra transformers
@type transformers: list
-
+
@ivar vocab_cache_report: whether the details of vocabulary file caching process should be reported as information (mainly for debug)
@type vocab_cache_report: Boolean
-
+
@ivar refresh_vocab_cache: whether the caching checks of vocabs should be by-passed, ie, if caches should be re-generated regardless of the stored date (important for vocab development)
@type refresh_vocab_cache: Boolean
-
+
@ivar embedded_rdf: whether embedded RDF (ie, turtle in an HTML script element or an RDF/XML content in SVG) should be extracted and added to the final graph. This is a non-standard option...
@type embedded_rdf: Boolean
-
+
@ivar vocab_expansion: whether the @vocab elements should be expanded and a mini-RDFS processing should be done on the merged graph
@type vocab_expansion: Boolean
-
+
@ivar vocab_cache: whether the system should use the vocabulary caching mechanism when expanding via the mini-RDFS, or should just fetch the graphs every time
@type vocab_cache: Boolean
-
+
@ivar host_language: the host language for the RDFa attributes. Default is HostLanguage.xhtml, but it can be HostLanguage.rdfa_core and HostLanguage.html5, or others...
@type host_language: integer (logically: an enumeration)
-
+
@ivar content_type: the content type of the host file. Default is None
@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...
@@ -171,7 +171,7 @@ class Options :
) :
self.space_preserve = space_preserve
self.transformers = transformers
- self.processor_graph = ProcessorGraph()
+ self.processor_graph = ProcessorGraph()
self.output_default_graph = output_default_graph
self.output_processor_graph = output_processor_graph
self.host_language = HostLanguage.rdfa_core
@@ -185,7 +185,7 @@ class Options :
if check_lite :
self.transformers.append(lite_prune)
self.experimental_features = experimental_features
-
+
def set_host_language(self, content_type) :
"""
Set the host language for processing, based on the recognized types. If this is not a recognized content type,
@@ -197,10 +197,10 @@ class Options :
self.host_language = content_to_host_language[content_type]
else :
self.host_language = HostLanguage.rdfa_core
-
+
if self.host_language in require_embedded_rdf :
self.embedded_rdf = True
-
+
def __str__(self) :
retval = """Current options:
preserve space : %s
@@ -212,7 +212,7 @@ class Options :
cache vocabulary graphs : %s
"""
return retval % (self.space_preserve, self.output_processor_graph, self.output_default_graph, self.host_language, self.embedded_rdf, self.check_lite, self.vocab_cache)
-
+
def reset_processor_graph(self):
"""Empty the processor graph. This is necessary if the same options is reused
for several RDFa sources, and new error messages should be generated.
@@ -221,7 +221,7 @@ class Options :
def add_warning(self, txt, warning_type=None, context=None, node=None, buggy_value=None) :
"""Add a warning to the processor graph.
- @param txt: the warning text.
+ @param txt: the warning text.
@keyword warning_type: Warning Class
@type warning_type: URIRef
@keyword context: possible context to be added to the processor graph
@@ -235,7 +235,7 @@ class Options :
def add_info(self, txt, info_type=None, context=None, node=None, buggy_value=None) :
"""Add an informational comment to the processor graph.
- @param txt: the information text.
+ @param txt: the information text.
@keyword info_type: Info Class
@type info_type: URIRef
@keyword context: possible context to be added to the processor graph
@@ -250,7 +250,7 @@ class Options :
def add_error(self, txt, err_type=None, context=None, node=None, buggy_value=None) :
"""Add an error to the processor graph.
- @param txt: the information text.
+ @param txt: the information text.
@keyword err_type: Error Class
@type err_type: URIRef
@keyword context: possible context to be added to the processor graph
diff --git a/rdflib/plugins/parsers/pyRdfa/parse.py b/rdflib/plugins/parsers/pyRdfa/parse.py
index 15ed344f..b2438d5e 100644
--- a/rdflib/plugins/parsers/pyRdfa/parse.py
+++ b/rdflib/plugins/parsers/pyRdfa/parse.py
@@ -45,8 +45,8 @@ from .utils import has_one_of_attributes
#######################################################################
def parse_one_node(node, graph, parent_object, incoming_state, parent_incomplete_triples) :
- """The (recursive) step of handling a single node.
-
+ """The (recursive) step of handling a single node.
+
This entry just switches between the RDFa 1.0 and RDFa 1.1 versions for parsing. This method is only invoked once,
actually, from the top level; the recursion then happens in the L{_parse_1_0} and L{_parse_1_1} methods for
RDFa 1.0 and RDFa 1.1, respectively.
@@ -72,7 +72,7 @@ def parse_one_node(node, graph, parent_object, incoming_state, parent_incomplete
def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_triples) :
"""The (recursive) step of handling a single node. See the
U{RDFa 1.1 Core document<http://www.w3.org/TR/rdfa-core/>} for further details.
-
+
This is the RDFa 1.1 version.
@param node: the DOM node to handle
@@ -108,18 +108,18 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
#---------------------------------------------------------------------------------
# Extra warning check on RDFa Lite
lite_check()
-
+
#---------------------------------------------------------------------------------
# Handling the role attribute is pretty much orthogonal to everything else...
handle_role_attribute(node, graph, state)
#---------------------------------------------------------------------------------
- # Handle the special case for embedded RDF, eg, in SVG1.2.
+ # Handle the special case for embedded RDF, eg, in SVG1.2.
# This may add some triples to the target graph that does not originate from RDFa parsing
# If the function return TRUE, that means that an rdf:RDF has been found. No
# RDFa parsing should be done on that subtree, so we simply return...
- if state.options.embedded_rdf and node.nodeType == node.ELEMENT_NODE and handle_embeddedRDF(node, graph, state) :
- return
+ if state.options.embedded_rdf and node.nodeType == node.ELEMENT_NODE and handle_embeddedRDF(node, graph, state) :
+ return
#---------------------------------------------------------------------------------
# calling the host language specific massaging of the DOM
@@ -143,7 +143,7 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
current_subject = None
current_object = None
typed_resource = None
-
+
if has_one_of_attributes(node, "rel", "rev") :
# in this case there is the notion of 'left' and 'right' of @rel/@rev
# in establishing the new Subject and the objectResource
@@ -153,22 +153,22 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
if node.hasAttribute("about") :
current_subject = state.getURI("about")
if node.hasAttribute("typeof") : typed_resource = current_subject
-
+
# get_URI may return None in case of an illegal CURIE, so
# we have to be careful here, not use only an 'else'
if current_subject == None :
current_subject = parent_object
else :
state.reset_list_mapping(origin = current_subject)
-
+
# set the object resource
current_object = state.getResource("resource", "href", "src")
-
+
if node.hasAttribute("typeof") and not node.hasAttribute("about") :
if current_object == None :
current_object = BNode()
typed_resource = current_object
-
+
if not node.hasAttribute("inlist") and current_object != None :
# In this case the newly defined object is, in fact, the head of the list
# just reset the whole thing.
@@ -196,7 +196,7 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
current_object = typed_resource
else :
current_object = current_subject
-
+
else :
current_subject = header_check(parent_object)
@@ -204,7 +204,7 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
# behave identically, though they also have their own priority
if current_subject == None :
current_subject = state.getResource("about", "resource", "href", "src")
-
+
# get_URI_ref may return None in case of an illegal CURIE, so
# we have to be careful here, not use only an 'else'
if current_subject == None :
@@ -221,7 +221,7 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
# the children node
current_object = current_subject
if node.hasAttribute("typeof") : typed_resource = current_subject
-
+
# ---------------------------------------------------------------------
## The possible typeof indicates a number of type statements on the typed resource
for defined_type in state.getURI("typeof") :
@@ -245,7 +245,7 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
# if that list was initialized already with a real content
# this call will have no effect
state.add_to_list_mapping(prop, None)
-
+
# Add a placeholder into the hanging rels
incomplete_triples.append( (None, prop, None) )
else :
@@ -270,7 +270,7 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
# ----------------------------------------------------------------------
# Generation of the @property values, including literals. The newSubject is the subject
# A particularity of property is that it stops the parsing down the DOM tree if an XML Literal is generated,
- # because everything down there is part of the generated literal.
+ # because everything down there is part of the generated literal.
if node.hasAttribute("property") :
ProcessProperty(node, graph, current_subject, state, typed_resource).generate_1_1()
@@ -285,7 +285,7 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
#-----------------------------------------------------------------------
# Here is the recursion step for all the children
for n in node.childNodes :
- if n.nodeType == node.ELEMENT_NODE :
+ if n.nodeType == node.ELEMENT_NODE :
_parse_1_1(n, graph, object_to_children, state, incomplete_triples)
# ---------------------------------------------------------------------
@@ -299,7 +299,7 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
if o == None : o = current_subject
graph.add((s,p,o))
- # Generate the lists, if any and if this is the level where a new list was originally created
+ # Generate the lists, if any and if this is the level where a new list was originally created
if state.new_list and not state.list_empty() :
for prop in state.get_list_props() :
vals = state.get_list_value(prop)
@@ -325,7 +325,7 @@ def _parse_1_1(node, graph, parent_object, incoming_state, parent_incomplete_tri
def _parse_1_0(node, graph, parent_object, incoming_state, parent_incomplete_triples) :
"""The (recursive) step of handling a single node. See the
U{RDFa 1.0 syntax document<http://www.w3.org/TR/rdfa-syntax>} for further details.
-
+
This is the RDFa 1.0 version.
@param node: the DOM node to handle
@@ -350,12 +350,12 @@ def _parse_1_0(node, graph, parent_object, incoming_state, parent_incomplete_tri
handle_role_attribute(node, graph, state)
#---------------------------------------------------------------------------------
- # Handle the special case for embedded RDF, eg, in SVG1.2.
+ # Handle the special case for embedded RDF, eg, in SVG1.2.
# This may add some triples to the target graph that does not originate from RDFa parsing
# If the function return TRUE, that means that an rdf:RDF has been found. No
# RDFa parsing should be done on that subtree, so we simply return...
- if state.options.embedded_rdf and node.nodeType == node.ELEMENT_NODE and handle_embeddedRDF(node, graph, state) :
- return
+ if state.options.embedded_rdf and node.nodeType == node.ELEMENT_NODE and handle_embeddedRDF(node, graph, state) :
+ return
#---------------------------------------------------------------------------------
# calling the host language specific massaging of the DOM
@@ -384,7 +384,7 @@ def _parse_1_0(node, graph, parent_object, incoming_state, parent_incomplete_tri
# in this case there is the notion of 'left' and 'right' of @rel/@rev
# in establishing the new Subject and the objectResource
current_subject = state.getResource("about","src")
-
+
# get_URI may return None in case of an illegal CURIE, so
# we have to be careful here, not use only an 'else'
if current_subject == None :
@@ -394,15 +394,15 @@ def _parse_1_0(node, graph, parent_object, incoming_state, parent_incomplete_tri
current_subject = parent_object
else :
state.reset_list_mapping(origin = current_subject)
-
+
# set the object resource
current_object = state.getResource("resource", "href")
-
+
else :
# in this case all the various 'resource' setting attributes
# behave identically, though they also have their own priority
current_subject = state.getResource("about", "src", "resource", "href")
-
+
# get_URI_ref may return None in case of an illegal CURIE, so
# we have to be careful here, not use only an 'else'
if current_subject == None :
@@ -418,7 +418,7 @@ def _parse_1_0(node, graph, parent_object, incoming_state, parent_incomplete_tri
# only role of the current_object Resource is to be transferred to
# the children node
current_object = current_subject
-
+
# ---------------------------------------------------------------------
## The possible typeof indicates a number of type statements on the new Subject
for defined_type in state.getURI("typeof") :
@@ -451,7 +451,7 @@ def _parse_1_0(node, graph, parent_object, incoming_state, parent_incomplete_tri
# ----------------------------------------------------------------------
# Generation of the literal values. The newSubject is the subject
# A particularity of property is that it stops the parsing down the DOM tree if an XML Literal is generated,
- # because everything down there is part of the generated literal.
+ # because everything down there is part of the generated literal.
if node.hasAttribute("property") :
ProcessProperty(node, graph, current_subject, state).generate_1_0()
@@ -466,7 +466,7 @@ def _parse_1_0(node, graph, parent_object, incoming_state, parent_incomplete_tri
#-----------------------------------------------------------------------
# Here is the recursion step for all the children
for n in node.childNodes :
- if n.nodeType == node.ELEMENT_NODE :
+ if n.nodeType == node.ELEMENT_NODE :
_parse_1_0(n, graph, object_to_children, state, incomplete_triples)
# ---------------------------------------------------------------------
@@ -506,14 +506,14 @@ def handle_role_attribute(node, graph, state) :
predicate = URIRef('http://www.w3.org/1999/xhtml/vocab#role')
for object in state.getURI("role") :
graph.add((subject, predicate, object))
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/rdflib/plugins/parsers/pyRdfa/property.py b/rdflib/plugins/parsers/pyRdfa/property.py
index 48cc20a0..e965a158 100644
--- a/rdflib/plugins/parsers/pyRdfa/property.py
+++ b/rdflib/plugins/parsers/pyRdfa/property.py
@@ -31,17 +31,17 @@ else :
from rdflib.RDF import RDFNS as ns_rdf
from rdflib.Literal import XSDToPython
-from . import IncorrectBlankNodeUsage, IncorrectLiteral, err_no_blank_node, ns_xsd
+from . import IncorrectBlankNodeUsage, IncorrectLiteral, err_no_blank_node, ns_xsd
from .utils import has_one_of_attributes, return_XML
from .host.html5 import handled_time_types
XMLLiteral = ns_rdf["XMLLiteral"]
-HTMLLiteral = URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML")
+HTMLLiteral = URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML")
class ProcessProperty :
"""Generate the value for C{@property} taking into account datatype, etc.
- Note: this class is created only if the C{@property} is indeed present, no need to check.
-
+ Note: this class is created only if the C{@property} is indeed present, no need to check.
+
@ivar node: DOM element node
@ivar graph: the (RDF) graph to add the properies to
@ivar subject: the RDFLib URIRef serving as a subject for the generated triples
@@ -63,7 +63,7 @@ class ProcessProperty :
self.subject = subject
self.state = state
self.typed_resource = typed_resource
-
+
def generate(self) :
"""
Common entry point for the RDFa 1.0 and RDFa 1.1 versions; bifurcates based on the RDFa version, as retrieved from the state object.
@@ -72,11 +72,11 @@ class ProcessProperty :
self.generate_1_1()
else :
self.generate_1_0()
-
+
def generate_1_1(self) :
"""Generate the property object, 1.1 version"""
-
- #########################################################################
+
+ #########################################################################
# See if the target is _not_ a literal
irirefs = ("resource", "href", "src")
noiri = ("content", "datatype", "rel", "rev")
@@ -89,7 +89,7 @@ class ProcessProperty :
object = self.typed_resource
else :
# We have to generate a literal
-
+
# Get, if exists, the value of @datatype
datatype = ''
dtset = False
@@ -98,7 +98,7 @@ class ProcessProperty :
dt = self.node.getAttribute("datatype")
if dt != "" :
datatype = self.state.getURI("datatype")
-
+
# Supress lange is set in case some elements explicitly want to supress the effect of language
# There were discussions, for example, that the <time> element should do so. Although,
# after all, this was reversed, the functionality is kept in the code in case another
@@ -107,7 +107,7 @@ class ProcessProperty :
lang = self.state.lang
else :
lang = ''
-
+
# The simple case: separate @content attribute
if self.node.hasAttribute("content") :
val = self.node.getAttribute("content")
@@ -130,29 +130,29 @@ class ProcessProperty :
object = Literal(self._get_HTML_literal(self.node), datatype=HTMLLiteral)
else :
litval = self._get_HTML_literal(self.node)
- o = Literal(litval, datatype=XMLLiteral)
- object = Literal(o, datatype=HTMLLiteral)
+ o = Literal(litval, datatype=XMLLiteral)
+ object = Literal(o, datatype=HTMLLiteral)
else :
object = self._create_Literal(self._get_literal(self.node), datatype=datatype, lang=lang)
else :
object = self._create_Literal(self._get_literal(self.node), lang=lang)
-
+
if object != None :
for prop in self.state.getURI("property") :
if not isinstance(prop, BNode) :
if self.node.hasAttribute("inlist") :
self.state.add_to_list_mapping(prop, object)
- else :
+ else :
self.graph.add( (self.subject, prop, object) )
else :
self.state.options.add_warning(err_no_blank_node % "property", warning_type=IncorrectBlankNodeUsage, node=self.node.nodeName)
-
+
# return
def generate_1_0(self) :
"""Generate the property object, 1.0 version"""
-
- #########################################################################
+
+ #########################################################################
# We have to generate a literal indeed.
# Get, if exists, the value of @datatype
datatype = ''
@@ -162,7 +162,7 @@ class ProcessProperty :
dt = self.node.getAttribute("datatype")
if dt != "" :
datatype = self.state.getURI("datatype")
-
+
if self.state.lang != None :
lang = self.state.lang
else :
@@ -193,8 +193,8 @@ class ProcessProperty :
object = Literal(self._get_HTML_literal(self.node), datatype=HTMLLiteral)
else :
litval = self._get_HTML_literal(self.node)
- o = Literal(litval, datatype=XMLLiteral)
- object = Literal(o, datatype=HTMLLiteral)
+ o = Literal(litval, datatype=XMLLiteral)
+ object = Literal(o, datatype=HTMLLiteral)
else :
object = self._create_Literal(self._get_literal(self.node), datatype=datatype, lang=lang)
else :
@@ -207,18 +207,18 @@ class ProcessProperty :
# At this point, there might be entities in the string that are returned as real characters by the dom
# implementation. That should be turned back
object = self._create_Literal(self._get_literal(self.node), lang=lang)
-
+
for prop in self.state.getURI("property") :
if not isinstance(prop,BNode) :
self.graph.add( (self.subject,prop,object) )
else :
self.state.options.add_warning(err_no_blank_node % "property", warning_type=IncorrectBlankNodeUsage, node=self.node.nodeName)
-
+
# return
-
+
######################################################################################################################################
-
-
+
+
def _putBackEntities(self, str) :
"""Put 'back' entities for the '&','<', and '>' characters, to produce a proper XML string.
Used by the XML Literal extraction.
@@ -227,11 +227,11 @@ class ProcessProperty :
@rtype: string
"""
return str.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
-
+
def _get_literal(self, Pnode):
"""
Get (recursively) the full text from a DOM Node.
-
+
@param Pnode: DOM Node
@return: string
"""
@@ -241,24 +241,24 @@ class ProcessProperty :
rc = rc + node.data
elif node.nodeType == node.ELEMENT_NODE :
rc = rc + self._get_literal(node)
-
+
# The decision of the group in February 2008 is not to normalize the result by default.
- # This is reflected in the default value of the option
-
+ # This is reflected in the default value of the option
+
if self.state.options.space_preserve :
return rc
else :
return re.sub(r'(\r| |\n|\t)+'," ",rc).strip()
# end getLiteral
-
+
def _get_XML_literal(self, Pnode) :
"""
- Get (recursively) the XML Literal content of a DOM Node.
-
+ Get (recursively) the XML Literal content of a DOM Node.
+
@param Pnode: DOM Node
@return: string
- """
- rc = ""
+ """
+ rc = ""
for node in Pnode.childNodes:
if node.nodeType == node.TEXT_NODE:
rc = rc + self._putBackEntities(node.data)
@@ -269,12 +269,12 @@ class ProcessProperty :
def _get_HTML_literal(self, Pnode) :
"""
- Get (recursively) the XML Literal content of a DOM Node.
-
+ Get (recursively) the XML Literal content of a DOM Node.
+
@param Pnode: DOM Node
@return: string
- """
- rc = ""
+ """
+ rc = ""
for node in Pnode.childNodes:
if node.nodeType == node.TEXT_NODE:
rc = rc + self._putBackEntities(node.data)
@@ -282,7 +282,7 @@ class ProcessProperty :
rc = rc + return_XML(self.state, node, base = False, xmlns = False )
return rc
# end getXMLLiteral
-
+
def _create_Literal(self, val, datatype = '', lang = '') :
"""
Create a literal, taking into account the datatype and language.
diff --git a/rdflib/plugins/parsers/pyRdfa/rdfs/cache.py b/rdflib/plugins/parsers/pyRdfa/rdfs/cache.py
index 6614002c..db1fd2cb 100644
--- a/rdflib/plugins/parsers/pyRdfa/rdfs/cache.py
+++ b/rdflib/plugins/parsers/pyRdfa/rdfs/cache.py
@@ -71,7 +71,7 @@ def _load(fname) :
return pickle.load(f)
finally :
f.close()
-
+
def _dump(obj, fname) :
"""
Dump an object into cached file
@@ -90,12 +90,12 @@ class CachedVocabIndex :
"""
Class to manage the cache index. Takes care of finding the vocab directory, and manages the index
to the individual vocab data.
-
+
The vocab directory is set to a platform specific area, unless an environment variable
sets it explicitly. The environment variable is "PyRdfaCacheDir"
-
+
Every time the index is changed, the index is put back (via pickle) to the directory.
-
+
@ivar app_data_dir: directory for the vocabulary cache directory
@ivar index_fname: the full path of the index file on the disc
@ivar indeces: the in-memory version of the index (a directory mapping URI-s to tuples)
@@ -131,12 +131,12 @@ class CachedVocabIndex :
"""
self.options = options
self.report = (options != None) and options.vocab_cache_report
-
+
# This is where the cache files should be
self.app_data_dir = self._give_preference_path()
self.index_fname = os.path.join(self.app_data_dir, self.vocabs)
self.indeces = {}
-
+
# Check whether that directory exists.
if not os.path.isdir(self.app_data_dir) :
try :
@@ -158,7 +158,7 @@ class CachedVocabIndex :
if os.access(self.index_fname, os.R_OK) :
self.indeces = _load(self.index_fname)
else :
- if self.report: options.add_info("Vocab cache index not readable", VocabCachingInfo)
+ if self.report: options.add_info("Vocab cache index not readable", VocabCachingInfo)
else :
# This is the very initial phase, creation
# of a a new index
@@ -170,30 +170,30 @@ class CachedVocabIndex :
(type,value,traceback) = sys.exc_info()
if self.report: options.add_info("Could not create the vocabulary index %s" % value, VocabCachingInfo)
else :
- if self.report: options.add_info("Vocabulary cache directory is not writeable", VocabCachingInfo)
- self.cache_writeable = False
-
+ if self.report: options.add_info("Vocabulary cache directory is not writeable", VocabCachingInfo)
+ self.cache_writeable = False
+
def add_ref(self, uri, vocab_reference) :
"""
Add a new entry to the index, possibly removing the previous one.
-
+
@param uri: the URI that serves as a key in the index directory
@param vocab_reference: tuple consisting of file name, modification date, and expiration date
"""
# Store the index right away
- self.indeces[uri] = vocab_reference
+ self.indeces[uri] = vocab_reference
try :
_dump(self.indeces, self.index_fname)
except Exception :
(type,value,traceback) = sys.exc_info()
if self.report: self.options.add_info("Could not store the cache index %s" % value, VocabCachingInfo)
-
+
def get_ref(self, uri) :
"""
Get an index entry, if available, None otherwise.
The return value is a tuple: file name, modification date, and expiration date
-
- @param uri: the URI that serves as a key in the index directory
+
+ @param uri: the URI that serves as a key in the index directory
"""
if uri in self.indeces :
return tuple(self.indeces[uri])
@@ -214,7 +214,7 @@ class CachedVocabIndex :
system = self.architectures[platform]
else :
system = "unix"
-
+
if system == "win" :
# there is a user variable set for that purpose
app_data = os.path.expandvars("%APPDATA%")
@@ -227,7 +227,7 @@ class CachedVocab(CachedVocabIndex) :
"""
Cache for a specific vocab. The content of the cache is the graph. These are also the data that are stored
on the disc (in pickled form)
-
+
@ivar graph: the RDF graph
@ivar URI: vocabulary URI
@ivar filename: file name (not the complete path) of the cached version
@@ -245,7 +245,7 @@ class CachedVocab(CachedVocabIndex) :
@type options: L{options.Options}
"""
# First see if this particular vocab has been handled before. If yes, it is extracted and everything
- # else can be forgotten.
+ # else can be forgotten.
self.uri = URI
(self.filename, self.creation_date, self.expiration_date) = ("",None,None)
self.graph = Graph()
@@ -264,7 +264,7 @@ class CachedVocab(CachedVocabIndex) :
if vocab_reference == None :
# This has never been cached before
if self.report: options.add_info("No cache exists for %s, generating one" % URI, VocabCachingInfo)
-
+
# Store all the cache data unless caching proves to be impossible
if self._get_vocab_data(newCache = True) and self.caching :
self.filename = create_file_name(self.uri)
@@ -310,11 +310,11 @@ class CachedVocab(CachedVocabIndex) :
self.creation_date = datetime.datetime.utcnow()
if self.report:
options.add_info("Generated a new cache for %s, with an expiration date of %s" % (URI,self.expiration_date), VocabCachingInfo, URI)
-
+
self._store_caches()
def _get_vocab_data(self, newCache = True) :
- """Just a macro like function to get the data to be cached"""
+ """Just a macro like function to get the data to be cached"""
from pyRdfa.rdfs.process import return_graph
(self.graph, self.expiration_date) = return_graph(self.uri, self.options, newCache)
return self.graph != None
@@ -332,12 +332,12 @@ class CachedVocab(CachedVocabIndex) :
if self.report : self.options.add_info("Could not write cache file %s (%s)", (fname,value), VocabCachingInfo, self.uri)
# Update the index
self.add_ref(self.uri,(self.filename, self.creation_date, self.expiration_date))
-
+
#########################################################################################################################################
def offline_cache_generation(args) :
"""Generate a cache for the vocabulary in args.
-
+
@param args: array of vocabulary URIs.
"""
class LocalOption :
@@ -350,37 +350,37 @@ def offline_cache_generation(args) :
print( wae + ": " + txt )
if context != None: print( context )
print( "====" )
-
+
def add_warning(self, txt, warning_type=None, context=None) :
"""Add a warning to the processor graph.
- @param txt: the warning text.
+ @param txt: the warning text.
@keyword warning_type: Warning Class
@type warning_type: URIRef
@keyword context: possible context to be added to the processor graph
@type context: URIRef or String
"""
self.pr("Warning",txt,warning_type,context)
-
+
def add_info(self, txt, info_type=None, context=None) :
"""Add an informational comment to the processor graph.
- @param txt: the information text.
+ @param txt: the information text.
@keyword info_type: Info Class
@type info_type: URIRef
@keyword context: possible context to be added to the processor graph
@type context: URIRef or String
"""
self.pr("Info",txt,info_type,context)
-
+
def add_error(self, txt, err_type=None, context=None) :
"""Add an error to the processor graph.
- @param txt: the information text.
+ @param txt: the information text.
@keyword err_type: Error Class
@type err_type: URIRef
@keyword context: possible context to be added to the processor graph
@type context: URIRef or String
"""
self.pr("Error",txt,err_type,context)
-
+
for uri in args :
# This should write the cache
print( ">>>>> Writing Cache <<<<<" )
@@ -392,4 +392,4 @@ def offline_cache_generation(args) :
print( "default vocab: " + rd.vocabulary )
print( "terms: %s prefixes: %s" % (rd.terms,rd.ns) )
- \ No newline at end of file
+
diff --git a/rdflib/plugins/parsers/pyRdfa/rdfs/process.py b/rdflib/plugins/parsers/pyRdfa/rdfs/process.py
index d29ce510..cbe2babf 100644
--- a/rdflib/plugins/parsers/pyRdfa/rdfs/process.py
+++ b/rdflib/plugins/parsers/pyRdfa/rdfs/process.py
@@ -28,11 +28,11 @@ else :
from rdflib.RDFS import RDFSNS as ns_rdfs
from rdflib.RDF import RDFNS as ns_rdf
from rdflib.Graph import Graph
-
+
ns_owl = Namespace("http://www.w3.org/2002/07/owl#")
-
+
from ..host import MediaTypes
-
+
from ..utils import URIOpener
from . import err_outdated_cache
@@ -54,11 +54,11 @@ def return_graph(uri, options, newCache = False) :
"""Parse a file, and return an RDFLib Graph. The URI's content type is checked and either one of
RDFLib's parsers is invoked (for the Turtle, RDF/XML, and N Triple cases) or a separate RDFa processing is invoked
on the RDFa content.
-
+
The Accept header of the HTTP request gives a preference to Turtle, followed by RDF/XML and then HTML (RDFa), in case content negotiation is used.
-
+
This function is used to retreive the vocabulary file and turn it into an RDFLib graph.
-
+
@param uri: URI for the graph
@param options: used as a place where warnings can be sent
@param newCache: in case this is used with caching, whether a new cache is generated; that modifies the warning text
@@ -69,11 +69,11 @@ def return_graph(uri, options, newCache = False) :
options.add_warning(err_unreachable_vocab % uri, warning_type=VocabReferenceError)
else :
options.add_warning(err_outdated_cache % uri, warning_type=VocabReferenceError)
-
+
retval = None
expiration_date = None
content = None
-
+
try :
content = URIOpener(uri,
{'Accept' : 'text/html;q=0.8, application/xhtml+xml;q=0.8, text/turtle;q=1.0, application/rdf+xml;q=0.9'})
@@ -89,10 +89,10 @@ def return_graph(uri, options, newCache = False) :
(type,value,traceback) = sys.exc_info()
return_to_cache(value)
return (None,None)
-
+
# Store the expiration date of the newly accessed data
expiration_date = content.expiration_date
-
+
if content.content_type == MediaTypes.turtle :
try :
retval = Graph()
@@ -125,9 +125,9 @@ def return_graph(uri, options, newCache = False) :
options.add_warning(err_unparsable_rdfa_vocab % (uri,value))
else :
options.add_warning(err_unrecognised_vocab_type % (uri, content.content_type))
-
+
return (retval, expiration_date)
-
+
############################################################################################
type = ns_rdf["type"]
Property = ns_rdf["Property"]
@@ -142,7 +142,7 @@ class MiniOWL :
Class implementing the simple OWL RL Reasoning required by RDFa in managing vocabulary files. This is done via
a forward chaining process (in the L{closure} method) using a few simple rules as defined by the RDF and the OWL Semantics
specifications.
-
+
@ivar graph: the graph that has to be expanded
@ivar added_triples: each cycle collects the triples that are to be added to the graph eventually.
@type added_triples: a set, to ensure the unicity of triples being added
@@ -210,20 +210,20 @@ class MiniOWL :
# extra resonings on the vocabulary only to reduce the overall load by reducing the expected number of chaining cycles
if p == subPropertyOf :
for Z,Y,xxx in self.graph.triples((o, subPropertyOf, None)) :
- self.store_triple((s,subPropertyOf,xxx))
+ self.store_triple((s,subPropertyOf,xxx))
elif p == equivalentProperty :
for Z,Y,xxx in self.graph.triples((o, equivalentProperty, None)) :
- self.store_triple((s,equivalentProperty,xxx))
+ self.store_triple((s,equivalentProperty,xxx))
for xxx,Y,Z in self.graph.triples((None, equivalentProperty, s)) :
- self.store_triple((xxx,equivalentProperty,o))
+ self.store_triple((xxx,equivalentProperty,o))
elif p == subClassOf :
for Z,Y,xxx in self.graph.triples((o, subClassOf, None)) :
self.store_triple((s,subClassOf,xxx))
elif p == equivalentClass :
for Z,Y,xxx in self.graph.triples((o, equivalentClass, None)) :
- self.store_triple((s,equivalentClass,xxx))
+ self.store_triple((s,equivalentClass,xxx))
for xxx,Y,Z in self.graph.triples((None, equivalentClass, s)) :
- self.store_triple((xxx,equivalentClass,o))
+ self.store_triple((xxx,equivalentClass,o))
else :
if p == subPropertyOf :
# prp-spo1
@@ -235,7 +235,7 @@ class MiniOWL :
self.store_triple((zzz, o, www))
# prp-eqp2
for zzz,Z,www in self.graph.triples((None, o, None)) :
- self.store_triple((zzz, s, www))
+ self.store_triple((zzz, s, www))
elif p == subClassOf :
# cax-sco
for vvv,Y,Z in self.graph.triples((None, type, s)) :
@@ -253,7 +253,7 @@ class MiniOWL :
def process_rdfa_sem(graph, options) :
"""
Expand the graph through the minimal RDFS and OWL rules defined for RDFa.
-
+
The expansion is done in several steps:
1. the vocabularies are retrieved from the incoming graph (there are RDFa triples generated for that)
2. all vocabularies are merged into a separate vocabulary graph
@@ -261,7 +261,7 @@ def process_rdfa_sem(graph, options) :
4. the (expanded) vocabulary graph content is added to the incoming graph
5. the incoming graph is expanded
6. the triples appearing in the vocabulary graph are removed from the incoming graph, to avoid unnecessary extra triples from the data
-
+
@param graph: an RDFLib Graph instance, to be expanded
@param options: options as defined for the RDFa run; used to generate warnings
@type options: L{pyRdfa.Options}
@@ -283,22 +283,22 @@ def process_rdfa_sem(graph, options) :
if v_graph != None :
for t in v_graph :
vocab_graph.add(t)
-
+
# 3. Get the closure of the vocab graph; this will take care of local subproperty, etc, statements
# Strictly speaking this is not necessary, but will speed up processing, because it may save chaining cycles on the
# real graph
MiniOWL(vocab_graph, schema_semantics = True).closure()
-
+
# 4. Now get the vocab graph content added to the default graph
for t in vocab_graph :
graph.add(t)
-
+
# 5. get the graph expanded through RDFS
MiniOWL(graph).closure()
-
+
# 4. clean up the graph by removing the schema triples
for t in vocab_graph : graph.remove(t)
-
+
# That was it...
return graph
diff --git a/rdflib/plugins/parsers/pyRdfa/state.py b/rdflib/plugins/parsers/pyRdfa/state.py
index db043de2..d2c585c8 100644
--- a/rdflib/plugins/parsers/pyRdfa/state.py
+++ b/rdflib/plugins/parsers/pyRdfa/state.py
@@ -42,17 +42,17 @@ from .host import HostLanguage, accept_xml_base, accept_xml_lang, beautifying_
from .termorcurie import TermOrCurie
from . import UnresolvablePrefix, UnresolvableTerm
-from . import err_lang
-from . import err_URI_scheme
-from . import err_illegal_safe_CURIE
-from . import err_no_CURIE_in_safe_CURIE
-from . import err_undefined_terms
-from . import err_non_legal_CURIE_ref
-from . import err_undefined_CURIE
+from . import err_lang
+from . import err_URI_scheme
+from . import err_illegal_safe_CURIE
+from . import err_no_CURIE_in_safe_CURIE
+from . import err_undefined_terms
+from . import err_non_legal_CURIE_ref
+from . import err_undefined_CURIE
if py_v_major >= 3 :
from urllib.parse import urlparse, urlunparse, urlsplit, urljoin
-else :
+else :
from urlparse import urlparse, urlunparse, urlsplit, urljoin
class ListStructure :
@@ -68,7 +68,7 @@ class ExecutionContext :
"""State at a specific node, including the current set of namespaces in the RDFLib sense, current language,
the base, vocabularies, etc. The class is also used to interpret URI-s and CURIE-s to produce
URI references for RDFLib.
-
+
@ivar options: reference to the overall options
@type options: L{Options}
@ivar base: the 'base' URI
@@ -88,11 +88,11 @@ class ExecutionContext :
@cvar _resource_type: dictionary; mapping table from attribute name to the exact method to retrieve the URI(s). Is initialized at first instantiation.
"""
- # list of attributes that allow for lists of values and should be treated as such
+ # list of attributes that allow for lists of values and should be treated as such
_list = [ "rel", "rev", "property", "typeof", "role" ]
# mapping table from attribute name to the exact method to retrieve the URI(s).
_resource_type = {}
-
+
def __init__(self, node, graph, inherited_state=None, base="", options=None, rdfa_version = None) :
"""
@param node: the current DOM Node
@@ -102,7 +102,7 @@ class ExecutionContext :
retrieved from the current node.
@type inherited_state: L{state.ExecutionContext}
@keyword base: string denoting the base URI for the specific node. This overrides the possible
- base inherited from the upper layers. The
+ base inherited from the upper layers. The
current XHTML+RDFa syntax does not allow the usage of C{@xml:base}, but SVG1.2 does, so this is
necessary for SVG (and other possible XML dialects that accept C{@xml:base})
@keyword options: invocation options, and references to warning graphs
@@ -118,27 +118,27 @@ class ExecutionContext :
return urlunparse((t[0],t[1],t[2],t[3],t[4],""))
except :
return uri
-
+
# This is, conceptually, an additional class initialization, but it must be done run time, otherwise import errors show up
- if len( ExecutionContext._resource_type ) == 0 :
+ if len( ExecutionContext._resource_type ) == 0 :
ExecutionContext._resource_type = {
"href" : ExecutionContext._URI,
"src" : ExecutionContext._URI,
"vocab" : ExecutionContext._URI,
-
- "about" : ExecutionContext._CURIEorURI,
- "resource" : ExecutionContext._CURIEorURI,
-
+
+ "about" : ExecutionContext._CURIEorURI,
+ "resource" : ExecutionContext._CURIEorURI,
+
"rel" : ExecutionContext._TERMorCURIEorAbsURI,
"rev" : ExecutionContext._TERMorCURIEorAbsURI,
"datatype" : ExecutionContext._TERMorCURIEorAbsURI,
"typeof" : ExecutionContext._TERMorCURIEorAbsURI,
"property" : ExecutionContext._TERMorCURIEorAbsURI,
"role" : ExecutionContext._TERMorCURIEorAbsURI,
- }
+ }
#-----------------------------------------------------------------
self.node = node
-
+
#-----------------------------------------------------------------
# Settling the base. In a generic XML, xml:base should be accepted at all levels (though this is not the
# case in, say, XHTML...)
@@ -148,22 +148,22 @@ class ExecutionContext :
self.rdfa_version = inherited_state.rdfa_version
self.base = inherited_state.base
self.options = inherited_state.options
-
+
self.list_mapping = inherited_state.list_mapping
self.new_list = False
-
+
# for generic XML versions the xml:base attribute should be handled
if self.options.host_language in accept_xml_base and node.hasAttribute("xml:base") :
self.base = remove_frag_id(node.getAttribute("xml:base"))
else :
- # this is the branch called from the very top
+ # this is the branch called from the very top
self.list_mapping = ListStructure()
self.new_list = True
-
+
if rdfa_version is not None :
self.rdfa_version = rdfa_version
else :
- from . import rdfa_current_version
+ from . import rdfa_current_version
self.rdfa_version = rdfa_current_version
# This value can be overwritten by a @version attribute
@@ -172,8 +172,8 @@ class ExecutionContext :
if top_version.find("RDFa 1.0") != -1 or top_version.find("RDFa1.0") != -1 :
self.rdfa_version = "1.0"
elif top_version.find("RDFa 1.1") != -1 or top_version.find("RDFa1.1") != -1 :
- self.rdfa_version = "1.1"
-
+ self.rdfa_version = "1.1"
+
# this is just to play safe. I believe this should actually not happen...
if options == None :
from . import Options
@@ -190,23 +190,23 @@ class ExecutionContext :
continue
elif self.options.host_language in accept_xml_base and node.hasAttribute("xml:base") :
self.base = remove_frag_id(node.getAttribute("xml:base"))
-
+
# If no local setting for base occurs, the input argument has it
if self.base == "" :
self.base = base
-
+
# Perform an extra beautification in RDFLib
if self.options.host_language in beautifying_prefixes :
dict = beautifying_prefixes[self.options.host_language]
for key in dict :
graph.bind(key,dict[key])
-
+
input_info = "Input Host Language:%s, RDFa version:%s, base:%s" % (self.options.host_language, self.rdfa_version, self.base)
self.options.add_info(input_info)
-
+
#-----------------------------------------------------------------
- # this will be used repeatedly, better store it once and for all...
+ # this will be used repeatedly, better store it once and for all...
self.parsedBase = urlsplit(self.base)
#-----------------------------------------------------------------
@@ -222,10 +222,10 @@ class ExecutionContext :
self.lang = inherited_state.lang
else :
self.lang = None
-
+
self.supress_lang = False
-
-
+
+
if self.options.host_language in [ HostLanguage.xhtml, HostLanguage.xhtml5, HostLanguage.html5 ] :
# we may have lang and xml:lang
if node.hasAttribute("lang") :
@@ -247,15 +247,15 @@ class ExecutionContext :
if len(lang) != 0 :
self.lang = lang
else :
- self.lang = None
+ self.lang = None
# Ideally, a warning should be generated if lang and xmllang are both present with different values. But
# the HTML5 Parser does its magic by overriding a lang value if xmllang is present, so the potential
# error situations are simply swallowed...
-
+
elif self.options.host_language in accept_xml_lang and node.hasAttribute("xml:lang") :
self.lang = node.getAttribute("xml:lang").lower()
if len(self.lang) == 0 : self.lang = None
-
+
#-----------------------------------------------------------------
# Set the default namespace. Used when generating XML Literals
if node.hasAttribute("xmlns") :
@@ -302,7 +302,7 @@ class ExecutionContext :
if len(v) > 0 and v[0] == '?' and (py_v_major < 3 and py_v_minor <= 5) :
return create_URIRef(base+v, check)
####
-
+
joined = urljoin(base, v)
try :
if v[-1] != joined[-1] and (v[-1] == "#" or v[-1] == "?") :
@@ -315,7 +315,7 @@ class ExecutionContext :
if val == "" :
# The fragment ID must be removed...
return URIRef(self.base)
-
+
# fall back on good old traditional URI-s.
# To be on the safe side, let us use the Python libraries
if self.parsedBase[0] == "" :
@@ -323,7 +323,7 @@ class ExecutionContext :
# The following call is just to be sure that some pathological cases when
# the ':' _does_ appear in the URI but not in a scheme position is taken
# care of properly...
-
+
key = urlsplit(val)[0]
if key == "" :
# relative URI, to be combined with local file name:
@@ -334,7 +334,7 @@ class ExecutionContext :
# Trust the python library...
# Well, not quite:-) there is what is, in my view, a bug in the urljoin; in some cases it
# swallows the '#' or '?' character at the end. This is clearly a problem with
- # Semantic Web URI-s
+ # Semantic Web URI-s
return join(self.base, val)
# end _URI
@@ -397,10 +397,10 @@ class ExecutionContext :
# This case excludes the pure base, ie, the empty value
if val == "" :
return None
-
+
from .termorcurie import ncname, termname
if termname.match(val) :
- # This is a term, must be handled as such...
+ # This is a term, must be handled as such...
retval = self.term_or_curie.term_to_URI(val)
if not retval :
self.options.add_warning(err_undefined_terms % val, UnresolvableTerm, node=self.node.nodeName, buggy_value = val)
@@ -446,7 +446,7 @@ class ExecutionContext :
return []
else :
return None
-
+
# This may raise an exception if the attr has no key. This, actually,
# should not happen if the code is correct, but it does not harm having it here...
try :
@@ -454,7 +454,7 @@ class ExecutionContext :
except :
# Actually, this should not happen...
func = ExecutionContext._URI
-
+
if attr in ExecutionContext._list :
# Allows for a list
resources = [ func(self, v.strip()) for v in val.strip().split() if v != None ]
@@ -463,7 +463,7 @@ class ExecutionContext :
retval = func(self, val.strip())
return retval
# end getURI
-
+
def getResource(self, *args) :
"""Get single resources from several different attributes. The first one that returns a valid URI wins.
@param args: variable list of attribute names, or a single attribute being a list itself.
@@ -475,12 +475,12 @@ class ExecutionContext :
rargs = args[0]
else :
rargs = args
-
+
for resource in rargs :
uri = self.getURI(resource)
if uri != None : return uri
return None
-
+
# -----------------------------------------------------------------------------------------------
def reset_list_mapping(self, origin=None) :
"""
@@ -496,39 +496,39 @@ class ExecutionContext :
@return: Boolean
"""
return len(self.list_mapping.mapping) == 0
-
+
def get_list_props(self) :
"""
Return the list of property values in the list structure
@return: list of URIRef
"""
return list(self.list_mapping.mapping.keys())
-
+
def get_list_value(self,prop) :
"""
Return the list of values in the list structure for a specific property
@return: list of RDF nodes
"""
return self.list_mapping.mapping[prop]
-
+
def set_list_origin(self, origin) :
"""
Set the origin of the list, ie, the subject to attach the final list(s) to
@param origin: URIRef
- """
+ """
self.list_mapping.origin = origin
-
+
def get_list_origin(self) :
"""
Return the origin of the list, ie, the subject to attach the final list(s) to
@return: URIRef
- """
+ """
return self.list_mapping.origin
-
+
def add_to_list_mapping(self, property, resource) :
"""Add a new property-resource on the list mapping structure. The latter is a dictionary of arrays;
if the array does not exist yet, it will be created on the fly.
-
+
@param property: the property URI, used as a key in the dictionary
@param resource: the resource to be added to the relevant array in the dictionary. Can be None; this is a dummy
placeholder for C{<span rel="property" inlist>...</span>} constructions that may be filled in by children or siblings; if not
@@ -540,13 +540,13 @@ class ExecutionContext :
if self.list_mapping.mapping[property] == None :
# replacing a dummy with real content
self.list_mapping.mapping[property] = [ resource ]
- else :
+ else :
self.list_mapping.mapping[property].append(resource)
else :
if resource != None :
self.list_mapping.mapping[property] = [ resource ]
else :
self.list_mapping.mapping[property] = None
-
+
####################
diff --git a/rdflib/plugins/parsers/pyRdfa/termorcurie.py b/rdflib/plugins/parsers/pyRdfa/termorcurie.py
index 56229245..a9dc91d5 100644
--- a/rdflib/plugins/parsers/pyRdfa/termorcurie.py
+++ b/rdflib/plugins/parsers/pyRdfa/termorcurie.py
@@ -29,7 +29,7 @@ import random
if sys.version_info[0] >= 3 :
from urllib.parse import urlsplit
-else :
+else :
from urlparse import urlsplit
@@ -53,17 +53,17 @@ from .host import MediaTypes, HostLanguage, predefined_1_0_rel, warn_xmlns_us
from . import IncorrectPrefixDefinition, RDFA_VOCAB, UnresolvableReference, PrefixRedefinitionWarning
from . import ns_rdfa
-from . import err_redefining_URI_as_prefix
-from . import err_xmlns_deprecated
-from . import err_bnode_local_prefix
-from . import err_col_local_prefix
-from . import err_missing_URI_prefix
-from . import err_invalid_prefix
-from . import err_no_default_prefix
-from . import err_prefix_and_xmlns
-from . import err_non_ncname_prefix
-from . import err_absolute_reference
-from . import err_query_reference
+from . import err_redefining_URI_as_prefix
+from . import err_xmlns_deprecated
+from . import err_bnode_local_prefix
+from . import err_col_local_prefix
+from . import err_missing_URI_prefix
+from . import err_invalid_prefix
+from . import err_no_default_prefix
+from . import err_prefix_and_xmlns
+from . import err_non_ncname_prefix
+from . import err_absolute_reference
+from . import err_query_reference
from . import err_fragment_reference
from . import err_prefix_redefinition
@@ -91,22 +91,22 @@ class InitialContext :
Get the initial context values. In most cases this class has an empty content, except for the
top level (in case of RDFa 1.1). Each L{TermOrCurie} class has one instance of this class. It provides initial
mappings for terms, namespace prefixes, etc, that the top level L{TermOrCurie} instance uses for its own initialization.
-
+
@ivar terms: collection of all term mappings
@type terms: dictionary
@ivar ns: namespace mapping
@type ns: dictionary
@ivar vocabulary: default vocabulary
@type vocabulary: string
- """
-
+ """
+
def __init__(self, state, top_level) :
"""
@param state: the state behind this term mapping
@type state: L{state.ExecutionContext}
@param top_level : whether this is the top node of the DOM tree (the only place where initial contexts are handled)
@type top_level : boolean
- """
+ """
self.state = state
# This is to store the local terms
@@ -115,10 +115,10 @@ class InitialContext :
self.ns = {}
# Default vocabulary
self.vocabulary = None
-
+
if state.rdfa_version < "1.1" or top_level == False :
return
-
+
from .initialcontext import initial_context as context_data
from .host import initial_contexts as context_ids
from .host import default_vocabulary
@@ -126,7 +126,7 @@ class InitialContext :
for id in context_ids[state.options.host_language] :
# This gives the id of a initial context, valid for this media type:
data = context_data[id]
-
+
# Merge the context data with the overall definition
if state.options.host_language in default_vocabulary :
self.vocabulary = default_vocabulary[state.options.host_language]
@@ -145,14 +145,14 @@ class TermOrCurie :
"""
Wrapper around vocabulary management, ie, mapping a term to a URI, as well as a CURIE to a URI. Each instance of this class belongs to a
"state", instance of L{state.ExecutionContext}. Context definitions are managed at initialization time.
-
+
(In fact, this class is, conceptually, part of the overall state at a node, and has been separated here for an
easier maintenance.)
-
+
The class takes care of the stack-like behavior of vocabulary items, ie, inheriting everything that is possible
from the "parent". At initialization time, this works through the prefix definitions (i.e., C{@prefix} or C{@xmln:} attributes)
and/or C{@vocab} attributes.
-
+
@ivar state: State to which this instance belongs
@type state: L{state.ExecutionContext}
@ivar graph: The RDF Graph under generation
@@ -164,7 +164,7 @@ class TermOrCurie :
@ivar default_curie_uri: URI for a default CURIE
"""
def __init__(self, state, graph, inherited_state) :
- """Initialize the vocab bound to a specific state.
+ """Initialize the vocab bound to a specific state.
@param state: the state to which this vocab instance belongs to
@type state: L{state.ExecutionContext}
@param graph: the RDF graph being worked on
@@ -177,14 +177,14 @@ class TermOrCurie :
if pr in uri_schemes :
# The prefix being defined is a registered URI scheme, better avoid it...
state.options.add_warning(err_redefining_URI_as_prefix % pr, node=state.node.nodeName)
-
+
self.state = state
self.graph = graph
-
+
# --------------------------------------------------------------------------------
# This is set to non-void only on the top level and in the case of 1.1
default_vocab = InitialContext(self.state, inherited_state == None)
-
+
# Set the default CURIE URI
if inherited_state == None :
# This is the top level...
@@ -192,7 +192,7 @@ class TermOrCurie :
# self.graph.bind(XHTML_PREFIX, self.default_curie_uri)
else :
self.default_curie_uri = inherited_state.term_or_curie.default_curie_uri
-
+
# --------------------------------------------------------------------------------
# Set the default term URI
# This is a 1.1 feature, ie, should be ignored if the version is < 1.0
@@ -202,11 +202,11 @@ class TermOrCurie :
self.default_term_uri = None
else :
self.default_term_uri = inherited_state.term_or_curie.default_term_uri
-
+
# see if the initial context has defined a default vocabulary:
if default_vocab.vocabulary :
self.default_term_uri = default_vocab.vocabulary
-
+
# see if there is local vocab that would override previous settings
# However, care should be taken with the vocab="" value that should not become a URI...
# Indeed, this value is used to 'vipe out', ie, get back to the default vocabulary...
@@ -214,12 +214,12 @@ class TermOrCurie :
self.default_term_uri = default_vocab.vocabulary
else :
def_term_uri = self.state.getURI("vocab")
- if def_term_uri and def_term_uri != "" :
+ if def_term_uri and def_term_uri != "" :
self.default_term_uri = def_term_uri
self.graph.add((URIRef(self.state.base),RDFA_VOCAB,URIRef(def_term_uri)))
else :
self.default_term_uri = None
-
+
# --------------------------------------------------------------------------------
# The simpler case: terms, adding those that have been defined by a possible initial context
if inherited_state is None :
@@ -246,7 +246,7 @@ class TermOrCurie :
# Add the locally defined namespaces using the xmlns: syntax
for i in range(0, state.node.attributes.length) :
attr = state.node.attributes.item(i)
- if attr.name.find('xmlns:') == 0 :
+ if attr.name.find('xmlns:') == 0 :
# yep, there is a namespace setting
prefix = attr.localName
if prefix != "" : # exclude the top level xmlns setting...
@@ -256,7 +256,7 @@ class TermOrCurie :
state.options.add_warning(err_bnode_local_prefix, IncorrectPrefixDefinition, node=state.node.nodeName)
elif prefix.find(':') != -1 :
state.options.add_warning(err_col_local_prefix % prefix, IncorrectPrefixDefinition, node=state.node.nodeName)
- else :
+ else :
# quote the URI, ie, convert special characters into %.. This is
# true, for example, for spaces
uri = quote_URI(attr.value, state.options)
@@ -279,7 +279,7 @@ class TermOrCurie :
if pr != None :
# separator character is whitespace
pr_list = pr.strip().split()
- # range(0, len(pr_list), 2)
+ # range(0, len(pr_list), 2)
for i in range(len(pr_list) - 2, -1, -2) :
prefix = pr_list[i]
# see if there is a URI at all
@@ -288,14 +288,14 @@ class TermOrCurie :
break
else :
value = pr_list[i+1]
-
+
# see if the value of prefix is o.k., ie, there is a ':' at the end
if prefix[-1] != ':' :
state.options.add_warning(err_invalid_prefix % (prefix,pr), IncorrectPrefixDefinition, node=state.node.nodeName)
continue
elif prefix == ":" :
state.options.add_warning(err_no_default_prefix % pr, IncorrectPrefixDefinition, node=state.node.nodeName)
- continue
+ continue
else :
prefix = prefix[:-1]
uri = Namespace(quote_URI(value, state.options))
@@ -335,13 +335,13 @@ class TermOrCurie :
else :
self.ns = {}
for key in inherited_prefixes : self.ns[key] = inherited_prefixes[key]
- for key in dict :
+ for key in dict :
if (key in inherited_prefixes and dict[key] != inherited_prefixes[key]) or (key in self.default_prefixes and dict[key] != self.default_prefixes[key][0]) :
state.options.add_warning(err_prefix_redefinition % key, PrefixRedefinitionWarning, node=state.node.nodeName)
self.ns[key] = dict[key]
-
- # the xmlns prefixes have to be stored separately, again for XML Literal generation
+
+ # the xmlns prefixes have to be stored separately, again for XML Literal generation
self.xmlns = {}
if len(xmlns_dict) == 0 and inherited_state :
self.xmlns = inherited_state.term_or_curie.xmlns
@@ -376,13 +376,13 @@ class TermOrCurie :
return True
def CURIE_to_URI(self, val) :
- """CURIE to URI mapping.
-
+ """CURIE to URI mapping.
+
This method does I{not} take care of the last step of CURIE processing, ie, the fact that if
it does not have a CURIE then the value is used a URI. This is done on the caller's side, because this has
to be combined with base, for example. The method I{does} take care of BNode processing, though, ie,
CURIE-s of the form "_:XXX".
-
+
@param val: the full CURIE
@type val: string
@return: URIRef of a URI or None.
@@ -395,7 +395,7 @@ class TermOrCurie :
return URIRef(self.default_curie_uri)
else :
return None
-
+
# See if this is indeed a valid CURIE, ie, it can be split by a colon
curie_split = val.split(':',1)
if len(curie_split) == 1 :
@@ -415,7 +415,7 @@ class TermOrCurie :
# return None
# if reference[0] == ":" :
# return None
-
+
# first possibility: empty prefix
if len(prefix) == 0 :
if self.default_curie_uri and self._check_reference(reference) :
@@ -439,7 +439,7 @@ class TermOrCurie :
return retval
# check if the prefix is a valid NCNAME
elif ncname.match(prefix) :
- # see if there is a binding for this:
+ # see if there is a binding for this:
if prefix in self.ns and self._check_reference(reference) :
# yep, a binding has been defined!
if len(reference) == 0 :
@@ -474,20 +474,20 @@ class TermOrCurie :
if termname.match(term) :
# It is a valid NCNAME
-
+
# First of all, a @vocab nukes everything. That has to be done first...
if self.default_term_uri != None :
return URIRef(self.default_term_uri + term)
# For default terms, the algorithm is (see 7.4.3 of the document): first make a case sensitive match;
- # if that fails than make a case insensive one
+ # if that fails than make a case insensive one
# 1. simple, case sensitive test:
if term in self.terms :
# yep, term is a valid key as is
# lazy binding of the xhv prefix for terms...
self.graph.bind(XHTML_PREFIX, XHTML_URI)
return self.terms[term]
-
+
# 2. case insensitive test
for defined_term in self.terms :
if term.lower() == defined_term.lower() :
diff --git a/rdflib/plugins/parsers/pyRdfa/transform/DublinCore.py b/rdflib/plugins/parsers/pyRdfa/transform/DublinCore.py
index fff31ae8..51b196fb 100755
--- a/rdflib/plugins/parsers/pyRdfa/transform/DublinCore.py
+++ b/rdflib/plugins/parsers/pyRdfa/transform/DublinCore.py
@@ -33,7 +33,7 @@ def DC_transform(html, options, state) :
from ..host import HostLanguage
if not( options.host_language in [ HostLanguage.xhtml, HostLanguage.html5, HostLanguage.xhtml5 ] ) :
return
-
+
# the head element is necessary; to be sure, the namespaces are set
# on that level only
head = None
diff --git a/rdflib/plugins/parsers/pyRdfa/transform/__init__.py b/rdflib/plugins/parsers/pyRdfa/transform/__init__.py
index 8a210f4a..bfb88224 100755
--- a/rdflib/plugins/parsers/pyRdfa/transform/__init__.py
+++ b/rdflib/plugins/parsers/pyRdfa/transform/__init__.py
@@ -34,10 +34,10 @@ def top_about(root, options, state) :
else :
if not has_one_of_attributes(node, "href", "resource", "about", "src") :
node.setAttribute("about","")
-
+
from ..host import HostLanguage
from ..utils import has_one_of_attributes
-
+
if not has_one_of_attributes(root, "about") :
# The situation is a bit complicated: if a @resource is present without anything else, then it sets
# the subject, ie, should be accepted...
@@ -46,7 +46,7 @@ def top_about(root, options, state) :
root.setAttribute("about","")
else :
root.setAttribute("about","")
-
+
if options.host_language in [ HostLanguage.xhtml, HostLanguage.html5, HostLanguage.xhtml5 ] :
if state.rdfa_version >= "1.1" :
pass
@@ -64,7 +64,7 @@ def empty_safe_curie(node, options, state) :
Remove the attributes whose value is an empty safe curie. It also adds an 'artificial' flag, ie, an
attribute (called 'emptysc') into the node to signal that there _is_ an attribute with an ignored
safe curie value. The name of the attribute is 'about_pruned' or 'resource_pruned'.
-
+
@param node: a DOM node for the top level element
@param options: invocation options
@type options: L{Options<pyRdfa.options>}
@@ -79,19 +79,19 @@ def empty_safe_curie(node, options, state) :
node.setAttribute(name+'_pruned','')
msg = "Attribute @%s uses an empty safe CURIE; the attribute is ignored" % name
options.add_warning(msg, node=node)
-
+
prune_safe_curie(node, "about")
prune_safe_curie(node, "resource")
for n in node.childNodes :
if n.nodeType == node.ELEMENT_NODE :
empty_safe_curie(n, options, state)
-
+
def vocab_for_role(node, options, state) :
"""
The value of the @role attribute (defined separately in the U{Role Attribute Specification Lite<http://www.w3.org/TR/role-attribute/#using-role-in-conjunction-with-rdfa>}) should be as if a @vocab value to the
XHTML vocabulary was defined for it. This method turns all terms in role attributes into full URI-s, so that
this would not be an issue for the run-time.
-
+
@param node: a DOM node for the top level element
@param options: invocation options
@type options: L{Options<pyRdfa.options>}
@@ -99,7 +99,7 @@ def vocab_for_role(node, options, state) :
@type state: L{State<pyRdfa.state>}
"""
from ..termorcurie import termname, XHTML_URI
-
+
def handle_role(node) :
if node.hasAttribute("role") :
old_values = node.getAttribute("role").strip().split()
@@ -115,6 +115,6 @@ def vocab_for_role(node, options, state) :
for n in node.childNodes :
if n.nodeType == node.ELEMENT_NODE :
vocab_for_role(n, options, state)
-
+
diff --git a/rdflib/plugins/parsers/pyRdfa/transform/lite.py b/rdflib/plugins/parsers/pyRdfa/transform/lite.py
index c3c958ab..64dccaf3 100755
--- a/rdflib/plugins/parsers/pyRdfa/transform/lite.py
+++ b/rdflib/plugins/parsers/pyRdfa/transform/lite.py
@@ -20,7 +20,7 @@ def lite_prune(top, options, state) :
usage of non-lite attributes. A more aggressive version would mean to remove those attributes, but that would,
in fact, define an RDFa Lite conformance level in the parser, which is against the WG decisions. So this should
not be done; the corresponding commands are commented in the code below...
-
+
@param top: a DOM node for the top level element
@param options: invocation options
@type options: L{Options<pyRdfa.options>}
@@ -70,4 +70,4 @@ def lite_prune(top, options, state) :
if n.nodeType == top.ELEMENT_NODE :
lite_prune(n, options, state)
- \ No newline at end of file
+
diff --git a/rdflib/plugins/parsers/pyRdfa/transform/prototype.py b/rdflib/plugins/parsers/pyRdfa/transform/prototype.py
index b34dc4a3..a791058f 100644
--- a/rdflib/plugins/parsers/pyRdfa/transform/prototype.py
+++ b/rdflib/plugins/parsers/pyRdfa/transform/prototype.py
@@ -34,4 +34,4 @@ def handle_prototypes(graph) :
if not ( p == ns_rdf["type"] and y == Prototype ) :
graph.add((x,p,y))
to_remove.add((PR,p,y))
- for t in to_remove : graph.remove(t) \ No newline at end of file
+ for t in to_remove : graph.remove(t)
diff --git a/rdflib/plugins/parsers/pyRdfa/utils.py b/rdflib/plugins/parsers/pyRdfa/utils.py
index 4aeb7b02..5d7862bd 100644
--- a/rdflib/plugins/parsers/pyRdfa/utils.py
+++ b/rdflib/plugins/parsers/pyRdfa/utils.py
@@ -48,13 +48,13 @@ class URIOpener :
sets a number of instance variable that might be relevant for processing.
The class also adds an accept header to the outgoing request, namely
text/html and application/xhtml+xml (unless set explicitly by the caller).
-
+
If the content type is set by the server, the relevant HTTP response field is used. Otherwise,
common suffixes are used (see L{host.preferred_suffixes}) to set the content type (this is really of importance
for C{file:///} URI-s). If none of these works, the content type is empty.
-
+
Interpretation of the content type for the return is done by Deron Meranda's U{httpheader module<http://deron.meranda.us/>}.
-
+
@ivar data: the real data, ie, a file-like object
@ivar headers: the return headers as sent back by the server
@ivar content_type: the content type of the resource or the empty string, if the content type cannot be determined
@@ -70,7 +70,7 @@ class URIOpener :
"""
@param name: URL to be opened
@keyword additional_headers: additional HTTP request headers to be added to the call
- """
+ """
try :
# Note the removal of the fragment ID. This is necessary, per the HTTP spec
req = Request(url=name.split('#')[0])
@@ -79,10 +79,10 @@ class URIOpener :
req.add_header(key, additional_headers[key])
if 'Accept' not in additional_headers :
req.add_header('Accept', 'text/html, application/xhtml+xml')
-
+
self.data = urlopen(req)
self.headers = self.data.info()
-
+
if URIOpener.CONTENT_TYPE in self.headers :
# The call below will remove the possible media type parameters, like charset settings
ct = content_type(self.headers[URIOpener.CONTENT_TYPE])
@@ -102,12 +102,12 @@ class URIOpener :
if name.endswith(suffix) :
self.content_type = preferred_suffixes[suffix]
break
-
+
if URIOpener.CONTENT_LOCATION in self.headers :
self.location = urljoin(self.data.geturl(),self.headers[URIOpener.CONTENT_LOCATION])
else :
self.location = name
-
+
self.expiration_date = datetime.datetime.utcnow() + datetime.timedelta(days=1)
if URIOpener.EXPIRES in self.headers :
try :
@@ -125,7 +125,7 @@ class URIOpener :
except :
# The last modified date format was wrong, sorry, forget it...
pass
-
+
except urllib_HTTPError :
e = sys.exc_info()[1]
from . import HTTPError
@@ -138,7 +138,7 @@ class URIOpener :
#########################################################################################################
-# 'safe' characters for the URI quoting, ie, characters that can safely stay as they are. Other
+# 'safe' characters for the URI quoting, ie, characters that can safely stay as they are. Other
# special characters are converted to their %.. equivalents for namespace prefixes
_unquotedChars = ':/\?=#~'
_warnChars = [' ','\n','\r','\t']
@@ -146,10 +146,10 @@ _warnChars = [' ','\n','\r','\t']
def quote_URI(uri, options = None) :
"""
'quote' a URI, ie, exchange special characters for their '%..' equivalents. Some of the characters
- may stay as they are (listed in L{_unquotedChars}. If one of the characters listed in L{_warnChars}
+ may stay as they are (listed in L{_unquotedChars}. If one of the characters listed in L{_warnChars}
is also in the uri, an extra warning is also generated.
@param uri: URI
- @param options:
+ @param options:
@type options: L{Options<pyRdfa.Options>}
"""
from . import err_unusual_char_in_URI
@@ -160,9 +160,9 @@ def quote_URI(uri, options = None) :
options.add_warning(err_unusual_char_in_URI % suri)
break
return quote(suri, _unquotedChars)
-
+
#########################################################################################################
-
+
def create_file_name(uri) :
"""
Create a suitable file name from an (absolute) URI. Used, eg, for the generation of a file name for a cached vocabulary file.
@@ -187,7 +187,7 @@ def has_one_of_attributes(node,*args) :
rargs = args[0]
else :
rargs = args
-
+
return True in [ node.hasAttribute(attr) for attr in rargs ]
#########################################################################################################
@@ -236,7 +236,7 @@ def return_XML(state, inode, base = True, xmlns = True) :
else :
if not node.getAttribute("xml:lang") :
node.setAttribute("xml:lang", state.lang)
-
+
if sys.version_info[0] >= 3 :
return node.toxml()
else :
@@ -252,6 +252,6 @@ def dump(node) :
@param node: DOM node
"""
print( node.toprettyxml(indent="", newl="") )
-
-
+
+
diff --git a/rdflib/plugins/parsers/structureddata.py b/rdflib/plugins/parsers/structureddata.py
index fb96efda..fbc4edd7 100644
--- a/rdflib/plugins/parsers/structureddata.py
+++ b/rdflib/plugins/parsers/structureddata.py
@@ -76,7 +76,7 @@ class RDFaParser(Parser):
rdfa_version=None,
embedded_rdf=False,
space_preserve=True,
- vocab_expansion=False,
+ vocab_expansion=False,
vocab_cache=False,
refresh_vocab_cache=False,
vocab_cache_report=False,
@@ -118,7 +118,7 @@ class RDFaParser(Parser):
requires the ability for the local application to write on the
local file system
@type vocab_chache: Boolean
- @keyword vocab_cache_report: whether the details of vocabulary file caching process should be reported
+ @keyword vocab_cache_report: whether the details of vocabulary file caching process should be reported
in the processor graph as information (mainly useful for debug)
@type vocab_cache_report: Boolean
@keyword refresh_vocab_cache: whether the caching checks of vocabs should be by-passed, ie, if caches should be re-generated regardless of the stored date (important for vocab development)
@@ -138,7 +138,7 @@ class RDFaParser(Parser):
rdfa_version=rdfa_version,
embedded_rdf=embedded_rdf,
space_preserve=space_preserve,
- vocab_expansion=vocab_expansion,
+ vocab_expansion=vocab_expansion,
vocab_cache=vocab_cache,
vocab_cache_report=vocab_cache_report,
refresh_vocab_cache=refresh_vocab_cache,
@@ -150,7 +150,7 @@ class RDFaParser(Parser):
rdfa_version=None,
embedded_rdf=False,
space_preserve=True,
- vocab_expansion=False,
+ vocab_expansion=False,
vocab_cache=False,
vocab_cache_report=False,
refresh_vocab_cache=False,
@@ -292,7 +292,7 @@ class StructuredDataParser(Parser):
as triples, to the processor graph, or whether they should be raised.
@type rdfOutput: Boolean
"""
- # Note that the media_type argument is ignored, and is here only to avoid an 'unexpected argument' error.
+ # Note that the media_type argument is ignored, and is here only to avoid an 'unexpected argument' error.
# This parser works for text/html only anyway...
(baseURI, orig_source) = _get_orig_source(source)
if rdfa_version == "" : rdfa_version = "1.1"
diff --git a/rdflib/plugins/sleepycat.py b/rdflib/plugins/sleepycat.py
index 2d71ff15..64096234 100644
--- a/rdflib/plugins/sleepycat.py
+++ b/rdflib/plugins/sleepycat.py
@@ -496,10 +496,10 @@ class Sleepycat(Store):
current = None
cursor.close()
- def add_graph(self, graph):
+ def add_graph(self, graph):
self.__contexts.put(bb(self._to_string(graph)), "")
- def remove_graph(self, graph):
+ def remove_graph(self, graph):
self.remove((None, None, None), graph)
def _from_string(self, i):
diff --git a/rdflib/plugins/sparql/__init__.py b/rdflib/plugins/sparql/__init__.py
index a295c994..250fb501 100644
--- a/rdflib/plugins/sparql/__init__.py
+++ b/rdflib/plugins/sparql/__init__.py
@@ -8,7 +8,7 @@ SPARQL implementation for RDFLib
SPARQL_LOAD_GRAPHS = True
"""
If True, using FROM <uri> and FROM NAMED <uri>
-will load/parse more data
+will load/parse more data
"""
diff --git a/rdflib/plugins/sparql/algebra.py b/rdflib/plugins/sparql/algebra.py
index 0402cfd4..fcaac02d 100644
--- a/rdflib/plugins/sparql/algebra.py
+++ b/rdflib/plugins/sparql/algebra.py
@@ -420,7 +420,7 @@ def _findVars(x, res):
res.add(x.var)
return x # stop recursion and finding vars in the expr
elif x.name == 'SubSelect':
- if x.projection:
+ if x.projection:
res.update(v.var or v.evar for v in x.projection)
return x
@@ -436,7 +436,7 @@ def _addVars(x, children):
elif x.name == 'SubSelect':
if x.projection:
s = set(v.var or v.evar for v in x.projection)
- else:
+ else:
s = set()
return s
@@ -467,7 +467,7 @@ def translateAggregates(q, M):
# select expr as ?var
if q.projection:
for v in q.projection:
- if v.evar:
+ if v.evar:
v.expr = traverse(v.expr, functools.partial(_sample, v=v.evar))
v.expr = traverse(v.expr, functools.partial(_aggs, A=A))
@@ -484,13 +484,13 @@ def translateAggregates(q, M):
# sample all other select vars
# TODO: only allowed for vars in group-by?
- if q.projection:
- for v in q.projection:
+ if q.projection:
+ for v in q.projection:
if v.var:
rv = Variable('__agg_%d__' % (len(A) + 1))
A.append(CompValue('Aggregate_Sample', vars=v.var, res=rv))
E.append((rv, v.var))
-
+
return CompValue('AggregateJoin', A=A, p=M), E
@@ -564,7 +564,7 @@ def translate(q):
if q.valuesClause:
M = Join(p1=M, p2=ToMultiSet(translateValues(q.valuesClause)))
- if not q.projection:
+ if not q.projection:
# select *
PV = list(VS)
else:
@@ -578,7 +578,7 @@ def translate(q):
PV.append(v.evar)
E.append((v.expr, v.evar))
- else:
+ else:
raise Exception("I expected a var or evar here!")
for e, v in E:
diff --git a/rdflib/plugins/sparql/evaluate.py b/rdflib/plugins/sparql/evaluate.py
index dbe615e6..692fd976 100644
--- a/rdflib/plugins/sparql/evaluate.py
+++ b/rdflib/plugins/sparql/evaluate.py
@@ -164,7 +164,7 @@ def evalGraph(ctx, part):
ctx = ctx.clone()
graph = ctx[part.term]
if graph is None:
-
+
for graph in ctx.dataset.contexts():
# in SPARQL the default graph is NOT a named graph
@@ -174,12 +174,12 @@ def evalGraph(ctx, part):
c = ctx.pushGraph(graph)
c = c.push()
graphSolution = [{part.term: graph.identifier}]
- for x in _join(evalPart(c, part.p), graphSolution):
+ for x in _join(evalPart(c, part.p), graphSolution):
yield x
else:
c = ctx.pushGraph(ctx.dataset.get_context(graph))
- for x in evalPart(c, part.p):
+ for x in evalPart(c, part.p):
yield x
diff --git a/rdflib/plugins/sparql/processor.py b/rdflib/plugins/sparql/processor.py
index 9513e4e3..a415859c 100644
--- a/rdflib/plugins/sparql/processor.py
+++ b/rdflib/plugins/sparql/processor.py
@@ -48,7 +48,7 @@ class SPARQLUpdateProcessor(UpdateProcessor):
self.graph = graph
def update(self, strOrQuery, initBindings={}, initNs={}):
- if isinstance(strOrQuery, basestring):
+ if isinstance(strOrQuery, basestring):
strOrQuery=translateUpdate(parseUpdate(strOrQuery), initNs=initNs)
return evalUpdate(self.graph, strOrQuery, initBindings)
diff --git a/rdflib/plugins/sparql/results/txtresults.py b/rdflib/plugins/sparql/results/txtresults.py
index fd86a784..7e91bc9e 100644
--- a/rdflib/plugins/sparql/results/txtresults.py
+++ b/rdflib/plugins/sparql/results/txtresults.py
@@ -6,22 +6,22 @@ def _termString(t, namespace_manager):
if t == None:
return "-"
if namespace_manager:
- if isinstance(t, URIRef):
+ if isinstance(t, URIRef):
return namespace_manager.normalizeUri(t)
- elif isinstance(t, BNode):
+ elif isinstance(t, BNode):
return t.n3()
- elif isinstance(t, Literal):
+ elif isinstance(t, Literal):
return t._literal_n3(qname_callback=namespace_manager.normalizeUri)
- else:
+ else:
return t.n3()
-class TXTResultSerializer(ResultSerializer):
+class TXTResultSerializer(ResultSerializer):
"""
A write only QueryResult serializer for text/ascii tables
"""
- def serialize(self, stream, encoding, namespace_manager = None):
+ def serialize(self, stream, encoding, namespace_manager = None):
"""
return a text table of query results
@@ -37,7 +37,7 @@ class TXTResultSerializer(ResultSerializer):
if w % 2: h2 += 1
return " " * h1 + s + " " * h2
- if self.result.type!='SELECT':
+ if self.result.type!='SELECT':
raise Exception("Can only pretty print SELECT results!")
if not self.result:
diff --git a/rdflib/plugins/stores/regexmatching.py b/rdflib/plugins/stores/regexmatching.py
index b0880b6c..c2dcfd0d 100644
--- a/rdflib/plugins/stores/regexmatching.py
+++ b/rdflib/plugins/stores/regexmatching.py
@@ -14,7 +14,7 @@ import re
# Store is capable of doing its own REGEX matching
NATIVE_REGEX = 0
-# Store uses Python's re module internally for REGEX matching
+# Store uses Python's re module internally for REGEX matching
PYTHON_REGEX = 1