def _make_uriref(string): """ internal function which returns rdflib.term.URIRef if successful; returns False otherwise """ uri_pattern = _rfc.format_patterns()["URI"] match = _re.compile(uri_pattern).match(string) if not match: return False return _rb.term.URIRef(string.decode("unicode-escape"))
def _make_literal(string): """ internal function which returns rdflib.term.Literal if successful; returns False otherwise """ # for literal string without other info lit_pattern = ur'([^"\\]+(?:\\.[^"\\]*)*)' # for literal string with other info litinfo_name_pattern = ur'"([^"\\]*(?:\\.[^"\\]*)*)"' # has double quote litinfo_info_pattern = ur'(?:@([a-z]+(?:-[a-z0-9]+)*)|\^\^(' + \ _rfc.format_patterns()["URI"] + ur'))?' litinfo_pattern = litinfo_name_pattern + litinfo_info_pattern # try matching both patterns match_lit = _re.compile(lit_pattern).match(string) match_litinfo = _re.compile(litinfo_pattern).match(string) if match_lit: lit = match_lit.groups()[0] lit = lit.decode("unicode-escape") # encoding is unicode lang = None dtype = None elif match_litinfo: lit, lang, dtype = match_litinfo.groups() lit = lit.decode("unicode-escape") # encoding is unicode if lang: lang = lang.decode("unicode-escape") else: lang = None if dtype: dtype = dtype.decode("unicode-escape") else: dtype = None else: # if no match return False return _rb.term.Literal(lit, lang, dtype)