changeset 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 8ecc5a7062e4
children d64b415c58ca
files browser_side/base_panels.py browser_side/panels.py browser_side/richtext.py libervia.py libervia_server/__init__.py libervia_server/blog.py twisted/plugins/libervia.py
diffstat 7 files changed, 49 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/base_panels.py	Sun Apr 27 18:53:37 2014 +0200
+++ b/browser_side/base_panels.py	Thu May 01 11:29:09 2014 +0200
@@ -39,7 +39,7 @@
 
 from html_tools import html_sanitize, html_strip, inlineRoot, convertNewLinesToXHTML
 
-from constants import Const
+from constants import Const as C
 from sat_frontends.tools.strings import addURLToText, addURLToImage
 from sat.core.i18n import _
 
@@ -97,7 +97,7 @@
             self._refresh()
 
     def _refresh(self):
-        state = (' %s' % Const.MUC_USER_STATES[self._state]) if self._state else ''
+        state = (' %s' % C.MUC_USER_STATES[self._state]) if self._state else ''
         special = "" if len(self.special) == 0 else " %s" % self.special
         self.setHTML("<div class='occupant'>%s%s%s</div>" % (html_sanitize(self.nick), special, state))
 
--- a/browser_side/panels.py	Sun Apr 27 18:53:37 2014 +0200
+++ b/browser_side/panels.py	Thu May 01 11:29:09 2014 +0200
@@ -53,7 +53,7 @@
 from browser_side import richtext
 from browser_side import contact
 
-from constants import Const
+from constants import Const as C
 from plugin_xep_0085 import ChatStateMachine
 from sat_frontends.tools.strings import addURLToText
 from sat_frontends.tools.games import SYMBOLS
@@ -527,7 +527,7 @@
         content = {'text': self.content_xhtml if self.content_xhtml else self.content,
                    'title': self.title_xhtml if self.title_xhtml else self.title}
         if self.content_xhtml:
-            content.update({'syntax': Const.SYNTAX_XHTML})
+            content.update({'syntax': C.SYNTAX_XHTML})
             if self.author != self._blog_panel.host.whoami.bare:
                 options = ['read_only']
             else:
@@ -621,7 +621,7 @@
         original_content = self.bubble.getOriginalContent()
         rich = not isinstance(self.bubble, richtext.RichTextEditor)
         if rich:
-            original_content['syntax'] = Const.SYNTAX_XHTML
+            original_content['syntax'] = C.SYNTAX_XHTML
 
         def setBubble(text):
             self.content = text
@@ -640,10 +640,10 @@
         if not rich:
             def confirm_cb(answer):
                 if answer:
-                    self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, Const.SYNTAX_CURRENT, Const.SYNTAX_TEXT)
+                    self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, C.SYNTAX_CURRENT, C.SYNTAX_TEXT)
             dialog.ConfirmDialog(confirm_cb, text=_("Do you really want to lose the title and text formatting?")).show()
         else:
-            self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, Const.SYNTAX_TEXT, Const.SYNTAX_XHTML)
+            self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, C.SYNTAX_TEXT, C.SYNTAX_XHTML)
 
 
 class MicroblogPanel(base_widget.LiberviaWidget):
@@ -972,7 +972,7 @@
 
     def __cleanContent(self, content):
         status = content['text']
-        if status == self.EMPTY_STATUS or status in Const.PRESENCE.values():
+        if status == self.EMPTY_STATUS or status in C.PRESENCE.values():
             content['text'] = ''
         return content
 
@@ -990,8 +990,8 @@
         except AttributeError:  # during initialization
             presence = None
         if not status:
-            if presence and presence in Const.PRESENCE:
-                status = Const.PRESENCE[presence]
+            if presence and presence in C.PRESENCE:
+                status = C.PRESENCE[presence]
             else:
                 status = self.EMPTY_STATUS
         self.display.setHTML(addURLToText(status))
@@ -1007,8 +1007,8 @@
         self.status_panel = StatusPanel(host, status=status)
         self.setPresence(presence)
         entries = {}
-        for value in Const.PRESENCE.keys():
-            entries.update({Const.PRESENCE[value]: {"value": value}})
+        for value in C.PRESENCE.keys():
+            entries.update({C.PRESENCE[value]: {"value": value}})
 
         def callback(sender, key):
             self.setPresence(entries[key]["value"])  # order matters
@@ -1253,13 +1253,13 @@
     def setState(self, state, nick=None):
         """Set the chat state (XEP-0085) of the contact. Leave nick to None
         to set the state for a one2one conversation, or give a nickname or
-        Const.ALL_OCCUPANTS to set the state of a participant within a MUC.
+        C.ALL_OCCUPANTS to set the state of a participant within a MUC.
         @param state: the new chat state
         @param nick: None for one2one, the MUC user nick or ALL_OCCUPANTS
         """
         if nick:
             assert(self.type == 'group')
-            occupants = self.occupants_list.occupants_list.keys() if nick == Const.ALL_OCCUPANTS else [nick]
+            occupants = self.occupants_list.occupants_list.keys() if nick == C.ALL_OCCUPANTS else [nick]
             for occupant in occupants:
                 self.occupants_list.occupants_list[occupant].setState(state)
         else:
--- a/browser_side/richtext.py	Sun Apr 27 18:53:37 2014 +0200
+++ b/browser_side/richtext.py	Thu May 01 11:29:09 2014 +0200
@@ -29,7 +29,7 @@
 from pyjamas.ui.KeyboardListener import KeyboardHandler
 from __pyjamas__ import doc
 
