After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 690921 - Gtk.UIManager add_ui_from_string cannot handle 2 byte UTF symbols
Gtk.UIManager add_ui_from_string cannot handle 2 byte UTF symbols
Status: RESOLVED DUPLICATE of bug 690329
Product: pygobject
Classification: Bindings
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2012-12-31 14:54 UTC by Benny Malengier
Modified: 2012-12-31 15:38 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Benny Malengier 2012-12-31 14:54:11 UTC
Trying to set following ui def:

<ui><menubar name="MenuBar"><menu action="ToolsMenu"><placeholder name="P_ToolsMenu"><menu action="Analys-och-utforskning"><menuitem action="dbrowse"/><menuitem action="eventcmp"/></menu><menu action="Bearbetar-Släktträd"><menuitem action="dupfind"/><menuitem action="excity"/><menuitem action="patchnames"/><menuitem action="chname"/><menuitem action="editowner"/><menuitem action="mergecitations"/><menuitem action="reorder_ids"/><menuitem action="sortevents"/><menuitem action="evname"/><menuitem action="chtype"/></menu><menu action="Felsökning"><menuitem action="test_for_date_parser_and_displayer"/><menuitem action="dgenstats"/><menuitem action="testcasegenerator"/><menuitem action="populatesources"/><menuitem action="eval"/><menuitem action="leak"/></menu><menu action="Hjälpmedel"><menuitem action="not_related"/><menuitem action="mediaman"/><menuitem action="soundgen"/><menuitem action="relcalc"/><menuitem action="verify"/></menu><menu action="Reparera-Släktträd"><menuitem action="rebuild_refmap"/><menuitem action="check"/><menuitem action="rebuild"/><menuitem action="remove_unused"/><menuitem action="rebuild_genstats"/></menu></placeholder></menu></menubar></ui>

Gives the error:

    self.tool_menu_ui_id = self.uistate.uimanager.add_ui_from_string(uidef)
  • File "/usr/lib64/python3.3/site-packages/gi/overrides/Gtk.py", line 297 in add_ui_from_string
    return Gtk.UIManager.add_ui_from_string(self, buffer, length)
  • File "/usr/lib64/python3.3/site-packages/gi/types.py", line 47 in function
    return info.invoke(*args, **kwargs)
gi._glib.GError: Fel på rad 1 tecken 1182:Dokumentet tog oväntat slut inuti stängningstaggen för elementet "menubar"

Translation:
gi._glib.GError:Error on line 1 character 1182:The document ended unexpectedly within the closing tag for the element "menubar"
The length of the string is 1181. 1182 points outside the string.

The reason seems to be 2 byte UTF-8 symbols. overrides/GTK.py does: 

class UIManager(Gtk.UIManager):
    def add_ui_from_string(self, buffer):
        if not isinstance(buffer, _basestring):
            raise TypeError('buffer must be a string')

        length = len(buffer)

        return Gtk.UIManager.add_ui_from_string(self, buffer, length)

which sets length to the number of characters in the buffer, while length should be the byte length I presume.

Workaround: there is no need for UTF-8 symbols in the ui string, so keep actions ASCII only, and set in the Gtk.Action the label to the UTF-8 to be shown (http://developer.gnome.org/gtk3/stable/GtkAction.html#gtk-action-new)
Comment 1 Benny Malengier 2012-12-31 15:25:10 UTC
I forgot to mention this is only with python 3. In python 2 this works.

Also, some other UTF-8 strings do seem to work, so this might be more complicated than simply using a special UTF-8 symbol.
Comment 2 Martin Pitt 2012-12-31 15:38:59 UTC
This was fixed recently, see bug 690329.

*** This bug has been marked as a duplicate of bug 690329 ***