diff libervia_server/__init__.py @ 433:bbdbee25123a

import constants.Const as C (according to the coding rules)
author souliane <souliane@mailoo.org>
date Thu, 01 May 2014 11:29:09 +0200
parents b5b440e6ea16
children e63fc04efef7
line wrap: on
line diff
--- a/libervia_server/__init__.py	Sun Apr 27 18:53:37 2014 +0200
+++ b/libervia_server/__init__.py	Thu May 01 11:29:09 2014 +0200
@@ -44,7 +44,7 @@
 from xml.dom import minidom
 from httplib import HTTPS_PORT
 
-from constants import Const
+from constants import Const as C
 from libervia_server.blog import MicroBlog
 from sat_frontends.bridge.DBus import DBusBridgeFrontend, BridgeExceptionNoService
 from sat.core.i18n import _, D_
@@ -68,7 +68,7 @@
         self.jid = None
 
 class LiberviaSession(server.Session):
-    sessionTimeout = Const.TIMEOUT
+    sessionTimeout = C.TIMEOUT
 
     def __init__(self, *args, **kwargs):
         self.__lock = False
@@ -149,7 +149,7 @@
                 d.callback(args[0])
 
         def _errback(result):
-            d.errback(Failure(jsonrpclib.Fault(Const.ERRNUM_BRIDGE_ERRBACK, unicode(result))))
+            d.errback(Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, unicode(result))))
 
         kwargs["callback"] = _callback
         kwargs["errback"] = _errback
@@ -169,7 +169,7 @@
         if not profile:
             #user is not identified, we return a jsonrpc fault
             parsed = jsonrpclib.loads(request.content.read())
