1.0.0 Porting Guide

The 0.1 through 1.0.0 releases focused on bringing in functions from yum and python-fedora. This porting guide tells how to port from those APIs to their kitchen replacements.

python-fedora

python-fedora

kitchen replacement

fedora.iterutils.isiterable()

kitchen.iterutils.isiterable() [1]

fedora.textutils.to_unicode()

kitchen.text.converters.to_unicode()

fedora.textutils.to_bytes()

kitchen.text.converters.to_bytes()

yum

yum

kitchen replacement

yum.i18n.dummy_wrapper()

kitchen.i18n.DummyTranslations.ugettext() [2]

yum.i18n.dummyP_wrapper()

kitchen.i18n.DummyTanslations.ungettext() [2]

yum.i18n.utf8_width()

kitchen.text.display.textual_width()

yum.i18n.utf8_width_chop()

kitchen.text.display.textual_width_chop() and kitchen.text.display.textual_width() [3] [5]

yum.i18n.utf8_valid()

kitchen.text.misc.byte_string_valid_encoding()

yum.i18n.utf8_text_wrap()

kitchen.text.display.wrap() [4]

yum.i18n.utf8_text_fill()

kitchen.text.display.fill() [4]

yum.i18n.to_unicode()

kitchen.text.converters.to_unicode() [6]

yum.i18n.to_unicode_maybe()

kitchen.text.converters.to_unicode() [6]

yum.i18n.to_utf8()

kitchen.text.converters.to_bytes() [6]

yum.i18n.to_str()

kitchen.text.converters.to_unicode() or kitchen.text.converters.to_bytes() [7]

yum.i18n.str_eq()

kitchen.text.misc.str_eq()

yum.misc.to_xml()

kitchen.text.converters.unicode_to_xml() or kitchen.text.converters.byte_string_to_xml() [8]

yum.i18n._()

See: Initializing Yum i18n

yum.i18n.P_()

See: Initializing Yum i18n

yum.i18n.exception2msg()

kitchen.text.converters.exception_to_unicode() or kitchen.text.converter.exception_to_bytes() [9]

Initializing Yum i18n

Previously, yum had several pieces of code to initialize i18n. From the toplevel of yum/i18n.py:

try:.
    '''
    Setup the yum translation domain and make _() and P_() translation wrappers
    available.
    using ugettext to make sure translated strings are in Unicode.
    '''
    import gettext
    t = gettext.translation('yum', fallback=True)
    _ = t.ugettext
    P_ = t.ungettext
except:
    '''
    Something went wrong so we make a dummy _() wrapper there is just
    returning the same text
    '''
    _ = dummy_wrapper
    P_ = dummyP_wrapper

With kitchen, this can be changed to this:

from kitchen.i18n import easy_gettext_setup, DummyTranslations
try:
    _, P_ = easy_gettext_setup('yum')
except:
    translations = DummyTranslations()
    _ = translations.ugettext
    P_ = translations.ungettext

Note

In Overcoming frustration: Correctly using unicode in python2, it is mentioned that for some things (like exception messages), using the byte str oriented functions is more appropriate. If this is desired, the setup portion is only a second call to kitchen.i18n.easy_gettext_setup():

b_, bP_ = easy_gettext_setup('yum', use_unicode=False)

The second place where i18n is setup is in yum.YumBase._getConfig() in yum/__init_.py if gaftonmode is in effect:

if startupconf.gaftonmode:
    global _
    _ = yum.i18n.dummy_wrapper

This can be changed to:

if startupconf.gaftonmode:
    global _
    _ = DummyTranslations().ugettext()