-from constants import Const
+from constants import Const as C
 from dialog import ConfirmDialog, InfoDialog
 from base_panels import TitlePanel, BaseTextEditor, HTMLTextEditor
 from list_manager import ListManager
@@ -199,14 +199,14 @@
                 self.display.addStyleName('richTextWysiwyg')
                 self.display.edit(True)
             content = self.getContent()
-            if content['text'] and content['syntax'] != Const.SYNTAX_XHTML:
-                self.host.bridge.call('syntaxConvert', syntaxConvertCb, content['text'], content['syntax'], Const.SYNTAX_XHTML)
+            if content['text'] and content['syntax'] != C.SYNTAX_XHTML:
+                self.host.bridge.call('syntaxConvert', syntaxConvertCb, content['text'], content['syntax'], C.SYNTAX_XHTML)
             else:
                 syntaxConvertCb(content['text'])
         else:
             syntaxConvertCb = lambda text: self.textarea.setText(text)
             text = self.display.getContent()['text']
-            if text and self.toolbar.syntax != Const.SYNTAX_XHTML:
+            if text and self.toolbar.syntax != C.SYNTAX_XHTML:
                 self.host.bridge.call('syntaxConvert', syntaxConvertCb, text)
             else:
                 syntaxConvertCb(text)
@@ -266,7 +266,7 @@
         assert(hasattr(self, 'textarea'))
         assert(hasattr(self, 'toolbar'))
         if self.wysiwyg:
-            content = {'text': self.display.getContent()['text'], 'syntax': Const.SYNTAX_XHTML}
+            content = {'text': self.display.getContent()['text'], 'syntax': C.SYNTAX_XHTML}
         else:
             content = {'text': self.strproc(self.textarea.getText()), 'syntax': self.toolbar.syntax}
         if hasattr(self, 'title_panel'):
--- a/libervia.py	Sun Apr 27 18:53:37 2014 +0200
+++ b/libervia.py	Thu May 01 11:29:09 2014 +0200
@@ -37,7 +37,7 @@
 
 from sat_frontends.tools.misc import InputHistory
 from sat_frontends.tools.strings import getURLParams
-from constants import Const
+from constants import Const as C
 from sat.core.i18n import _
 
 
@@ -188,8 +188,8 @@
         self.initialised = False
         self.init_cache = []  # used to cache events until initialisation is done
         # define here the parameters that have an incidende to UI refresh
-        self.params_ui = {"unibox": {"name": Const.ENABLE_UNIBOX_PARAM,
-                                     "category": Const.ENABLE_UNIBOX_KEY,
+        self.params_ui = {"unibox": {"name": C.ENABLE_UNIBOX_PARAM,
+                                     "category": C.ENABLE_UNIBOX_KEY,
                                      "cast": lambda value: value == 'true',
                                      "value": None
                                      }
@@ -803,7 +803,7 @@
         """
         if from_jid_s == '@ALL@':
             target = '@ALL@'
-            nick = Const.ALL_OCCUPANTS
+            nick = C.ALL_OCCUPANTS
         else:
             from_jid = JID(from_jid_s)
             target = from_jid.bare
--- 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)
--- a/libervia_server/blog.py	Sun Apr 27 18:53:37 2014 +0200
+++ b/libervia_server/blog.py	Thu May 01 11:29:09 2014 +0200
@@ -25,7 +25,7 @@
 from twisted.web.resource import Resource
 from twisted.words.protocols.jabber.jid import JID
 from datetime import datetime
-from constants import Const
+from constants import Const as C
 import uuid
 import re
 
@@ -84,7 +84,7 @@
                         self.host.bridge.getLastGroupBlogs(pub_jid.userhost(), 10, 'libervia', d2.callback, d2.errback)
 
                 d1 = defer.Deferred()
-                JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', Const.SERVER_SECURITY_LIMIT, prof_found, callback=d1.callback, errback=d1.errback))
+                JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', C.SERVER_SECURITY_LIMIT, prof_found, callback=d1.callback, errback=d1.errback))
                 d1.addCallbacks(got_jid)
 
                 return server.NOT_DONE_YET
@@ -103,7 +103,7 @@
                 style = {}
             self.__render_html_blog(mblog_data, style, request, profile)
         eb = lambda failure: self.render_error_blog(failure, request, profile)
-        self.host.bridge.asyncGetParamA('Blog banner', 'Misc', 'value', Const.SERVER_SECURITY_LIMIT, profile, callback=check_banner, errback=eb)
+        self.host.bridge.asyncGetParamA('Blog banner', 'Misc', 'value', C.SERVER_SECURITY_LIMIT, profile, callback=check_banner, errback=eb)
 
     def __render_html_blog(self, mblog_data, style, request, profile):
         """Actually render the static blog. If mblog_data is a list of dict, we are missing
--- a/twisted/plugins/libervia.py	Sun Apr 27 18:53:37 2014 +0200
+++ b/twisted/plugins/libervia.py	Thu May 01 11:29:09 2014 +0200
@@ -25,7 +25,7 @@
 
 from xdg.BaseDirectory import save_config_path
 from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError
-from sat.core.constants import Const
+from sat.core.constants import Const as C
 try:
     from libervia_server import Libervia
     opt_params = Libervia.OPT_PARAMETERS
@@ -49,7 +49,7 @@
         if the  options values are the hard-coded ones or if they have been passed on the command line.
         """
         config = SafeConfigParser()
-        config.read(Const.CONFIG_FILES)
+        config.read(C.CONFIG_FILES)
         for index, param in list(enumerate(self.optParameters)):
             # index is only used to not modify the loop variable "param"
             name = param[0]