How to use the yaspin.helpers.to_unicode function in yaspin

To help you get started, we’ve selected a few yaspin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pavdmyt / yaspin / tests / test_properties.py View on Github external
def test_text_getter(text):
    swirl = yaspin(text=text)
    assert swirl.text == to_unicode(text)
github pavdmyt / yaspin / tests / test_properties.py View on Github external
def test_text_setter(text):
    swirl = yaspin()
    swirl.text = text
    assert isinstance(swirl._text, str)
    assert swirl._text == to_unicode(text)
github pavdmyt / yaspin / yaspin / core.py View on Github external
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)
github pavdmyt / yaspin / yaspin / core.py View on Github external
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
github pavdmyt / yaspin / yaspin / core.py View on Github external
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(
github pavdmyt / yaspin / yaspin / core.py View on Github external
def _set_text(text):
        if PY2:
            return to_unicode(text)
        return text