Exemplo n.º 1
0
 def test_nonvalidating_unquote(self):
     safe = b(
         """<http://example.org/alice/foaf.rdf#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/alice/foaf1.rdf> ."""
     )
     ntriples.validate = False
     res = ntriples.unquote(safe)
     self.assert_(isinstance(res, unicode))
Exemplo n.º 2
0
 def test_validating_unquote(self):
     quot = """<http://example.org/alice/foaf.rdf#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/alice/foaf1.rdf> ."""
     ntriples.validate = True
     res = ntriples.unquote(quot)
     # revert to default
     ntriples.validate = False
     log.debug("restype %s" % type(res))
Exemplo n.º 3
0
 def test_validating_unquote(self):
     quot = """<http://example.org/alice/foaf.rdf#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/alice/foaf1.rdf> ."""
     ntriples.validate = True
     res = ntriples.unquote(quot)
     # revert to default
     ntriples.validate = False
     log.debug("restype %s" % type(res))
Exemplo n.º 4
0
 def test_nonvalidating_unquote(self):
     safe = b(
         """<http://example.org/alice/foaf.rdf#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://example.org/alice/foaf1.rdf> ."""
     )
     ntriples.validate = False
     res = ntriples.unquote(safe)
     self.assert_(isinstance(res, unicode))
Exemplo n.º 5
0
 def literal(self):
     if self.peek('"'):
         lit, lang, dtype = self.eat(r_literal).groups()
         if lang:
             lang = lang
         else:
             lang = None
         if dtype:
             dtype = unquote(dtype)
             dtype = uriquote(dtype)
             dtype = URI(dtype)
         else:
             dtype = None
         if lang and dtype:
             raise ParseError("Can't have both a language and a datatype")
         lit = unquote(lit)
         return Literal(lit, lang, dtype)
     return False
Exemplo n.º 6
0
def parse_literal(strng):
    m = r_literal.match(strng)
    if not m:
        m = r_literal.match(strng.replace("\\", ""))
    if not m:
        raise ParseError("Failed to eat %s at %s" % (r_literal.pattern, strng))
    lit, lang, dtype = m.groups()
    if lang:
        lang = lang
    else:
        lang = None
    if dtype:
        dtype = dtype
    else:
        dtype = None
    if lang and dtype:
        raise ParseError("Can't have both a language and a datatype")
    lit = unquote(lit)
    return Literal(lit, lang, dtype)
Exemplo n.º 7
0
 def uriref(self):
     if self.peek('<'):
         uri = self.eat(r_uriref).group(1)
         uri = rdfuri.clear_signs(unquote(uri))
         return rdfuri.Node(uri, rdfuri.NodeType.XID)
     return False