Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_text_getter(text):
swirl = yaspin(text=text)
assert swirl.text == to_unicode(text)
def test_text_setter(text):
swirl = yaspin()
swirl.text = text
assert isinstance(swirl._text, str)
assert swirl._text == to_unicode(text)
def _freeze(self, final_text):
"""Stop spinner, compose last frame and 'freeze' it."""
text = to_unicode(final_text)
self._last_frame = self._compose_out(text, mode="last")
# Should be stopped here, otherwise prints after
# self._freeze call will mess up the spinner
self.stop()
with self._stdout_lock:
sys.stdout.write(self._last_frame)
def _set_frames(spinner, reversal):
# type: (base_spinner.Spinner, bool) -> Union[str, List]
uframes = None # unicode frames
uframes_seq = None # sequence of unicode frames
if isinstance(spinner.frames, basestring):
uframes = to_unicode(spinner.frames) if PY2 else spinner.frames
# TODO (pavdmyt): support any type that implements iterable
if isinstance(spinner.frames, (list, tuple)):
# Empty ``spinner.frames`` is handled by ``Yaspin._set_spinner``
if spinner.frames and isinstance(spinner.frames[0], bytes):
uframes_seq = [to_unicode(frame) for frame in spinner.frames]
else:
uframes_seq = spinner.frames
_frames = uframes or uframes_seq
if not _frames:
# Empty ``spinner.frames`` is handled by ``Yaspin._set_spinner``.
# This code is very unlikely to be executed. However, it's still
# here to be on a safe side.
raise ValueError(
"{0!r}: no frames found in spinner".format(spinner)
)
# Builtin ``reversed`` returns reverse iterator,
# which adds unnecessary difficulty for returning
# unicode value;
# Hence using [::-1] syntax
def _set_frames(spinner, reversal):
# type: (base_spinner.Spinner, bool) -> Union[str, List]
uframes = None # unicode frames
uframes_seq = None # sequence of unicode frames
if isinstance(spinner.frames, basestring):
uframes = to_unicode(spinner.frames) if PY2 else spinner.frames
# TODO (pavdmyt): support any type that implements iterable
if isinstance(spinner.frames, (list, tuple)):
# Empty ``spinner.frames`` is handled by ``Yaspin._set_spinner``
if spinner.frames and isinstance(spinner.frames[0], bytes):
uframes_seq = [to_unicode(frame) for frame in spinner.frames]
else:
uframes_seq = spinner.frames
_frames = uframes or uframes_seq
if not _frames:
# Empty ``spinner.frames`` is handled by ``Yaspin._set_spinner``.
# This code is very unlikely to be executed. However, it's still
# here to be on a safe side.
raise ValueError(
def _set_text(text):
if PY2:
return to_unicode(text)
return text