Skip to content

Commit

Permalink
Remove redundant Python 2 code (#671)
Browse files Browse the repository at this point in the history
* Remove Python 2 code

* Upgrade Python syntax with pyupgrade --py3-plus

* Post-Black cleanup: explicitly join implicitly concatenated strings
  • Loading branch information
hugovk committed Jul 28, 2021
1 parent 822ea1a commit 56f3b9b
Show file tree
Hide file tree
Showing 52 changed files with 95 additions and 157 deletions.
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# This file is execfile()d with the current directory set to its containing dir
#
Expand Down
9 changes: 4 additions & 5 deletions docs/vectors/python/argondriver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python
#
from __future__ import division, print_function

import argparse
import json
Expand All @@ -10,7 +9,7 @@
import sys


class argonRunner(object):
class argonRunner:
GOODCHARS = string.ascii_letters + string.digits

def __init__(self, args):
Expand All @@ -37,11 +36,11 @@ def _runOnce(self, passwd, salt, dgst_len, maxmem, iters):
self.exe,
salt.encode("ascii"),
"-t",
"{0:2d}".format(iters),
"{:2d}".format(iters),
"-m",
"{0:2d}".format(maxmem),
"{:2d}".format(maxmem),
"-l",
"{0:3d}".format(dgst_len),
"{:3d}".format(dgst_len),
"-v",
self.version,
]
Expand Down
7 changes: 3 additions & 4 deletions release.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.

from __future__ import absolute_import, division, print_function

import getpass
import glob
Expand All @@ -19,7 +18,7 @@


def run(*args, **kwargs):
print("[running] {0}".format(list(args)))
print("[running] {}".format(list(args)))
subprocess.check_call(list(args), **kwargs)


