How to use the mitogen.core.to_text function in mitogen

To help you get started, we’ve selected a few mitogen 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 dw / mitogen / mitogen / parent.py View on Github external
def __init__(self, max_message_size, name=None, remote_name=None,
                 python_path=None, debug=False, connect_timeout=None,
                 profiling=False, unidirectional=False, old_router=None):
        self.name = name
        self.max_message_size = max_message_size
        if python_path:
            self.python_path = python_path
        if connect_timeout:
            self.connect_timeout = connect_timeout
        if remote_name is None:
            remote_name = get_default_remote_name()
        if '/' in remote_name or '\\' in remote_name:
            raise ValueError('remote_name= cannot contain slashes')
        if remote_name:
            self.remote_name = mitogen.core.to_text(remote_name)
        self.debug = debug
        self.profiling = profiling
        self.unidirectional = unidirectional
        self.max_message_size = max_message_size
        self.connect_deadline = mitogen.core.now() + self.connect_timeout
github dw / mitogen / ansible_mitogen / runner.py View on Github external
self._run_code(code, mod)
            except SystemExit:
                exc = sys.exc_info()[1]
                rc = exc.args[0]
            except Exception:
                # This writes to stderr by default.
                traceback.print_exc()
                rc = 1

        finally:
            self.atexit_wrapper.run_callbacks()

        return {
            u'rc': rc,
            u'stdout': mitogen.core.to_text(sys.stdout.getvalue()),
            u'stderr': mitogen.core.to_text(sys.stderr.getvalue()),
        }
github dw / mitogen / ansible_mitogen / runner.py View on Github external
rc, stdout, stderr = ansible_mitogen.target.exec_args(
                args=self._get_argv(),
                emulate_tty=self.emulate_tty,
            )
        except Exception:
            LOG.exception('While running %s', self._get_argv())
            e = sys.exc_info()[1]
            return {
                u'rc': 1,
                u'stdout': u'',
                u'stderr': u'%s: %s' % (type(e), e),
            }

        return {
            u'rc': rc,
            u'stdout': mitogen.core.to_text(stdout),
            u'stderr': mitogen.core.to_text(stderr),
        }
github dw / mitogen / mitogen / docker.py View on Github external
def __init__(self, container=None, image=None, docker_path=None,
                 username=None, **kwargs):
        super(Options, self).__init__(**kwargs)
        assert container or image
        if container:
            self.container = mitogen.core.to_text(container)
        if image:
            self.image = mitogen.core.to_text(image)
        if docker_path:
            self.docker_path = mitogen.core.to_text(docker_path)
        if username:
            self.username = mitogen.core.to_text(username)
github dw / mitogen / ansible_mitogen / transport_config.py View on Github external
def ssh_args(self):
        return [
            mitogen.core.to_text(term)
            for s in (
                (
                    self._host_vars.get('ansible_ssh_args') or
                    getattr(C, 'ANSIBLE_SSH_ARGS', None) or
                    os.environ.get('ANSIBLE_SSH_ARGS')
                    # TODO: ini entry. older versions.
                ),
                (
                    self._host_vars.get('ansible_ssh_common_args') or
                    os.environ.get('ANSIBLE_SSH_COMMON_ARGS')
                    # TODO: ini entry.
                ),
                (
                    self._host_vars.get('ansible_ssh_extra_args') or
                    os.environ.get('ANSIBLE_SSH_EXTRA_ARGS')
                    # TODO: ini entry.
github dw / mitogen / mitogen / master.py View on Github external
modnames = [modname, '%s.%s' % (fullname, modname)]
            else:
                modnames = [
                    '%s%s' % (self.resolve_relpath(fullname, level), modname)
                ]

            maybe_names.extend(modnames)
            maybe_names.extend(
                '%s.%s' % (mname, name)
                for mname in modnames
                for name in namelist
            )

        return self._related_cache.setdefault(fullname, sorted(
            set(
                mitogen.core.to_text(name)
                for name in maybe_names
                if sys.modules.get(name) is not None
                and not is_stdlib_name(name)
                and u'six.moves' not in name  # TODO: crap
            )
github dw / mitogen / mitogen / parent.py View on Github external
def make_msg(self, fn, *args, **kwargs):
        if getattr(fn, closure_attr, None) is not None:
            raise TypeError(self.closures_msg)
        if fn.__name__ == '':
            raise TypeError(self.lambda_msg)

        if inspect.ismethod(fn):
            im_self = getattr(fn, IM_SELF_ATTR)
            if not inspect.isclass(im_self):
                raise TypeError(self.method_msg)
            klass = mitogen.core.to_text(im_self.__name__)
        else:
            klass = None

        tup = (
            self.chain_id,
            mitogen.core.to_text(fn.__module__),
            klass,
            mitogen.core.to_text(fn.__name__),
            args,
            mitogen.core.Kwargs(kwargs)
        )
        return mitogen.core.Message.pickled(tup,
            handle=mitogen.core.CALL_FUNCTION)
github dw / mitogen / mitogen / doas.py View on Github external
for buf in it:
            LOG.debug('%r: received %r', self, buf)
            if buf.endswith(self.EC0_MARKER):
                self._ec0_received()
                return
            if any(s in buf.lower() for s in self.incorrect_prompts):
                if password_sent:
                    raise PasswordError(self.password_incorrect_msg)
            elif self.password_prompt in buf.lower():
                if self.password is None:
                    raise PasswordError(self.password_required_msg)
                if password_sent:
                    raise PasswordError(self.password_incorrect_msg)
                LOG.debug('sending password')
                self.diag_stream.transmit_side.write(
                    mitogen.core.to_text(self.password + '\n').encode('utf-8')
                )
                password_sent = True
        raise mitogen.core.StreamError('bootstrap failed')
github dw / mitogen / mitogen / su.py View on Github external
for buf in it:
            LOG.debug('%r: received %r', self, buf)
            if buf.endswith(self.EC0_MARKER):
                self._ec0_received()
                return
            if any(s in buf.lower() for s in self.incorrect_prompts):
                if password_sent:
                    raise PasswordError(self.password_incorrect_msg)
            elif self.password_prompt in buf.lower():
                if self.password is None:
                    raise PasswordError(self.password_required_msg)
                if password_sent:
                    raise PasswordError(self.password_incorrect_msg)
                LOG.debug('sending password')
                self.transmit_side.write(
                    mitogen.core.to_text(self.password + '\n').encode('utf-8')
                )
                password_sent = True

        raise mitogen.core.StreamError('bootstrap failed')
github dw / mitogen / ansible_mitogen / services.py View on Github external
def _get_custom_tups(self, builtin_path, resolved):
        return [
            (mitogen.core.to_text(fullname),
             mitogen.core.to_text(path),
             is_pkg)
            for fullname, path, is_pkg in resolved
            if not os.path.abspath(path).startswith(builtin_path)
        ]