diff --git a/src/allmydata/grid_manager.py b/src/allmydata/grid_manager.py index b6ae04136..f502c413e 100644 --- a/src/allmydata/grid_manager.py +++ b/src/allmydata/grid_manager.py @@ -6,7 +6,7 @@ import sys from datetime import ( datetime, ) -from typing import Optional +from typing import Optional, Union from twisted.python.filepath import FilePath @@ -338,7 +338,7 @@ def save_grid_manager(file_path, grid_manager, create=True): f.write(b"\n") -def parse_grid_manager_certificate(gm_data): +def parse_grid_manager_certificate(gm_data: Union[str, bytes]): """ :param gm_data: some data that might be JSON that might be a valid Grid Manager Certificate diff --git a/src/allmydata/scripts/admin.py b/src/allmydata/scripts/admin.py index 36266f3dd..6a24614c0 100644 --- a/src/allmydata/scripts/admin.py +++ b/src/allmydata/scripts/admin.py @@ -10,12 +10,9 @@ from future.utils import PY2 if PY2: from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 -from six import ensure_binary, ensure_str +from six import ensure_binary -try: - from allmydata.scripts.types_ import SubCommands -except ImportError: - pass +from typing import Union from twisted.python import usage from twisted.python.filepath import ( @@ -29,14 +26,12 @@ from allmydata.storage import ( crawler, expirer, ) -from twisted.python.filepath import FilePath - +from allmydata.scripts.types_ import SubCommands from allmydata.client import read_config from allmydata.grid_manager import ( parse_grid_manager_certificate, ) from allmydata.scripts.cli import _default_nodedir -from allmydata.scripts.common import BaseOptions from allmydata.util.encodingutil import argv_to_abspath from allmydata.util import jsonbytes @@ -127,8 +122,10 @@ class AddGridManagerCertOptions(BaseOptions): raise usage.UsageError( "Must provide --filename option" ) + + data : Union [bytes, str] if self['filename'] == '-': - print(ensure_str("reading certificate from stdin"), file=self.parent.parent.stderr) + print("reading certificate from stdin", file=self.parent.parent.stderr) data = self.parent.parent.stdin.read() if len(data) == 0: raise usage.UsageError( @@ -201,7 +198,7 @@ def add_grid_manager_cert(options): options['name'], cert_path.path, ) - print(ensure_str(msg), file=options.parent.parent.stderr) + print(msg, file=options.parent.parent.stderr) return 1 config.set_config("storage", "grid_management", "True") @@ -212,7 +209,7 @@ def add_grid_manager_cert(options): f.write(cert_bytes) cert_count = len(config.enumerate_section("grid_manager_certificates")) - print(ensure_str("There are now {} certificates").format(cert_count), + print("There are now {} certificates".format(cert_count), file=options.parent.parent.stderr) return 0 diff --git a/src/allmydata/scripts/types_.py b/src/allmydata/scripts/types_.py index 1bed6e11e..e2a5c2f1e 100644 --- a/src/allmydata/scripts/types_.py +++ b/src/allmydata/scripts/types_.py @@ -2,8 +2,6 @@ Type definitions used by modules in this package. """ -# Python 3 only - from typing import List, Tuple, Type, Sequence, Any from twisted.python.usage import Options