Expand Down Expand Up @@ -122,12 +121,12 @@ def release(version):
"""
github_token = getpass.getpass("Github person access token: ")

run("git", "tag", "-s", version, "-m", "{0} release".format(version))
run("git", "tag", "-s", version, "-m", "{} release".format(version))
run("git", "push", "--tags")

run("python", "setup.py", "sdist")

packages = glob.glob("dist/PyNaCl-{0}*".format(version))
packages = glob.glob("dist/PyNaCl-{}*".format(version))
run("twine", "upload", "-s", *packages)

github_actions_wheel_paths = build_github_actions_wheels(
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

import errno
import functools
Expand Down
5 changes: 2 additions & 3 deletions src/bindings/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

import glob
import os.path
Expand All @@ -36,7 +35,7 @@
ffi = FFI()

for header in HEADERS:
with open(header, "r") as hfile:
with open(header) as hfile:
ffi.cdef(hfile.read())

source = []
Expand All @@ -51,7 +50,7 @@
source.append("#include <sodium.h>")

for header in MINIMAL_HEADERS:
with open(header, "r") as hfile:
with open(header) as hfile:
source.append(hfile.read())

if sys.platform == "win32":
Expand Down
5 changes: 2 additions & 3 deletions src/nacl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

__all__ = [
"__title__",
Expand All @@ -27,7 +26,7 @@

__title__ = "PyNaCl"
__summary__ = (
"Python binding to the Networking and Cryptography (NaCl) " "library"
"Python binding to the Networking and Cryptography (NaCl) library"
)
__uri__ = "https://github.com/pyca/pynacl/"

Expand All @@ -37,4 +36,4 @@
__email__ = "cryptography-dev@python.org"

__license__ = "Apache License 2.0"
__copyright__ = "Copyright 2013-2018 {0}".format(__author__)
__copyright__ = "Copyright 2013-2018 {}".format(__author__)
1 change: 0 additions & 1 deletion src/nacl/bindings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

from nacl.bindings.crypto_aead import (
crypto_aead_chacha20poly1305_ABYTES,
Expand Down
37 changes: 18 additions & 19 deletions src/nacl/bindings/crypto_aead.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

from nacl import exceptions as exc
from nacl._sodium import ffi, lib
Expand Down Expand Up @@ -109,7 +108,7 @@ def crypto_aead_chacha20poly1305_ietf_encrypt(message, aad, nonce, key):

ensure(
mlen <= crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX,
"Message must be at most {0} bytes long".format(
"Message must be at most {} bytes long".format(
crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX
),
raising=exc.ValueError,
Expand All @@ -124,7 +123,7 @@ def crypto_aead_chacha20poly1305_ietf_encrypt(message, aad, nonce, key):
ensure(
isinstance(nonce, bytes)
and len(nonce) == crypto_aead_chacha20poly1305_ietf_NPUBBYTES,
"Nonce must be a {0} bytes long bytes sequence".format(
"Nonce must be a {} bytes long bytes sequence".format(
crypto_aead_chacha20poly1305_ietf_NPUBBYTES
),
raising=exc.TypeError,
Expand All @@ -133,7 +132,7 @@ def crypto_aead_chacha20poly1305_ietf_encrypt(message, aad, nonce, key):
ensure(
isinstance(key, bytes)
and len(key) == crypto_aead_chacha20poly1305_ietf_KEYBYTES,
"Key must be a {0} bytes long bytes sequence".format(
"Key must be a {} bytes long bytes sequence".format(
crypto_aead_chacha20poly1305_ietf_KEYBYTES
),
raising=exc.TypeError,
Expand Down Expand Up @@ -186,7 +185,7 @@ def crypto_aead_chacha20poly1305_ietf_decrypt(ciphertext, aad, nonce, key):

ensure(
clen <= _aead_chacha20poly1305_ietf_CRYPTBYTES_MAX,
"Ciphertext must be at most {0} bytes long".format(
"Ciphertext must be at most {} bytes long".format(
_aead_chacha20poly1305_ietf_CRYPTBYTES_MAX
),
raising=exc.ValueError,
Expand All @@ -201,7 +200,7 @@ def crypto_aead_chacha20poly1305_ietf_decrypt(ciphertext, aad, nonce, key):
ensure(
isinstance(nonce, bytes)
and len(nonce) == crypto_aead_chacha20poly1305_ietf_NPUBBYTES,
"Nonce must be a {0} bytes long bytes sequence".format(
"Nonce must be a {} bytes long bytes sequence".format(
crypto_aead_chacha20poly1305_ietf_NPUBBYTES
),
raising=exc.TypeError,
Expand All @@ -210,7 +209,7 @@ def crypto_aead_chacha20poly1305_ietf_decrypt(ciphertext, aad, nonce, key):
ensure(
isinstance(key, bytes)
and len(key) == crypto_aead_chacha20poly1305_ietf_KEYBYTES,
"Key must be a {0} bytes long bytes sequence".format(
"Key must be a {} bytes long bytes sequence".format(
crypto_aead_chacha20poly1305_ietf_KEYBYTES
),
raising=exc.TypeError,
Expand Down Expand Up @@ -263,7 +262,7 @@ def crypto_aead_chacha20poly1305_encrypt(message, aad, nonce, key):

ensure(
mlen <= crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX,
"Message must be at most {0} bytes long".format(
"Message must be at most {} bytes long".format(
crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX
),
raising=exc.ValueError,
Expand All @@ -278,7 +277,7 @@ def crypto_aead_chacha20poly1305_encrypt(message, aad, nonce, key):
ensure(
isinstance(nonce, bytes)
and len(nonce) == crypto_aead_chacha20poly1305_NPUBBYTES,
"Nonce must be a {0} bytes long bytes sequence".format(
"Nonce must be a {} bytes long bytes sequence".format(
crypto_aead_chacha20poly1305_NPUBBYTES
),
raising=exc.TypeError,
Expand All @@ -287,7 +286,7 @@ def crypto_aead_chacha20poly1305_encrypt(message, aad, nonce, key):
ensure(
isinstance(key, bytes)
and len(key) == crypto_aead_chacha20poly1305_KEYBYTES,
"Key must be a {0} bytes long bytes sequence".format(
"Key must be a {} bytes long bytes sequence".format(
crypto_aead_chacha20poly1305_KEYBYTES
),
raising=exc.TypeError,
Expand Down Expand Up @@ -341,7 +340,7 @@ def crypto_aead_chacha20poly1305_decrypt(ciphertext, aad, nonce, key):

ensure(
clen <= _aead_chacha20poly1305_CRYPTBYTES_MAX,
"Ciphertext must be at most {0} bytes long".format(
"Ciphertext must be at most {} bytes long".format(
_aead_chacha20poly1305_CRYPTBYTES_MAX
),
raising=exc.ValueError,
Expand All @@ -356,7 +355,7 @@ def crypto_aead_chacha20poly1305_decrypt(ciphertext, aad, nonce, key):
ensure(
isinstance(nonce, bytes)
and len(nonce) == crypto_aead_chacha20poly1305_NPUBBYTES,
"Nonce must be a {0} bytes long bytes sequence".format(
"Nonce must be a {} bytes long bytes sequence".format(
crypto_aead_chacha20poly1305_NPUBBYTES
),
raising=exc.TypeError,
Expand All @@ -365,7 +364,7 @@ def crypto_aead_chacha20poly1305_decrypt(ciphertext, aad, nonce, key):
ensure(
isinstance(key, bytes)
and len(key) == crypto_aead_chacha20poly1305_KEYBYTES,
"Key must be a {0} bytes long bytes sequence".format(
"Key must be a {} bytes long bytes sequence".format(
crypto_aead_chacha20poly1305_KEYBYTES
),
raising=exc.TypeError,
Expand Down Expand Up @@ -418,7 +417,7 @@ def crypto_aead_xchacha20poly1305_ietf_encrypt(message, aad, nonce, key):

ensure(
mlen <= crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX,
"Message must be at most {0} bytes long".format(
"Message must be at most {} bytes long".format(
crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX
),
raising=exc.ValueError,
Expand All @@ -433,7 +432,7 @@ def crypto_aead_xchacha20poly1305_ietf_encrypt(message, aad, nonce, key):
ensure(
isinstance(nonce, bytes)
and len(nonce) == crypto_aead_xchacha20poly1305_ietf_NPUBBYTES,
"Nonce must be a {0} bytes long bytes sequence".format(
"Nonce must be a {} bytes long bytes sequence".format(
crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
),
raising=exc.TypeError,
Expand All @@ -442,7 +441,7 @@ def crypto_aead_xchacha20poly1305_ietf_encrypt(message, aad, nonce, key):
ensure(
isinstance(key, bytes)
and len(key) == crypto_aead_xchacha20poly1305_ietf_KEYBYTES,
"Key must be a {0} bytes long bytes sequence".format(
"Key must be a {} bytes long bytes sequence".format(
crypto_aead_xchacha20poly1305_ietf_KEYBYTES
),
raising=exc.TypeError,
Expand Down Expand Up @@ -496,7 +495,7 @@ def crypto_aead_xchacha20poly1305_ietf_decrypt(ciphertext, aad, nonce, key):

ensure(
clen <= _aead_xchacha20poly1305_ietf_CRYPTBYTES_MAX,
"Ciphertext must be at most {0} bytes long".format(
"Ciphertext must be at most {} bytes long".format(
_aead_xchacha20poly1305_ietf_CRYPTBYTES_MAX
),
raising=exc.ValueError,
Expand All @@ -511,7 +510,7 @@ def crypto_aead_xchacha20poly1305_ietf_decrypt(ciphertext, aad, nonce, key):
ensure(
isinstance(nonce, bytes)
and len(nonce) == crypto_aead_xchacha20poly1305_ietf_NPUBBYTES,
"Nonce must be a {0} bytes long bytes sequence".format(
"Nonce must be a {} bytes long bytes sequence".format(
crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
),
raising=exc.TypeError,
Expand All @@ -520,7 +519,7 @@ def crypto_aead_xchacha20poly1305_ietf_decrypt(ciphertext, aad, nonce, key):
ensure(
isinstance(key, bytes)
and len(key) == crypto_aead_xchacha20poly1305_ietf_KEYBYTES,
"Key must be a {0} bytes long bytes sequence".format(
"Key must be a {} bytes long bytes sequence".format(
crypto_aead_xchacha20poly1305_ietf_KEYBYTES
),
raising=exc.TypeError,
Expand Down
3 changes: 1 addition & 2 deletions src/nacl/bindings/crypto_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

from nacl import exceptions as exc
from nacl._sodium import ffi, lib
Expand Down Expand Up @@ -300,7 +299,7 @@ def crypto_box_seal_open(ciphertext, pk, sk):

ensure(
_clen >= crypto_box_SEALBYTES,
("Input cyphertext must be " "at least {} long").format(
("Input cyphertext must be at least {} long").format(
crypto_box_SEALBYTES
),
raising=exc.TypeError,
Expand Down
1 change: 0 additions & 1 deletion src/nacl/bindings/crypto_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

from nacl import exceptions as exc
from nacl._sodium import ffi, lib
Expand Down
3 changes: 1 addition & 2 deletions src/nacl/bindings/crypto_generichash.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

from nacl import exceptions as exc
from nacl._sodium import ffi, lib
Expand Down Expand Up @@ -137,7 +136,7 @@ def generichash_blake2b_salt_personal(
return ffi.buffer(digest, digest_size)[:]


class Blake2State(object):
class Blake2State:
"""
Python-level wrapper for the crypto_generichash_blake2b state buffer
"""
Expand Down
1 change: 0 additions & 1 deletion src/nacl/bindings/crypto_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

from nacl import exceptions as exc
from nacl._sodium import ffi, lib
Expand Down

0 comments on commit 56f3b9b

Please sign in to comment.