Skip to content

Commit

Permalink
Made Literal.language/datatype into readonly properties.
Browse files Browse the repository at this point in the history
fixes #226
  • Loading branch information
gromgull committed Nov 17, 2012
1 parent da696ff commit 203efc5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions rdflib/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class Literal(Identifier):
"""
__doc__ = py3compat.format_doctest_out(doc)

__slots__ = ("language", "datatype", "_cmp_value")
__slots__ = ("language", "datatype", "_language", "_datatype", "_cmp_value")

def __new__(cls, value, lang=None, datatype=None):
if lang is not None and datatype is not None:
Expand All @@ -417,11 +417,18 @@ def __new__(cls, value, lang=None, datatype=None):
inst = unicode.__new__(cls, value)
except UnicodeDecodeError:
inst = unicode.__new__(cls, value, 'utf-8')
inst.language = lang
inst.datatype = datatype
inst._language = lang
inst._datatype = datatype
inst._cmp_value = inst._toCompareValue()
return inst

@property
def language(self): return self._language

@property
def datatype(self): return self._datatype


def __reduce__(self):
return (Literal, (unicode(self), self.language, self.datatype),)

Expand All @@ -430,8 +437,8 @@ def __getstate__(self):

def __setstate__(self, arg):
_, d = arg
self.language = d["language"]
self.datatype = d["datatype"]
self._language = d["language"]
self._datatype = d["datatype"]

@py3compat.format_doctest_out
def __add__(self, val):
Expand Down

0 comments on commit 203efc5

Please sign in to comment.