[Python-modules-commits] [python-spur] 01/06: Import python-spur_0.3.17.orig.tar.gz
Ruben Undheim
rubund-guest at moszumanska.debian.org
Fri May 13 18:21:41 UTC 2016
This is an automated email from the git hooks/post-receive script.
rubund-guest pushed a commit to branch master
in repository python-spur.
commit 29f634c75b823b4eb7f0a5b292119ac83473f88b
Author: Ruben Undheim <ruben.undheim at gmail.com>
Date: Fri May 13 20:06:52 2016 +0200
Import python-spur_0.3.17.orig.tar.gz
---
CHANGES | 10 ++++++++++
README.rst | 2 +-
setup.py | 4 ++--
spur/__init__.py | 8 ++++----
spur/io.py | 46 +++++++++++++++++++++++-----------------------
spur/local.py | 12 +++++++-----
spur/ssh.py | 12 ++++++------
tests/process_test_set.py | 13 +++++++++++++
8 files changed, 66 insertions(+), 41 deletions(-)
diff --git a/CHANGES b/CHANGES
index 8e3ee60..9d9766e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,15 @@
# CHANGES
+## 0.3.17
+
+* When encoding argument is set, decode output before writing to stdout and
+ stderr arguments. This changes the behaviour to match the documented
+ behaviour: previously, only the output on the result object was decoded.
+
+## 0.3.16
+
+* Remove non-ASCII character from README.rst.
+
## 0.3.15
* Add encoding argument to spawn and run.
diff --git a/README.rst b/README.rst
index c29b027..61a8240 100644
--- a/README.rst
+++ b/README.rst
@@ -106,7 +106,7 @@ Optional arguments:
* ``load_system_host_keys`` -- by default, Spur will attempt to read host keys
from the user's known hosts file, as used by OpenSSH, and no exception will
- be raised if the file can’t be read.
+ be raised if the file can't be read.
Set to ``False`` to disable this behaviour.
Shell interface
diff --git a/setup.py b/setup.py
index 4702a43..78c346f 100644
--- a/setup.py
+++ b/setup.py
@@ -1,14 +1,14 @@
#!/usr/bin/env python
import os
-from distutils.core import setup
+from setuptools import setup
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(
name='spur',
- version='0.3.15',
+ version='0.3.17',
description='Run commands and manipulate files locally or over SSH using the same interface',
long_description=read("README.rst"),
author='Michael Williamson',
diff --git a/spur/__init__.py b/spur/__init__.py
index a48a9ac..cccc801 100644
--- a/spur/__init__.py
+++ b/spur/__init__.py
@@ -1,7 +1,7 @@
-from spur.local import LocalShell
-from spur.ssh import SshShell
-from spur.results import RunProcessError
-from spur.errors import NoSuchCommandError, CommandInitializationError
+from .local import LocalShell
+from .ssh import SshShell
+from .results import RunProcessError
+from .errors import NoSuchCommandError, CommandInitializationError
__all__ = ["LocalShell", "SshShell", "RunProcessError", "NoSuchCommandError",
"CommandInitializationError"]
diff --git a/spur/io.py b/spur/io.py
index 50e4ff7..6c24a2f 100644
--- a/spur/io.py
+++ b/spur/io.py
@@ -1,5 +1,8 @@
+from __future__ import unicode_literals
+
import threading
import os
+import codecs
class IoHandler(object):
@@ -21,27 +24,22 @@ class Channel(object):
def _output_handler(channel, encoding):
- bytes_handler = _bytes_output_handler(channel)
if encoding is None:
- return bytes_handler
+ file_in = channel.file_in
+ empty = b""
else:
- return _EncodedOutputHandler(bytes_handler, encoding)
-
-
-class _EncodedOutputHandler(object):
- def __init__(self, bytes_handler, encoding):
- self._bytes_handler = bytes_handler
- self._encoding = encoding
+ file_in = codecs.getreader(encoding)(channel.file_in)
+ empty = ""
- def wait(self):
- return self._bytes_handler.wait().decode(self._encoding)
-
-
-def _bytes_output_handler(channel):
if channel.file_out is None and not channel.is_pty:
- return _ReadOutputAtEnd(channel.file_in)
+ return _ReadOutputAtEnd(file_in)
else:
- return _ContinuousReader(channel)
+ return _ContinuousReader(
+ file_in=file_in,
+ file_out=channel.file_out,
+ is_pty=channel.is_pty,
+ empty=empty,
+ )
class _ReadOutputAtEnd(object):
@@ -53,11 +51,13 @@ class _ReadOutputAtEnd(object):
class _ContinuousReader(object):
- def __init__(self, channel):
- self._file_in = channel.file_in
- self._file_out = channel.file_out
- self._is_pty = channel.is_pty
- self._output = b""
+ def __init__(self, file_in, file_out, is_pty, empty):
+ self._file_in = file_in
+ self._file_out = file_out
+ self._is_pty = is_pty
+ self._empty = empty
+
+ self._output = empty
self._thread = threading.Thread(target=self._capture_output)
self._thread.daemon = True
@@ -74,7 +74,7 @@ class _ContinuousReader(object):
output = self._file_in.read(1)
except IOError:
if self._is_pty:
- output = b""
+ output = self._empty
else:
raise
if output:
@@ -82,5 +82,5 @@ class _ContinuousReader(object):
self._file_out.write(output)
output_buffer.append(output)
else:
- self._output = b"".join(output_buffer)
+ self._output = self._empty.join(output_buffer)
return
diff --git a/spur/local.py b/spur/local.py
index c1a7d07..3362fe9 100644
--- a/spur/local.py
+++ b/spur/local.py
@@ -1,8 +1,10 @@
+from __future__ import absolute_import
+
import os
import sys
import subprocess
import shutil
-io = __import__("io")
+import io
import threading
import errno
@@ -11,9 +13,9 @@ try:
except ImportError:
pty = None
-from spur.tempdir import create_temporary_dir
-from spur.files import FileOperations
-import spur.results
+from .tempdir import create_temporary_dir
+from .files import FileOperations
+from . import results
from .io import IoHandler, Channel
from .errors import NoSuchCommandError
@@ -169,7 +171,7 @@ class LocalProcess(object):
output, stderr_output = self._io.wait()
return_code = self._subprocess.wait()
- return spur.results.result(
+ return results.result(
return_code,
self._allow_error,
output,
diff --git a/spur/ssh.py b/spur/ssh.py
index 7836ccd..1bf1632 100644
--- a/spur/ssh.py
+++ b/spur/ssh.py
@@ -14,11 +14,11 @@ import io
import paramiko
-from spur.tempdir import create_temporary_dir
-from spur.files import FileOperations
-import spur.results
+from .tempdir import create_temporary_dir
+from .files import FileOperations
+from . import results
from .io import IoHandler, Channel
-from .errors import NoSuchCommandError
+from .errors import NoSuchCommandError, CommandInitializationError
_ONE_MINUTE = 60
@@ -296,7 +296,7 @@ def _read_int_initialization_line(output_file):
try:
return int(line)
except ValueError:
- raise spur.errors.CommandInitializationError(line)
+ raise CommandInitializationError(line)
class SftpFile(object):
@@ -369,7 +369,7 @@ class SshProcess(object):
output, stderr_output = self._io.wait()
return_code = self._channel.recv_exit_status()
- return spur.results.result(
+ return results.result(
return_code,
self._allow_error,
output,
diff --git a/tests/process_test_set.py b/tests/process_test_set.py
index 9cbb5b1..96bf56c 100644
--- a/tests/process_test_set.py
+++ b/tests/process_test_set.py
@@ -173,6 +173,19 @@ class ProcessTestSet(object):
assert process.is_running()
process.stdin_write(b"\n")
assert_equal(b"hello\n", process.wait_for_result().stderr_output)
+
+ @test
+ def when_encoding_is_set_then_stdout_is_decoded_before_writing_to_stdout_argument(shell):
+ output_file = io.StringIO()
+ process = shell.spawn(
+ ["bash", "-c", r'echo -e "\u2603"hello; read dont_care'],
+ stdout=output_file,
+ encoding="utf-8",
+ )
+ _wait_for_assertion(lambda: assert_equal(_u("☃hello\n"), output_file.getvalue()))
+ assert process.is_running()
+ process.stdin_write(b"\n")
+ assert_equal(_u("☃hello\n"), process.wait_for_result().output)
@test
def can_get_process_id_of_process_if_store_pid_is_true(shell):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-spur.git
More information about the Python-modules-commits
mailing list