Ejemplo n.º 1
0
	def handle_role(node) :
		if node.hasAttribute("role") :
			old_values = node.getAttribute("role").strip().split()
			new_values = ""
			for val in old_values :
				if termname.match(val) :
					new_values += XHTML_URI + val + ' '
				else :
					new_values += val + ' '
			node.setAttribute("role", new_values.strip())
Ejemplo n.º 2
0
	def _massage_node(node,attr) :
		"""The real work for remove_rel is done here, parametrized with @rel and @rev"""
		if node.hasAttribute("property") and node.hasAttribute(attr) :
			vals = node.getAttribute(attr).strip().split()
			if len(vals) != 0 :
				final_vals = [ v for v in vals if not termname.match(v) ]
				if len(final_vals) == 0 :
					node.removeAttribute(attr)
				else :
					node.setAttribute(attr, reduce(lambda x,y: x+' '+y,final_vals))
Ejemplo n.º 3
0
 def handle_role(node):
     if node.hasAttribute("role"):
         old_values = node.getAttribute("role").strip().split()
         new_values = ""
         for val in old_values:
             if termname.match(val):
                 new_values += XHTML_URI + val + ' '
             else:
                 new_values += val + ' '
         node.setAttribute("role", new_values.strip())
Ejemplo n.º 4
0
 def _massage_node(node, attr):
     """The real work for remove_rel is done here, parametrized with @rel and @rev"""
     if node.hasAttribute("property") and node.hasAttribute(attr):
         vals = node.getAttribute(attr).strip().split()
         if len(vals) != 0:
             final_vals = [v for v in vals if not termname.match(v)]
             if len(final_vals) == 0:
                 node.removeAttribute(attr)
             else:
                 node.setAttribute(
                     attr, reduce(lambda x, y: x + ' ' + y, final_vals))
Ejemplo n.º 5
0
    def _TERMorCURIEorAbsURI(self, val):
        """Returns a URI either for a term or for a CURIE. The value must be an NCNAME to be handled as a term; otherwise
		the method falls back on a CURIE or an absolute URI.
		@param val: attribute value to be interpreted
		@type val: string
		@return: an RDFLib URIRef instance or None
		"""
        from pyRdfa import uri_schemes
        # This case excludes the pure base, ie, the empty value
        if val == "":
            return None

        from pyRdfa.termorcurie import ncname, termname
        if termname.match(val):
            # 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)
                return None
            else:
                return retval
        else:
            # try a CURIE
            retval = self.term_or_curie.CURIE_to_URI(val)
            if retval:
                return retval
            elif self.rdfa_version >= "1.1":
                # See if it is an absolute URI
                scheme = urlsplit(val)[0]
                if scheme == "":
                    # bug; there should be no relative URIs here
                    self.options.add_warning(err_non_legal_CURIE_ref % val,
                                             UnresolvablePrefix,
                                             node=self.node.nodeName)
                    return None
                else:
                    if scheme not in uri_schemes:
                        self.options.add_warning(err_URI_scheme % val.strip(),
                                                 node=self.node.nodeName)
                    return URIRef(val)
            else:
                # rdfa 1.0 case
                self.options.add_warning(err_undefined_CURIE % val.strip(),
                                         UnresolvablePrefix,
                                         node=self.node.nodeName)
                return None
Ejemplo n.º 6
0
	def _TERMorCURIEorAbsURI(self, val) :
		"""Returns a URI either for a term or for a CURIE. The value must be an NCNAME to be handled as a term; otherwise
		the method falls back on a CURIE or an absolute URI.
		@param val: attribute value to be interpreted
		@type val: string
		@return: an RDFLib URIRef instance or None
		"""
		from pyRdfa	import uri_schemes
		# This case excludes the pure base, ie, the empty value
		if val == "" :
			return None
		
		from pyRdfa.termorcurie import ncname, termname
		if termname.match(val) :
			# 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)
				return None
			else :
				return retval
		else :
			# try a CURIE
			retval = self.term_or_curie.CURIE_to_URI(val)
			if retval :
				return retval
			elif self.rdfa_version >= "1.1" :
				# See if it is an absolute URI
				scheme = urlsplit(val)[0]
				if scheme == "" :
					# bug; there should be no relative URIs here
					self.options.add_warning(err_non_legal_CURIE_ref % val, UnresolvablePrefix, node=self.node.nodeName)
					return None
				else :
					if scheme not in uri_schemes :
						self.options.add_warning(err_URI_scheme % val.strip(), node=self.node.nodeName)
					return URIRef(val)
			else :
				# rdfa 1.0 case
				self.options.add_warning(err_undefined_CURIE % val.strip(), UnresolvablePrefix, node=self.node.nodeName)
				return None