-            fault = jsonrpclib.Fault(Const.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia
+            fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia
             return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc'))
         return jsonrpc.JSONRPC.render(self, request)
 
@@ -425,7 +425,7 @@
         """Give the path of all the tarot cards"""
         _join = os.path.join
         _media_dir = _join(self.sat_host.media_dir,'')
-        return map(lambda x: _join(Const.MEDIA_DIR, x[len(_media_dir):]), glob.glob(_join(_media_dir, Const.CARDS_DIR, '*_*.png')));
+        return map(lambda x: _join(C.MEDIA_DIR, x[len(_media_dir):]), glob.glob(_join(_media_dir, C.CARDS_DIR, '*_*.png')));
 
     def jsonrpc_tarotGameReady(self, player, referee):
         """Tell to the server that we are ready to start the game"""
@@ -474,7 +474,7 @@
     def jsonrpc_getParamsUI(self):
         """Return the parameters XML for profile"""
         profile = ISATSession(self.session).profile
-        d = self.asyncBridgeCall("getParams", Const.SECURITY_LIMIT, Const.APP_NAME, profile)
+        d = self.asyncBridgeCall("getParams", C.SECURITY_LIMIT, C.APP_NAME, profile)
 
         def setAuthorizedParams(params_xml):
             if self.authorized_params is None:
@@ -497,13 +497,13 @@
     def jsonrpc_asyncGetParamA(self, param, category, attribute="value"):
         """Return the parameter value for profile"""
         profile = ISATSession(self.session).profile
-        d = self.asyncBridgeCall("asyncGetParamA", param, category, attribute, Const.SECURITY_LIMIT, profile_key=profile)
+        d = self.asyncBridgeCall("asyncGetParamA", param, category, attribute, C.SECURITY_LIMIT, profile_key=profile)
         return d
 
     def jsonrpc_setParam(self, name, value, category):
         profile = ISATSession(self.session).profile
         if category in self.authorized_params and name in self.authorized_params[category]:
-            return self.sat_host.bridge.setParam(name, value, category, Const.SECURITY_LIMIT, profile)
+            return self.sat_host.bridge.setParam(name, value, category, C.SECURITY_LIMIT, profile)
         else:
             warning("Trying to set parameter '%s' in category '%s' without authorization!!!"
                     % (name, category))
@@ -532,7 +532,7 @@
         profile = ISATSession(self.session).profile
         self.sat_host.bridge.confirmationAnswer(confirmation_id, result, answer_data, profile)
 
-    def jsonrpc_syntaxConvert(self, text, syntax_from=Const.SYNTAX_XHTML, syntax_to=Const.SYNTAX_CURRENT):
+    def jsonrpc_syntaxConvert(self, text, syntax_from=C.SYNTAX_XHTML, syntax_to=C.SYNTAX_CURRENT):
         """ Convert a text between two syntaxes
         @param text: text to convert
         @param syntax_from: source syntax (e.g. "markdown")
@@ -576,7 +576,7 @@
             profile = ISATSession(_session).profile
             if not profile:
                 #user is not identified, we return a jsonrpc fault
-                fault = jsonrpclib.Fault(Const.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia
+                fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia
                 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc'))
         self.request = request
         return jsonrpc.JSONRPC.render(self, request)
@@ -770,18 +770,18 @@
         </individual>
         </params>
         """ % {
-            'category_name': Const.ENABLE_UNIBOX_KEY,
-            'category_label': _(Const.ENABLE_UNIBOX_KEY),
-            'param_name': Const.ENABLE_UNIBOX_PARAM,
-            'param_label': _(Const.ENABLE_UNIBOX_PARAM)
+            'category_name': C.ENABLE_UNIBOX_KEY,
+            'category_label': _(C.ENABLE_UNIBOX_KEY),
+            'param_name': C.ENABLE_UNIBOX_PARAM,
+            'param_label': _(C.ENABLE_UNIBOX_PARAM)
         }
 
-        self.sat_host.bridge.paramsRegisterApp(params, Const.SECURITY_LIMIT, Const.APP_NAME)
+        self.sat_host.bridge.paramsRegisterApp(params, C.SECURITY_LIMIT, C.APP_NAME)
 
     def jsonrpc_getMenus(self):
         """Return the parameters XML for profile"""
         # XXX: we put this method in Register because we get menus before being logged
-        return self.sat_host.bridge.getMenus('', Const.SECURITY_LIMIT)
+        return self.sat_host.bridge.getMenus('', C.SECURITY_LIMIT)
 
     def __getSecurityWarning(self):
         """@return: a security warning message, or None if the connection is secure"""
@@ -888,7 +888,7 @@
         profile = ISATSession(_session).profile
         if not profile:
             #user is not identified, we return a jsonrpc fault
-            fault = jsonrpclib.Fault(Const.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia
+            fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia
             return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc'))
         self.request = request
         return jsonrpc.JSONRPC.render(self, request)
@@ -1020,7 +1020,7 @@
         self.redirect_to_https = kwargs['redirect_to_https']
         self.security_warning = kwargs['security_warning']
         self._cleanup = []
-        root = ProtectedFile(Const.LIBERVIA_DIR)
+        root = ProtectedFile(C.LIBERVIA_DIR)
         self.signal_handler = SignalHandler(self)
         _register = Register(self)
         _upload_radiocol = UploadManagerRadioCol(self)
@@ -1058,8 +1058,8 @@
         root.putChild('upload_avatar', _upload_avatar)
         root.putChild('blog', MicroBlog(self))
         root.putChild('css', ProtectedFile("server_css/"))
-        root.putChild(os.path.dirname(Const.MEDIA_DIR), ProtectedFile(self.media_dir))
-        root.putChild(os.path.dirname(Const.AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, Const.AVATARS_DIR)))
+        root.putChild(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir))
+        root.putChild(os.path.dirname(C.AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, C.AVATARS_DIR)))
         root.putChild('radiocol', ProtectedFile(_upload_radiocol.getTmpDir(), defaultType="audio/ogg")) #We cheat for PoC because we know we are on the same host, so we use directly upload dir
         self.site = server.Site(root)
         self.site.sessionFactory = LiberviaSession
@@ -1120,6 +1120,6 @@
 
 
 registerAdapter(SATSession, server.Session, ISATSession)
-application = service.Application(Const.APP_NAME)
+application = service.Application(C.APP_NAME)
 service = Libervia()
 service.setServiceParent(application)