Mercurial > code > home > repos > rdfdb
view rdfdb/rdflibpatch_literal.py @ 94:8bc63c7b619b
mv syncedgraph to subdir
author | drewp@bigasterisk.com |
---|---|
date | Sat, 21 May 2022 22:15:14 -0700 |
parents | 36f4318442f2 |
children |
line wrap: on
line source
from rdflib.term import _PLAIN_LITERAL_TYPES, Literal def _literal_n3(self, use_plain=False, qname_callback=None): if use_plain and self.datatype in _PLAIN_LITERAL_TYPES: try: self.toPython() # check validity # py3 makes %s give much nicer presentations return '%s' % self except ValueError: pass # if it's in, we let it out? encoded = self._quote_encode() datatype = self.datatype quoted_dt = None if datatype: if qname_callback: quoted_dt = qname_callback(datatype) if not quoted_dt: quoted_dt = "<%s>" % datatype language = self.language if language: if datatype: # TODO: this isn't valid RDF (it's datatype XOR language) return '%s@%s^^%s' % (encoded, language, quoted_dt) return '%s@%s' % (encoded, language) elif datatype: return '%s^^%s' % (encoded, quoted_dt) else: return '%s' % encoded def patch(): Literal._literal_n3 = _literal_n3