python - Pipe Twisted Request Content to STDIN of Process -


i'm looking pipe content of http post or put stdin of process. i'm using klein library , have following code:

from klein import run, route twisted.internet import reactor, defer, protocol     import os  class curlprocprotocol(protocol.processprotocol):     def __init__(self, data):         self.data = data      def connectionmade(self):         self.transport.write(self.data)         self.transport.closestdin()      def outreceived(self, data):         return 'got ' + str(data)  @route('/') def home(request):     d = defer.deferred()      reactor.spawnprocess(curlprocprotocol(request.channel),                          '/usr/bin/curl',                          args=['curl', '-t', '-', 'ftp://localhost/test.txt'],                          env={'home': os.environ['home']},                          usepty=false)      d.addcallback(reactor.run)      return d  run("localhost", 8080) 

the problem i'm struggling part of request pass curlprocprotocol, , how in turn pass self.transport?

i ended dumping klein , going twisted

from twisted.web import server, resource twisted.internet import reactor, protocol  import os   class curlprocprotocol(protocol.processprotocol):     def __init__(self, request):         self.request = request      def connectionmade(self):         self.transport.write(self.request.content.read())         self.transport.closestdin()          self.request.write("done!\n")         self.request.finish()      def outreceived(self, data):         print 'got: ' + str(data)   class simple(resource.resource):     isleaf = true      def render_post(self, request):          reactor.spawnprocess(curlprocprotocol(request),                              '/usr/bin/curl',                              args=['curl', '-t', '-', 'ftp://localhost/test.txt'],                              env={'home': os.environ['home']},                              usepty=false)          return server.not_done_yet   site = server.site(simple(), logpath='access.log') reactor.listentcp(8080, site) reactor.run() 

Comments

Popular posts from this blog

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

wordpress - (T_ENDFOREACH) php error -

Using django-mptt to get only the categories that have items -