jdswinbank / Comet

A complete VOEvent transport system
http://comet.transientskp.org/
BSD 2-Clause "Simplified" License
23 stars 9 forks source link

External command handler fails (for Python 3) #43

Closed evertrol closed 8 years ago

evertrol commented 8 years ago

The external command handler using the option --cmd appears to fail when using current master (3.0.0a0) and Python 3.

After switching back a few times to 2.0.1 with Python 2, I gave the issue a closer look: it appears spawn.py is still using the text attribute for event, while the corresponding xml_document class in xml.py is using raw_bytes. Simply replacing text with raw_bytes, and removing an .encoding() method call, fixes this for me.

What confuses me somewhat is that changes to xml_document and in spawn.py were made on the same day, which somewhat suggests this should just work and I'm overlooking something.

A very quick test shows that the same issue actually occurs for Python 2, and the same diff below fixes it there as well.

The diff is

@@ -14,12 +14,12 @@
 __all__ = ["SpawnCommand"]

 class SpawnCommandProtocol(ProcessProtocol):
-    def __init__(self, deferred, raw_bytes):
+    def __init__(self, deferred, text):
         self.deferred = deferred
-        self.raw_bytes = raw_bytes
+        self.text = text

     def connectionMade(self):
-        self.transport.write(self.raw_bytes)
+        self.transport.write(self.text.encode('utf-8'))
         self.transport.closeStdin()

     def processEnded(self, reason):
@@ -47,7 +47,7 @@
         d = defer.Deferred()
         log.info("Running external command: %s" % (self.cmd,))
         reactor.spawnProcess(
-            SpawnCommandProtocol(d, event.raw_bytes),
+            SpawnCommandProtocol(d, event.text),
             self.cmd,
             args=self.args,
             env=os.environ
jdswinbank commented 8 years ago

Thanks for the report & sorry for the slow response. Should be fixed on the current master.