changeset 662:ebb602d8b3f2 frontends_multi_profiles

browser_side: replace all instances of 'str' with 'unicode'
author souliane <souliane@mailoo.org>
date Tue, 03 Mar 2015 06:51:13 +0100
parents 2664fe93ceb3
children 423182fea41c
files src/browser/libervia_main.py src/browser/sat_browser/base_menu.py src/browser/sat_browser/blog.py src/browser/sat_browser/chat.py src/browser/sat_browser/dialog.py src/browser/sat_browser/libervia_widget.py src/browser/sat_browser/main_panel.py src/browser/sat_browser/plugin_sec_otr.py src/browser/sat_browser/xmlui.py
diffstat 9 files changed, 61 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Tue Mar 03 06:24:27 2015 +0100
+++ b/src/browser/libervia_main.py	Tue Mar 03 06:51:13 2015 +0100
@@ -212,7 +212,7 @@
         """Return avatar of a jid if in cache, else ask for it.
 
         @param jid_ (jid.JID): JID of the contact
-        @return: the URL to the avatar (str)
+        @return: the URL to the avatar (unicode)
         """
         assert isinstance(jid_, jid.JID)
         contact_list = self.contact_list  # pyjamas issue: need a temporary variable to call a property's method
@@ -434,7 +434,7 @@
     def _actionEb(self, err_data):
         err_code, err_obj = err_data
         dialog.InfoDialog("Error",
-                          str(err_obj), Width="400px").center()
+                          unicode(err_obj), Width="400px").center()
 
     def launchAction(self, callback_id, data):
         """ Launch a dynamic action
@@ -648,7 +648,7 @@
     #     @param class_ (class): class of the panel (ChatPanel, MicroblogPanel...)
     #     @param entity (dict): dictionnary to define the entity.
     #     @param select (bool): if True, select the widget that has been found or created
-    #     @param new_tab (str): if not None, a widget which is created is created in
+    #     @param new_tab (unicode): if not None, a widget which is created is created in
     #     a new tab. In that case new_tab is a unicode to label that new tab.
     #     If new_tab is not None and a widget is found, no tab is created.
     #     @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS
@@ -885,7 +885,7 @@
     # def _chatStateReceivedCb(self, from_jid_s, state):
     #     """Callback when a new chat state is received.
     #     @param from_jid_s: JID of the contact who sent his state, or '@ALL@'
-    #     @param state: new state (string)
+    #     @param state (unicode): new state
     #     """
     #     if from_jid_s == '@ALL@':
     #         for lib_wid in self.libervia_widgets:
@@ -923,15 +923,15 @@
     def getCachedParam(self, category, name):
         """Return a parameter cached value (e.g for refreshing the UI)
 
-        @param category (str): the parameter category
-        @pram name (str): the parameter name
+        @param category (unicode): the parameter category
+        @pram name (unicode): the parameter name
         """
         return self.cached_params[(category, name)] if (category, name) in self.cached_params else None
 
     def sendError(self, errorData):
         dialog.InfoDialog("Error while sending message",
                           "Your message can't be sent", Width="400px").center()
-        log.error("sendError: %s" % str(errorData))
+        log.error("sendError: %s" % unicode(errorData))
 
     # FIXME: this method is fat too complicated and depend of widget type
     #        must be refactored and moved to each widget instead
--- a/src/browser/sat_browser/base_menu.py	Tue Mar 03 06:24:27 2015 +0100
+++ b/src/browser/sat_browser/base_menu.py	Tue Mar 03 06:51:13 2015 +0100
@@ -36,13 +36,16 @@
 import re
 
 
+unicode = str  # FIXME: pyjamas workaround
+
+
 class MenuCmd(object):
     """Return an object with an "execute" method that can be set to a menu item callback"""
 
     def __init__(self, object_, handler=None, data=None):
         """
         @param object_ (object): a callable or a class instance
-        @param handler (str): method name if object_ is a class instance
+        @param handler (unicode): method name if object_ is a class instance
         @param data (dict): data to pass as the callback argument
         """
         if handler is None:
@@ -80,7 +83,7 @@
 
     def __init__(self, name=None, item=None, menu=None, flat_level=0):
         """
-        @param name (str): node name
+        @param name (unicode): node name
         @param item (MenuItem): associated menu item
         @param menu (GenericMenuBar): associated menu bar
         @param flat_level (int): sub-menus until that level see their items
@@ -96,9 +99,9 @@
         """Return the requested category. If create is True, path_i18n and
         types are specified, recursively create the category and its parent.
 
