Mercurial > libervia-web
comparison libervia.tac @ 10:c28a4840e1a8
server: microblog resource
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 25 Mar 2011 00:32:58 +0100 |
parents | 154d4caa57f4 |
children | 331c093e4eb3 |
comparison
equal
deleted
inserted
replaced
9:c80b75bf2e91 | 10:c28a4840e1a8 |
---|---|
26 | 26 |
27 from twisted.web import server | 27 from twisted.web import server |
28 from twisted.web import error as weberror | 28 from twisted.web import error as weberror |
29 from twisted.web.static import File | 29 from twisted.web.static import File |
30 from twisted.web.resource import Resource | 30 from twisted.web.resource import Resource |
31 from twisted.words.protocols.jabber.jid import JID | |
31 from txjsonrpc.web import jsonrpc | 32 from txjsonrpc.web import jsonrpc |
32 from txjsonrpc import jsonrpclib | 33 from txjsonrpc import jsonrpclib |
33 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService | 34 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService |
35 | |
36 from server_side.blog import MicroBlog | |
34 | 37 |
35 TIMEOUT = 120 #Session's time out, after that the user will be disconnected | 38 TIMEOUT = 120 #Session's time out, after that the user will be disconnected |
36 | 39 |
37 | 40 |
38 class MethodHandler(jsonrpc.JSONRPC): | 41 class MethodHandler(jsonrpc.JSONRPC): |
235 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia | 238 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia |
236 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) | 239 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) |
237 self.request = request | 240 self.request = request |
238 return jsonrpc.JSONRPC.render(self, request) | 241 return jsonrpc.JSONRPC.render(self, request) |
239 | 242 |
243 | |
240 class Libervia(service.Service): | 244 class Libervia(service.Service): |
241 | 245 |
242 def __init__(self): | 246 def __init__(self): |
243 root = File("output/") | 247 root = File("output/") |
244 self.signal_handler = SignalHandler(self) | 248 self.signal_handler = SignalHandler(self) |
245 root.putChild('json_signal_api', self.signal_handler) | |
246 _register = Register(self) | 249 _register = Register(self) |
247 self.signal_handler.plugRegister(_register) | 250 self.signal_handler.plugRegister(_register) |
248 root.putChild('json_api', MethodHandler(self)) | |
249 root.putChild('register_api', _register) | |
250 self.site = server.Site(root) | |
251 self.sessions = {} #key = session value = user | 251 self.sessions = {} #key = session value = user |
252 ## bridge ## | 252 ## bridge ## |
253 try: | 253 try: |
254 self.bridge=DBusBridgeFrontend() | 254 self.bridge=DBusBridgeFrontend() |
255 except BridgeExceptionNoService: | 255 except BridgeExceptionNoService: |
258 sys.exit(1) | 258 sys.exit(1) |
259 self.bridge.register("connected", self.signal_handler.connected) | 259 self.bridge.register("connected", self.signal_handler.connected) |
260 self.bridge.register("connectionError", self.signal_handler.connectionError) | 260 self.bridge.register("connectionError", self.signal_handler.connectionError) |
261 for signal_name in ['presenceUpdate', 'personalEvent']: | 261 for signal_name in ['presenceUpdate', 'personalEvent']: |
262 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) | 262 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) |
263 root.putChild('json_signal_api', self.signal_handler) | |
264 root.putChild('json_api', MethodHandler(self)) | |
265 root.putChild('register_api', _register) | |
266 root.putChild('blog', MicroBlog(self)) | |
267 root.putChild('css', File("server_css/")) | |
268 self.site = server.Site(root) | |
263 | 269 |
264 def startService(self): | 270 def startService(self): |
265 reactor.listenTCP(8080, self.site) | 271 reactor.listenTCP(8080, self.site) |
266 | 272 |
267 def run(self): | 273 def run(self): |