comparison sat_frontends/quick_frontend/quick_blog.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 0b7ce5daee9b
children 9d0df638c8b4
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
28 from sat_frontends.tools import jid 28 from sat_frontends.tools import jid
29 from sat.tools.common import data_format 29 from sat.tools.common import data_format
30 30
31 try: 31 try:
32 # FIXME: to be removed when an acceptable solution is here 32 # FIXME: to be removed when an acceptable solution is here
33 unicode("") # XXX: unicode doesn't exist in pyjamas 33 str("") # XXX: unicode doesn't exist in pyjamas
34 except ( 34 except (
35 TypeError, 35 TypeError,
36 AttributeError, 36 AttributeError,
37 ): # Error raised is not the same depending on pyjsbuild options 37 ): # Error raised is not the same depending on pyjsbuild options
38 unicode = str 38 str = str
39 39
40 ENTRY_CLS = None 40 ENTRY_CLS = None
41 COMMENTS_CLS = None 41 COMMENTS_CLS = None
42 42
43 43
264 264
265 mb_data = {} 265 mb_data = {}
266 for key in keys_to_keep: 266 for key in keys_to_keep:
267 value = getattr(self.item, key) 267 value = getattr(self.item, key)
268 if value is not None: 268 if value is not None:
269 mb_data[key] = unicode(value) 269 mb_data[key] = str(value)
270 270
271 for prefix in ("content", "title"): 271 for prefix in ("content", "title"):
272 for suffix in ("", "_rich", "_xhtml"): 272 for suffix in ("", "_rich", "_xhtml"):
273 name = "{}{}".format(prefix, suffix) 273 name = "{}{}".format(prefix, suffix)
274 value = getattr(self.item, name) 274 value = getattr(self.item, name)
285 285
286 if self.blog.new_message_target == C.GROUP: 286 if self.blog.new_message_target == C.GROUP:
287 mb_data['groups'] = list(self.blog.targets) 287 mb_data['groups'] = list(self.blog.targets)
288 288
289 self.blog.host.bridge.mbSend( 289 self.blog.host.bridge.mbSend(
290 unicode(self.service or ""), 290 str(self.service or ""),
291 self.node or "", 291 self.node or "",
292 data_format.serialise(mb_data), 292 data_format.serialise(mb_data),
293 profile=self.blog.profile, 293 profile=self.blog.profile,
294 ) 294 )
295 295
298 298
299 This doesn't delete any entry in PubSub, just locally 299 This doesn't delete any entry in PubSub, just locally
300 all children entries will be recursively removed too 300 all children entries will be recursively removed too
301 """ 301 """
302 # XXX: named delete and not remove to avoid conflict with pyjamas 302 # XXX: named delete and not remove to avoid conflict with pyjamas
303 log.debug(u"deleting entry {}".format("EDIT ENTRY" if self.new else self.item.id)) 303 log.debug("deleting entry {}".format("EDIT ENTRY" if self.new else self.item.id))
304 for child in self.entries: 304 for child in self.entries:
305 child.delete() 305 child.delete()
306 try: 306 try:
307 self.manager.entries.remove(self) 307 self.manager.entries.remove(self)
308 except ValueError: 308 except ValueError:
309 if self != self.manager.edit_entry: 309 if self != self.manager.edit_entry:
310 log.error(u"Internal Error: entry not found in manager") 310 log.error("Internal Error: entry not found in manager")
311 else: 311 else:
312 self.manager.edit_entry = None 312 self.manager.edit_entry = None
313 if not self.new: 313 if not self.new:
314 # we must remove references to self 314 # we must remove references to self
315 # in QuickBlog's dictionary 315 # in QuickBlog's dictionary
326 if there is a comments node, it will be purged too 326 if there is a comments node, it will be purged too
327 """ 327 """
328 # TODO: manage several comments nodes case. 328 # TODO: manage several comments nodes case.
329 if self.item.comments: 329 if self.item.comments:
330 self.blog.host.bridge.psNodeDelete( 330 self.blog.host.bridge.psNodeDelete(
331 unicode(self.item.comments_service) or "", 331 str(self.item.comments_service) or "",
332 self.item.comments_node, 332 self.item.comments_node,
333 profile=self.blog.profile, 333 profile=self.blog.profile,
334 ) 334 )
335 self.blog.host.bridge.mbRetract( 335 self.blog.host.bridge.mbRetract(
336 unicode(self.service or ""), 336 str(self.service or ""),
337 self.node or "", 337 self.node or "",
338 self.item.id, 338 self.item.id,
339 profile=self.blog.profile, 339 profile=self.blog.profile,
340 ) 340 )
341 341
356 if not targets: 356 if not targets:
357 targets = () # XXX: we use empty tuple instead of None to workaround a pyjamas bug 357 targets = () # XXX: we use empty tuple instead of None to workaround a pyjamas bug
358 quick_widgets.QuickWidget.__init__(self, host, targets, C.PROF_KEY_NONE) 358 quick_widgets.QuickWidget.__init__(self, host, targets, C.PROF_KEY_NONE)
359 self._targets_type = C.ALL 359 self._targets_type = C.ALL
360 else: 360 else:
361 assert isinstance(targets[0], basestring) 361 assert isinstance(targets[0], str)
362 quick_widgets.QuickWidget.__init__(self, host, targets[0], C.PROF_KEY_NONE) 362 quick_widgets.QuickWidget.__init__(self, host, targets[0], C.PROF_KEY_NONE)
363 for target in targets[1:]: 363 for target in targets[1:]:
364 assert isinstance(target, basestring) 364 assert isinstance(target, str)
365 self.addTarget(target) 365 self.addTarget(target)
366 self._targets_type = C.GROUP 366 self._targets_type = C.GROUP
367 367
368 @property 368 @property
369 def new_message_target(self): 369 def new_message_target(self):
373 return C.GROUP 373 return C.GROUP
374 else: 374 else:
375 raise ValueError("Unkown targets type") 375 raise ValueError("Unkown targets type")
376 376
377 def __str__(self): 377 def __str__(self):
378 return u"Blog Widget [target: {}, profile: {}]".format( 378 return "Blog Widget [target: {}, profile: {}]".format(
379 ", ".join(self.targets), self.profile 379 ", ".join(self.targets), self.profile
380 ) 380 )
381 381
382 def _getResultsCb(self, data, rt_session): 382 def _getResultsCb(self, data, rt_session):
383 remaining, results = data 383 remaining, results = data
434 callback=gotSession, 434 callback=gotSession,
435 ) 435 )
436 own_pep = self.host.whoami.bare 436 own_pep = self.host.whoami.bare
437 self.host.bridge.mbGetFromManyWithComments( 437 self.host.bridge.mbGetFromManyWithComments(
438 C.JID, 438 C.JID,
439 (unicode(own_pep),), 439 (str(own_pep),),
440 10, 440 10,
441 10, 441 10,
442 {}, 442 {},
443 {}, 443 {},
444 profile=self.profile, 444 profile=self.profile,
445 callback=gotSession, 445 callback=gotSession,
446 ) 446 )
447 else: 447 else:
448 raise NotImplementedError( 448 raise NotImplementedError(
449 u"{} target type is not managed".format(self._targets_type) 449 "{} target type is not managed".format(self._targets_type)
450 ) 450 )
451 451
452 def isJidAccepted(self, jid_): 452 def isJidAccepted(self, jid_):
453 """Tell if a jid is actepted and must be shown in this panel 453 """Tell if a jid is actepted and must be shown in this panel
454 454