diff options
Diffstat (limited to 'libbe/comment.py')
-rw-r--r-- | libbe/comment.py | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/libbe/comment.py b/libbe/comment.py index d03f8ce..ca5f884 100644 --- a/libbe/comment.py +++ b/libbe/comment.py @@ -23,11 +23,7 @@ """ import base64 -import os -import os.path -import sys import time -import types try: from email.mime.base import MIMEBase from email.encoders import encode_base64 @@ -35,10 +31,7 @@ except ImportError: # adjust to old python 2.4 from email.MIMEBase import MIMEBase from email.Encoders import encode_base64 -try: # import core module, Python >= 2.5 - from xml.etree import ElementTree -except ImportError: # look for non-core module - from elementtree import ElementTree +from xml.etree import ElementTree import xml.sax.saxutils import libbe @@ -51,10 +44,15 @@ import libbe.storage.util.mapfile as mapfile from libbe.util.tree import Tree import libbe.util.utility as utility -if libbe.TESTING == True: +if libbe.TESTING: import doctest +# https://stackoverflow.com/a/56719588/164233 +def cmp(a, b): + return (int(a) > int(b)) - (int(a) < int(b)) + + class MissingReference(ValueError): def __init__(self, comment): msg = "Missing reference to %s" % (comment.in_reply_to) @@ -77,7 +75,7 @@ def load_comments(bug, load_full=False): comments = [] for uuid in uuids: comm = Comment(bug, uuid, from_storage=True) - if load_full == True: + if load_full: comm.load_settings() dummy = comm.body # force the body to load comments.append(comm) @@ -141,7 +139,7 @@ class Comment (Tree, settings_object.SavedSettingsObject): def date(): return {} def _get_time(self): - if self.date == None: + if self.date is None: return None return utility.str_to_time(self.date) def _set_time(self, value): @@ -211,7 +209,7 @@ class Comment (Tree, settings_object.SavedSettingsObject): self.uuid = uuid self.id = libbe.util.id.ID(self, 'comment') if from_storage == False: - if uuid == None: + if uuid is None: self.uuid = libbe.util.id.uuid_gen() self.time = int(time.time()) # only save to second precision self.in_reply_to = in_reply_to @@ -254,7 +252,7 @@ class Comment (Tree, settings_object.SavedSettingsObject): def _setting_attr_string(self, setting): value = getattr(self, setting) - if value == None: + if value is None: return "" if type(value) not in (str,): return str(value) @@ -268,7 +266,7 @@ class Comment (Tree, settings_object.SavedSettingsObject): * if that id matches another comments .alt_id, in which case return the matching comments .uuid. """ - if self.in_reply_to == None: + if self.in_reply_to is None: return None else: try: @@ -478,9 +476,9 @@ class Comment (Tree, settings_object.SavedSettingsObject): self.alt_id = None for estr in other.extra_strings: if not estr in self.extra_strings: - if accept_extra_strings == True: + if accept_extra_strings: self.extra_strings.append(estr) - elif change_exception == True: + elif change_exception: raise ValueError('Merge would add extra string "%s" to comment %s' \ % (estr, self.uuid)) @@ -492,7 +490,7 @@ class Comment (Tree, settings_object.SavedSettingsObject): >>> print comm.string(indent=2) --------- Comment --------- Name: //abc - From: + From: Date: Thu, 01 Jan 1970 00:00:00 +0000 <BLANKLINE> Some @@ -544,50 +542,50 @@ class Comment (Tree, settings_object.SavedSettingsObject): >>> print a.string_thread(flatten=True) --------- Comment --------- Name: //a - From: + From: Date: Thu, 20 Nov 2008 01:00:00 +0000 <BLANKLINE> Insightful remarks --------- Comment --------- Name: //b - From: + From: Date: Thu, 20 Nov 2008 02:00:00 +0000 <BLANKLINE> Critique original comment --------- Comment --------- Name: //c - From: + From: Date: Thu, 20 Nov 2008 03:00:00 +0000 <BLANKLINE> Begin flamewar :p --------- Comment --------- Name: //d - From: + From: Date: Thu, 20 Nov 2008 04:00:00 +0000 <BLANKLINE> Useful examples >>> print a.string_thread() --------- Comment --------- Name: //a - From: + From: Date: Thu, 20 Nov 2008 01:00:00 +0000 <BLANKLINE> Insightful remarks --------- Comment --------- Name: //b - From: + From: Date: Thu, 20 Nov 2008 02:00:00 +0000 <BLANKLINE> Critique original comment --------- Comment --------- Name: //c - From: + From: Date: Thu, 20 Nov 2008 03:00:00 +0000 <BLANKLINE> Begin flamewar :p --------- Comment --------- Name: //d - From: + From: Date: Thu, 20 Nov 2008 04:00:00 +0000 <BLANKLINE> Useful examples @@ -607,7 +605,7 @@ class Comment (Tree, settings_object.SavedSettingsObject): def load_settings(self, settings_mapfile=None): if self.uuid == INVALID_UUID: return - if settings_mapfile == None: + if settings_mapfile is None: settings_mapfile = self.storage.get( self.id.storage('values'), '{}\n') try: @@ -732,8 +730,8 @@ def cmp_attr(comment_1, comment_2, attr, invert=False): return 1 val_1 = getattr(comment_1, attr) val_2 = getattr(comment_2, attr) - if val_1 == None: val_1 = None - if val_2 == None: val_2 = None + if val_1 is None: val_1 = None + if val_2 is None: val_2 = None if invert == True : return -cmp(val_1, val_2) @@ -767,5 +765,5 @@ class CommentCompoundComparator (object): cmp_full = CommentCompoundComparator() -if libbe.TESTING == True: +if libbe.TESTING: suite = doctest.DocTestSuite() |