Example #1
0
def test_libintl():
    if sys.platform != "darwin" and not sys.platform.startswith("linux"):
        py.test.skip("there is (maybe) no libintl here")
    _gettext = external('gettext', [rffi.CCHARP], rffi.CCHARP)
    p = rffi.str2charp("1234")
    res = _gettext(p)
    assert res == p
    assert rffi.charp2str(res) == "1234"
    rffi.free_charp(p)
Example #2
0
def test_libintl():
    if sys.platform != "darwin" and not sys.platform.startswith("linux"):
        py.test.skip("there is (maybe) no libintl here")
    _gettext = external('gettext', [rffi.CCHARP], rffi.CCHARP)
    p = rffi.str2charp("1234")
    res = _gettext(p)
    assert res == p
    assert rffi.charp2str(res) == "1234"
    rffi.free_charp(p)
Example #3
0
                  charp2uni(space, lp.c_positive_sign))
    space.setitem(w_result, w("negative_sign"),
                  charp2uni(space, lp.c_negative_sign))
    space.setitem(w_result, w("int_frac_digits"), w(lp.c_int_frac_digits))
    space.setitem(w_result, w("frac_digits"), w(lp.c_frac_digits))
    space.setitem(w_result, w("p_cs_precedes"), w(lp.c_p_cs_precedes))
    space.setitem(w_result, w("p_sep_by_space"), w(lp.c_p_sep_by_space))
    space.setitem(w_result, w("n_cs_precedes"), w(lp.c_n_cs_precedes))
    space.setitem(w_result, w("n_sep_by_space"), w(lp.c_n_sep_by_space))
    space.setitem(w_result, w("p_sign_posn"), w(lp.c_p_sign_posn))
    space.setitem(w_result, w("n_sign_posn"), w(lp.c_n_sign_posn))

    return w_result


_wcscoll = rlocale.external('wcscoll', [rffi.CWCHARP, rffi.CWCHARP], rffi.INT)


def strcoll(space, w_s1, w_s2):
    "string,string -> int. Compares two strings according to the locale."

    s1, s2 = space.unicode_w(w_s1), space.unicode_w(w_s2)

    s1_c = rffi.unicode2wcharp(s1)
    s2_c = rffi.unicode2wcharp(s2)
    try:
        result = _wcscoll(s1_c, s2_c)
    finally:
        rffi.free_wcharp(s1_c)
        rffi.free_wcharp(s2_c)
Example #4
0
    space.setitem(w_result, w("p_cs_precedes"),
                  w(lp.c_p_cs_precedes))
    space.setitem(w_result, w("p_sep_by_space"),
                  w(lp.c_p_sep_by_space))
    space.setitem(w_result, w("n_cs_precedes"),
                  w(lp.c_n_cs_precedes))
    space.setitem(w_result, w("n_sep_by_space"),
                  w(lp.c_n_sep_by_space))
    space.setitem(w_result, w("p_sign_posn"),
                  w(lp.c_p_sign_posn))
    space.setitem(w_result, w("n_sign_posn"),
                  w(lp.c_n_sign_posn))

    return w_result

_strcoll = rlocale.external('strcoll', [rffi.CCHARP, rffi.CCHARP], rffi.INT)
_wcscoll = rlocale.external('wcscoll', [rffi.CWCHARP, rffi.CWCHARP], rffi.INT)


def strcoll(space, w_s1, w_s2):
    "string,string -> int. Compares two strings according to the locale."

    if (space.isinstance_w(w_s1, space.w_str) and
        space.isinstance_w(w_s2, space.w_str)):

        s1, s2 = space.str_w(w_s1), space.str_w(w_s2)
        s1_c = rffi.str2charp(s1)
        s2_c = rffi.str2charp(s2)
        try:
            return space.wrap(_strcoll(s1_c, s2_c))
        finally:
Example #5
0
#def money_format(space, args_w):
#    """Formats a number as a currency string."""
#    raise NotImplementedError()


@wrap(['space', int])
def nl_langinfo(space, item):
    """Query language and locale information."""
    try:
        return space.newstr(rnl_langinfo(item))
    except ValueError:
        space.ec.warn("nl_langinfo(): Item '%d' is not valid" % item)
        return space.w_False


_strcoll = rlocale.external('strcoll', [rffi.CCHARP, rffi.CCHARP], rffi.INT)


def strcoll_u(str1, str2):
    return _strcoll(rffi.str2charp(str1), rffi.str2charp(str2))


@wrap(['space', str, str])
def strcoll(space, str1, str2):
    """Locale based string comparison."""
    return space.newint(strcoll_u(str1, str2))


_tolower = rlocale.external('tolower', [rffi.INT], rffi.INT)
_toupper = rlocale.external('toupper', [rffi.INT], rffi.INT)
Example #6
0
#@wrap(['space', 'args_w'])
#def money_format(space, args_w):
#    """Formats a number as a currency string."""
#    raise NotImplementedError()


@wrap(['space', int])
def nl_langinfo(space, item):
    """Query language and locale information."""
    try:
        return space.newstr(rnl_langinfo(item))
    except ValueError:
        space.ec.warn("nl_langinfo(): Item '%d' is not valid" % item)
        return space.w_False

_strcoll = rlocale.external('strcoll', [rffi.CCHARP, rffi.CCHARP], rffi.INT)

def strcoll_u(str1, str2):
    return _strcoll(rffi.str2charp(str1), rffi.str2charp(str2))


@wrap(['space', str, str])
def strcoll(space, str1, str2):
    """Locale based string comparison."""
    return space.newint(strcoll_u(str1, str2))

_tolower = rlocale.external('tolower', [rffi.INT], rffi.INT)
_toupper = rlocale.external('toupper', [rffi.INT], rffi.INT)


@wrap(['space', str])