[tor-commits] [onionperf/master] Open Tor control log files with \r\n as newline.
karsten at torproject.org
karsten at torproject.org
Tue May 12 07:26:32 UTC 2020
commit f863ee46e82a7acdf670752664eb4df93de0a247
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Sat May 9 19:51:42 2020 +0200
Open Tor control log files with \r\n as newline.
Turns out that Tor control log files use \r\n for newlines. When we
open these files without providing a newline parameter, line endings
are translated by Python 3 into '\n' before being returned to the us.
If we do specify a newline parameter, line endings are returned to us
untranslated. We need \r\n as newlines for Stem to recognize and parse
control events.
On the other hand TGen log files use \n as newline, which is why we
need to make newlines configurable.
---
onionperf/analysis.py | 2 +-
onionperf/util.py | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/onionperf/analysis.py b/onionperf/analysis.py
index 041d8c3..8e2b7df 100644
--- a/onionperf/analysis.py
+++ b/onionperf/analysis.py
@@ -825,7 +825,7 @@ class TorCtlParser(Parser):
def parse(self, source, do_simple=True):
self.do_simple = do_simple
- source.open()
+ source.open(newline='\r\n')
for line in source:
# ignore line parsing errors
try:
diff --git a/onionperf/util.py b/onionperf/util.py
index 7c8e80f..cb9f065 100644
--- a/onionperf/util.py
+++ b/onionperf/util.py
@@ -203,18 +203,18 @@ class DataSource(object):
def __next__(self):
return next(self.source) if self.source is not None else None
- def open(self):
+ def open(self, newline=None):
if self.source is None:
if self.filename == '-':
self.source = sys.stdin
elif self.compress or self.filename.endswith(".xz"):
self.compress = True
- self.source = lzma.open(self.filename, mode='rt')
+ self.source = lzma.open(self.filename, mode='rt', newline=newline)
elif self.filename.endswith(".gz"):
self.compress = True
- self.source = gzip.open(self.filename, 'rt')
+ self.source = gzip.open(self.filename, 'rt', newline=newline)
else:
- self.source = open(self.filename, 'rt')
+ self.source = open(self.filename, 'rt', newline=newline)
def get_file_handle(self):
if self.source is None:
More information about the tor-commits
mailing list