Fix lint, and some Python 3 cleanups.
This commit is contained in:
parent
0cd197d4d0
commit
ae29ea2b23
@ -4,29 +4,13 @@
|
|||||||
Ported to Python 3.
|
Ported to Python 3.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from typing import Union, Optional
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import division
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
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
|
|
||||||
else:
|
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
|
|
||||||
import os, sys, textwrap
|
import os, sys, textwrap
|
||||||
import codecs
|
import codecs
|
||||||
from os.path import join
|
from os.path import join
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
try:
|
|
||||||
from typing import Optional
|
|
||||||
from .types_ import Parameters
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
from yaml import (
|
from yaml import (
|
||||||
safe_dump,
|
safe_dump,
|
||||||
)
|
)
|
||||||
@ -37,6 +21,8 @@ from allmydata.util.assertutil import precondition
|
|||||||
from allmydata.util.encodingutil import quote_output, \
|
from allmydata.util.encodingutil import quote_output, \
|
||||||
quote_local_unicode_path, argv_to_abspath
|
quote_local_unicode_path, argv_to_abspath
|
||||||
from allmydata.scripts.default_nodedir import _default_nodedir
|
from allmydata.scripts.default_nodedir import _default_nodedir
|
||||||
|
from .types_ import Parameters
|
||||||
|
|
||||||
|
|
||||||
def get_default_nodedir():
|
def get_default_nodedir():
|
||||||
return _default_nodedir
|
return _default_nodedir
|
||||||
@ -59,7 +45,7 @@ class BaseOptions(usage.Options):
|
|||||||
def opt_version(self):
|
def opt_version(self):
|
||||||
raise usage.UsageError("--version not allowed on subcommands")
|
raise usage.UsageError("--version not allowed on subcommands")
|
||||||
|
|
||||||
description = None # type: Optional[str]
|
description : Optional[str] = None
|
||||||
description_unwrapped = None # type: Optional[str]
|
description_unwrapped = None # type: Optional[str]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@ -80,10 +66,10 @@ class BaseOptions(usage.Options):
|
|||||||
class BasedirOptions(BaseOptions):
|
class BasedirOptions(BaseOptions):
|
||||||
default_nodedir = _default_nodedir
|
default_nodedir = _default_nodedir
|
||||||
|
|
||||||
optParameters = [
|
optParameters : Parameters = [
|
||||||
["basedir", "C", None, "Specify which Tahoe base directory should be used. [default: %s]"
|
["basedir", "C", None, "Specify which Tahoe base directory should be used. [default: %s]"
|
||||||
% quote_local_unicode_path(_default_nodedir)],
|
% quote_local_unicode_path(_default_nodedir)],
|
||||||
] # type: Parameters
|
]
|
||||||
|
|
||||||
def parseArgs(self, basedir=None):
|
def parseArgs(self, basedir=None):
|
||||||
# This finds the node-directory option correctly even if we are in a subcommand.
|
# This finds the node-directory option correctly even if we are in a subcommand.
|
||||||
@ -283,9 +269,8 @@ def get_alias(aliases, path_unicode, default):
|
|||||||
quote_output(alias))
|
quote_output(alias))
|
||||||
return uri.from_string_dirnode(aliases[alias]).to_string(), path[colon+1:]
|
return uri.from_string_dirnode(aliases[alias]).to_string(), path[colon+1:]
|
||||||
|
|
||||||
def escape_path(path):
|
def escape_path(path: Union[str, bytes]) -> str:
|
||||||
# type: (Union[str,bytes]) -> str
|
"""
|
||||||
u"""
|
|
||||||
Return path quoted to US-ASCII, valid URL characters.
|
Return path quoted to US-ASCII, valid URL characters.
|
||||||
|
|
||||||
>>> path = u'/føö/bar/☃'
|
>>> path = u'/føö/bar/☃'
|
||||||
@ -302,9 +287,4 @@ def escape_path(path):
|
|||||||
]),
|
]),
|
||||||
"ascii"
|
"ascii"
|
||||||
)
|
)
|
||||||
# Eventually (i.e. as part of Python 3 port) we want this to always return
|
|
||||||
# Unicode strings. However, to reduce diff sizes in the short term it'll
|
|
||||||
# return native string (i.e. bytes) on Python 2.
|
|
||||||
if PY2:
|
|
||||||
result = result.encode("ascii").__native__()
|
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user