lib/bup/client.py | 46 +++++++++++++++++-------------------
lib/bup/cmd/validate_refs.py | 7 +++---
lib/bup/cmd/web.py | 3 +--
lib/bup/git.py | 33 +++++++++++---------------
lib/bup/hashsplit.py | 22 ++++++++---------
lib/bup/helpers.py | 13 ++++------
lib/bup/index.py | 10 ++++----
lib/bup/io.py | 3 +--
lib/bup/metadata.py | 17 +++++--------
lib/bup/protocol.py | 2 +-
lib/bup/shquote.py | 16 +++++--------
lib/bup/vfs.py | 4 ++--
lib/bup/vint.py | 3 +--
lib/bup/xstat.py | 17 ++++++-------
test/int/test_metadata.py | 3 +--
16 files changed, 85 insertions(+), 115 deletions(-)
diff --git a/.pylintrc b/.pylintrc
index 8dd0e19c..8bd2c43e 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -46,6 +46,7 @@ enable=
logging-not-lazy,
no-else-continue,
no-else-raise,
+ no-else-return,
no-value-for-parameter,
redefined-outer-name,
reimported,
diff --git a/lib/bup/client.py b/lib/bup/client.py
index 335cad4b..1f8b261f 100644
--- a/lib/bup/client.py
+++ b/lib/bup/client.py
@@ -101,23 +101,22 @@ def _raw_write_bwlimit(f, buf, bwcount, bwtime):
if not bwlimit:
f.write(buf)
return (len(buf), time.time())
- else:
- # We want to write in reasonably large blocks, but not so large that
- # they're likely to overflow a router's queue. So our bwlimit timing
- # has to be pretty granular. Also, if it takes too long from one
- # transmit to the next, we can't just make up for lost time to bring
- # the average back up to bwlimit - that will risk overflowing the
- # outbound queue, which defeats the purpose. So if we fall behind
- # by more than one block delay, we shouldn't ever try to catch up.
- for i in range(0,len(buf),4096):
- now = time.time()
- next = max(now, bwtime + 1.0*bwcount/bwlimit)
- time.sleep(next-now)
- sub = buf[i:i+4096]
- f.write(sub)
- bwcount = len(sub) # might be less than 4096
- bwtime = next
- return (bwcount, bwtime)
+ # We want to write in reasonably large blocks, but not so large that
+ # they're likely to overflow a router's queue. So our bwlimit timing
+ # has to be pretty granular. Also, if it takes too long from one
+ # transmit to the next, we can't just make up for lost time to bring
+ # the average back up to bwlimit - that will risk overflowing the
+ # outbound queue, which defeats the purpose. So if we fall behind
+ # by more than one block delay, we shouldn't ever try to catch up.
+ for i in range(0,len(buf),4096):
+ now = time.time()
+ next = max(now, bwtime + 1.0*bwcount/bwlimit)
+ time.sleep(next-now)
+ sub = buf[i:i+4096]
+ f.write(sub)
+ bwcount = len(sub) # might be less than 4096
+ bwtime = next
+ return (bwcount, bwtime)
def _legacy_cache_id_for_host_path(host, path):
@@ -643,22 +642,21 @@ class Client:
raise EOFError('EOF while reading config value type')
if kind == 0:
return None
- elif kind == 1:
+ if kind == 1:
return True
- elif kind == 2:
+ if kind == 2:
return False
- elif kind == 3:
+ if kind == 3:
val = read_vint(conn)
if val is None: raise EOFError('EOF while reading vint')
return val
- elif kind == 4:
+ if kind == 4:
val = read_bvec(conn)
if val is None: raise EOFError('EOF while reading bvec')
return val
- elif kind == 5:
+ if kind == 5:
raise PermissionError(f'config-get does not allow remote access to {name}')
- else:
- raise TypeError(f'Unrecognized result type {kind}')
+ raise TypeError(f'Unrecognized result type {kind}')
class RemotePackStore:
diff --git a/lib/bup/cmd/validate_refs.py b/lib/bup/cmd/validate_refs.py
index 6e96e1f2..90d96e36 100644
--- a/lib/bup/cmd/validate_refs.py
+++ b/lib/bup/cmd/validate_refs.py
@@ -114,7 +114,7 @@ def main(argv):
exp_n = expected_bup_entry_count_for_tree(b''.join(info[3]))
if bupm_n == exp_n:
return True
- elif bupm_n > exp_n:
+ if bupm_n > exp_n:
bad_bupm += 1
log(f'error: tree with extra bupm entries ({bupm_n} > {exp_n})'
f' (please report): {parent.oid.hex()}\n')
@@ -143,9 +143,8 @@ def main(argv):
live_objs.close()
if bad_bupm:
return EXIT_FAILURE
- elif (ref_missing + found_missing + abridged_bupm):
+ if (ref_missing + found_missing + abridged_bupm):
if (ref_missing or found_missing) and not opt.links:
log('note: missing object list may be incomplete without --links\n')
return EXIT_FALSE
- else:
- return EXIT_TRUE
+ return EXIT_TRUE
diff --git a/lib/bup/cmd/web.py b/lib/bup/cmd/web.py
index c23a0959..0ef9ba8f 100644
--- a/lib/bup/cmd/web.py
+++ b/lib/bup/cmd/web.py
@@ -316,8 +316,7 @@ class BupRequestHandler(tornado.web.RequestHandler):
ext = ext.lower()
if ext in self.extensions_map:
return self.extensions_map[ext]
- else:
- return self.extensions_map['']
+ return self.extensions_map['']
if not mimetypes.inited:
mimetypes.init() # try to read system mime.types
diff --git a/lib/bup/git.py b/lib/bup/git.py
index 85c5d09f..3ecba804 100644
--- a/lib/bup/git.py
+++ b/lib/bup/git.py
@@ -80,7 +80,7 @@ def git_config_get(path, option, *, opttype=None):
if rc == 0:
if opttype == 'int':
return int(r)
- elif opttype == 'bool': # any positive int is true for git --bool
+ if opttype == 'bool': # any positive int is true for git --bool
if not r:
return None
if r in (b'0', b'false'):
@@ -169,10 +169,9 @@ def mangle_name(name, mode, gitmode):
if stat.S_ISREG(mode) and not stat.S_ISREG(gitmode):
assert(stat.S_ISDIR(gitmode))
return name + b'.bup'
- elif name.endswith(b'.bup') or name[:-1].endswith(b'.bup'):
+ if name.endswith(b'.bup') or name[:-1].endswith(b'.bup'):
return name + b'.bupl'
- else:
- return name
+ return name
(BUP_NORMAL, BUP_CHUNKED) = (0,1)
@@ -189,12 +188,12 @@ def demangle_name(name, mode):
"""
if name.endswith(b'.bupl'):
return (name[:-5], BUP_NORMAL)
- elif name.endswith(b'.bup'):
+ if name.endswith(b'.bup'):
return (name[:-4], BUP_CHUNKED)
- elif name.endswith(b'.bupm'):
+ if name.endswith(b'.bupm'):
return (name[:-5],
BUP_CHUNKED if stat.S_ISDIR(mode) else BUP_NORMAL)
- elif name.endswith(b'.bupd'): # should be unreachable
+ if name.endswith(b'.bupd'): # should be unreachable
raise ValueError(f'Cannot unmangle *.bupd files: {path_msg(name)}')
return (name, BUP_NORMAL)
@@ -730,24 +729,21 @@ def open_idx(filename):
if version == 2:
contexts.pop_all()
return PackIdxV2(filename, f)
- else:
- raise GitError('%s: expected idx file version 2, got %d'
- % (path_msg(filename), version))
- elif len(header) == 8 and header[0:4] < b'\377tOc':
+ raise GitError('%s: expected idx file version 2, got %d'
+ % (path_msg(filename), version))
+ if len(header) == 8 and header[0:4] < b'\377tOc':
contexts.pop_all()
return PackIdxV1(filename, f)
- else:
- raise GitError('%s: unrecognized idx file header'
- % path_msg(filename))
+ raise GitError('%s: unrecognized idx file header'
+ % path_msg(filename))
def open_object_idx(filename):
if filename.endswith(b'.idx'):
return open_idx(filename)
- elif filename.endswith(b'.midx'):
+ if filename.endswith(b'.midx'):
return open_midx(filename)
- else:
- raise GitError('pack index filenames must end with .idx or .midx')
+ raise GitError('pack index filenames must end with .idx or .midx')
def idxmerge(idxlist, final_progress=True):
@@ -1070,8 +1066,7 @@ def read_ref(refname, repo_dir = None):
if l:
assert(len(l) == 1)
return l[0][1]
- else:
- return None
+ return None
def rev_list_invocation(ref_or_refs, format=None):
diff --git a/lib/bup/hashsplit.py b/lib/bup/hashsplit.py
index 5a7f19f0..13a87406 100644
--- a/lib/bup/hashsplit.py
+++ b/lib/bup/hashsplit.py
@@ -108,15 +108,14 @@ def split_to_shalist(makeblob, maketree,
for (sha,size,level) in sl:
shal.append((GIT_MODE_FILE, sha, size))
return _make_shalist(shal)[0]
- else:
- stacks = [[]]
- for (sha,size,level) in sl:
- stacks[0].append((GIT_MODE_FILE, sha, size))
- _squish(maketree, stacks, level)
- #log('stacks: %r\n' % [len(i) for i in stacks])
- _squish(maketree, stacks, len(stacks)-1)
- #log('stacks: %r\n' % [len(i) for i in stacks])
- return _make_shalist(stacks[-1])[0]
+ stacks = [[]]
+ for (sha,size,level) in sl:
+ stacks[0].append((GIT_MODE_FILE, sha, size))
+ _squish(maketree, stacks, level)
+ #log('stacks: %r\n' % [len(i) for i in stacks])
+ _squish(maketree, stacks, len(stacks)-1)
+ #log('stacks: %r\n' % [len(i) for i in stacks])
+ return _make_shalist(stacks[-1])[0]
def split_to_blob_or_tree(makeblob, maketree,
@@ -125,7 +124,6 @@ def split_to_blob_or_tree(makeblob, maketree,
shalist = list(split_to_shalist(makeblob, maketree, splitter))
if len(shalist) == 1:
return (shalist[0][0], shalist[0][2])
- elif len(shalist) == 0:
+ if len(shalist) == 0:
return (GIT_MODE_FILE, makeblob(b''))
- else:
- return (GIT_MODE_TREE, maketree(shalist))
+ return (GIT_MODE_TREE, maketree(shalist))
diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py
index 8dd2aa05..2af42b88 100644
--- a/lib/bup/helpers.py
+++ b/lib/bup/helpers.py
@@ -331,9 +331,9 @@ def shstr(cmd):
"""
if isinstance(cmd, (bytes, str)):
return cmd
- elif all(isinstance(x, bytes) for x in cmd):
+ if all(isinstance(x, bytes) for x in cmd):
return b' '.join(map(bquote, cmd))
- elif all(isinstance(x, str) for x in cmd):
+ if all(isinstance(x, str) for x in cmd):
return ' '.join(map(squote, cmd))
raise TypeError('unsupported shstr argument: ' + repr(cmd))
@@ -507,8 +507,7 @@ class Conn(BaseConn):
if rl:
assert(rl[0] == self.inp.fileno())
return True
- else:
- return None
+ return None
def checked_reader(fd, n):
@@ -636,8 +635,7 @@ class DemuxConn(BaseConn):
if len(buf) < csize[0]:
csize[0] -= len(buf)
return None
- else:
- return csize[0]
+ return csize[0]
return b''.join(self._read_parts(until_size))
def has_input(self):
@@ -762,8 +760,7 @@ def slashappend(s):
assert isinstance(s, bytes)
if s and not s.endswith(b'/'):
return s + b'/'
- else:
- return s
+ return s
def _mmap_do(f, sz, flags, prot, close):
diff --git a/lib/bup/index.py b/lib/bup/index.py
index cc932108..948178e3 100644
--- a/lib/bup/index.py
+++ b/lib/bup/index.py
@@ -260,8 +260,7 @@ class Entry:
def _fixup_time(self, t):
if self.tmax is not None and t > self.tmax:
return self.tmax
- else:
- return t
+ return t
def is_valid(self):
f = IX_HASHVALID|IX_EXISTS
@@ -641,10 +640,9 @@ def _slashappend_or_add_error(p, caller):
except OSError as e:
add_error('%s: %s' % (caller, e))
return None
- else:
- if stat.S_ISDIR(st.st_mode):
- return slashappend(p)
- return p
+ if stat.S_ISDIR(st.st_mode):
+ return slashappend(p)
+ return p
def unique_resolved_paths(paths):
diff --git a/lib/bup/io.py b/lib/bup/io.py
index 844d1c9f..fe2bfa66 100644
--- a/lib/bup/io.py
+++ b/lib/bup/io.py
@@ -280,8 +280,7 @@ def walk_path_msg(ref_name, item_path):
path = f'{path_msg(item_path[root].name)}:{path}'
if S_ISDIR(item_path[-1].mode):
return f'{path_msg(ref_name)} {path}/'
- else:
- return f'{path_msg(ref_name)} {path}'
+ return f'{path_msg(ref_name)} {path}'
def qsql_id(s):
diff --git a/lib/bup/metadata.py b/lib/bup/metadata.py
index af64b2f3..42c3bb9d 100644
--- a/lib/bup/metadata.py
+++ b/lib/bup/metadata.py
@@ -183,10 +183,9 @@ def _clean_up_extract_path(p):
result = p.lstrip(b'/')
if result == b'':
return b'.'
- elif _risky_path(result):
+ if _risky_path(result):
return None
- else:
- return result
+ return result
# These tags are currently conceptually private to Metadata, and they
@@ -488,8 +487,7 @@ class Metadata:
def _encode_path(self):
if self.path:
return vint.pack('s', self.path)
- else:
- return None
+ return None
def _load_path_rec(self, port):
data = vint.read_bvec(port)
@@ -570,8 +568,7 @@ class Metadata:
if len(acls) == 2:
return vint.pack('ssss', acls[0], acls[1], b'', b'')
return vint.pack('ssss', acls[0], acls[1], acls[2], acls[3])
- else:
- return None
+ return None
@staticmethod
def _correct_posix1e_v1_delimiters(acls, path):
@@ -668,8 +665,7 @@ class Metadata:
def _encode_linux_attr(self):
if self.linux_attr:
return vint.pack('V', self.linux_attr)
- else:
- return None
+ return None
def _load_linux_attr_rec(self, port):
data = vint.read_bvec(port)
@@ -723,8 +719,7 @@ class Metadata:
for name, value in self.linux_xattr:
result += vint.pack('ss', name, value)
return result
- else:
- return None
+ return None
def _load_linux_xattr_rec(self, file):
data = vint.read_bvec(file)
diff --git a/lib/bup/protocol.py b/lib/bup/protocol.py
index 7158bf24..855ae400 100644
--- a/lib/bup/protocol.py
+++ b/lib/bup/protocol.py
@@ -266,7 +266,7 @@ class Server:
self.conn.write(b'%s.idx\n' % name)
self.conn.ok()
return
- elif n == 0xffffffff:
+ if n == 0xffffffff:
debug2('bup server: receive-objects suspending.\n')
self.suspended = True
self.conn.ok()
diff --git a/lib/bup/shquote.py b/lib/bup/shquote.py
index 303017dc..47065106 100644
--- a/lib/bup/shquote.py
+++ b/lib/bup/shquote.py
@@ -92,10 +92,8 @@ def unfinished_word(line):
if firstchar in [q, qq]:
# pylint: disable-next=used-before-assignment
return (firstchar, word)
- else:
- return (None, word)
- else:
- return (None, b'')
+ return (None, word)
+ return (None, b'')
def quotify(qtype, word, terminate):
"""Return a bytes corresponding to given word, quoted using qtype.
@@ -113,10 +111,9 @@ def quotify(qtype, word, terminate):
"""
if qtype == qq:
return qq + word.replace(qq, b'\\"') + (terminate and qq or b'')
- elif qtype == q:
+ if qtype == q:
return q + word.replace(q, b"\\'") + (terminate and q or b'')
- else:
- return re.sub(br'([\"\' \t\n\r])', br'\\\1', word)
+ return re.sub(br'([\"\' \t\n\r])', br'\\\1', word)
def quotify_list(words):
@@ -163,6 +160,5 @@ def what_to_add(qtype, origword, newword, terminate):
"""
if not newword.startswith(origword):
return b''
- else:
- qold = quotify(qtype, origword, terminate=False)
- return quotify(qtype, newword, terminate=terminate)[len(qold):]
+ qold = quotify(qtype, origword, terminate=False)
+ return quotify(qtype, newword, terminate=terminate)[len(qold):]
diff --git a/lib/bup/vfs.py b/lib/bup/vfs.py
index 643a07fc..92423ba0 100644
--- a/lib/bup/vfs.py
+++ b/lib/bup/vfs.py
@@ -432,7 +432,7 @@ def item_mode(item):
m = item.meta
if isinstance(m, Metadata):
return m.mode
- elif isinstance(m, int):
+ if isinstance(m, int):
return m
raise TypeError(f'not integer or Metadata {m!r}')
@@ -990,7 +990,7 @@ def tags_items(repo, names):
for _ in it: pass
if typ == b'blob':
return Item(meta=default_file_mode, oid=oid)
- elif typ == b'tree':
+ if typ == b'tree':
return Item(meta=default_dir_mode, oid=oid)
raise Exception('unexpected tag type ' + typ.decode('ascii')
+ ' for tag ' + path_msg(name))
diff --git a/lib/bup/vint.py b/lib/bup/vint.py
index 5f8f8a37..3bb5e6ae 100644
--- a/lib/bup/vint.py
+++ b/lib/bup/vint.py
@@ -115,8 +115,7 @@ def read_vint(port):
break
if negative:
return -result
- else:
- return result
+ return result
def write_bvec(port, x):
diff --git a/lib/bup/xstat.py b/lib/bup/xstat.py
index 6f98d67c..84062552 100644
--- a/lib/bup/xstat.py
+++ b/lib/bup/xstat.py
@@ -39,8 +39,7 @@ def fstime_to_sec_bytes(fstime):
s += 1
if ns == 0:
return b'%d' % s
- else:
- return b'%d.%09d' % (s, ns)
+ return b'%d.%09d' % (s, ns)
def utime(path, times):
"""Times must be provided as (atime_ns, mtime_ns)."""
@@ -113,18 +112,16 @@ def classification_str(mode, include_exec):
and (pystat.S_IMODE(mode) \
& (pystat.S_IXUSR | pystat.S_IXGRP | pystat.S_IXOTH)):
return '*'
- else:
- return ''
- elif pystat.S_ISDIR(mode):
+ return ''
+ if pystat.S_ISDIR(mode):
return '/'
- elif pystat.S_ISLNK(mode):
+ if pystat.S_ISLNK(mode):
return '@'
- elif pystat.S_ISFIFO(mode):
+ if pystat.S_ISFIFO(mode):
return '|'
- elif pystat.S_ISSOCK(mode):
+ if pystat.S_ISSOCK(mode):
return '='
- else:
- return ''
+ return ''
def local_time_str(t):
diff --git a/test/int/test_metadata.py b/test/int/test_metadata.py
index eb3b65fe..6f958bfd 100644
--- a/test/int/test_metadata.py
+++ b/test/int/test_metadata.py
@@ -181,8 +181,7 @@ def _linux_attr_supported(path):
except OSError as e:
if e.errno in (errno.ENOTTY, errno.ENOSYS, errno.EOPNOTSUPP):
return False
- else:
- raise
+ raise
return True
--
2.47.3