forked from AGProjects/python3-eventlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwisted_xcap_proxy.py
More file actions
31 lines (25 loc) · 1.02 KB
/
twisted_xcap_proxy.py
File metadata and controls
31 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from twisted.internet.protocol import Factory
from twisted.internet import reactor
from twisted.protocols import basic
from xcaplib.green import XCAPClient
from eventlib.twistedutil import deferToGreenThread
from eventlib.twistedutil import join_reactor
class LineOnlyReceiver(basic.LineOnlyReceiver):
def lineReceived(self, line):
print('received: %r' % line)
if not line:
return
app, context, node = (line + ' ').split(' ', 3)
context = {'u' : 'users', 'g': 'global'}.get(context, context)
d = deferToGreenThread(client._get, app, node, globaltree=context=='global')
def callback(result):
self.transport.write(str(result))
def errback(error):
self.transport.write(error.getTraceback())
d.addCallback(callback)
d.addErrback(errback)
class MyFactory(Factory):
protocol = LineOnlyReceiver
reactor.listenTCP(8007, MyFactory())
reactor.run()