-        @param path (list[str]): path to the category
-        @param path_i18n (list[str]): internationalized path to the category
-        @param types (list[str]): types of the category and its parents
+        @param path (list[unicode]): path to the category
+        @param path_i18n (list[unicode]): internationalized path to the category
+        @param types (list[unicode]): types of the category and its parents
         @param create (bool): if True, create the category
         @param sub_menu (GenericMenuBar): instance to popup as the category
         sub-menu, if it is created. Otherwise keep the previous sub-menu.
@@ -122,7 +125,7 @@
         """Return all the categories of the current node, or those of the
         sub-category which is specified by target_path.
 
-        @param target_path (list[str]): path to the target node
+        @param target_path (list[unicode]): path to the target node
         @return: list[MenuNode]
         """
         assert(self.menu)  # this method applies to category nodes
@@ -135,9 +138,9 @@
     def addMenuItem(self, path, path_i18n, types, callback=None, asHTML=False):
         """Recursively add a new node, which could be a category or a leaf node.
 
-        @param path (list[str], str): path to the item
-        @param path_i18n (list[str], str): internationalized path to the item
-        @param types (list[str], str): types of the item and its parents
+        @param path (list[unicode], unicode): path to the item
+        @param path_i18n (list[unicode], unicode): internationalized path to the item
+        @param types (list[unicode], unicode): types of the item and its parents
         @param callback (MenuCmd, PluginMenuCmd or GenericMenuBar): instance to
         execute as a leaf's callback or to popup as a category sub-menu
         @param asHTML (boolean): True to display the UI item as HTML
@@ -148,9 +151,9 @@
         category = isinstance(callback, GenericMenuBar)
         assert(not leaf_node or not category)
 
-        path = [path] if isinstance(path, str) else path
-        path_i18n = [path_i18n] if isinstance(path_i18n, str) else path_i18n
-        types = [types for dummy in range(len(path_i18n))] if isinstance(types, str) else types
+        path = [path] if isinstance(path, unicode) else path
+        path_i18n = [path_i18n] if isinstance(path_i18n, unicode) else path_i18n
+        types = [types for dummy in range(len(path_i18n))] if isinstance(types, unicode) else types
 
         if category:
             return self._getOrCreateCategory(path, path_i18n, types, True, callback)
@@ -164,9 +167,9 @@
     def addCategory(self, path, path_i18n, types, menu_bar=None):
         """Recursively add a new category.
 
-        @param path (list[str], str): path to the category
-        @param path_i18n (list[str], str): internationalized path to the category
-        @param types (list[str], str): types of the category and its parents
+        @param path (list[unicode], unicode): path to the category
+        @param path_i18n (list[unicode], unicode): internationalized path to the category
+        @param types (list[unicode], unicode): types of the category and its parents
         @param menu_bar (GenericMenuBar): instance to popup as the category sub-menu.
         """
         if menu_bar:
@@ -181,7 +184,7 @@
         @param item: see MenuBar.addItem
         @param asHTML: see MenuBar.addItem
         @param popup: see MenuBar.addItem
-        @param name (str): the item node's name
+        @param name (unicode): the item node's name
         """
         if item is None:  # empty string is allowed to set a separator
             return None
@@ -212,7 +215,7 @@
             if len(path) != len(path_i18n):
                 log.error("inconsistency between menu paths")
                 continue
-            if isinstance(action_id, str):
+            if isinstance(action_id, unicode):
                 callback = PluginMenuCmd(self.menu.host, action_id, menu_data)
             elif callable(action_id):
                 callback = MenuCmd(action_id, data=menu_data)
@@ -248,9 +251,9 @@
         """Build the html to be used for displaying a category item.
 
         Inheriting classes may overwrite this method.
-        @param menu_name_i18n (str): internationalized category name
-        @param type_ (str): category type
-        @return: str
+        @param menu_name_i18n (unicode): internationalized category name
+        @param type_ (unicode): category type
+        @return: unicode
         """
         return menu_name_i18n
 
--- a/src/browser/sat_browser/blog.py	Tue Mar 03 06:24:27 2015 +0100
+++ b/src/browser/sat_browser/blog.py	Tue Mar 03 06:51:13 2015 +0100
@@ -166,7 +166,7 @@
         is_publisher = self.author == self._blog_panel.host.whoami.bare
         if is_publisher:
             self.update_label = addIcon(u"✍", "Edit this message")
-        if is_publisher or str(self.node).endswith(unicode(self._blog_panel.host.whoami.bare)):
+        if is_publisher or unicode(self.node).endswith(unicode(self._blog_panel.host.whoami.bare)):
             self.delete_label = addIcon(u"✗", "Delete this message")
 
     def updateAvatar(self, new_avatar):
@@ -191,7 +191,7 @@
         if not content['text']:  # previous content has been emptied
             self._delete(True)
             return False
