diff options
author | Jeff Quast <contact@jeffquast.com> | 2015-09-20 19:43:31 -0700 |
---|---|---|
committer | Jeff Quast <contact@jeffquast.com> | 2015-09-20 19:43:31 -0700 |
commit | b6e25ba148a4ffdf5ba0e4ba61aa78f449773cca (patch) | |
tree | ba2eec8a8bd1df7f0b21115f8ae8896db9ad364c /pexpect/__init__.py | |
parent | 7f046a6cf86d8f60a6cf23c40ef625e5acbc1a32 (diff) | |
parent | f5993888e092bd8cecc98ac9558700d4fe8624cf (diff) | |
download | pexpect-git-document-blocking-write.tar.gz |
Merge remote-tracking branch 'origin/master' into document-blocking-writedocument-blocking-write
Diffstat (limited to 'pexpect/__init__.py')
-rw-r--r-- | pexpect/__init__.py | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/pexpect/__init__.py b/pexpect/__init__.py index 4b153f4..db5be16 100644 --- a/pexpect/__init__.py +++ b/pexpect/__init__.py @@ -77,7 +77,7 @@ __all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'spawnu', 'run', 'runu 'which', 'split_command_line', '__version__', '__revision__'] def run(command, timeout=30, withexitstatus=False, events=None, - extra_args=None, logfile=None, cwd=None, env=None): + extra_args=None, logfile=None, cwd=None, env=None, **kwargs): ''' This function runs the given command; waits for it to finish; then @@ -159,29 +159,16 @@ def run(command, timeout=30, withexitstatus=False, events=None, sent to the child. 'extra_args' is not used by directly run(). It provides a way to pass data to a callback function through run() through the locals dictionary passed to a callback. - ''' - return _run(command, timeout=timeout, withexitstatus=withexitstatus, - events=events, extra_args=extra_args, logfile=logfile, cwd=cwd, - env=env, _spawn=spawn) - -def runu(command, timeout=30, withexitstatus=False, events=None, - extra_args=None, logfile=None, cwd=None, env=None, **kwargs): - """This offers the same interface as :func:`run`, but using unicode. - Like :class:`spawnu`, you can pass ``encoding`` and ``errors`` parameters, - which will be used for both input and output. - """ - return _run(command, timeout=timeout, withexitstatus=withexitstatus, - events=events, extra_args=extra_args, logfile=logfile, cwd=cwd, - env=env, _spawn=spawnu, **kwargs) - -def _run(command, timeout, withexitstatus, events, extra_args, logfile, cwd, - env, _spawn, **kwargs): + Like :class:`spawn`, passing *encoding* will make it work with unicode + instead of bytes. You can pass *codec_errors* to control how errors in + encoding and decoding are handled. + ''' if timeout == -1: - child = _spawn(command, maxread=2000, logfile=logfile, cwd=cwd, env=env, + child = spawn(command, maxread=2000, logfile=logfile, cwd=cwd, env=env, **kwargs) else: - child = _spawn(command, timeout=timeout, maxread=2000, logfile=logfile, + child = spawn(command, timeout=timeout, maxread=2000, logfile=logfile, cwd=cwd, env=env, **kwargs) if isinstance(events, list): patterns= [x for x,y in events] @@ -232,4 +219,13 @@ def _run(command, timeout, withexitstatus, events, extra_args, logfile, cwd, else: return child_result +def runu(command, timeout=30, withexitstatus=False, events=None, + extra_args=None, logfile=None, cwd=None, env=None, **kwargs): + """Deprecated: pass encoding to run() instead. + """ + kwargs.setdefault('encoding', 'utf-8') + return run(command, timeout=timeout, withexitstatus=withexitstatus, + events=events, extra_args=extra_args, logfile=logfile, cwd=cwd, + env=env, **kwargs) + # vim: set shiftround expandtab tabstop=4 shiftwidth=4 ft=python autoindent : |