[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Replacing split("\n") with splitlines()
commit 1f13b0b665ca22fe11febeeb3d610f5852a3ba49
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Thu Jan 5 21:23:12 2012 -0800
Replacing split("\n") with splitlines()
Oops, didn't spot that there was a str method for splitting on line breaks.
This behaves slightly differently with respect to trailing newlines and
preserving '\r\n' entries, but is something I should have been using...
---
stem/util/system.py | 2 +-
test/integ/socket/control_message.py | 2 +-
test/output.py | 2 +-
test/runner.py | 2 +-
test/unit/socket/control_message.py | 8 ++++----
5 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/stem/util/system.py b/stem/util/system.py
index 3e086c7..8eced97 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -596,7 +596,7 @@ def call(command, suppress_exc = True):
elif stderr:
log.trace(trace_prefix + ", stderr:\n%s" % stderr)
- if stdout: return stdout.split("\n")
+ if stdout: return stdout.splitlines()
else: return []
except OSError, exc:
log.debug("System call (failed): %s (error: %s)" % (command, exc))
diff --git a/test/integ/socket/control_message.py b/test/integ/socket/control_message.py
index 90ac623..d0c44dc 100644
--- a/test/integ/socket/control_message.py
+++ b/test/integ/socket/control_message.py
@@ -135,7 +135,7 @@ class TestControlMessage(unittest.TestCase):
torrc_contents = []
- for line in runner.get_torrc_contents().split("\n"):
+ for line in runner.get_torrc_contents().splitlines():
line = line.strip()
if line and not line.startswith("#"):
diff --git a/test/output.py b/test/output.py
index a22d738..3ebed9e 100644
--- a/test/output.py
+++ b/test/output.py
@@ -45,7 +45,7 @@ def apply_filters(testing_output, *filters):
results = []
- for line in testing_output.split("\n"):
+ for line in testing_output.splitlines():
# determine the type of the line
line_type = LineType.CONTENT
diff --git a/test/runner.py b/test/runner.py
index d6da306..10c4699 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -470,7 +470,7 @@ class Runner:
_print_status("done\n", STATUS_ATTR, quiet)
- for line in self._torrc_contents.strip().split("\n"):
+ for line in self._torrc_contents.strip().splitlines():
_print_status(" %s\n" % line.strip(), SUBSTATUS_ATTR, quiet)
_print_status("\n", (), quiet)
diff --git a/test/unit/socket/control_message.py b/test/unit/socket/control_message.py
index 92d79c2..8bb6fef 100644
--- a/test/unit/socket/control_message.py
+++ b/test/unit/socket/control_message.py
@@ -77,7 +77,7 @@ class TestControlMessage(unittest.TestCase):
# GETINFO version (basic single-line results)
message = self.assert_message_parses(GETINFO_VERSION)
self.assertEquals(2, len(list(message)))
- self.assertEquals(2, len(str(message).split("\n")))
+ self.assertEquals(2, len(str(message).splitlines()))
# manually checks the contents
contents = message.content()
@@ -88,7 +88,7 @@ class TestControlMessage(unittest.TestCase):
# GETINFO info/names (data entry)
message = self.assert_message_parses(GETINFO_INFONAMES)
self.assertEquals(2, len(list(message)))
- self.assertEquals(8, len(str(message).split("\n")))
+ self.assertEquals(8, len(str(message).splitlines()))
# manually checks the contents
contents = message.content()
@@ -110,7 +110,7 @@ class TestControlMessage(unittest.TestCase):
# causes a parsing error. This should test line endings for both data
# entry parsing and non-data.
- infonames_lines = [line + "\n" for line in GETINFO_INFONAMES.split("\n")[:-1]]
+ infonames_lines = [line + "\n" for line in GETINFO_INFONAMES.splitlines()]
for i in range(len(infonames_lines)):
# replace the CRLF for the line
@@ -172,7 +172,7 @@ class TestControlMessage(unittest.TestCase):
self.assertEqual(controller_reply, message.raw_content())
# checks that the contents match the input
- message_lines = str(message).split("\n")
+ message_lines = str(message).splitlines()
controller_lines = controller_reply.split("\r\n")
controller_lines.pop() # the ControlMessage won't have a trailing newline
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits