Mercurial > libervia-backend
comparison sat/memory/persistent.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | c652d079a9a1 |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SAT: a jabber client | 4 # SAT: a jabber client |
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
6 | 6 |
61 d.addCallback(self._setCache) | 61 d.addCallback(self._setCache) |
62 d.addCallback(lambda __: self) | 62 d.addCallback(lambda __: self) |
63 return d | 63 return d |
64 | 64 |
65 def iteritems(self): | 65 def iteritems(self): |
66 return self._cache.iteritems() | 66 return iter(self._cache.items()) |
67 | 67 |
68 def items(self): | 68 def items(self): |
69 return self._cache.items() | 69 return list(self._cache.items()) |
70 | 70 |
71 def __repr__(self): | 71 def __repr__(self): |
72 return self._cache.__repr__() | 72 return self._cache.__repr__() |
73 | 73 |
74 def __str__(self): | 74 def __str__(self): |
96 return self._cache.__cmp__(other) | 96 return self._cache.__cmp__(other) |
97 | 97 |
98 def __hash__(self): | 98 def __hash__(self): |
99 return self._cache.__hash__() | 99 return self._cache.__hash__() |
100 | 100 |
101 def __nonzero__(self): | 101 def __bool__(self): |
102 return self._cache.__len__() | 102 return self._cache.__len__() != 0 |
103 | 103 |
104 def __contains__(self, key): | 104 def __contains__(self, key): |
105 return self._cache.__contains__(key) | 105 return self._cache.__contains__(key) |
106 | 106 |
107 def __iter__(self): | 107 def __iter__(self): |
147 """Persistent dict where value can be any python data (instead of string only)""" | 147 """Persistent dict where value can be any python data (instead of string only)""" |
148 binary = True | 148 binary = True |
149 | 149 |
150 | 150 |
151 class LazyPersistentBinaryDict(PersistentBinaryDict): | 151 class LazyPersistentBinaryDict(PersistentBinaryDict): |
152 ur"""PersistentBinaryDict which get key/value when needed | 152 r"""PersistentBinaryDict which get key/value when needed |
153 | 153 |
154 This Persistent need more database access, it is suitable for largest data, | 154 This Persistent need more database access, it is suitable for largest data, |
155 to save memory. | 155 to save memory. |
156 /!\ most of methods return a Deferred | 156 /!\ most of methods return a Deferred |
157 """ | 157 """ |
158 # TODO: missing methods should be implemented using database access | 158 # TODO: missing methods should be implemented using database access |
159 # TODO: a cache would be useful (which is deleted after a timeout) | 159 # TODO: a cache would be useful (which is deleted after a timeout) |
160 | 160 |
161 def load(self): | 161 def load(self): |
162 # we show a warning as calling load on LazyPersistentBinaryDict sounds like a code mistake | 162 # we show a warning as calling load on LazyPersistentBinaryDict sounds like a code mistake |
163 log.warning(_(u"Calling load on LazyPersistentBinaryDict while it's not needed")) | 163 log.warning(_("Calling load on LazyPersistentBinaryDict while it's not needed")) |
164 | 164 |
165 def iteritems(self): | 165 def iteritems(self): |
166 raise NotImplementedError | 166 raise NotImplementedError |
167 | 167 |
168 def items(self): | 168 def items(self): |
194 | 194 |
195 def __cmp__(self, other): | 195 def __cmp__(self, other): |
196 raise NotImplementedError | 196 raise NotImplementedError |
197 | 197 |
198 def __hash__(self): | 198 def __hash__(self): |
199 return hash(unicode(self.__class__) + self.namespace + (self.profile or u'')) | 199 return hash(str(self.__class__) + self.namespace + (self.profile or '')) |
200 | 200 |
201 def __nonzero__(self): | 201 def __bool__(self): |
202 raise NotImplementedError | 202 raise NotImplementedError |
203 | 203 |
204 def __contains__(self, key): | 204 def __contains__(self, key): |
205 raise NotImplementedError | 205 raise NotImplementedError |
206 | 206 |