diff options
author | gromgull <gromgull@gmail.com> | 2013-03-05 10:22:25 +0100 |
---|---|---|
committer | gromgull <gromgull@gmail.com> | 2013-03-05 10:22:25 +0100 |
commit | c6045ddcc72c0f2d35c17b6bf93a16a2925d4cd7 (patch) | |
tree | 3475fe5398e448ed1b7742491957a2f6a2339fda /rdflib/term.py | |
parent | 94e94114db945182e64d33bb18c3d2c21fdd737d (diff) | |
download | rdflib-c6045ddcc72c0f2d35c17b6bf93a16a2925d4cd7.tar.gz |
property function for bi-directional python object <->literal lexical form bindings. Fixes #14.
Diffstat (limited to 'rdflib/term.py')
-rw-r--r-- | rdflib/term.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/rdflib/term.py b/rdflib/term.py index 35fcf839..af096583 100644 --- a/rdflib/term.py +++ b/rdflib/term.py @@ -1287,15 +1287,25 @@ _toPythonMapping = {} _toPythonMapping.update(XSDToPython) -def bind(datatype, conversion_function): +def bind(datatype, pythontype, constructor=None, lexicalizer=None): """ - bind a datatype to a function for converting it into a Python - instance. + register a new datatype<->pythontype binding + + Args: + constructor : an optional function for converting lexical forms + into a Python instances, if not given the pythontype + is used directly + lexicalizer : an optinoal function for converting python objects to + lexical form, if not given object.__str__ is used + """ if datatype in _toPythonMapping: _LOGGER.warning("datatype '%s' was already bound. Rebinding." % datatype) - _toPythonMapping[datatype] = conversion_function + + if constructor==None: constructor=pythontype + _toPythonMapping[datatype] = constructor + _PythonToXSD.append((pythontype, (lexicalizer, datatype))) class Variable(Identifier): |