Merge pull request from tahoe-lafs/3699.flakes-on-py3

Run flake8 on Python 3

Fixes ticket:3699
This commit is contained in:
Itamar Turner-Trauring 2021-05-10 09:59:14 -04:00 committed by GitHub
commit 16dd3e96f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 47 additions and 22 deletions
integration
misc
coding_tools
operations_helpers/provisioning
simulators
newsfragments
src/allmydata
tox.ini

@ -9,6 +9,8 @@ WebAPI *should* do in every situation. It's not clear the latter
exists anywhere, however.
"""
from past.builtins import unicode
import time
import json
import urllib2

@ -1,3 +1,5 @@
from past.builtins import unicode
import sys
import time
import json

@ -52,6 +52,8 @@ system where Tahoe is installed, or in a source tree with setup.py like this:
setup.py run_with_pythonpath -p -c 'misc/make-canary-files.py ARGS..'
"""
from past.builtins import cmp
import os, hashlib
from twisted.python import usage
from allmydata.immutable import upload

@ -18,7 +18,7 @@ def factorial(n):
factorial(n) with n<0 is -factorial(abs(n))
"""
result = 1
for i in xrange(1, abs(n)+1):
for i in range(1, abs(n)+1):
result *= i
assert n >= 0
return result
@ -30,7 +30,7 @@ def binomial(n, k):
# calculate n!/k! as one product, avoiding factors that
# just get canceled
P = k+1
for i in xrange(k+2, n+1):
for i in range(k+2, n+1):
P *= i
# if you are paranoid:
# C, rem = divmod(P, factorial(n-k))

@ -79,7 +79,7 @@ def make_candidate(B, K, K1, K2, q, T, T_min, L_hash, lg_N, sig_bytes, c_sign, c
# Winternitz with B < 4 is never optimal. For example, going from B=4 to B=2 halves the
# chain depth, but that is cancelled out by doubling (roughly) the number of digits.
range_B = xrange(4, 33)
range_B = range(4, 33)
M = pow(2, lg_M)
@ -100,7 +100,7 @@ def calculate(K, K1, K2, q_max, L_hash, trees):
T_min = ceil_div(lg_M - lg_K1, lg_K)
last_q = None
for T in xrange(T_min, T_min+21):
for T in range(T_min, T_min+21):
# lg(total number of leaf private keys)
lg_S = lg_K1 + lg_K*T
lg_N = lg_S + lg_K2
@ -137,14 +137,14 @@ def calculate(K, K1, K2, q_max, L_hash, trees):
# We approximate lg(M-x) as lg(M)
lg_px_step = lg_M + lg_p - lg_1_p
for x in xrange(1, j):
for x in range(1, j):
lg_px[x] = lg_px[x-1] - lg(x) + lg_px_step
q = None
# Find the minimum acceptable value of q.
for q_cand in xrange(1, q_max+1):
for q_cand in range(1, q_max+1):
lg_q = lg(q_cand)
lg_pforge = [lg_px[x] + (lg_q*x - lg_K2)*q_cand for x in xrange(1, j)]
lg_pforge = [lg_px[x] + (lg_q*x - lg_K2)*q_cand for x in range(1, j)]
if max(lg_pforge) < -L_hash + lg(j) and lg_px[j-1] + 1.0 < -L_hash:
#print("K = %d, K1 = %d, K2 = %d, L_hash = %d, lg_K2 = %.3f, q = %d, lg_pforge_1 = %.3f, lg_pforge_2 = %.3f, lg_pforge_3 = %.3f"
# % (K, K1, K2, L_hash, lg_K2, q, lg_pforge_1, lg_pforge_2, lg_pforge_3))
@ -246,13 +246,13 @@ def search():
K_max = 50
c2 = compressions(2*L_hash)
c3 = compressions(3*L_hash)
for dau in xrange(0, 10):
for dau in range(0, 10):
a = pow(2, dau)
for tri in xrange(0, ceil_log(30-dau, 3)):
for tri in range(0, ceil_log(30-dau, 3)):
x = int(a*pow(3, tri))
h = dau + 2*tri
c_x = int(sum_powers(2, dau)*c2 + a*sum_powers(3, tri)*c3)
for y in xrange(1, x+1):
for y in range(1, x+1):
if tri > 0:
# If the bottom level has arity 3, then for every 2 nodes by which the tree is
# imperfect, we can save c3 compressions by pruning 3 leaves back to their parent.
@ -267,16 +267,16 @@ def search():
if y not in trees or (h, c_y, (dau, tri)) < trees[y]:
trees[y] = (h, c_y, (dau, tri))
#for x in xrange(1, K_max+1):
#for x in range(1, K_max+1):
# print(x, trees[x])
candidates = []
progress = 0
fuzz = 0
complete = (K_max-1)*(2200-200)/100
for K in xrange(2, K_max+1):
for K2 in xrange(200, 2200, 100):
for K1 in xrange(max(2, K-fuzz), min(K_max, K+fuzz)+1):
for K in range(2, K_max+1):
for K2 in range(200, 2200, 100):
for K1 in range(max(2, K-fuzz), min(K_max, K+fuzz)+1):
candidates += calculate(K, K1, K2, q_max, L_hash, trees)
progress += 1
print("searching: %3d %% \r" % (100.0 * progress / complete,), end=' ', file=stderr)
@ -285,7 +285,7 @@ def search():
step = 2.0
bins = {}
limit = floor_div(limit_cost, step)
for bin in xrange(0, limit+2):
for bin in range(0, limit+2):
bins[bin] = []
for c in candidates:
@ -296,7 +296,7 @@ def search():
# For each in a range of signing times, find the best candidate.
best = []
for bin in xrange(0, limit):
for bin in range(0, limit):
candidates = bins[bin] + bins[bin+1] + bins[bin+2]
if len(candidates) > 0:
best += [min(candidates, key=lambda c: c['sig_bytes'])]

@ -4,6 +4,8 @@
from __future__ import print_function
from past.builtins import cmp
import random
SERVER_CAPACITY = 10**12

@ -2,6 +2,11 @@
from __future__ import print_function
from future.utils import PY2
if PY2:
from future.builtins import input
import random, math, re
from twisted.python import usage
@ -205,7 +210,7 @@ def graph():
series["alacrity"][file_size] = s.bytes_until_some_data
g.plot([ (fs, series["overhead"][fs])
for fs in sizes ])
raw_input("press return")
input("press return")
if __name__ == '__main__':

0
newsfragments/3699.minor Normal file

@ -7,6 +7,9 @@ from future.utils import PY3
if PY3:
raise RuntimeError("Just use subprocess.Popen")
# This is necessary to pacify flake8 on Python 3, while we're still supporting
# Python 2.
from past.builtins import unicode
# -*- coding: utf-8 -*-

@ -660,7 +660,6 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
if line]
except ValueError:
print("response is:", res)
print("undecodeable line was '%s'" % line)
raise
self.failUnlessReallyEqual(len(units), 5+1)
# should be parent-first

@ -16,7 +16,7 @@ if PY2:
# Don't import bytes or str, to prevent future's newbytes leaking and
# breaking code that only expects normal bytes.
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, dict, list, object, range, max, min # noqa: F401
str = unicode
from past.builtins import unicode as str
from past.builtins import unicode, long

@ -32,7 +32,7 @@ def get_registry_setting(key, name, _topkey=None):
regkey = winreg.OpenKey(topkey, key)
sublen, vallen, timestamp = winreg.QueryInfoKey(regkey)
for validx in xrange(vallen):
for validx in range(vallen):
keyname, value, keytype = winreg.EnumValue(regkey, validx)
if keyname == name and keytype == winreg.REG_SZ:
return value

14
tox.ini

@ -10,14 +10,14 @@ python =
3.6: py36-coverage
3.7: py37-coverage
3.8: py38-coverage
3.9: py39-coverage,typechecks
3.9: py39-coverage,typechecks,codechecks3
pypy-3.7: pypy3
[pytest]
twisted = 1
[tox]
envlist = typechecks,codechecks,py{27,36,37,38,39}-{coverage},pypy27,pypy3
envlist = typechecks,codechecks,codechecks3,py{27,36,37,38,39}-{coverage},pypy27,pypy3
minversion = 2.4
[testenv]
@ -128,6 +128,16 @@ commands =
python -m towncrier.check --config towncrier.pyproject.toml
[testenv:codechecks3]
basepython = python3
setenv =
# If no positional arguments are given, try to run the checks on the
# entire codebase, including various pieces of supporting code.
DEFAULT_FILES=src integration static misc setup.py
commands =
flake8 {posargs:{env:DEFAULT_FILES}}
[testenv:typechecks]
basepython = python3
skip_install = True