# Path: hamster_gtk/helpers.py
# def _u(string):
#     """
#     Return passed string as a text instance.
# 
#     This helper is particularly useful to wrap Gtk 'string return values' as
#     they depend on the used python version. On python 2 Gtk will return utf-8
#     encoded bytestrings while on python 3 it will return 'unicode strings'.
# 
#     The reason we have to use this and not ``six.u`` is that six does not make
#     assumptions about the encoding and hence can not be used to safely decode
#     non ascii bytestrings into unicode.
# 
#     Args:
#         string (str): A string instance. On ``py2`` this will be a bytestring,
#             on ``py3`` a 'unicode string'.
# 
#     Returns:
#         text_type: Returns a 'unicode text type'. Under ``py2`` that means a
#         ``unicode`` instance, under ``py3`` this will be a ``str`` instance.
#     """
#     if six.PY2:
#         return string.decode('utf-8')
#     else:
#         return string


from gettext import gettext as _
from gi.repository import Gtk
from hamster_lib import Fact
from six import text_type
from hamster_gtk.helpers import _u
        super(EditFactDialog, self).__init__()
        self._fact = fact

        self.set_transient_for(parent)
        self.set_default_size(600, 200)
        # ``self.content_area`` is a ``Gtk.Box``. We strive for an
        # ``Gtk.Grid`` only based layout. So we have to add this extra step.
        self._mainbox = self._get_main_box()
        self.get_content_area().add(self._mainbox)

        # We do not use ``self.add_buttons`` because this only allows to pass
        #  on strings not actual button instances. We want to pass button
        # instances however so we can customize them if we want to.
        self.add_action_widget(self._get_delete_button(), Gtk.ResponseType.REJECT)
        self.add_action_widget(self._get_apply_button(), Gtk.ResponseType.APPLY)
        self.add_action_widget(self._get_cancel_button(), Gtk.ResponseType.CANCEL)
        self.show_all()

    @property
    def updated_fact(self):
        """Fact instance using values at the time of accessing it."""
        def get_raw_fact_value():
            """Get text from raw fact entry field."""
            return _u(self._raw_fact_widget.get_text())

        def get_description_value():
            """Get unicode value from widget."""
            text_view = self._description_widget.get_child()
            text_buffer = text_view.get_buffer()
            start, end = text_buffer.get_bounds()

# Path: hamster_gtk/helpers.py
# def _u(string):
#     """
#     Return passed string as a text instance.
# 
#     This helper is particularly useful to wrap Gtk 'string return values' as
#     they depend on the used python version. On python 2 Gtk will return utf-8
#     encoded bytestrings while on python 3 it will return 'unicode strings'.
# 
#     The reason we have to use this and not ``six.u`` is that six does not make
#     assumptions about the encoding and hence can not be used to safely decode
#     non ascii bytestrings into unicode.
# 
#     Args:
#         string (str): A string instance. On ``py2`` this will be a bytestring,
#             on ``py3`` a 'unicode string'.
# 
#     Returns:
#         text_type: Returns a 'unicode text type'. Under ``py2`` that means a
#         ``unicode`` instance, under ``py3`` this will be a ``str`` instance.
#     """
#     if six.PY2:
#         return string.decode('utf-8')
#     else:
#         return string


# Path: hamster_gtk/misc/dialogs/edit_fact_dialog.py
from gettext import gettext as _
from gi.repository import Gtk
from hamster_lib import Fact
from six import text_type
from hamster_gtk.helpers import _u

        super(EditFactDialog, self).__init__()
        self._fact = fact

        self.set_transient_for(parent)
        self.set_default_size(600, 200)
        # ``self.content_area`` is a ``Gtk.Box``. We strive for an
        # ``Gtk.Grid`` only based layout. So we have to add this extra step.
        self._mainbox = self._get_main_box()
        self.get_content_area().add(self._mainbox)

        # We do not use ``self.add_buttons`` because this only allows to pass
        #  on strings not actual button instances. We want to pass button
        # instances however so we can customize them if we want to.
        self.add_action_widget(self._get_delete_button(), Gtk.ResponseType.REJECT)
        self.add_action_widget(self._get_apply_button(), Gtk.ResponseType.APPLY)
        self.add_action_widget(self._get_cancel_button(), Gtk.ResponseType.CANCEL)
        self.show_all()

    @property
    def updated_fact(self):
        """Fact instance using values at the time of accessing it."""
        def get_raw_fact_value():
            """Get text from raw fact entry field."""
            return _u(self._raw_fact_widget.get_text())

        def get_description_value():
            """Get unicode value from widget."""
            text_view = self._description_widget.get_child()
            text_buffer = text_view.get_buffer()
            start, end = text_buffer.get_bounds()

            return _u(text_buffer.get_text(start, end, True))