def qname()

in assets/lambda_helper_neptune/python/rdflib/plugins/parsers/notation3.py [0:0]


    def qname(self, argstr, i, res):
        """
        xyz:def -> ('xyz', 'def')
        If not in keywords and keywordsSet: def -> ('', 'def')
        :def -> ('', 'def')
        """

        i = self.skipSpace(argstr, i)
        if i < 0:
            return -1

        c = argstr[i]
        if c in "0123456789-+.":
            return -1
        if c not in _notNameChars:
            ln = c
            i = i + 1
            while i < len(argstr):
                c = argstr[i]
                if c not in _notNameChars:
                    ln = ln + c
                    i = i + 1
                else:
                    break

            if argstr[i - 1] == ".":  # qname cannot end with "."
                ln = ln[:-1]
                if not ln: return -1
                i -= 1

        else:  # First character is non-alpha
            ln = ''    # Was:  None - TBL (why? useful?)

        if i < len(argstr) and argstr[i] == ':':
            pfx = ln
            # bnodes names have different rules
            if pfx == '_':
                allowedChars = _notNameChars
            else:
                allowedChars = _notQNameChars

            i = i + 1
            lastslash = False
            # start = i # TODO first char .
            ln = ''
            while i < len(argstr):
                c = argstr[i]
                if not lastslash and c == '\\':
                    lastslash = True
                    i += 1

                elif lastslash or c not in allowedChars:

                    if lastslash:
                        if c not in escapeChars:
                            raise BadSyntax(self._thisDoc, self.line, argstr, i,
                                            "illegal escape "+c)
                    elif c=='%':
                        if argstr[i+1] not in hexChars or argstr[i+2] not in hexChars:
                            raise BadSyntax(self._thisDoc, self.line, argstr, i,
                                            "illegal hex escape "+c)

                    ln = ln + c
                    i = i + 1
                    lastslash = False
                else:
                    break

            if lastslash:
                raise BadSyntax(
                    self._thisDoc, self.line, argstr, i,
                    "qname cannot end with \\")


            if argstr[i-1]=='.':
                # localname cannot end in .
                ln = ln[:-1]
                if not ln: return -1
                i -= 1

            res.append((pfx, ln))
            return i

        else:   # delimiter was not ":"
            if ln and self.keywordsSet and ln not in self.keywords:
                res.append(('', ln))
                return i
            return -1