Mercurial > genshi > mirror
diff genshi/core.py @ 279:a99666402b12 trunk
Some adjustments to make core data structures picklable (requires protocol 2).
author | cmlenz |
---|---|
date | Mon, 02 Oct 2006 19:08:36 +0000 |
parents | d6c58473a9d0 |
children | f999da894391 |
line wrap: on
line diff
--- a/genshi/core.py +++ b/genshi/core.py @@ -22,6 +22,11 @@ class StreamEventKind(str): """A kind of event on an XML stream.""" + __slots__ = [] + _instances = {} + + def __new__(cls, val): + return cls._instances.setdefault(val, str.__new__(cls, val)) class Stream(object): @@ -503,6 +508,15 @@ return uri return object.__new__(cls, uri) + def __getnewargs__(self): + return (self.uri,) + + def __getstate__(self): + return self.uri + + def __setstate__(self, uri): + self.uri = uri + def __init__(self, uri): self.uri = unicode(uri) @@ -572,3 +586,6 @@ self = unicode.__new__(cls, qname) self.namespace, self.localname = None, unicode(qname) return self + + def __getnewargs__(self): + return (self.lstrip('{'),)