aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
Diffstat (limited to 'libbe')
-rw-r--r--libbe/bugdir.py18
-rw-r--r--libbe/command/base.py48
-rw-r--r--libbe/command/comment.py8
-rw-r--r--libbe/command/commit.py8
-rw-r--r--libbe/command/depend.py14
-rw-r--r--libbe/command/diff.py8
-rw-r--r--libbe/command/due.py2
-rw-r--r--libbe/command/help.py2
-rw-r--r--libbe/command/html.py22
-rw-r--r--libbe/command/import_xml.py20
-rw-r--r--libbe/command/list.py6
-rw-r--r--libbe/command/merge.py2
-rw-r--r--libbe/command/new.py10
-rw-r--r--libbe/command/serve_commands.py2
-rw-r--r--libbe/command/set.py6
-rw-r--r--libbe/command/show.py2
-rw-r--r--libbe/command/subscribe.py14
-rw-r--r--libbe/command/tag.py4
-rw-r--r--libbe/command/target.py16
-rw-r--r--libbe/command/util.py18
-rw-r--r--libbe/diff.py14
-rw-r--r--libbe/storage/base.py9
-rw-r--r--libbe/storage/util/config.py4
-rw-r--r--libbe/storage/util/properties.py193
-rw-r--r--libbe/storage/util/settings_object.py40
-rw-r--r--libbe/storage/util/upgrade.py2
-rw-r--r--libbe/storage/vcs/base.py18
-rw-r--r--libbe/storage/vcs/bzr.py8
-rw-r--r--libbe/storage/vcs/darcs.py8
-rw-r--r--libbe/storage/vcs/git.py6
-rw-r--r--libbe/storage/vcs/hg.py6
-rw-r--r--libbe/storage/vcs/monotone.py10
-rw-r--r--libbe/ui/command_line.py14
-rw-r--r--libbe/ui/util/editor.py4
-rw-r--r--libbe/ui/util/user.py8
-rw-r--r--libbe/util/encoding.py10
-rw-r--r--libbe/util/id.py16
-rw-r--r--libbe/util/subproc.py8
-rw-r--r--libbe/util/wsgi.py8
39 files changed, 348 insertions, 268 deletions
diff --git a/libbe/bugdir.py b/libbe/bugdir.py
index a5d384d..a694e89 100644
--- a/libbe/bugdir.py
+++ b/libbe/bugdir.py
@@ -133,8 +133,8 @@ class BugDir (list, settings_object.SavedSettingsObject):
def inactive_status(): return {}
def _extra_strings_check_fn(value):
- return utility.iterable_full_of_strings(value, \
- alternative=settings_object.EMPTY)
+ return utility.iterable_full_of_strings(value,
+ alternative=settings_object.EMPTY)
def _extra_strings_change_hook(self, old, new):
self.extra_strings.sort() # to make merging easier
self._prop_save_settings(old, new)
@@ -175,7 +175,7 @@ class BugDir (list, settings_object.SavedSettingsObject):
else:
if self.uuid is None:
self.uuid = libbe.util.id.uuid_gen()
- if self.storage != None and self.storage.is_writeable():
+ if self.storage is not None and self.storage.is_writeable():
self.save()
# methods for saving/loading/accessing settings and properties.
@@ -235,7 +235,7 @@ class BugDir (list, settings_object.SavedSettingsObject):
def _refresh_uuid_cache(self):
self._uuids_cache = set()
# list bugs that are in storage
- if self.storage != None and self.storage.is_readable():
+ if self.storage is not None and self.storage.is_readable():
child_uuids = libbe.util.id.child_uuids(
self.storage.children(self.id.storage()))
for id in child_uuids:
@@ -274,7 +274,7 @@ class BugDir (list, settings_object.SavedSettingsObject):
if hasattr(self, '_uuids_cache') and bug.uuid in self._uuids_cache:
self._uuids_cache.remove(bug.uuid)
self.remove(bug)
- if self.storage != None and self.storage.is_writeable():
+ if self.storage is not None and self.storage.is_writeable():
bug.remove()
def bug_from_uuid(self, uuid):
@@ -752,12 +752,12 @@ if libbe.TESTING:
bug_b.creator = 'Jane Doe <jdoe@example.com>'
bug_b.time = 0
bug_b.status = 'closed'
- if self.storage != None:
+ if self.storage is not None:
self.storage.disconnect() # flush to storage
self.storage.connect()
def cleanup(self):
- if self.storage != None:
+ if self.storage is not None:
self.storage.writeable = True
self.storage.disconnect()
self.storage.destroy()
@@ -765,7 +765,7 @@ if libbe.TESTING:
self._dir_ref.cleanup()
def flush_reload(self):
- if self.storage != None:
+ if self.storage is not None:
self.storage.disconnect()
self.storage.connect()
self._clear_bugs()
@@ -885,7 +885,7 @@ if libbe.TESTING:
self.storage.disconnect()
self.storage.connect()
def tearDown(self):
- if self.storage != None:
+ if self.storage is not None:
self.storage.disconnect()
self.storage.destroy()
self.dir.cleanup()
diff --git a/libbe/command/base.py b/libbe/command/base.py
index 806d880..b6a9e15 100644
--- a/libbe/command/base.py
+++ b/libbe/command/base.py
@@ -74,7 +74,7 @@ def get_command(command_name):
>>> try:
... get_command('asdf')
- ... except UnknownCommand, e:
+ ... except UnknownCommand as e:
... print(e)
Unknown command 'asdf'
(No module named asdf)
@@ -99,7 +99,7 @@ def get_command_class(module=None, command_name=None):
>>> repr(import_xml)
"<class 'libbe.command.import_xml.Import_XML'>"
"""
- if module == None:
+ if module is None:
module = get_command(command_name)
try:
cname = command_name.capitalize().replace('-', '_')
@@ -121,7 +121,7 @@ def modname_to_command_name(modname):
... try:
... if issubclass(attr, Command):
... commands.append(attr)
- ... except TypeError, e:
+ ... except TypeError as e:
... pass
... if len(commands) == 0:
... raise Exception('No Command classes in %s' % dir(mod))
@@ -163,7 +163,7 @@ class Argument (CommandInput):
self.optional = optional
self.repeatable = repeatable
self.completion_callback = completion_callback
- if self.metavar == None:
+ if self.metavar is None:
self.metavar = self.name.upper()
class Option (CommandInput):
@@ -173,17 +173,17 @@ class Option (CommandInput):
self.callback = callback
self.short_name = short_name
self.arg = arg
- if self.arg == None and self.callback == None:
+ if self.arg is None and self.callback is None:
# use an implicit boolean argument
self.arg = Argument(name=self.name, help=self.help,
default=False, type='bool')
self.validate()
def validate(self):
- if self.arg == None:
- assert self.callback != None, self.name
+ if self.arg is None:
+ assert self.callback is not None, self.name
return
- assert self.callback == None, '%s: %s' % (self.name, self.callback)
+ assert self.callback is None, '%s: %s' % (self.name, self.callback)
assert self.arg.name == self.name, \
'Name missmatch: %s != %s' % (self.arg.name, self.name)
assert self.arg.optional == False, self.name
@@ -208,13 +208,13 @@ class _DummyParser (optparse.OptionParser):
# from libbe.ui.command_line.CmdOptionParser._add_option
option.validate()
long_opt = '--%s' % option.name
- if option.short_name != None:
+ if option.short_name is not None:
short_opt = '-%s' % option.short_name
assert '_' not in option.name, \
'Non-reconstructable option name %s' % option.name
kwargs = {'dest':option.name.replace('-', '_'),
'help':option.help}
- if option.arg == None or option.arg.type == 'bool':
+ if option.arg is None or option.arg.type == 'bool':
kwargs['action'] = 'store_true'
kwargs['metavar'] = None
kwargs['default'] = False
@@ -223,7 +223,7 @@ class _DummyParser (optparse.OptionParser):
kwargs['action'] = 'store'
kwargs['metavar'] = option.arg.metavar
kwargs['default'] = option.arg.default
- if option.short_name != None:
+ if option.short_name is not None:
opt = optparse.Option(short_opt, long_opt, **kwargs)
else:
opt = optparse.Option(long_opt, **kwargs)
@@ -291,7 +291,7 @@ class Command (object):
pass
else:
params.pop('help')
- if params['complete'] != None:
+ if params['complete'] is not None:
pass
else:
params.pop('complete')
@@ -303,16 +303,16 @@ class Command (object):
return self.status
def _parse_options_args(self, options=None, args=None):
- if options == None:
+ if options is None:
options = {}
- if args == None:
+ if args is None:
args = []
params = {}
for option in self.options:
assert option.name not in params, params[option.name]
if option.name in options:
params[option.name] = options.pop(option.name)
- elif option.arg != None:
+ elif option.arg is not None:
params[option.name] = option.arg.default
else: # non-arg options are flags, set to default flag value
params[option.name] = False
@@ -385,13 +385,13 @@ class Command (object):
return "A detailed help message."
def complete(self, argument=None, fragment=None):
- if argument == None:
+ if argument is None:
ret = ['--%s' % o.name for o in self.options
if o.name != 'complete']
- if len(self.args) > 0 and self.args[0].completion_callback != None:
+ if len(self.args) > 0 and self.args[0].completion_callback is not None:
ret.extend(self.args[0].completion_callback(self, argument, fragment))
return ret
- elif argument.completion_callback != None:
+ elif argument.completion_callback is not None:
# finish a particular argument
return argument.completion_callback(self, argument, fragment)
return [] # the particular argument doesn't supply completion info
@@ -413,7 +413,7 @@ class Command (object):
>>> c = Command()
>>> try:
... c._check_restricted_access(s, os.path.expanduser('~/.ssh/id_rsa'))
- ... except UserError, e:
+ ... except UserError as e:
... assert str(e).startswith('file access restricted!'), str(e)
... print('we got the expected error')
we got the expected error
@@ -457,9 +457,9 @@ class StdInputOutput (InputOutput):
InputOutput.__init__(self, stdin, stdout)
def _get_io(self, input_encoding=None, output_encoding=None):
- if input_encoding == None:
+ if input_encoding is None:
input_encoding = libbe.util.encoding.get_input_encoding()
- if output_encoding == None:
+ if output_encoding is None:
output_encoding = libbe.util.encoding.get_output_encoding()
stdin = codecs.getreader(input_encoding)(sys.stdin)
stdin.encoding = input_encoding
@@ -512,7 +512,7 @@ class UnconnectedStorageGetter (object):
class StorageCallbacks (object):
def __init__(self, location=None):
- if location == None:
+ if location is None:
location = '.'
self.location = location
self._get_unconnected_storage = UnconnectedStorageGetter(location)
@@ -532,7 +532,7 @@ class StorageCallbacks (object):
intended for the init command, which calls Storage.init().
"""
if not hasattr(self, '_unconnected_storage'):
- if self._get_unconnected_storage == None:
+ if self._get_unconnected_storage is None:
raise NotImplementedError
self._unconnected_storage = self._get_unconnected_storage()
return self._unconnected_storage
@@ -574,7 +574,7 @@ class StorageCallbacks (object):
class UserInterface (object):
def __init__(self, io=None, location=None):
- if io == None:
+ if io is None:
io = StringInputOutput()
self.io = io
self.storage_callbacks = StorageCallbacks(location)
diff --git a/libbe/command/comment.py b/libbe/command/comment.py
index bfd24fe..c579610 100644
--- a/libbe/command/comment.py
+++ b/libbe/command/comment.py
@@ -126,7 +126,7 @@ class Comment (libbe.command.Command):
bugdir,bug,parent = (
libbe.command.util.bugdir_bug_comment_from_user_id(
bugdirs, params['id']))
- if params['comment'] == None:
+ if params['comment'] is None:
# try to launch an editor for comment-body entry
try:
if parent == bug.comment_root:
@@ -144,7 +144,7 @@ class Comment (libbe.command.Command):
if body is None:
raise libbe.command.UserError('No comment entered.')
elif params['comment'] == '-': # read body from stdin
- binary = not (params['content-type'] == None
+ binary = not (params['content-type'] is None
or params['content-type'].startswith("text/"))
if not binary:
body = self.stdin.read()
@@ -156,12 +156,12 @@ class Comment (libbe.command.Command):
body = params['comment']
if not body.endswith('\n'):
body+='\n'
- if params['author'] == None:
+ if params['author'] is None:
params['author'] = self._get_user_id()
new = parent.new_reply(body=body, content_type=params['content-type'])
for key in ['alt-id', 'author']:
- if params[key] != None:
+ if params[key] is not None:
setattr(new, new._setting_name_to_attr_name(key), params[key])
if params['full-uuid']:
comment_id = new.id.long_user()
diff --git a/libbe/command/commit.py b/libbe/command/commit.py
index 077980d..afe082d 100644
--- a/libbe/command/commit.py
+++ b/libbe/command/commit.py
@@ -71,10 +71,10 @@ class Commit (libbe.command.Command):
summary = sys.stdin.readline()
else:
summary = params['summary']
- if summary == None and params['body'] == None:
+ if summary is None and params['body'] is None:
params['body'] = 'EDITOR'
storage = self._get_storage()
- if params['body'] == None:
+ if params['body'] is None:
body = None
elif params['body'] == 'EDITOR':
body = libbe.ui.util.editor.editor_string(
@@ -83,8 +83,8 @@ class Commit (libbe.command.Command):
self._check_restricted_access(storage, params['body'])
body = libbe.util.encoding.get_file_contents(
params['body'], decode=True)
- if summary == None: # use the first body line as the summary
- if body == None:
+ if summary is None: # use the first body line as the summary
+ if body is None:
raise libbe.command.UserError(
'cannot commit without a summary')
lines = body.splitlines()
diff --git a/libbe/command/depend.py b/libbe/command/depend.py
index 4cb0efd..fe02ce0 100644
--- a/libbe/command/depend.py
+++ b/libbe/command/depend.py
@@ -54,7 +54,7 @@ class Filter (object):
else:
target_bug = libbe.command.target.bug_target(bugdirs, bug)
if self.target in ['none', None]:
- if target_bug.summary != None:
+ if target_bug.summary is not None:
return False
else:
if target_bug.summary != self.target:
@@ -195,14 +195,14 @@ class Depend (libbe.command.Command):
])
def _run(self, **params):
- if params['repair'] == True and params['bug-id'] != None:
+ if params['repair'] == True and params['bug-id'] is not None:
raise libbe.command.UserError(
'No arguments with --repair calls.')
- if params['repair'] == False and params['bug-id'] == None:
+ if params['repair'] == False and params['bug-id'] is None:
raise libbe.command.UserError(
'Must specify either --repair or a BUG-ID')
- if params['tree-depth'] != None \
- and params['blocking-bug-id'] != None:
+ if params['tree-depth'] is not None \
+ and params['blocking-bug-id'] is not None:
raise libbe.command.UserError(
'Only one bug id used in tree mode.')
bugdirs = self._get_bugdirs()
@@ -223,7 +223,7 @@ class Depend (libbe.command.Command):
libbe.command.util.bugdir_bug_comment_from_user_id(
bugdirs, params['bug-id']))
- if params['tree-depth'] != None:
+ if params['tree-depth'] is not None:
dtree = DependencyTree(bugdirs, bugA, params['tree-depth'], filter)
if len(dtree.blocked_by_tree()) > 0:
print('%s blocked by:' % bugA.id.user(), file=self.stdout)
@@ -241,7 +241,7 @@ class Depend (libbe.command.Command):
% (' '*(depth), self.bug_string(node.bug, params))), file=self.stdout)
return 0
- if params['blocking-bug-id'] != None:
+ if params['blocking-bug-id'] is not None:
bugdirB,bugB,dummy_comment = (
libbe.command.util.bugdir_bug_comment_from_user_id(
bugdirs, params['blocking-bug-id']))
diff --git a/libbe/command/diff.py b/libbe/command/diff.py
index d8aea37..aca54c3 100644
--- a/libbe/command/diff.py
+++ b/libbe/command/diff.py
@@ -97,18 +97,18 @@ class Diff (libbe.command.Command):
def diff(self, bugdir, subscriptions, params):
- if params['repo'] == None:
+ if params['repo'] is None:
if bugdir.storage.versioned == False:
raise libbe.command.UserError(
'This repository is not revision-controlled.')
- if params['revision'] == None: # get the most recent revision
+ if params['revision'] is None: # get the most recent revision
params['revision'] = bugdir.storage.revision_id(-1)
old_bd = libbe.bugdir.RevisionedBugDir(bugdir, params['revision'])
else:
old_storage = libbe.storage.get_storage(params['repo'])
old_storage.connect()
old_bd_current = libbe.bugdir.BugDir(old_storage, from_disk=True)
- if params['revision'] == None: # use the current working state
+ if params['revision'] is None: # use the current working state
old_bd = old_bd_current
else:
if old_bd_current.storage.versioned == False:
@@ -127,7 +127,7 @@ class Diff (libbe.command.Command):
print('\n'.join(uuids), file=self.stdout)
else :
rep = tree.report_string()
- if rep != None:
+ if rep is not None:
print(rep, file=self.stdout)
return 0
diff --git a/libbe/command/due.py b/libbe/command/due.py
index ddf111a..2f7d181 100644
--- a/libbe/command/due.py
+++ b/libbe/command/due.py
@@ -65,7 +65,7 @@ class Due (libbe.command.Command):
bugdir,bug,comment = (
libbe.command.util.bugdir_bug_comment_from_user_id(
bugdirs, params['bug-id']))
- if params['due'] == None:
+ if params['due'] is None:
due_time = get_due(bug)
if due_time is None:
print('No due date assigned.', file=self.stdout)
diff --git a/libbe/command/help.py b/libbe/command/help.py
index 981ea1a..c7961ac 100644
--- a/libbe/command/help.py
+++ b/libbe/command/help.py
@@ -93,7 +93,7 @@ class Help (libbe.command.Command):
])
def _run(self, **params):
- if params['topic'] == None:
+ if params['topic'] is None:
if hasattr(self.ui, 'help'):
print(self.ui.help().rstrip('\n'), file=self.stdout)
elif params['topic'] in libbe.command.commands(command_names=True):
diff --git a/libbe/command/html.py b/libbe/command/html.py
index ed43808..5ec8691 100644
--- a/libbe/command/html.py
+++ b/libbe/command/html.py
@@ -100,21 +100,11 @@ class ServerApp (libbe.util.wsgi.WSGI_AppObject,
self.logger.log(
self.log_level, 'generate {} index file for {} bugs'.format(
bug_type, len(bugs)))
- template_info = {
- 'title': self.title,
- 'charset': 'UTF-8',
- 'stylesheet': 'style.css',
- 'header': self.header,
- 'active_class': 'tab nsel',
- 'inactive_class': 'tab nsel',
- 'target_class': 'tab nsel',
- 'bugs': bugs,
- 'bug_entry': self.template.get_template('index_bug_entry.html'),
- 'bug_dir': self.bug_dir,
- 'index_file': self._index_file,
- 'generation_time': self._generation_time(),
- }
- template_info['{}_class'.format(bug_type)] = 'tab sel'
+ template_info = {'title': self.title, 'charset': 'UTF-8', 'stylesheet': 'style.css', 'header': self.header,
+ 'active_class': 'tab nsel', 'inactive_class': 'tab nsel', 'target_class': 'tab nsel',
+ 'bugs': bugs, 'bug_entry': self.template.get_template('index_bug_entry.html'),
+ 'bug_dir': self.bug_dir, 'index_file': self._index_file,
+ 'generation_time': self._generation_time(), '{}_class'.format(bug_type): 'tab sel'}
if bug_type == 'target':
template = self.template.get_template('target_index.html')
template_info['targets'] = [
@@ -314,7 +304,7 @@ class ServerApp (libbe.util.wsgi.WSGI_AppObject,
return time.ctime()
def _escape(self, string):
- if string == None:
+ if string is None:
return ''
return xml.sax.saxutils.escape(string)
diff --git a/libbe/command/import_xml.py b/libbe/command/import_xml.py
index 391b2ed..42b9b49 100644
--- a/libbe/command/import_xml.py
+++ b/libbe/command/import_xml.py
@@ -102,7 +102,7 @@ class Import_XML (libbe.command.Command):
bugdirs = self._get_bugdirs()
writeable = storage.writeable
storage.writeable = False
- if params['root'] != None:
+ if params['root'] is not None:
root_bugdir,root_bug,root_comment = (
libbe.command.util.bugdir_bug_comment_from_user_id(
bugdirs, params['root']))
@@ -136,7 +136,7 @@ class Import_XML (libbe.command.Command):
comms = []
for c in root_bug.comments():
comms.append(c.uuid)
- if c.alt_id != None:
+ if c.alt_id is not None:
comms.append(c.alt_id)
if root_comment.uuid == libbe.comment.INVALID_UUID:
root_text = root_bug.id.user()
@@ -496,13 +496,13 @@ if libbe.TESTING == True:
c1 = bugB.comment_from_uuid('c1')
comments.remove(c1)
self.assertTrue(c1.uuid == 'c1', c1.uuid)
- self.assertTrue(c1.alt_id == None, c1.alt_id)
+ self.assertTrue(c1.alt_id is None, c1.alt_id)
self.assertTrue(c1.author == 'Jane', c1.author)
self.assertTrue(c1.body == 'So long\n', c1.body)
c2 = bugB.comment_from_uuid('c2')
comments.remove(c2)
self.assertTrue(c2.uuid == 'c2', c2.uuid)
- self.assertTrue(c2.alt_id == None, c2.alt_id)
+ self.assertTrue(c2.alt_id is None, c2.alt_id)
self.assertTrue(c2.author == 'Jess', c2.author)
self.assertTrue(c2.body == 'World\n', c2.body)
c4 = comments[0]
@@ -530,13 +530,13 @@ if libbe.TESTING == True:
c1 = bugB.comment_from_uuid('c1')
comments.remove(c1)
self.assertTrue(c1.uuid == 'c1', c1.uuid)
- self.assertTrue(c1.alt_id == None, c1.alt_id)
+ self.assertTrue(c1.alt_id is None, c1.alt_id)
self.assertTrue(c1.author == 'Jane', c1.author)
self.assertTrue(c1.body == 'Hello\n', c1.body)
c2 = bugB.comment_from_uuid('c2')
comments.remove(c2)
self.assertTrue(c2.uuid == 'c2', c2.uuid)
- self.assertTrue(c2.alt_id == None, c2.alt_id)
+ self.assertTrue(c2.alt_id is None, c2.alt_id)
self.assertTrue(c2.author == 'Jess', c2.author)
self.assertTrue(c2.body == 'World\n', c2.body)
c4 = comments[0]
@@ -566,13 +566,13 @@ if libbe.TESTING == True:
c1 = bugB.comment_from_uuid('c1')
comments.remove(c1)
self.assertTrue(c1.uuid == 'c1', c1.uuid)
- self.assertTrue(c1.alt_id == None, c1.alt_id)
+ self.assertTrue(c1.alt_id is None, c1.alt_id)
self.assertTrue(c1.author == 'Jane', c1.author)
self.assertTrue(c1.body == 'So long\n', c1.body)
c2 = bugB.comment_from_uuid('c2')
comments.remove(c2)
self.assertTrue(c2.uuid == 'c2', c2.uuid)
- self.assertTrue(c2.alt_id == None, c2.alt_id)
+ self.assertTrue(c2.alt_id is None, c2.alt_id)
self.assertTrue(c2.author == 'Jess', c2.author)
self.assertTrue(c2.body == 'World\n', c2.body)
c4 = comments[0]
@@ -601,13 +601,13 @@ if libbe.TESTING == True:
c1 = bugB.comment_from_uuid('c1')
comments.remove(c1)
self.assertTrue(c1.uuid == 'c1', c1.uuid)
- self.assertTrue(c1.alt_id == None, c1.alt_id)
+ self.assertTrue(c1.alt_id is None, c1.alt_id)
self.assertTrue(c1.author == 'Jane', c1.author)
self.assertTrue(c1.body == 'Hello\n', c1.body)
c2 = bugB.comment_from_uuid('c2')
comments.remove(c2)
self.assertTrue(c2.uuid == 'c2', c2.uuid)
- self.assertTrue(c2.alt_id == None, c2.alt_id)
+ self.assertTrue(c2.alt_id is None, c2.alt_id)
self.assertTrue(c2.author == 'Jess', c2.author)
self.assertTrue(c2.body == 'World\n', c2.body)
c4 = comments[0]
diff --git a/libbe/command/list.py b/libbe/command/list.py
index 41e1bed..567e3fe 100644
--- a/libbe/command/list.py
+++ b/libbe/command/list.py
@@ -156,7 +156,7 @@ class List (libbe.command.Command):
def _parse_params(self, bugdirs, params):
cmp_list = []
- if params['sort'] != None:
+ if params['sort'] is not None:
for cmp in params['sort'].split(','):
if cmp not in AVAILABLE_IDXS:
raise libbe.command.UserError(
@@ -167,7 +167,7 @@ class List (libbe.command.Command):
severity = parse_severity(params['severity'],
important=params['important'])
# select assigned
- if params['assigned'] == None:
+ if params['assigned'] is None:
if params['mine'] == True:
assigned = [self._get_user_id()]
else:
@@ -178,7 +178,7 @@ class List (libbe.command.Command):
for i in range(len(assigned)):
if assigned[i] == '-':
assigned[i] = params['user-id']
- if params['extra-strings'] == None:
+ if params['extra-strings'] is None:
extra_strings_regexps = []
else:
extra_strings_regexps = [re.compile(x)
diff --git a/libbe/command/merge.py b/libbe/command/merge.py
index 4ee67cf..5100803 100644
--- a/libbe/command/merge.py
+++ b/libbe/command/merge.py
@@ -170,7 +170,7 @@ class Merge (libbe.command.Command):
for comment in newCommTree.traverse(): # all descendant comments
comment.bug = bugA
# uuids must be unique in storage
- if comment.alt_id == None:
+ if comment.alt_id is None:
comment.storage = None
comment.alt_id = comment.uuid
comment.storage = storage
diff --git a/libbe/command/new.py b/libbe/command/new.py
index 4a0288b..6a5ac1f 100644
--- a/libbe/command/new.py
+++ b/libbe/command/new.py
@@ -126,19 +126,19 @@ class New (libbe.command.Command):
'Ambiguous bugdir {}'.format(sorted(bugdirs.values())))
storage.writeable = False
bug = bugdir.new_bug(summary=summary.strip())
- if params['creator'] != None:
+ if params['creator'] is not None:
bug.creator = params['creator']
else:
bug.creator = self._get_user_id()
- if params['reporter'] != None:
+ if params['reporter'] is not None:
bug.reporter = params['reporter']
else:
bug.reporter = bug.creator
- if params['assigned'] != None:
+ if params['assigned'] is not None:
bug.assigned = _parse_assigned(self, params['assigned'])
- if params['status'] != None:
+ if params['status'] is not None:
bug.status = params['status']
- if params['severity'] != None:
+ if params['severity'] is not None:
bug.severity = params['severity']
storage.writeable = True
bug.save()
diff --git a/libbe/command/serve_commands.py b/libbe/command/serve_commands.py
index dbdb76b..1541d12 100644
--- a/libbe/command/serve_commands.py
+++ b/libbe/command/serve_commands.py
@@ -202,7 +202,7 @@ if libbe.TESTING:
('Content-Type', 'application/octet-stream'
) in self.response_headers,
self.response_headers)
- self.assertTrue(self.exc_info == None, self.exc_info)
+ self.assertTrue(self.exc_info is None, self.exc_info)
# TODO: integration tests on ServeCommands?
unitsuite =unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
diff --git a/libbe/command/set.py b/libbe/command/set.py
index 9ec7e2c..698e657 100644
--- a/libbe/command/set.py
+++ b/libbe/command/set.py
@@ -83,7 +83,7 @@ class Set (libbe.command.Command):
else:
raise libbe.command.UserError(
'Ambiguous bugdir {}'.format(sorted(bugdirs.values())))
- if params['setting'] == None:
+ if params['setting'] is None:
keys = bugdir.settings_properties
keys.sort()
for key in keys:
@@ -94,7 +94,7 @@ class Set (libbe.command.Command):
msg += 'Allowed settings:\n '
msg += '\n '.join(bugdir.settings_properties)
raise libbe.command.UserError(msg)
- if params['value'] == None:
+ if params['value'] is None:
print(_value_string(bugdir, params['setting']))
else:
if params['value'] == 'none':
@@ -181,7 +181,7 @@ def get_bugdir_settings():
lines = dstr.split('\n')
while lines[0].startswith('This property defaults to') == False:
lines.pop(0)
- assert len(lines) != None, \
+ assert len(lines) is not None, \
'Unexpected vcs_name docstring:\n "%s"' % dstr
lines.insert(
0, 'The name of the revision control system to use.\n')
diff --git a/libbe/command/show.py b/libbe/command/show.py
index c08fd1f..2e7d59e 100644
--- a/libbe/command/show.py
+++ b/libbe/command/show.py
@@ -166,7 +166,7 @@ def _xml_footer():
return ['</be-xml>']
def output(bugdirs, ids, encoding, as_xml=True, with_comments=True):
- if ids == None or len(ids) == 0:
+ if ids is None or len(ids) == 0:
ids = []
for bugdir in list(bugdirs.values()):
bugdir.load_all_bugs()
diff --git a/libbe/command/subscribe.py b/libbe/command/subscribe.py
index 45cd0dd..b6f9cf0 100644
--- a/libbe/command/subscribe.py
+++ b/libbe/command/subscribe.py
@@ -127,17 +127,17 @@ class Subscribe (libbe.command.Command):
if params['list-all'] == True:
assert len(params['id']) == 0, params['id']
subscriber = params['subscriber']
- if subscriber == None:
+ if subscriber is None:
subscriber = self._get_user_id()
if params['unsubscribe'] == True:
- if params['servers'] == None:
+ if params['servers'] is None:
params['servers'] = 'INVALID'
- if params['types'] == None:
+ if params['types'] is None:
params['types'] = 'INVALID'
else:
- if params['servers'] == None:
+ if params['servers'] is None:
params['servers'] = '*'
- if params['types'] == None:
+ if params['types'] is None:
params['types'] = 'all'
servers = params['servers'].split(',')
types = params['types'].split(',')
@@ -247,7 +247,7 @@ def _get_subscriber(extra_strings, subscriber, type_root):
def subscribe(extra_strings, subscriber, types, servers, type_root):
args = _get_subscriber(extra_strings, subscriber, type_root)
- if args == None: # no match
+ if args is None: # no match
extra_strings.append(_generate_string(subscriber, types, servers))
return extra_strings
# Alter matched string
@@ -270,7 +270,7 @@ def subscribe(extra_strings, subscriber, types, servers, type_root):
def unsubscribe(extra_strings, subscriber, types, servers, type_root):
args = _get_subscriber(extra_strings, subscriber, type_root)
- if args == None: # no match
+ if args is None: # no match
return extra_strings # pass
# Remove matched string
i,s,ts,srvs = args
diff --git a/libbe/command/tag.py b/libbe/command/tag.py
index 51e2abe..bbffe09 100644
--- a/libbe/command/tag.py
+++ b/libbe/command/tag.py
@@ -104,9 +104,9 @@ class Tag (libbe.command.Command):
])
def _run(self, **params):
- if params['id'] == None and params['list'] == False:
+ if params['id'] is None and params['list'] == False:
raise libbe.command.UserError('Please specify a bug id.')
- if params['id'] != None and params['list'] == True:
+ if params['id'] is not None and params['list'] == True:
raise libbe.command.UserError(
'Do not specify a bug id with the --list option.')
bugdirs = self._get_bugdirs()
diff --git a/libbe/command/target.py b/libbe/command/target.py
index b13647e..eb11c11 100644
--- a/libbe/command/target.py
+++ b/libbe/command/target.py
@@ -90,10 +90,10 @@ class Target (libbe.command.Command):
def _run(self, **params):
if params['resolve'] == False:
- if params['id'] == None:
+ if params['id'] is None:
raise libbe.command.UserError('Please specify a bug id.')
else:
- if params['target'] != None:
+ if params['target'] is not None:
raise libbe.command.UserError('Too many arguments')
params['target'] = params.pop('id')
bugdirs = self._get_bugdirs()
@@ -106,7 +106,7 @@ class Target (libbe.command.Command):
raise libbe.command.UserError(
'Ambiguous bugdir {}'.format(sorted(bugdirs.values())))
bug = bug_from_target_summary(bugdirs, bugdir, params['target'])
- if bug == None:
+ if bug is None:
print('No target assigned.', file=self.stdout)
else:
print(bug.id.long_user(), file=self.stdout)
@@ -114,9 +114,9 @@ class Target (libbe.command.Command):
bugdir,bug,comment = (
libbe.command.util.bugdir_bug_comment_from_user_id(
bugdirs, params['id']))
- if params['target'] == None:
+ if params['target'] is None:
target = bug_target(bugdirs, bug)
- if target == None:
+ if target is None:
print('No target assigned.', file=self.stdout)
else:
print(target.summary, file=self.stdout)
@@ -157,8 +157,8 @@ by UUID), try
"""
def bug_from_target_summary(bugdirs, bugdir, summary=None):
- if summary == None:
- if bugdir.target == None:
+ if summary is None:
+ if bugdir.target is None:
return None
else:
return bugdir.bug_from_uuid(bugdir.target)
@@ -196,7 +196,7 @@ def remove_target(bugdirs, bug):
def add_target(bugdirs, bugdir, bug, summary):
target = bug_from_target_summary(bugdirs, bugdir, summary)
- if target == None:
+ if target is None:
target = bugdir.new_bug(summary=summary)
target.severity = 'target'
libbe.command.depend.add_block(target, bug)
diff --git a/libbe/command/util.py b/libbe/command/util.py
index 49f3490..632e22c 100644
--- a/libbe/command/util.py
+++ b/libbe/command/util.py
@@ -38,7 +38,7 @@ def complete_command(command, argument, fragment=None):
def comp_path(fragment=None):
"""List possible path completions for fragment."""
- if fragment == None:
+ if fragment is None:
fragment = '.'
comps = glob.glob(fragment+'*') + glob.glob(fragment+'/*')
if len(comps) == 1 and os.path.isdir(comps[0]):
@@ -64,14 +64,14 @@ def assignees(bugdirs):
for bugdir in list(bugdirs.values()):
bugdir.load_all_bugs()
ret.update(set([bug.assigned for bug in bugdir
- if bug.assigned != None]))
+ if bug.assigned is not None]))
return list(ret)
def complete_assigned(command, argument, fragment=None):
return assignees(command._get_bugdirs())
def complete_extra_strings(command, argument, fragment=None):
- if fragment == None:
+ if fragment is None:
return []
return [fragment]
@@ -88,7 +88,7 @@ def complete_bug_comment_id(command, argument, fragment=None,
import libbe.bugdir
import libbe.util.id
bugdirs = command._get_bugdirs()
- if fragment == None or len(fragment) == 0:
+ if fragment is None or len(fragment) == 0:
fragment = '/'
try:
p = libbe.util.id.parse_user(bugdirs, fragment)
@@ -101,7 +101,7 @@ def complete_bug_comment_id(command, argument, fragment=None,
except libbe.util.id.NoIDMatches:
return []
except libbe.util.id.MultipleIDMatches as e:
- if e.common == None:
+ if e.common is None:
# choose among bugdirs
return e.matches
common = e.common
@@ -109,7 +109,7 @@ def complete_bug_comment_id(command, argument, fragment=None,
root,residual = libbe.util.id.residual(common, fragment)
p = libbe.util.id.parse_user(bugdirs, e.common)
bug = None
- if matches == None: # fragment was complete, get a list of children uuids
+ if matches is None: # fragment was complete, get a list of children uuids
if p['type'] == 'bugdir':
bugdir = bugdirs[p['bugdir']]
matches = bugdir.uuids()
@@ -131,11 +131,11 @@ def complete_bug_comment_id(command, argument, fragment=None,
if comments == False:
return[fragment]
bugdir = bugdirs[p['bugdir']]
- if bug == None:
+ if bug is None:
bug = bugdir.bug_from_uuid(p['bug'])
child_fn = bug.comment_from_uuid
elif p['type'] == 'comment':
- assert matches == None, matches
+ assert matches is None, matches
return [fragment]
possible = []
common += '/'
@@ -180,7 +180,7 @@ def select_values(string, possible_values, name="unkown"):
['abc', 'def', 'hij']
"""
possible_values = list(possible_values) # don't alter the original
- if string == None:
+ if string is None:
pass
elif string.startswith('-'):
blacklisted_values = set(string[1:].split(','))
diff --git a/libbe/diff.py b/libbe/diff.py
index 595d512..f7ddfbe 100644
--- a/libbe/diff.py
+++ b/libbe/diff.py
@@ -256,7 +256,7 @@ class DiffTree (libbe.util.tree.Tree):
pass
else:
self.join(root, parent, data_part)
- if data_part != None:
+ if data_part is not None:
depth += 1
for child in self:
root = child.report(root, self, depth)
@@ -264,7 +264,7 @@ class DiffTree (libbe.util.tree.Tree):
def make_root(self):
return []
def join(self, root, parent, data_part):
- if data_part != None:
+ if data_part is not None:
root.append(data_part)
def data_part(self, depth, indent=True):
if self.data is None:
@@ -452,9 +452,9 @@ class Diff (object):
if BUGDIR_TYPE_ALL in bugdir_types \
or BUGDIR_TYPE_MOD in bugdir_types \
or uuid in subscribed_bugs:
- if old_bug.storage != None and old_bug.storage.is_readable():
+ if old_bug.storage is not None and old_bug.storage.is_readable():
old_bug.load_comments()
- if new_bug.storage != None and new_bug.storage.is_readable():
+ if new_bug.storage is not None and new_bug.storage.is_readable():
new_bug.load_comments()
if old_bug != new_bug:
modified.append((old_bug, new_bug))
@@ -534,7 +534,7 @@ class Diff (object):
for p in properties]
return self._attribute_changes(old, new, attributes)
def _bugdir_attribute_changes(self):
- return self._settings_properties_attribute_changes( \
+ return self._settings_properties_attribute_changes(
self.old_bugdir, self.new_bugdir)
def _bug_attribute_changes(self, old, new):
return self._settings_properties_attribute_changes(old, new)
@@ -558,8 +558,8 @@ class Diff (object):
root = self._cached_full_report
bugdir_types = [s.type for s in subscriptions if s.id == BUGDIR_ID]
subscribed_bugs = [s.id for s in subscriptions
- if BUG_TYPE_ALL.has_descendant( \
- s.type, match_self=True)]
+ if BUG_TYPE_ALL.has_descendant(
+ s.type, match_self=True)]
selected_by_bug = [node.name
for node in root.child_by_path('bugdir/bugs')]
if BUGDIR_TYPE_ALL in bugdir_types:
diff --git a/libbe/storage/base.py b/libbe/storage/base.py
index 09e176b..3ee056d 100644
--- a/libbe/storage/base.py
+++ b/libbe/storage/base.py
@@ -569,6 +569,7 @@ class VersionedStorage (Storage):
if TESTING:
+ # noinspection PyBroadException
class StorageTestCase (unittest.TestCase):
"""Test cases for Storage class."""
@@ -1131,11 +1132,11 @@ if TESTING:
storage_testcase_classes = [
c for c in (
ob for ob in list(globals().values()) if isinstance(ob, type))
- if ((issubclass(c, StorageTestCase) \
- and c.Class == Storage)
+ if ((issubclass(c, StorageTestCase)
+ and c.Class == Storage)
or
- (issubclass(c, VersionedStorageTestCase) \
- and c.Class == VersionedStorage))]
+ (issubclass(c, VersionedStorageTestCase)
+ and c.Class == VersionedStorage))]
for base_class in storage_testcase_classes:
testcase_class_name = storage_class.__name__ + base_class.__name__
diff --git a/libbe/storage/util/config.py b/libbe/storage/util/config.py
index f53f5b2..c6546a0 100644
--- a/libbe/storage/util/config.py
+++ b/libbe/storage/util/config.py
@@ -69,7 +69,7 @@ def set_val(name, value, section="DEFAULT", encoding=None):
encoding : str
The config file's encoding, defaults to :py:data:`default_encoding`.
"""
- if encoding == None:
+ if encoding is None:
encoding = default_encoding
config = configparser.ConfigParser()
if os.path.exists(path()) == False: # touch file or config
@@ -112,7 +112,7 @@ def get_val(name, section="DEFAULT", default=None, encoding=None):
True
"""
if os.path.exists(path()):
- if encoding == None:
+ if encoding is None:
encoding = default_encoding
config = configparser.ConfigParser()
f = codecs.open(path(), 'r', encoding)
diff --git a/libbe/storage/util/properties.py b/libbe/storage/util/properties.py
index 6a2b964..4489a44 100644
--- a/libbe/storage/util/properties.py
+++ b/libbe/storage/util/properties.py
@@ -42,50 +42,53 @@ import copy
import types
import libbe
+
if libbe.TESTING:
import unittest
-class ValueCheckError (ValueError):
+class ValueCheckError(ValueError):
def __init__(self, name, value, allowed):
- action = "in" # some list of allowed values
- if type(allowed) == types.FunctionType:
- action = "allowed by" # some allowed-value check function
+ action = "in" # some list of allowed values
+ if isinstance(allowed, types.FunctionType):
+ action = "allowed by" # some allowed-value check function
msg = "%s not %s %s for %s" % (value, action, allowed, name)
ValueError.__init__(self, msg)
self.name = name
self.value = value
self.allowed = allowed
+
def Property(funcs):
"""
End a chain of property decorators, returning a property.
"""
- args = {}
- args["fget"] = funcs.get("fget", None)
- args["fset"] = funcs.get("fset", None)
- args["fdel"] = funcs.get("fdel", None)
- args["doc"] = funcs.get("doc", None)
-
- #print("Creating a property with")
- #for key, val in args.items(): print(key, value)
+ args = {"fget": funcs.get("fget", None), "fset": funcs.get("fset", None), "fdel": funcs.get("fdel", None),
+ "doc": funcs.get("doc", None)}
+
+ # print("Creating a property with")
+ # for key, val in args.items(): print(key, value)
return property(**args)
+
def doc_property(doc=None):
"""
Add a docstring to a chain of property decorators.
"""
+
def decorator(funcs=None):
"""
Takes either a dict of funcs {"fget":fnX, "fset":fnY, ...}
or a function fn() returning such a dict.
"""
if hasattr(funcs, "__call__"):
- funcs = funcs() # convert from function-arg to dict
+ funcs = funcs() # convert from function-arg to dict
funcs["doc"] = doc
return funcs
+
return decorator
+
def local_property(name, null=None, mutable_null=False):
"""
Define get/set access to per-parent-instance local storage. Uses
@@ -95,11 +98,13 @@ def local_property(name, null=None, mutable_null=False):
If mutable_null == True, we only release deepcopies of the null to
the outside world.
"""
+
def decorator(funcs):
if hasattr(funcs, "__call__"):
funcs = funcs()
fget = funcs.get("fget", None)
fset = funcs.get("fset", None)
+
def _fget(self):
if fget is not None:
fget(self)
@@ -109,40 +114,49 @@ def local_property(name, null=None, mutable_null=False):
ret_null = null
value = getattr(self, "_%s_value" % name, ret_null)
return value
+
def _fset(self, value):
setattr(self, "_%s_value" % name, value)
if fset is not None:
fset(self, value)
+
funcs["fget"] = _fget
funcs["fset"] = _fset
funcs["name"] = name
return funcs
+
return decorator
+
def settings_property(name, null=None):
"""
Similar to local_property, except where local_property stores the
value in instance._<name>_value, settings_property stores the
value in instance.settings[name].
"""
+
def decorator(funcs):
if hasattr(funcs, "__call__"):
funcs = funcs()
fget = funcs.get("fget", None)
fset = funcs.get("fset", None)
+
def _fget(self):
if fget is not None:
fget(self)
value = self.settings.get(name, null)
return value
+
def _fset(self, value):
self.settings[name] = value
if fset is not None:
fset(self, value)
+
funcs["fget"] = _fget
funcs["fset"] = _fset
funcs["name"] = name
return funcs
+
return decorator
@@ -158,22 +172,30 @@ def settings_property(name, null=None):
# True
def _hash_mutable_value(value):
return repr(value)
+
+
def _init_mutable_property_cache(self):
if not hasattr(self, "_mutable_property_cache_hash"):
# first call to _fget for any mutable property
self._mutable_property_cache_hash = {}
self._mutable_property_cache_copy = {}
+
+
def _set_cached_mutable_property(self, cacher_name, property_name, value):
_init_mutable_property_cache(self)
self._mutable_property_cache_hash[(cacher_name, property_name)] = \
_hash_mutable_value(value)
self._mutable_property_cache_copy[(cacher_name, property_name)] = \
copy.deepcopy(value)
+
+
def _get_cached_mutable_property(self, cacher_name, property_name, default=None):
_init_mutable_property_cache(self)
if (cacher_name, property_name) not in self._mutable_property_cache_copy:
return default
return self._mutable_property_cache_copy[(cacher_name, property_name)]
+
+
def _eq_cached_mutable_property(self, cacher_name, property_name, value, default=None):
_init_mutable_property_cache(self)
if (cacher_name, property_name) not in self._mutable_property_cache_hash:
@@ -194,12 +216,14 @@ def defaulting_property(default=None, null=None,
null should never escape to the outside world, so don't worry
about it being a mutable.
"""
+
def decorator(funcs):
if hasattr(funcs, "__call__"):
funcs = funcs()
fget = funcs.get("fget")
fset = funcs.get("fset")
name = funcs.get("name", "<unknown>")
+
def _fget(self):
value = fget(self)
if value == null:
@@ -208,63 +232,81 @@ def defaulting_property(default=None, null=None,
else:
return default
return value
+
def _fset(self, value):
if value == default:
value = null
fset(self, value)
+
funcs["fget"] = _fget
funcs["fset"] = _fset
return funcs
+
return decorator
+
def fn_checked_property(value_allowed_fn):
"""
Define allowed values for get/set access to a property.
"""
+
def decorator(funcs):
if hasattr(funcs, "__call__"):
funcs = funcs()
fget = funcs.get("fget")
fset = funcs.get("fset")
name = funcs.get("name", "<unknown>")
+
def _fget(self):
value = fget(self)
- if value_allowed_fn(value) != True:
+ if not value_allowed_fn(value):
raise ValueCheckError(name, value, value_allowed_fn)
return value
+
def _fset(self, value):
- if value_allowed_fn(value) != True:
+ if not value_allowed_fn(value):
raise ValueCheckError(name, value, value_allowed_fn)
fset(self, value)
+
funcs["fget"] = _fget
funcs["fset"] = _fset
return funcs
+
return decorator
-def checked_property(allowed=[]):
+
+def checked_property(allowed=None):
"""
Define allowed values for get/set access to a property.
"""
+
def decorator(funcs):
if hasattr(funcs, "__call__"):
funcs = funcs()
fget = funcs.get("fget")
fset = funcs.get("fset")
name = funcs.get("name", "<unknown>")
+
def _fget(self):
value = fget(self)
if value not in allowed:
raise ValueCheckError(name, value, allowed)
return value
+
def _fset(self, value):
if value not in allowed:
raise ValueCheckError(name, value, allowed)
fset(self, value)
+
funcs["fget"] = _fget
funcs["fset"] = _fset
return funcs
+ if allowed is None:
+ allowed = []
+
return decorator
+
def cached_property(generator, initVal=None, mutable=False):
"""
Allow caching of values generated by generator(instance), where
@@ -291,11 +333,13 @@ def cached_property(generator, initVal=None, mutable=False):
generator is called whenever the cached value would otherwise be
used.
"""
+
def decorator(funcs):
if hasattr(funcs, "__call__"):
funcs = funcs()
fget = funcs.get("fget")
name = funcs.get("name", "<unknown>")
+
def _fget(self):
cache = getattr(self, "_%s_cache" % name, True)
value = fget(self)
@@ -309,10 +353,13 @@ def cached_property(generator, initVal=None, mutable=False):
else:
value = generator(self)
return value
+
funcs["fget"] = _fget
return funcs
+
return decorator
+
def primed_property(primer, initVal=None, unprimeableVal=None):
"""
Just like a cached_property, except that instead of returning a
@@ -326,14 +373,17 @@ def primed_property(primer, initVal=None, unprimeableVal=None):
whenever ._<name>_prime is True, or is False or missing and
value == initVal.
"""
+
def decorator(funcs):
if hasattr(funcs, "__call__"):
funcs = funcs()
fget = funcs.get("fget")
name = funcs.get("name", "<unknown>")
+
def _fget(self):
prime = getattr(self, "_%s_prime" % name, False)
- if prime == False:
+ value = None
+ if not prime:
value = fget(self)
if prime == True or (prime == False and value == initVal):
primer(self)
@@ -341,10 +391,13 @@ def primed_property(primer, initVal=None, unprimeableVal=None):
if prime == False and value == initVal:
return unprimeableVal
return value
+
funcs["fget"] = _fget
return funcs
+
return decorator
+
def change_hook_property(hook, mutable=False, default=None):
"""Call the function `hook` whenever a value different from the
current value is set.
@@ -373,40 +426,46 @@ def change_hook_property(hook, mutable=False, default=None):
`hook(instance, old_value, new_value)`, where `instance` is a
reference to the class instance to which this property belongs.
"""
+
def decorator(funcs):
if hasattr(funcs, "__call__"):
funcs = funcs()
fget = funcs.get("fget")
fset = funcs.get("fset")
name = funcs.get("name", "<unknown>")
- def _fget(self, new_value=None, from_fset=False): # only used if mutable == True
+
+ def _fget(self, new_value=None, from_fset=False): # only used if mutable == True
if from_fset:
- value = new_value # compare new value with cached
+ value = new_value # compare new value with cached
else:
- value = fget(self) # compare current value with cached
+ value = fget(self) # compare current value with cached
if _eq_cached_mutable_property(self, "change hook property", name, value, default) != 0:
# there has been a change, cache new value
old_value = _get_cached_mutable_property(self, "change hook property", name, default)
_set_cached_mutable_property(self, "change hook property", name, value)
- if from_fset: # return previously cached value
+ if from_fset: # return previously cached value
value = old_value
- else: # the value changed while we weren't looking
+ else: # the value changed while we weren't looking
hook(self, old_value, value)
return value
+
def _fset(self, value):
- if mutable: # get cached previous value
+ if mutable: # get cached previous value
old_value = _fget(self, new_value=value, from_fset=True)
else:
old_value = fget(self)
fset(self, value)
if value != old_value:
hook(self, old_value, value)
+
if mutable:
funcs["fget"] = _fget
funcs["fset"] = _fset
return funcs
+
return decorator
+
if libbe.TESTING:
class DecoratorTests(unittest.TestCase):
def testLocalDoc(self):
@@ -415,40 +474,48 @@ if libbe.TESTING:
@doc_property("A fancy property")
def x():
return {}
+
self.assertTrue(Test.x.__doc__ == "A fancy property",
Test.x.__doc__)
+
def testLocalProperty(self):
class Test(object):
@Property
@local_property(name="LOCAL")
def x():
return {}
+
t = Test()
- self.assertTrue(t.x == None, str(t.x))
- t.x = 'z' # the first set initializes ._LOCAL_value
+ self.assertTrue(t.x is None, str(t.x))
+ t.x = 'z' # the first set initializes ._LOCAL_value
self.assertTrue(t.x == 'z', str(t.x))
self.assertTrue("_LOCAL_value" in dir(t), dir(t))
self.assertTrue(t._LOCAL_value == 'z', t._LOCAL_value)
+
def testSettingsProperty(self):
class Test(object):
@Property
@settings_property(name="attr")
def x():
return {}
+
def __init__(self):
self.settings = {}
+
t = Test()
- self.assertTrue(t.x == None, str(t.x))
- t.x = 'z' # the first set initializes ._LOCAL_value
+ self.assertTrue(t.x is None, str(t.x))
+ t.x = 'z' # the first set initializes ._LOCAL_value
self.assertTrue(t.x == 'z', str(t.x))
self.assertTrue("attr" in t.settings, t.settings)
self.assertTrue(t.settings["attr"] == 'z', t.settings["attr"])
+
def testDefaultingLocalProperty(self):
class Test(object):
@Property
@defaulting_property(default='y', null='x')
@local_property(name="DEFAULT", null=5)
def x(): return {}
+
t = Test()
self.assertTrue(t.x == 5, str(t.x))
t.x = 'x'
@@ -459,14 +526,17 @@ if libbe.TESTING:
self.assertTrue(t.x == 'z', str(t.x))
t.x = 5
self.assertTrue(t.x == 5, str(t.x))
+
def testCheckedLocalProperty(self):
class Test(object):
@Property
@checked_property(allowed=['x', 'y', 'z'])
@local_property(name="CHECKED")
def x(): return {}
+
def __init__(self):
self._CHECKED_value = 'x'
+
t = Test()
self.assertTrue(t.x == 'x', str(t.x))
try:
@@ -475,6 +545,7 @@ if libbe.TESTING:
except ValueCheckError as e:
pass
self.assertTrue(type(e) == ValueCheckError, type(e))
+
def testTwoCheckedLocalProperties(self):
class Test(object):
@Property
@@ -486,9 +557,11 @@ if libbe.TESTING:
@checked_property(allowed=['a', 'b', 'c'])
@local_property(name="A")
def a(): return {}
+
def __init__(self):
self._A_value = 'a'
self._X_value = 'x'
+
t = Test()
try:
t.x = 'a'
@@ -508,14 +581,17 @@ if libbe.TESTING:
t.a = 'a'
t.a = 'b'
t.a = 'c'
+
def testFnCheckedLocalProperty(self):
class Test(object):
@Property
- @fn_checked_property(lambda v : v in ['x', 'y', 'z'])
+ @fn_checked_property(lambda v: v in ['x', 'y', 'z'])
@local_property(name="CHECKED")
def x(): return {}
+
def __init__(self):
self._CHECKED_value = 'x'
+
t = Test()
self.assertTrue(t.x == 'x', str(t.x))
try:
@@ -524,57 +600,65 @@ if libbe.TESTING:
except ValueCheckError as e:
pass
self.assertTrue(type(e) == ValueCheckError, type(e))
+
def testCachedLocalProperty(self):
class Gen(object):
def __init__(self):
self.i = 0
+
def __call__(self, owner):
self.i += 1
return self.i
+
class Test(object):
@Property
@cached_property(generator=Gen(), initVal=None)
@local_property(name="CACHED")
def x(): return {}
+
t = Test()
self.assertFalse("_CACHED_cache" in dir(t),
- getattr(t, "_CACHED_cache", None))
+ getattr(t, "_CACHED_cache", None))
self.assertTrue(t.x == 1, t.x)
self.assertTrue(t.x == 1, t.x)
self.assertTrue(t.x == 1, t.x)
t.x = 8
self.assertTrue(t.x == 8, t.x)
self.assertTrue(t.x == 8, t.x)
- t._CACHED_cache = False # Caching is off, but the stored value
- val = t.x # is 8, not the initVal (None), so we
- self.assertTrue(val == 8, val) # get 8.
- t._CACHED_value = None # Now we've set the stored value to None
- val = t.x # so future calls to fget (like this)
- self.assertTrue(val == 2, val) # will call the generator every time...
+ t._CACHED_cache = False # Caching is off, but the stored value
+ val = t.x # is 8, not the initVal (None), so we
+ self.assertTrue(val == 8, val) # get 8.
+ t._CACHED_value = None # Now we've set the stored value to None
+ val = t.x # so future calls to fget (like this)
+ self.assertTrue(val == 2, val) # will call the generator every time...
val = t.x
self.assertTrue(val == 3, val)
val = t.x
self.assertTrue(val == 4, val)
- t._CACHED_cache = True # We turn caching back on, and get
- self.assertTrue(t.x == 1, str(t.x)) # the original cached value.
- del t._CACHED_cached_value # Removing that value forces a
- self.assertTrue(t.x == 5, str(t.x)) # single cache-regenerating call
- self.assertTrue(t.x == 5, str(t.x)) # to the genenerator, after which
- self.assertTrue(t.x == 5, str(t.x)) # we get the new cached value.
+ t._CACHED_cache = True # We turn caching back on, and get
+ self.assertTrue(t.x == 1, str(t.x)) # the original cached value.
+ del t._CACHED_cached_value # Removing that value forces a
+ self.assertTrue(t.x == 5, str(t.x)) # single cache-regenerating call
+ self.assertTrue(t.x == 5, str(t.x)) # to the genenerator, after which
+ self.assertTrue(t.x == 5, str(t.x)) # we get the new cached value.
+
def testPrimedLocalProperty(self):
class Test(object):
def prime(self):
self.settings["PRIMED"] = self.primeVal
+
@Property
@primed_property(primer=prime, initVal=None, unprimeableVal=2)
@settings_property(name="PRIMED")
def x(): return {}
+
def __init__(self):
- self.settings={}
+ self.settings = {}
self.primeVal = "initialized"
+
t = Test()
self.assertFalse("_PRIMED_prime" in dir(t),
- getattr(t, "_PRIMED_prime", None))
+ getattr(t, "_PRIMED_prime", None))
self.assertTrue(t.x == "initialized", t.x)
t.x = 1
self.assertTrue(t.x == 1, t.x)
@@ -590,6 +674,7 @@ if libbe.TESTING:
t.x = None
t.primeVal = None
self.assertTrue(t.x == 2, t.x)
+
def testChangeHookLocalProperty(self):
class Test(object):
def _hook(self, old, new):
@@ -600,16 +685,18 @@ if libbe.TESTING:
@change_hook_property(_hook)
@local_property(name="HOOKED")
def x(): return {}
+
t = Test()
t.x = 1
- self.assertTrue(t.old == None, t.old)
+ self.assertTrue(t.old is None, t.old)
self.assertTrue(t.new == 1, t.new)
t.x = 1
- self.assertTrue(t.old == None, t.old)
+ self.assertTrue(t.old is None, t.old)
self.assertTrue(t.new == 1, t.new)
t.x = 2
self.assertTrue(t.old == 1, t.old)
self.assertTrue(t.new == 2, t.new)
+
def testChangeHookMutableProperty(self):
class Test(object):
def _hook(self, old, new):
@@ -621,10 +708,11 @@ if libbe.TESTING:
@change_hook_property(_hook, mutable=True)
@local_property(name="HOOKED")
def x(): return {}
+
t = Test()
t.hook_calls = 0
t.x = []
- self.assertTrue(t.old == None, t.old)
+ self.assertTrue(t.old is None, t.old)
self.assertTrue(t.new == [], t.new)
self.assertTrue(t.hook_calls == 1, t.hook_calls)
a = t.x
@@ -650,19 +738,20 @@ if libbe.TESTING:
self.assertTrue(t.old == [], t.old)
self.assertTrue(t.new == [5], t.new)
self.assertTrue(t.hook_calls == 4, t.hook_calls)
- t.x.append(6) # this append(6) is not noticed yet
+ t.x.append(6) # this append(6) is not noticed yet
self.assertTrue(t.old == [], t.old)
- self.assertTrue(t.new == [5,6], t.new)
+ self.assertTrue(t.new == [5, 6], t.new)
self.assertTrue(t.hook_calls == 4, t.hook_calls)
# this append(7) is not noticed, but the t.x get causes the
# append(6) to be noticed
t.x.append(7)
self.assertTrue(t.old == [5], t.old)
- self.assertTrue(t.new == [5,6,7], t.new)
+ self.assertTrue(t.new == [5, 6, 7], t.new)
self.assertTrue(t.hook_calls == 5, t.hook_calls)
- a = t.x # now the append(7) is noticed
- self.assertTrue(t.old == [5,6], t.old)
- self.assertTrue(t.new == [5,6,7], t.new)
+ a = t.x # now the append(7) is noticed
+ self.assertTrue(t.old == [5, 6], t.old)
+ self.assertTrue(t.new == [5, 6, 7], t.new)
self.assertTrue(t.hook_calls == 6, t.hook_calls)
+
suite = unittest.TestLoader().loadTestsFromTestCase(DecoratorTests)
diff --git a/libbe/storage/util/settings_object.py b/libbe/storage/util/settings_object.py
index d872f49..8981e35 100644
--- a/libbe/storage/util/settings_object.py
+++ b/libbe/storage/util/settings_object.py
@@ -57,7 +57,7 @@ class EMPTY (_Token):
def prop_save_settings(self, old, new):
"""The default action undertaken when a property changes.
"""
- if self.storage != None and self.storage.is_writeable():
+ if self.storage is not None and self.storage.is_writeable():
self.save_settings()
def prop_load_settings(self):
@@ -68,7 +68,7 @@ def prop_load_settings(self):
`._setup_saved_settings()` internally. If `.storage` is
inaccessible, don't do anything.
"""
- if self.storage != None and self.storage.is_readable():
+ if self.storage is not None and self.storage.is_readable():
self.load_settings()
# Some name-mangling routines for pretty printing setting names
@@ -160,18 +160,18 @@ def versioned_property(name, doc,
required_saved_properties.append(name)
def decorator(funcs):
fulldoc = doc
- if default != None or generator == None:
+ if default is not None or generator is None:
defaulting = defaulting_property(default=default, null=EMPTY,
mutable_default=mutable)
fulldoc += "\n\nThis property defaults to %s." % default
- if generator != None:
+ if generator is not None:
cached = cached_property(generator=generator, initVal=EMPTY,
mutable=mutable)
fulldoc += "\n\nThis property is generated with %s." % generator
- if check_fn != None:
+ if check_fn is not None:
fn_checked = fn_checked_property(value_allowed_fn=check_fn)
fulldoc += "\n\nThis property is checked with %s." % check_fn
- if allowed != None:
+ if allowed is not None:
checked = checked_property(allowed=allowed)
fulldoc += "\n\nThe allowed values for this property are: %s." \
% (', '.join(allowed))
@@ -182,13 +182,13 @@ def versioned_property(name, doc,
settings = settings_property(name=name, null=UNPRIMED)
docp = doc_property(doc=fulldoc)
deco = hooked(primed(settings(docp(funcs))))
- if default != None or generator == None:
+ if default is not None or generator is None:
deco = defaulting(deco)
- if generator != None:
+ if generator is not None:
deco = cached(deco)
- if check_fn != None:
+ if check_fn is not None:
deco = fn_checked(deco)
- if allowed != None:
+ if allowed is not None:
deco = checked(deco)
return Property(deco)
return decorator
@@ -233,7 +233,7 @@ class SavedSettingsObject(object):
Sets up a settings dict loaded from storage. Fills in
all missing settings entries with EMPTY.
"""
- if settings == None:
+ if settings is None:
settings = {}
for property in self.settings_properties:
if property not in self.settings \
@@ -274,7 +274,7 @@ class SavedSettingsObject(object):
def clear_cached_setting(self, setting=None):
"If setting=None, clear *all* cached settings"
- if setting != None:
+ if setting is not None:
if hasattr(self, "_%s_cached_value" % setting):
delattr(self, "_%s_cached_value" % setting)
else:
@@ -342,20 +342,20 @@ if libbe.TESTING == True:
# accessing t.content_type triggers the priming, but
# t.storage.is_readable() == False, so nothing happens.
t.storage.readable = False
- self.assertTrue(t.content_type == None, t.content_type)
+ self.assertTrue(t.content_type is None, t.content_type)
self.assertTrue(t.settings == {}, t.settings)
self.assertTrue(len(t.settings) == 0, len(t.settings))
- self.assertTrue(t.content_type == None, t.content_type)
+ self.assertTrue(t.content_type is None, t.content_type)
# accessing t.content_type triggers the priming again, and
# now that t.storage.is_readable() == True, this fills out
# t.settings with EMPTY data. At this point there should
# be one load and no saves.
t.storage.readable = True
- self.assertTrue(t.content_type == None, t.content_type)
+ self.assertTrue(t.content_type is None, t.content_type)
self.assertTrue(len(t.settings) == 1, len(t.settings))
self.assertTrue(t.settings["Content-type"] == EMPTY,
t.settings["Content-type"])
- self.assertTrue(t.content_type == None, t.content_type)
+ self.assertTrue(t.content_type is None, t.content_type)
self.assertTrue(t.load_count == 1, t.load_count)
self.assertTrue(len(t.storage) == 0, len(t.storage))
# an explicit call to load settings forces a reload,
@@ -364,7 +364,7 @@ if libbe.TESTING == True:
self.assertTrue(len(t.settings) == 1, len(t.settings))
self.assertTrue(t.settings["Content-type"] == EMPTY,
t.settings["Content-type"])
- self.assertTrue(t.content_type == None, t.content_type)
+ self.assertTrue(t.content_type is None, t.content_type)
self.assertTrue(t.load_count == 2, t.load_count)
self.assertTrue(len(t.storage) == 0, len(t.storage))
# now we set a value
@@ -400,7 +400,7 @@ if libbe.TESTING == True:
t.content_type = EMPTY
self.assertTrue(t.settings["Content-type"] == EMPTY,
t.settings["Content-type"])
- self.assertTrue(t.content_type == None, t.content_type)
+ self.assertTrue(t.content_type is None, t.content_type)
self.assertTrue(len(t.settings) == 1, len(t.settings))
self.assertTrue(t.settings["Content-type"] == EMPTY,
t.settings["Content-type"])
@@ -592,7 +592,7 @@ if libbe.TESTING == True:
def list_type(): return {}
t = Test()
self.assertTrue(len(t.storage) == 0, len(t.storage))
- self.assertTrue(t.list_type == None, t.list_type)
+ self.assertTrue(t.list_type is None, t.list_type)
self.assertTrue(len(t.storage) == 0, len(t.storage))
self.assertTrue(t.settings["List-type"]==EMPTY,
t.settings["List-type"])
@@ -614,6 +614,6 @@ if libbe.TESTING == True:
{'List-type':[5]}],
t.storage)
- unitsuite = unittest.TestLoader().loadTestsFromTestCase( \
+ unitsuite = unittest.TestLoader().loadTestsFromTestCase(
SavedSettingsObjectTests)
suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()])
diff --git a/libbe/storage/util/upgrade.py b/libbe/storage/util/upgrade.py
index 12d177a..6b278f1 100644
--- a/libbe/storage/util/upgrade.py
+++ b/libbe/storage/util/upgrade.py
@@ -117,7 +117,7 @@ class Upgrader (object):
self.repo = repo
vcs_name = self._get_vcs_name()
- if vcs_name == None:
+ if vcs_name is None:
vcs_name = 'None'
self.vcs = libbe.storage.vcs.vcs_by_name(vcs_name)
self.vcs.repo = self.repo
diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py
index 0521e90..813905c 100644
--- a/libbe/storage/vcs/base.py
+++ b/libbe/storage/vcs/base.py
@@ -430,7 +430,7 @@ class VCS (libbe.storage.base.VersionedStorage):
Get the file contents as they were in a given revision.
Revision==None specifies the current revision.
"""
- if revision != None:
+ if revision is not None:
raise libbe.storage.base.InvalidRevision(
'The %s VCS does not support revision specifiers' % self.name)
path = os.path.join(self.repo, path)
@@ -553,7 +553,7 @@ class VCS (libbe.storage.base.VersionedStorage):
-1
"""
if not hasattr(self, '_parsed_version') \
- or self._parsed_version == None:
+ or self._parsed_version is None:
num_part = self.version().split(' ')[0]
self._parsed_version = []
for num in num_part.split('.'):
@@ -598,7 +598,7 @@ class VCS (libbe.storage.base.VersionedStorage):
return -1
def installed(self):
- if self.version() != None:
+ if self.version() is not None:
return True
return False
@@ -769,7 +769,7 @@ class VCS (libbe.storage.base.VersionedStorage):
self._cached_path_id.remove_id(id)
def _ancestors(self, id=None, revision=None):
- if id==None:
+ if id is None:
path = self.be_dir
else:
path = self.path(id, revision, relpath=False)
@@ -794,7 +794,7 @@ class VCS (libbe.storage.base.VersionedStorage):
self._u_rel_path(path), revision)
listdir = lambda path : self._vcs_listdir(
self._u_rel_path(path), revision)
- if id==None:
+ if id is None:
path = self.be_dir
else:
path = self.path(id, revision, relpath=False)
@@ -813,7 +813,7 @@ class VCS (libbe.storage.base.VersionedStorage):
if c is None: continue
cpath = os.path.join(path, c)
children[i] = self._u_path_to_id(cpath)
- return [c for c in children if c != None]
+ return [c for c in children if c is not None]
def _get(self, id, default=libbe.util.InvalidObject, revision=None):
try:
@@ -1017,7 +1017,7 @@ class VCS (libbe.storage.base.VersionedStorage):
'/a.b/c/.be'
"""
if root is None:
- assert self.repo != None, "VCS not rooted"
+ assert self.repo is not None, "VCS not rooted"
root = self.repo
return os.path.abspath(os.path.join(root, path))
@@ -1138,7 +1138,7 @@ if libbe.TESTING:
dp = os.path.realpath(self.dirname)
vcs_name = self.Class.name
self.assertTrue(
- dp == rp or rp == None,
+ dp == rp or rp is None,
"%(vcs_name)s VCS root in wrong dir (%(dp)s %(rp)s)" % vars())
class VCS_get_user_id_TestCase(VCSTestCase):
@@ -1151,7 +1151,7 @@ if libbe.TESTING:
if user_id is None:
return
name,email = libbe.ui.util.user.parse_user_id(user_id)
- if email != None:
+ if email is not None:
self.assertTrue('@' in email, email)
def make_vcs_testcase_subclasses(vcs_class, namespace):
diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py
index 6da299a..fa5b879 100644
--- a/libbe/storage/vcs/bzr.py
+++ b/libbe/storage/vcs/bzr.py
@@ -64,7 +64,7 @@ class Bzr(base.VCS):
self.versioned = True
def _vcs_version(self):
- if bzrlib == None:
+ if bzrlib is None:
return None
return bzrlib.__version__
@@ -77,7 +77,7 @@ class Bzr(base.VCS):
return c.username()
def _vcs_detect(self, path):
- if self._u_search_parent_directories(path, '.bzr') != None :
+ if self._u_search_parent_directories(path, '.bzr') is not None:
return True
return False
@@ -135,7 +135,7 @@ class Bzr(base.VCS):
pass
def _parse_revision_string(self, revision=None):
- if revision == None:
+ if revision is None:
return revision
rev_opt = bzrlib.option.Option.OPTIONS['revision']
try:
@@ -145,7 +145,7 @@ class Bzr(base.VCS):
return rev_spec
def _vcs_get_file_contents(self, path, revision=None):
- if revision == None:
+ if revision is None:
return base.VCS._vcs_get_file_contents(self, path, revision)
path = os.path.join(self.repo, path)
revision = self._parse_revision_string(revision)
diff --git a/libbe/storage/vcs/darcs.py b/libbe/storage/vcs/darcs.py
index 12eabf4..07ddb9e 100644
--- a/libbe/storage/vcs/darcs.py
+++ b/libbe/storage/vcs/darcs.py
@@ -178,7 +178,7 @@ class Darcs(base.VCS):
if revision is None:
return base.VCS._vcs_get_file_contents(self, path, revision)
if self.version_cmp(2, 0, 0) == 1:
- status,output,error = self._u_invoke_client( \
+ status,output,error = self._u_invoke_client(
'show', 'contents', '--patch', revision, path)
return output
# Darcs versions < 2.0.0pre2 lack the 'show contents' command
@@ -209,7 +209,7 @@ class Darcs(base.VCS):
if self.version_cmp(2, 3, 1) == 1:
# Sun Nov 15 20:32:06 EST 2009 thomashartman1@gmail.com
# * add versioned show files functionality (darcs show files -p 'some patch')
- status,output,error = self._u_invoke_client( \
+ status,output,error = self._u_invoke_client(
'show', 'files', '--no-files', '--patch', revision)
children = output.rstrip('\n').splitlines()
rpath = '.'
@@ -227,7 +227,7 @@ class Darcs(base.VCS):
# Wed Dec 9 05:42:21 EST 2009 Luca Molteni <volothamp@gmail.com>
# * resolve issue835 show file with file directory arguments
path = path.rstrip(os.path.sep)
- status,output,error = self._u_invoke_client( \
+ status,output,error = self._u_invoke_client(
'show', 'files', '--patch', revision, path)
files = output.rstrip('\n').splitlines()
if path == '.':
@@ -243,7 +243,7 @@ class Darcs(base.VCS):
def _vcs_commit(self, commitfile, allow_empty=False):
id = self.get_user_id()
- if id == None or '@' not in id:
+ if id is None or '@' not in id:
id = '%s <%s@invalid.com>' % (id, id)
args = ['record', '--all', '--author', id, '--logfile', commitfile]
status,output,error = self._u_invoke_client(*args)
diff --git a/libbe/storage/vcs/git.py b/libbe/storage/vcs/git.py
index 9a15c92..d8a966d 100644
--- a/libbe/storage/vcs/git.py
+++ b/libbe/storage/vcs/git.py
@@ -191,7 +191,7 @@ class PygitGit(base.VCS):
return eobj
def _vcs_get_file_contents(self, path, revision=None):
- if revision == None:
+ if revision is None:
return base.VCS._vcs_get_file_contents(self, path, revision)
else:
blob = self._git_get_object(path=path, revision=revision)
@@ -311,7 +311,7 @@ class ExecGit (PygitGit):
return None # Git has no infomation
def _vcs_detect(self, path):
- if self._u_search_parent_directories(path, '.git') != None :
+ if self._u_search_parent_directories(path, '.git') is not None:
return True
return False
@@ -339,7 +339,7 @@ class ExecGit (PygitGit):
if not os.path.isdir(self._u_abspath(path)):
self._u_invoke_client('rm', '-f', path)
def _vcs_get_file_contents(self, path, revision=None):
- if revision == None:
+ if revision is None:
return base.VCS._vcs_get_file_contents(self, path, revision)
else:
arg = '%s:%s' % (revision,path)
diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py
index 0ebdfb0..6198bc8 100644
--- a/libbe/storage/vcs/hg.py
+++ b/libbe/storage/vcs/hg.py
@@ -74,7 +74,7 @@ class Hg(base.VCS):
self.__updated = [] # work around http://mercurial.selenic.com/bts/issue618
def _vcs_version(self):
- if version == None:
+ if version is None:
return None
return version()
@@ -106,7 +106,7 @@ class Hg(base.VCS):
def _vcs_detect(self, path):
"""Detect whether a directory is revision-controlled using Mercurial"""
- if self._u_search_parent_directories(path, '.hg') != None:
+ if self._u_search_parent_directories(path, '.hg') is not None:
return True
return False
@@ -131,7 +131,7 @@ class Hg(base.VCS):
self.__updated.append(path) # work around http://mercurial.selenic.com/bts/issue618
def _vcs_get_file_contents(self, path, revision=None):
- if revision == None:
+ if revision is None:
return base.VCS._vcs_get_file_contents(self, path, revision)
else:
return self._u_invoke_client('cat', '-r', revision, path)
diff --git a/libbe/storage/vcs/monotone.py b/libbe/storage/vcs/monotone.py
index 1d74c5b..4eaced8 100644
--- a/libbe/storage/vcs/monotone.py
+++ b/libbe/storage/vcs/monotone.py
@@ -86,7 +86,7 @@ class Monotone (base.VCS):
-1
"""
if not hasattr(self, '_parsed_version') \
- or self._parsed_version == None:
+ or self._parsed_version is None:
self._parsed_version = [int(x) for x in self.version().split('.')]
for current,other in zip(self._parsed_version, args):
c = cmp(current,other)
@@ -129,7 +129,7 @@ class Monotone (base.VCS):
return None # Monotone has no infomation
def _vcs_detect(self, path):
- if self._u_search_parent_directories(path, '_MTN') != None :
+ if self._u_search_parent_directories(path, '_MTN') is not None:
return True
return False
@@ -153,11 +153,11 @@ class Monotone (base.VCS):
"""Invoke the client on our branch.
"""
arglist = []
- if self._db_path != None:
+ if self._db_path is not None:
arglist.extend(['--db', self._db_path])
- if self._key != None:
+ if self._key is not None:
arglist.extend(['--key', self._key])
- if self._key_dir != None:
+ if self._key_dir is not None:
arglist.extend(['--keydir', self._key_dir])
arglist.extend(args)
args = tuple(arglist)
diff --git a/libbe/ui/command_line.py b/libbe/ui/command_line.py
index b649e24..3b8089f 100644
--- a/libbe/ui/command_line.py
+++ b/libbe/ui/command_line.py
@@ -59,13 +59,13 @@ class CmdOptionParser(optparse.OptionParser):
option.validate()
self._option_by_name[option.name] = option
long_opt = '--%s' % option.name
- if option.short_name != None:
+ if option.short_name is not None:
short_opt = '-%s' % option.short_name
assert '_' not in option.name, \
'Non-reconstructable option name %s' % option.name
kwargs = {'dest':option.name.replace('-', '_'),
'help':option.help}
- if option.arg == None: # a callback option
+ if option.arg is None: # a callback option
kwargs['action'] = 'callback'
kwargs['callback'] = self.callback
elif option.arg.type == 'bool':
@@ -77,7 +77,7 @@ class CmdOptionParser(optparse.OptionParser):
kwargs['action'] = 'store'
kwargs['metavar'] = option.arg.metavar
kwargs['default'] = option.arg.default
- if option.short_name != None:
+ if option.short_name is not None:
opt = optparse.Option(short_opt, long_opt, **kwargs)
else:
opt = optparse.Option(long_opt, **kwargs)
@@ -95,7 +95,7 @@ class CmdOptionParser(optparse.OptionParser):
for name,value in list(options.items()):
argument = None
option = self._option_by_name[name]
- if option.arg != None:
+ if option.arg is not None:
argument = option.arg
if value == '--complete':
fragment = None
@@ -108,7 +108,7 @@ class CmdOptionParser(optparse.OptionParser):
name = args[i-1][2:]
if name == option.name:
break
- elif option.short_name != None \
+ elif option.short_name is not None \
and args[i-1].startswith('-') \
and args[i-1].endswith(option.short_name):
break
@@ -163,7 +163,7 @@ class CmdOptionParser(optparse.OptionParser):
def complete(self, argument=None, fragment=None):
comps = self.command.complete(argument, fragment)
- if fragment != None:
+ if fragment is not None:
comps = [c for c in comps if c.startswith(fragment)]
if len(comps) > 0:
print('\n'.join(comps), file=self.command.stdout)
@@ -258,7 +258,7 @@ class BE (libbe.command.Command):
cmdlist = []
for name in libbe.command.commands():
Class = libbe.command.get_command_class(command_name=name)
- assert hasattr(Class, '__doc__') and Class.__doc__ != None, \
+ assert hasattr(Class, '__doc__') and Class.__doc__ is not None, \
'Command class %s missing docstring' % Class
cmdlist.append((Class.name, Class.__doc__.splitlines()[0]))
cmdlist.sort()
diff --git a/libbe/ui/util/editor.py b/libbe/ui/util/editor.py
index 8412ff6..5ab519f 100644
--- a/libbe/ui/util/editor.py
+++ b/libbe/ui/util/editor.py
@@ -64,14 +64,14 @@ def editor_string(comment=None, encoding=None):
>>> del os.environ["EDITOR"]
>>> del os.environ["VISUAL"]
"""
- if encoding == None:
+ if encoding is None:
encoding = libbe.util.encoding.get_text_file_encoding()
editor = None
for name in ('VISUAL', 'EDITOR'):
if name in os.environ and os.environ[name] != '':
editor = os.environ[name]
break
- if editor == None:
+ if editor is None:
raise CantFindEditor()
fhandle, fname = tempfile.mkstemp()
try:
diff --git a/libbe/ui/util/user.py b/libbe/ui/util/user.py
index 4a4e7f1..1d7e874 100644
--- a/libbe/ui/util/user.py
+++ b/libbe/ui/util/user.py
@@ -92,7 +92,7 @@ def create_user_id(name, email=None):
parse_user_id : inverse
"""
assert len(name) > 0
- if email == None or len(email) == 0:
+ if email is None or len(email) == 0:
return name
else:
return formataddr((name, email))
@@ -137,11 +137,11 @@ def get_user_id(storage=None):
configured it directly.
"""
user = libbe.storage.util.config.get_val('user')
- if user != None:
+ if user is not None:
return user
- if storage != None and hasattr(storage, 'get_user_id'):
+ if storage is not None and hasattr(storage, 'get_user_id'):
user = storage.get_user_id()
- if user != None:
+ if user is not None:
return user
name = get_fallback_fullname()
email = get_fallback_email()
diff --git a/libbe/util/encoding.py b/libbe/util/encoding.py
index c5e242b..8a3b53e 100644
--- a/libbe/util/encoding.py
+++ b/libbe/util/encoding.py
@@ -45,18 +45,18 @@ def get_encoding():
Guess a useful input/output/filesystem encoding... Maybe we need
seperate encodings for input/output and filesystem? Hmm...
"""
- if ENCODING != None:
+ if ENCODING is not None:
return ENCODING
encoding = locale.getpreferredencoding() or sys.getdefaultencoding()
return encoding
def get_input_encoding():
- if INPUT_ENCODING != None:
+ if INPUT_ENCODING is not None:
return INPUT_ENCODING
return sys.__stdin__.encoding or get_encoding()
def get_output_encoding():
- if OUTPUT_ENCODING != None:
+ if OUTPUT_ENCODING is not None:
return OUTPUT_ENCODING
return sys.__stdout__.encoding or get_encoding()
@@ -83,7 +83,7 @@ def known_encoding(encoding):
def get_file_contents(path, mode='r', encoding=None, decode=False):
if decode == True:
- if encoding == None:
+ if encoding is None:
encoding = get_text_file_encoding()
f = codecs.open(path, mode, encoding)
else:
@@ -94,7 +94,7 @@ def get_file_contents(path, mode='r', encoding=None, decode=False):
def set_file_contents(path, contents, mode='w', encoding=None):
if type(contents) == str:
- if encoding == None:
+ if encoding is None:
encoding = get_text_file_encoding()
f = codecs.open(path, mode, encoding)
else:
diff --git a/libbe/util/id.py b/libbe/util/id.py
index 078dd3f..f4d19ae 100644
--- a/libbe/util/id.py
+++ b/libbe/util/id.py
@@ -156,7 +156,7 @@ class NoIDMatches (KeyError):
self.possible_ids = possible_ids
self.msg = msg
def __str__(self):
- if self.msg == None:
+ if self.msg is None:
return 'No id matches %s.\n%s' % (self.id, self.possible_ids)
return self.msg
@@ -175,7 +175,7 @@ class InvalidIDStructure (KeyError):
self.id = id
self.msg = msg
def __str__(self):
- if self.msg == None:
+ if self.msg is None:
return 'Invalid id structure "%s"' % self.id
return self.msg
@@ -188,7 +188,7 @@ def _assemble(args, check_length=False):
"""
args = list(args)
for i,arg in enumerate(args):
- if arg == None:
+ if arg is None:
args[i] = ''
id = '/'.join(args)
if check_length == True:
@@ -271,7 +271,7 @@ def _expand(truncated_id, common, other_ids):
other_ids = list(other_ids)
if len(other_ids) == 0:
raise NoIDMatches(truncated_id, other_ids)
- if truncated_id == None:
+ if truncated_id is None:
if len(other_ids) == 1:
return other_ids[0]
raise MultipleIDMatches(truncated_id, common, other_ids)
@@ -377,7 +377,7 @@ class ID (object):
def user(self):
ids = []
for o in self._ancestors():
- if o == None:
+ if o is None:
ids.append(None)
else:
ids.append(_truncate(o.uuid, o.sibling_uuids()))
@@ -480,7 +480,7 @@ class IDreplacer (object):
def __call__(self, match):
ids = []
for m in match.groups():
- if m == None:
+ if m is None:
m = ''
ids.append(m)
try:
@@ -577,7 +577,7 @@ def _parse_user(id):
ret = {}
args = _split(id, check_length=True)
for i,(type,arg) in enumerate(zip(HIERARCHY, args)):
- if arg != None and len(arg) == 0:
+ if arg is not None and len(arg) == 0:
raise InvalidIDStructure(
id, 'Invalid %s part %d "%s" of id "%s"' % (type, i, arg, id))
ret['type'] = type
@@ -609,7 +609,7 @@ if libbe.TESTING == True:
def __init__(self, uuid, parent=None, siblings=[]):
self.uuid = uuid
self._siblings = siblings
- if parent == None:
+ if parent is None:
type_i = 0
else:
assert parent.type in HIERARCHY, parent
diff --git a/libbe/util/subproc.py b/libbe/util/subproc.py
index 5412b08..912433f 100644
--- a/libbe/util/subproc.py
+++ b/libbe/util/subproc.py
@@ -54,7 +54,7 @@ def invoke(args, stdin=None, stdout=PIPE, stderr=PIPE, expect=(0,),
unicode_output == True, convert stdout and stdin strings to
unicode before returing them.
"""
- if cwd == None:
+ if cwd is None:
cwd = '.'
if isinstance(shell, (str,)):
list_args = ' '.split(args) # sloppy, but just for logging
@@ -81,11 +81,11 @@ def invoke(args, stdin=None, stdout=PIPE, stderr=PIPE, expect=(0,),
stdout,stderr = q.communicate(input=stdin)
status = q.wait()
if unicode_output == True:
- if encoding == None:
+ if encoding is None:
encoding = get_encoding()
- if stdout != None:
+ if stdout is not None:
stdout = str(stdout, encoding)
- if stderr != None:
+ if stderr is not None:
stderr = str(stderr, encoding)
libbe.LOG.debug('{0}\n{1}{2}'.format(status, stdout, stderr))
else:
diff --git a/libbe/util/wsgi.py b/libbe/util/wsgi.py
index cfa43be..9f22596 100644
--- a/libbe/util/wsgi.py
+++ b/libbe/util/wsgi.py
@@ -46,7 +46,7 @@ try:
import cherrypy.wsgiserver
except ImportError:
cherrypy = None
-if cherrypy != None:
+if cherrypy is not None:
try: # CherryPy >= 3.2
import cherrypy.wsgiserver.ssl_builtin
except ImportError: # CherryPy <= 3.1.X
@@ -239,9 +239,9 @@ class WSGI_Object (object):
req_uri += '?' + environ['QUERY_STRING']
start = time.localtime()
if time.daylight:
- offset = time.altzone / 60 / 60 * -100
+ offset = time.altzone // 60 // 60 * -100
else:
- offset = time.timezone / 60 / 60 * -100
+ offset = time.timezone // 60 // 60 * -100
if offset >= 0:
offset = '+{:04d}'.format(offset)
elif offset < 0:
@@ -800,7 +800,7 @@ if libbe.TESTING:
('Content-Type','text/plain'),
('X-Dummy-Header','Dummy Value')],
self.caller.response_headers)
- self.assertTrue(self.caller.exc_info == None, self.caller.exc_info)
+ self.assertTrue(self.caller.exc_info is None, self.caller.exc_info)
def test_log_request(self):
self.app.log_request(