-        extra = {'published': str(self.published)}
+        extra = {'published': unicode(self.published)}
         if isinstance(self.bubble, richtext.RichTextEditor):
             # TODO: if the user change his parameters after the message edition started,
             # the message syntax could be different then the current syntax: pass the
@@ -275,7 +275,7 @@
             self._current_comment.bubble.setFocus(True)
             self._blog_panel.setSelectedEntry(self._current_comment, True)
             return
-        data = {'id': str(time()),
+        data = {'id': unicode(time()),
                 'new': True,
                 'type': 'comment',
                 'author': unicode(self._blog_panel.host.whoami.bare),
@@ -408,7 +408,7 @@
             def addBox():
                 if hasattr(self, 'new_button'):
                     self.new_button.setVisible(False)
-                data = {'id': str(time()),
+                data = {'id': unicode(time()),
                         'new': True,
                         'author': unicode(self.host.whoami.bare),
                         }
--- a/src/browser/sat_browser/chat.py	Tue Mar 03 06:24:27 2015 +0100
+++ b/src/browser/sat_browser/chat.py	Tue Mar 03 06:51:13 2015 +0100
@@ -111,7 +111,7 @@
         self.vpanel.setCellHeight(self._body, '100%')
         self.addStyleName('chatPanel')
         self.setWidget(self.vpanel)
-        self.state_machine = plugin_xep_0085.ChatStateMachine(self.host, str(self.target))
+        self.state_machine = plugin_xep_0085.ChatStateMachine(self.host, unicode(self.target))
         self._state = None
         self.refresh()
         if type_ == C.CHAT_ONE2ONE:
@@ -185,7 +185,7 @@
         return ("ONE2ONE" if self.type == C.CHAT_ONE2ONE else "GROUP", msg)
 
     def onTextEntered(self, text):
-        self.host.sendMessage(str(self.target),
+        self.host.sendMessage(unicode(self.target),
                               text,
                               mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT,
                              errback=self.host.sendError,
@@ -204,7 +204,8 @@
 
     def setPresents(self, nicks):
         """Set the users presents in this room
-        @param occupants: list of nicks (string)"""
+        @param occupants (list[unicode]): list of nicks
+        """
         self.occupants_panel.setList([jid.JID(u"%s/%s" % (self.target,nick)) for nick in nicks])
 
     # def userJoined(self, nick, data):
@@ -335,7 +336,7 @@
 
     def setConnected(self, jid_s, resource, availability, priority, statuses):
         """Set connection status
-        @param jid_s (str): JID userhost as unicode
+        @param jid_s (unicode): JID userhost as unicode
         """
         raise Exception("should not be there") # FIXME
         assert(jid_s == self.target.bare)
--- a/src/browser/sat_browser/dialog.py	Tue Mar 03 06:24:27 2015 +0100
+++ b/src/browser/sat_browser/dialog.py	Tue Mar 03 06:51:13 2015 +0100
@@ -563,7 +563,7 @@
         minus_button = Button("-", self.onMinus)
         self.box = WheelTextBox()
         self.box.setVisibleLength(visible_len)
-        self.box.setText(str(value))
+        self.box.setText(unicode(value))
         self.box.addInputListener(self)
         self.box.addMouseWheelListener(self)
         plus_button = Button("+", self.onPlus)
@@ -586,19 +586,19 @@
     def setValue(self, value):
         """Change the value and fire valueChange listeners"""
         self.value = value
-        self.box.setText(str(value))
+        self.box.setText(unicode(value))
         self._callListeners()
 
     def onMinus(self, sender, step=1):
         self.value = max(0, self.value - step)
-        self.box.setText(str(self.value))
+        self.box.setText(unicode(self.value))
         self._callListeners()
 
     def onPlus(self, sender, step=1):
         self.value += step
         if self.value_max:
             self.value = min(self.value, self.value_max)
-        self.box.setText(str(self.value))
+        self.box.setText(unicode(self.value))
         self._callListeners()
 
     def onInput(self, sender):
@@ -609,7 +609,7 @@
             pass
         if self.value_max:
             self.value = min(self.value, self.value_max)
-        self.box.setText(str(self.value))
+        self.box.setText(unicode(self.value))
         self._callListeners()
 
     def onMouseWheel(self, sender, velocity):
--- a/src/browser/sat_browser/libervia_widget.py	Tue Mar 03 06:24:27 2015 +0100
+++ b/src/browser/sat_browser/libervia_widget.py	Tue Mar 03 06:51:13 2015 +0100
@@ -50,6 +50,9 @@
 import base_panel
 
 
+unicode = str  # FIXME: pyjamas workaround
+
+
 # FIXME: we need to group several unrelated panels/widgets in this module because of isinstance tests and other references to classes (e.g. if we separate Drag n Drop classes in a separate module, we'll have cyclic import because of the references to LiberviaWidget in DropCell).
 # TODO: use a more generic method (either use duck typing, or register classes in a generic way, without hard references), then split classes in separate modules
 
@@ -358,8 +361,8 @@
         """Init the widget
 
         @param host (SatWebFrontend): SatWebFrontend instance
-        @param title (str): title shown in the header of the widget
-        @param info (str, callable): info shown in the header of the widget
+        @param title (unicode): title shown in the header of the widget
+        @param info (unicode, callable): info shown in the header of the widget
         @param selectable (bool): True is widget can be selected by user
         """
         VerticalPanel.__init__(self)
@@ -372,7 +375,7 @@
         self._title = Label(title)
         self._title.setStyleName('widgetHeader_title')
         if info is not None:
-            if isinstance(info, str):
+            if isinstance(info, unicode):
                 self._info = HTML(info)
             else:  # the info will be set by a callback
                 assert callable(info)
--- a/src/browser/sat_browser/main_panel.py	Tue Mar 03 06:24:27 2015 +0100
+++ b/src/browser/sat_browser/main_panel.py	Tue Mar 03 06:51:13 2015 +0100
@@ -176,7 +176,7 @@
 
     def changePresenceCb(self, presence=''):
         """Callback to notice the backend of a new presence set by the user.
-        @param presence (str): the new presence is a value in ('', 'chat', 'away', 'dnd', 'xa')
+        @param presence (unicode): the new presence is a value in ('', 'chat', 'away', 'dnd', 'xa')
         """
         self.host.bridge.call('setStatus', None, presence, self.parent_panel.status_panel.status)
 
--- a/src/browser/sat_browser/plugin_sec_otr.py	Tue Mar 03 06:24:27 2015 +0100
+++ b/src/browser/sat_browser/plugin_sec_otr.py	Tue Mar 03 06:51:13 2015 +0100
@@ -135,7 +135,7 @@
     def getPolicy(self, key):
         """Get the value of the specified policy
 
-        @param key (str): a value in:
+        @param key (unicode): a value in:
             - ALLOW_V1 (apriori removed from otr.js)
             - ALLOW_V2
             - ALLOW_V3
@@ -143,7 +143,7 @@
             - SEND_WHITESPACE_TAG
             - WHITESPACE_START_AKE
             - ERROR_START_AKE
-        @return: str
+        @return: unicode
         """
         if key in DEFAULT_POLICY_FLAGS:
             return DEFAULT_POLICY_FLAGS[key]
@@ -242,11 +242,11 @@
     def smpAuthCb(self, type_, data, act=None):
         """OTR v3 authentication using the socialist millionaire protocol.
 
-        @param type_ (str): a value in ('question', 'trust', 'abort')
-        @param data (str, bool): this could be:
+        @param type_ (unicode): a value in ('question', 'trust', 'abort')
+        @param data (unicode, bool): this could be:
             - a string containing the question if type_ is 'question'
             - a boolean value telling if the authentication succeed when type_ is 'trust'
-        @param act (str): a value in ('asked', 'answered')
+        @param act (unicode): a value in ('asked', 'answered')
         """
         log.debug("smpAuthCb: type={type}, data={data}, act={act}".format(type=type_, data=data, act=act))
         if act is None:
@@ -369,9 +369,9 @@
     def getInfoText(self, state=otr.context.STATE_PLAINTEXT, trust=''):
         """Get the widget info text for a certain message state and trust.
 
-        @param state (str): message state
-        @param trust (str): trust
-        @return: str
+        @param state (unicode): message state
+        @param trust (unicode): trust
+        @return: unicode
         """
         if not state:
             state = OTR_MSG_STATES.keys()[0]
@@ -492,7 +492,7 @@
     def endSession(self, other_jid, profile, finish=False):
         """Finish or disconnect an OTR session
 
-        @param other_jid (jid.JID): str
+        @param other_jid (jid.JID): contact JID
         @param finish: if True, finish the session but do not disconnect it
         @return: True if the session has been finished or disconnected, False if there was nothing to do
         """
--- a/src/browser/sat_browser/xmlui.py	Tue Mar 03 06:24:27 2015 +0100
+++ b/src/browser/sat_browser/xmlui.py	Tue Mar 03 06:51:13 2015 +0100
@@ -71,7 +71,7 @@
         """Add a divider
 
         @param _xmlui_parent
-        @param style (string): one of:
+        @param style (unicode): one of:
             - line: a simple line
             - dot: a line of dots
             - dash: a line of dashes