From 84da25f6cc67a2c80326d5c48c75995fa48ba6e2 Mon Sep 17 00:00:00 2001 From: Donald Stufft <donald@stufft.io> Date: Sun, 17 Mar 2013 13:37:29 -0400 Subject: [PATCH] Remove nacl.* implicit imports in favor of explicit --- docs/secret.rst | 8 ++++---- nacl/__about__.py | 21 --------------------- nacl/__init__.py | 23 ++++++++++++----------- setup.py | 25 +++++++++++-------------- tests/test_hash.py | 2 +- tests/test_random.py | 6 +++--- tests/test_signing.py | 2 +- 7 files changed, 32 insertions(+), 55 deletions(-) delete mode 100644 nacl/__about__.py diff --git a/docs/secret.rst b/docs/secret.rst index fa2f65b7..dd20c429 100644 --- a/docs/secret.rst +++ b/docs/secret.rst @@ -15,11 +15,11 @@ Example .. code:: python - import nacl + import nacl.random import nacl.secret # This must be kept secret, this is the combination to your safe - key = nacl.random(nacl.secret.SecretBox.KEY_SIZE) + key = nacl.random.random(nacl.secret.SecretBox.KEY_SIZE) # This is your safe, you can use it to encrypt or decrypt messages box = nacl.secret.SecretBox(key) @@ -31,7 +31,7 @@ Example # This is a nonce, it *MUST* only be used once, but it is not considered # secret and can be transmitted or stored alongside the ciphertext. A # good source of nonce is just 24 random bytes. - nonce = nacl.random(nacl.secret.SecretBox.NONCE_SIZE) + nonce = nacl.random.random(nacl.secret.SecretBox.NONCE_SIZE) # Encrypt our message, it will be exactly 16 bytes longer than the original # message as it stores authentication information alongside it. @@ -76,7 +76,7 @@ is not enough to simply use a random value and hope that it's not being reused One good method of generating nonces is for each person to pick a unique prefix, for example ``b"p1"`` and ``b"p2"``. When each person generates a nonce they -prefix it, so instead of ``nacl.random(24)`` you'd do ``b"p1" + nacl.random(22)``. +prefix it, so instead of ``nacl.random.random(24)`` you'd do ``b"p1" + nacl.random.random(22)``. This prefix serves as a guarantee that no two messages from different people will inadvertently overlap nonces while in transit. They should still record every nonce they've personally used and every nonce they've received to prevent diff --git a/nacl/__about__.py b/nacl/__about__.py deleted file mode 100644 index 60fbfcf0..00000000 --- a/nacl/__about__.py +++ /dev/null @@ -1,21 +0,0 @@ -# pylint: disable=C0301 -from __future__ import absolute_import -from __future__ import division -from __future__ import unicode_literals - -__all__ = [ - "__title__", "__summary__", "__uri__", "__version__", "__author__", - "__email__", "__license__", "__copyright__", -] - -__title__ = "PyNaCl" -__summary__ = "Python binding to the Networking and Cryptography (NaCl) library" # nopep8 -__uri__ = "https://github.com/dstufft/pynacl/" - -__version__ = "0.1dev1" - -__author__ = "Donald Stufft" -__email__ = "donald@stufft.io" - -__license__ = "Simplified BSD" -__copyright__ = "Copyright 2012 Donald Stufft" diff --git a/nacl/__init__.py b/nacl/__init__.py index 2dcf301c..69e3431d 100644 --- a/nacl/__init__.py +++ b/nacl/__init__.py @@ -1,18 +1,19 @@ from __future__ import absolute_import from __future__ import division -from . import __about__ -from . import hash # pylint: disable=W0622 -from . import signing -from .random import random +__all__ = [ + "__title__", "__summary__", "__uri__", "__version__", "__author__", + "__email__", "__license__", "__copyright__", +] +__title__ = "PyNaCl" +__summary__ = "Python binding to the Networking and Cryptography (NaCl) library" +__uri__ = "https://github.com/dstufft/pynacl/" -__all__ = ["hash", "random"] + __about__.__all__ +__version__ = "0.1dev1" +__author__ = "Donald Stufft" +__email__ = "donald@stufft.io" -# - Meta Information - -# This is pretty ugly -for attr in __about__.__all__: - if hasattr(__about__, attr): - globals()[attr] = getattr(__about__, attr) -# - End Meta Information - +__license__ = "Simplified BSD" +__copyright__ = "Copyright 2012 Donald Stufft" diff --git a/setup.py b/setup.py index 3e4ab38a..9cec5549 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,10 @@ #!/usr/bin/env python -from setuptools import setup -from setuptools.command.test import test as TestCommand import sys -__about__ = {} - -with open("nacl/__about__.py") as fp: - exec(fp.read(), None, __about__) +from setuptools import setup +from setuptools.command.test import test as TestCommand +import nacl try: import nacl.nacl @@ -32,16 +29,16 @@ class PyTest(TestCommand): setup( - name=__about__["__title__"], - version=__about__["__version__"], + name=nacl.__title__, + version=nacl.__version__, - description=__about__["__summary__"], + description=nacl.__summary__, long_description=open("README.rst").read(), - url=__about__["__uri__"], - license=__about__["__license__"], + url=nacl.__uri__, + license=nacl.__license__, - author=__about__["__author__"], - author_email=__about__["__email__"], + author=nacl.__author__, + author_email=nacl.__email__, install_requires=[ "cffi", @@ -59,5 +56,5 @@ setup( ext_modules=ext_modules, zip_safe=False, - cmdclass = {'test': PyTest}, + cmdclass={"test": PyTest}, ) diff --git a/tests/test_hash.py b/tests/test_hash.py index b24b25bd..66730124 100644 --- a/tests/test_hash.py +++ b/tests/test_hash.py @@ -1,6 +1,6 @@ import pytest -import nacl +import nacl.hash import nacl.encoding diff --git a/tests/test_random.py b/tests/test_random.py index 6c43388f..4ec3817b 100644 --- a/tests/test_random.py +++ b/tests/test_random.py @@ -1,9 +1,9 @@ -import nacl +import nacl.random def test_random_bytes_produces(): - assert len(nacl.random(16)) == 16 + assert len(nacl.random.random(16)) == 16 def test_random_bytes_produces_different_bytes(): - assert nacl.random(16) != nacl.random(16) + assert nacl.random.random(16) != nacl.random.random(16) diff --git a/tests/test_signing.py b/tests/test_signing.py index d22e2944..2122d1ca 100644 --- a/tests/test_signing.py +++ b/tests/test_signing.py @@ -6,7 +6,7 @@ import os import pytest -import nacl +import nacl.signing import nacl.encoding import nacl.nacl -- GitLab