def graph(self, uri): if self.query_type not in [CLEAR]: raise ValueError('The specified <%s> query type does not support the CLEAR GRAPH clause' % (self.query_type)) if type(uri) not in (URIRef, Namespace) and not is_uri(uri): raise ValueError('The argument is not a uri') self._clear_uri = uri return self
def into(self, *uris): if self.query_type not in [INSERT_DATA, INSERT, LOAD]: raise ValueError('The specified <%s> query type does not support the INTO clause' % (self.query_type)) if self.query_type is LOAD and len(uris) != 1: raise ValueError('The LOAD query, supports only one uri for the INTO clause') self._into_uri.extend([uri for uri in uris if type(uri) is URIRef or is_uri(uri)]) return self
def into(self, *uris): if self.query_type not in [INSERT_DATA, INSERT]: raise ValueError('The specified <%s> query type does not support the INTO clause' % (self.query_type)) if self.query_type is LOAD and len(uris) != 1: raise ValueError('The LOAD query, supports only one uri for the INTO clause') self._into_uri.extend([uri for uri in uris if type(uri) is URIRef or is_uri(uri)]) return self
def load(self, remote_uri): if self.query_type not in [LOAD]: raise ValueError('The specified <%s> query type does not support the LOAD clause' % (self.query_type)) if type(remote_uri) is not URIRef and not is_uri(remote_uri): raise ValueError('The argument is not a uri') self._remote_uri = remote_uri return self
def graph(self, uri): if self.query_type not in [CLEAR]: raise ValueError('The specified <%s> query type does not support the CLEAR GRAPH clause' % (self.query_type)) if type(uri) is not URIRef and not is_uri(uri): raise ValueError('The argument is not a uri') self._clear_uri = uri return self
def from_(self, *uris): if self.query_type not in [DELETE_DATA, DELETE]: raise ValueError( 'The specified <%s> query type does not support the FROM clause' % (self.query_type)) self._from_uri.extend( [uri for uri in uris if type(uri) is URIRef or is_uri(uri)]) return self
def __uri(self, uri): """ For **internal** use only, convert the `uri` to a `URIRef`. """ if not uri: return None if type(uri) is URIRef: return uri else: if not is_uri(uri): attrname = de_camel_case(uri, '_', DE_CAMEL_CASE_DEFAULT) uri, _ = attr2rdf(attrname) return URIRef(uri)
def _term(self, term): if type(term) in [URIRef, BNode]: return '%s' % (term.n3()) elif type(term) in [str, unicode]: if term.startswith('?'): return '%s' % term elif is_uri(term): return '<%s>' % term else: return '"%s"' % term elif type(term) is Literal: return term.n3() elif type(term) in [list, tuple]: return '"%s"@%s' % (term[0], term[1]) elif type(term) is type and hasattr(term, 'uri'): return '%s' % term.uri().n3() elif hasattr(term, 'subject'): return '%s' % term.subject.n3() return term.__str__()
def string_val(term): if isinstance(term, (URIRef, BNode)): return '%s' % (term.n3()) elif isinstance(term, str): if term.startswith('?'): return '%s' % term elif is_uri(term): return '<%s>' % term else: return '"%s"' % term elif type(term) is Literal: return term.n3() elif isinstance(term, (list, tuple)): return '"%s"@%s' % (term[0], term[1]) elif type(term) is type and hasattr(term, 'uri'): return '%s' % term.uri().n3() elif hasattr(term, 'subject'): return '%s' % term.subject.n3() return term.__str__()
def _term(self, term): if isinstance(term, (URIRef, BNode)): return u'{0:s}'.format elif isinstance(term, (str, str)): if term.startswith('?'): return u'{0:s}'.format(term) elif is_uri(term): return u'<{0:s}>'.format(term) else: return u'"{0:s}"'.format(term) elif type(term) is Literal: return term.n3() elif isinstance(term, (list, tuple)): return '"{0:s}"@{1:s}'.format(term[0], term[1]) elif type(term) is type and hasattr(term, 'uri'): return u'{0:s}'.format elif hasattr(term, 'subject'): return u'{0:s}'.format return term.__str__()
def _term(self, term): if type(term) in [URIRef, BNode]: return u'{0:s}'.format elif type(term) in [str, unicode]: if term.startswith('?'): return u'{0:s}'.format(term) elif is_uri(term): return u'<{0:s}>'.format(term) else: return u'"{0:s}"'.format(term) elif type(term) is Literal: return term.n3() elif type(term) in [list, tuple]: return '"{0:s}"@{1:s}'.format(term[0], term[1]) elif type(term) is type and hasattr(term, 'uri'): return u'{0:s}'.format elif hasattr(term, 'subject'): return u'{0:s}'.format return term.__str__()
def from_(self, *uris): if self.query_type not in [DELETE_DATA, DELETE]: raise ValueError('The specified <%s> query type does not support the FROM clause' % (self.query_type)) self._from_uri.extend([uri for uri in uris if type(uri) is URIRef or is_uri(uri)]) return self