raise a specific error when spaces are detected, pass along the docstring to the user
This commit is contained in:
parent
d4d3320277
commit
5be436b81d
|
@ -4,7 +4,8 @@ start = time.time()
|
||||||
import os, sys, textwrap
|
import os, sys, textwrap
|
||||||
from twisted.internet.defer import maybeDeferred
|
from twisted.internet.defer import maybeDeferred
|
||||||
from twisted.internet.task import react
|
from twisted.internet.task import react
|
||||||
from ..errors import TransferError, WrongPasswordError, WelcomeError, Timeout
|
from ..errors import (TransferError, WrongPasswordError, WelcomeError, Timeout,
|
||||||
|
KeyFormatError)
|
||||||
from ..timing import DebugTiming
|
from ..timing import DebugTiming
|
||||||
from .cli_args import parser
|
from .cli_args import parser
|
||||||
top_import_finish = time.time()
|
top_import_finish = time.time()
|
||||||
|
@ -49,7 +50,8 @@ def run(reactor, argv, cwd, stdout, stderr, executable=None):
|
||||||
d.addBoth(_maybe_dump_timing)
|
d.addBoth(_maybe_dump_timing)
|
||||||
def _explain_error(f):
|
def _explain_error(f):
|
||||||
# these errors don't print a traceback, just an explanation
|
# these errors don't print a traceback, just an explanation
|
||||||
f.trap(TransferError, WrongPasswordError, WelcomeError, Timeout)
|
f.trap(TransferError, WrongPasswordError, WelcomeError, Timeout,
|
||||||
|
KeyFormatError)
|
||||||
if f.check(WrongPasswordError):
|
if f.check(WrongPasswordError):
|
||||||
msg = textwrap.fill("ERROR: " + textwrap.dedent(f.value.__doc__))
|
msg = textwrap.fill("ERROR: " + textwrap.dedent(f.value.__doc__))
|
||||||
print(msg, file=stderr)
|
print(msg, file=stderr)
|
||||||
|
|
|
@ -15,7 +15,7 @@ from . import __version__
|
||||||
from . import codes
|
from . import codes
|
||||||
#from .errors import ServerError, Timeout
|
#from .errors import ServerError, Timeout
|
||||||
from .errors import (WrongPasswordError, UsageError, WelcomeError,
|
from .errors import (WrongPasswordError, UsageError, WelcomeError,
|
||||||
WormholeClosedError)
|
WormholeClosedError, KeyFormatError)
|
||||||
from .timing import DebugTiming
|
from .timing import DebugTiming
|
||||||
from .util import (to_bytes, bytes_to_hexstr, hexstr_to_bytes,
|
from .util import (to_bytes, bytes_to_hexstr, hexstr_to_bytes,
|
||||||
dict_to_bytes, bytes_to_dict)
|
dict_to_bytes, bytes_to_dict)
|
||||||
|
@ -476,6 +476,13 @@ class _Wormhole:
|
||||||
|
|
||||||
def _event_learned_code(self, code):
|
def _event_learned_code(self, code):
|
||||||
self._timing.add("code established")
|
self._timing.add("code established")
|
||||||
|
# bail out early if the password contains spaces...
|
||||||
|
# this should raise a useful error
|
||||||
|
if ' ' in code:
|
||||||
|
raise KeyFormatError(
|
||||||
|
"code (%s) contains spaces. Words must be separated by dashes"
|
||||||
|
% code
|
||||||
|
)
|
||||||
self._code = code
|
self._code = code
|
||||||
mo = re.search(r'^(\d+)-', code)
|
mo = re.search(r'^(\d+)-', code)
|
||||||
if not mo:
|
if not mo:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user