in assets/lambda_helper_neptune/python/rdflib/plugins/parsers/notation3.py [0:0]
def uri_ref2(self, argstr, i, res):
"""Generate uri from n3 representation.
Note that the RDF convention of directly concatenating
NS and local name is now used though I prefer inserting a '#'
to make the namesapces look more like what XML folks expect.
"""
qn = []
j = self.qname(argstr, i, qn)
if j >= 0:
pfx, ln = qn[0]
if pfx is None:
assert 0, "not used?"
ns = self._baseURI + ADDED_HASH
else:
try:
ns = self._bindings[pfx]
except KeyError:
if pfx == "_": # Magic prefix 2001/05/30, can be changed
res.append(self.anonymousNode(ln))
return j
if not self.turtle and pfx == "":
ns = join(self._baseURI or "", "#")
else:
self.BadSyntax(argstr, i,
"Prefix \"%s:\" not bound" % (pfx))
symb = self._store.newSymbol(ns + ln)
if symb in self._variables:
res.append(self._variables[symb])
else:
res.append(symb) # @@@ "#" CONVENTION
return j
i = self.skipSpace(argstr, i)
if i < 0:
return -1
if argstr[i] == "?":
v = []
j = self.variable(argstr, i, v)
if j > 0: # Forget varibles as a class, only in context.
res.append(v[0])
return j
return -1
elif argstr[i] == "<":
i = i + 1
st = i
while i < len(argstr):
if argstr[i] == ">":
uref = argstr[st:i] # the join should dealt with "":
# expand unicode escapes
uref = unicodeEscape8.sub(unicodeExpand, uref)
uref = unicodeEscape4.sub(unicodeExpand, uref)
if self._baseURI:
uref = join(self._baseURI, uref) # was: uripath.join
else:
assert ":" in uref, \
"With no base URI, cannot deal with relative URIs"
if argstr[i - 1:i] == "#" and not uref[-1:] == "#":
uref = uref + \
"#" # She meant it! Weirdness in urlparse?
symb = self._store.newSymbol(uref)
if symb in self._variables:
res.append(self._variables[symb])
else:
res.append(symb)
return i + 1
i = i + 1
self.BadSyntax(argstr, j,
"unterminated URI reference")
elif self.keywordsSet:
v = []
j = self.bareWord(argstr, i, v)
if j < 0:
return -1 # Forget varibles as a class, only in context.
if v[0] in self.keywords:
self.BadSyntax(argstr, i,
'Keyword "%s" not allowed here.' % v[0])
res.append(self._store.newSymbol(self._bindings[""] + v[0]))
return j
else:
return -1