Commit 02e5c006 authored by Andi Vajda's avatar Andi Vajda
Browse files

added support for ICU 71

parent 883fbe31
Version 2.8.1 ->
--------------------
- added support for ICU 71.1rc
- added wrappers for UMeasurePrefix, MeasureUnit.withPrefix()|getPrefix()
- added UNumberRoundingPriority, FractionPrecision.withSignificantDigits()
- added UNumberTrailingZeroDisplay, Precision.trailingZeroDisplay()
-
Version 2.8 -> 2.8.1
--------------------
- renamed _icu extension module to _icu_ and moved it into icu module
......
/* ====================================================================
* Copyright (c) 2004-2019 Open Source Applications Foundation.
* Copyright (c) 2004-2022 Open Source Applications Foundation.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
......@@ -37,6 +37,10 @@ DECLARE_CONSTANTS_TYPE(UTimeUnitFields)
DECLARE_CONSTANTS_TYPE(UMeasureUnitComplexity)
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
DECLARE_CONSTANTS_TYPE(UMeasurePrefix)
#endif
DECLARE_CONSTANTS_TYPE(UCurrNameStyle)
/* MeasureUnit */
......@@ -61,6 +65,11 @@ static PyObject *t_measureunit_reciprocal(t_measureunit *self);
static PyObject *t_measureunit_forIdentifier(PyTypeObject *type, PyObject *arg);
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
static PyObject *t_measureunit_withPrefix(t_measureunit *self, PyObject *arg);
static PyObject *t_measureunit_getPrefix(t_measureunit *self);
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(53, 0, 0)
static PyObject *t_measureunit_createAcre(PyTypeObject *type);
static PyObject *t_measureunit_createArcMinute(PyTypeObject *type);
......@@ -288,6 +297,11 @@ static PyMethodDef t_measureunit_methods[] = {
DECLARE_METHOD(t_measureunit, forIdentifier, METH_CLASS | METH_O),
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
DECLARE_METHOD(t_measureunit, withPrefix, METH_O),
DECLARE_METHOD(t_measureunit, getPrefix, METH_NOARGS),
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(53, 0, 0)
DECLARE_METHOD(t_measureunit, createAcre, METH_NOARGS | METH_CLASS),
DECLARE_METHOD(t_measureunit, createArcMinute, METH_NOARGS | METH_CLASS),
......@@ -855,6 +869,33 @@ static PyObject *t_measureunit_forIdentifier(PyTypeObject *type, PyObject *arg)
return PyErr_SetArgsError(type, "forIdentifier", arg);
}
#endif // ICU >= 67
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
static PyObject *t_measureunit_withPrefix(t_measureunit *self, PyObject *arg)
{
UMeasurePrefix prefix;
if (!parseArg(arg, "i", &prefix))
{
MeasureUnit mu;
STATUS_CALL(mu = self->object->withPrefix(prefix, status));
return wrap_MeasureUnit((MeasureUnit *) mu.clone(), T_OWNED);
}
return PyErr_SetArgsError((PyObject *) self, "withPrefix", arg);
}
static PyObject *t_measureunit_getPrefix(t_measureunit *self)
{
UMeasurePrefix prefix;
STATUS_CALL(prefix = self->object->getPrefix(status));
return PyInt_FromLong(prefix);
}
#endif
......@@ -1476,6 +1517,9 @@ void _init_measureunit(PyObject *m)
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(67, 0, 0)
INSTALL_CONSTANTS_TYPE(UMeasureUnitComplexity, m);
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
INSTALL_CONSTANTS_TYPE(UMeasurePrefix, m);
#endif
INSTALL_CONSTANTS_TYPE(UCurrNameStyle, m);
......@@ -1520,4 +1564,36 @@ void _init_measureunit(PyObject *m)
INSTALL_ENUM(UCurrNameStyle, "FORMAL_SYMBOL_NAME", UCURR_FORMAL_SYMBOL_NAME);
INSTALL_ENUM(UCurrNameStyle, "VARIANT_SYMBOL_NAME", UCURR_VARIANT_SYMBOL_NAME);
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
INSTALL_ENUM(UMeasurePrefix, "ONE", UMEASURE_PREFIX_ONE);
INSTALL_ENUM(UMeasurePrefix, "YOTTA", UMEASURE_PREFIX_YOTTA);
INSTALL_ENUM(UMeasurePrefix, "ZETTA", UMEASURE_PREFIX_ZETTA);
INSTALL_ENUM(UMeasurePrefix, "EXA", UMEASURE_PREFIX_EXA);
INSTALL_ENUM(UMeasurePrefix, "PETA", UMEASURE_PREFIX_PETA);
INSTALL_ENUM(UMeasurePrefix, "TERA", UMEASURE_PREFIX_TERA);
INSTALL_ENUM(UMeasurePrefix, "GIGA", UMEASURE_PREFIX_GIGA);
INSTALL_ENUM(UMeasurePrefix, "MEGA", UMEASURE_PREFIX_MEGA);
INSTALL_ENUM(UMeasurePrefix, "KILO", UMEASURE_PREFIX_KILO);
INSTALL_ENUM(UMeasurePrefix, "HECTO", UMEASURE_PREFIX_HECTO);
INSTALL_ENUM(UMeasurePrefix, "DEKA", UMEASURE_PREFIX_DEKA);
INSTALL_ENUM(UMeasurePrefix, "DECI", UMEASURE_PREFIX_DECI);
INSTALL_ENUM(UMeasurePrefix, "CENTI", UMEASURE_PREFIX_CENTI);
INSTALL_ENUM(UMeasurePrefix, "MILLI", UMEASURE_PREFIX_MILLI);
INSTALL_ENUM(UMeasurePrefix, "MICRO", UMEASURE_PREFIX_MICRO);
INSTALL_ENUM(UMeasurePrefix, "NANO", UMEASURE_PREFIX_NANO);
INSTALL_ENUM(UMeasurePrefix, "PICO", UMEASURE_PREFIX_PICO);
INSTALL_ENUM(UMeasurePrefix, "FEMTO", UMEASURE_PREFIX_FEMTO);
INSTALL_ENUM(UMeasurePrefix, "ATTO", UMEASURE_PREFIX_ATTO);
INSTALL_ENUM(UMeasurePrefix, "ZEPTO", UMEASURE_PREFIX_ZEPTO);
INSTALL_ENUM(UMeasurePrefix, "YOCTO", UMEASURE_PREFIX_YOCTO);
INSTALL_ENUM(UMeasurePrefix, "KIBI", UMEASURE_PREFIX_KIBI);
INSTALL_ENUM(UMeasurePrefix, "MEBI", UMEASURE_PREFIX_MEBI);
INSTALL_ENUM(UMeasurePrefix, "GIBI", UMEASURE_PREFIX_GIBI);
INSTALL_ENUM(UMeasurePrefix, "TEBI", UMEASURE_PREFIX_TEBI);
INSTALL_ENUM(UMeasurePrefix, "PEBI", UMEASURE_PREFIX_PEBI);
INSTALL_ENUM(UMeasurePrefix, "EXBI", UMEASURE_PREFIX_EXBI);
INSTALL_ENUM(UMeasurePrefix, "ZEBI", UMEASURE_PREFIX_ZEBI);
INSTALL_ENUM(UMeasurePrefix, "YOBI", UMEASURE_PREFIX_YOBI);
#endif
}
......@@ -68,6 +68,11 @@ DECLARE_CONSTANTS_TYPE(UNumberFormatStyle)
DECLARE_CONSTANTS_TYPE(UNumberRangeCollapse)
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
DECLARE_CONSTANTS_TYPE(UNumberRoundingPriority)
DECLARE_CONSTANTS_TYPE(UNumberTrailingZeroDisplay)
#endif
/* DecimalFormatSymbols */
class t_decimalformatsymbols : public _wrapper {
......@@ -1045,6 +1050,10 @@ static PyObject *t_precision_minMaxSignificantDigits(PyTypeObject *type, PyObjec
static PyObject *t_precision_increment(PyTypeObject *type, PyObject *arg);
static PyObject *t_precision_currency(PyTypeObject *type, PyObject *arg);
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
static PyObject *t_precision_trailingZeroDisplay(t_precision *self, PyObject *arg);
#endif
static PyMethodDef t_precision_methods[] = {
DECLARE_METHOD(t_precision, unlimited, METH_NOARGS | METH_CLASS),
DECLARE_METHOD(t_precision, integer, METH_NOARGS | METH_CLASS),
......@@ -1058,6 +1067,9 @@ static PyMethodDef t_precision_methods[] = {
DECLARE_METHOD(t_precision, minMaxSignificantDigits, METH_VARARGS | METH_CLASS),
DECLARE_METHOD(t_precision, increment, METH_O | METH_CLASS),
DECLARE_METHOD(t_precision, currency, METH_O | METH_CLASS),
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
DECLARE_METHOD(t_precision, trailingZeroDisplay, METH_O),
#endif
{ NULL, NULL, 0, NULL }
};
......@@ -1075,9 +1087,17 @@ static PyObject *t_fractionprecision_minSignificantDigits(
static PyObject *t_fractionprecision_maxSignificantDigits(
t_fractionprecision *self, PyObject *arg);
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
static PyObject *t_fractionprecision_withSignificantDigits(
t_fractionprecision *self, PyObject *args);
#endif
static PyMethodDef t_fractionprecision_methods[] = {
DECLARE_METHOD(t_fractionprecision, minSignificantDigits, METH_O),
DECLARE_METHOD(t_fractionprecision, maxSignificantDigits, METH_O),
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
DECLARE_METHOD(t_fractionprecision, withSignificantDigits, METH_VARARGS),
#endif
{ NULL, NULL, 0, NULL }
};
......@@ -4644,6 +4664,23 @@ static PyObject *t_precision_currency(PyTypeObject *type, PyObject *arg)
return PyErr_SetArgsError(type, "currency", arg);
}
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
static PyObject *t_precision_trailingZeroDisplay(t_precision *self, PyObject *arg)
{
UNumberTrailingZeroDisplay tzd;
if (!parseArg(arg, "i", &tzd))
{
return wrap_Precision(self->object->trailingZeroDisplay(tzd));
}
return PyErr_SetArgsError((PyObject *) self, "trailingZeroDisplay", arg);
}
#endif
/* FractionPrecision */
static PyObject *t_fractionprecision_minSignificantDigits(
......@@ -4672,6 +4709,38 @@ static PyObject *t_fractionprecision_maxSignificantDigits(
return PyErr_SetArgsError((PyObject *) self, "maxSignificantDigits", arg);
}
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
static PyObject *t_fractionprecision_withSignificantDigits(
t_fractionprecision *self, PyObject *args)
{
int minDigits, maxDigits;
UNumberRoundingPriority priority = UNUM_ROUNDING_PRIORITY_RELAXED;
switch (PyTuple_Size(args)) {
case 2:
if (!parseArgs(args, "ii", &minDigits, &maxDigits))
{
return wrap_Precision(
self->object->withSignificantDigits(
minDigits, maxDigits, priority));
}
break;
case 3:
if (!parseArgs(args, "iii", &minDigits, &maxDigits, &priority))
{
return wrap_Precision(
self->object->withSignificantDigits(
minDigits, maxDigits, priority));
}
break;
}
return PyErr_SetArgsError((PyObject *) self, "withSignificantDigits", args);
}
#endif
/* IncrementPrecision */
......@@ -5442,6 +5511,16 @@ void _init_numberformat(PyObject *m)
INSTALL_ENUM(UNumberFormatRoundingMode, "HALF_ODD", UNUM_ROUND_HALF_ODD);
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
INSTALL_CONSTANTS_TYPE(UNumberRoundingPriority, m);
INSTALL_ENUM(UNumberRoundingPriority, "RELAXED", UNUM_ROUNDING_PRIORITY_RELAXED);
INSTALL_ENUM(UNumberRoundingPriority, "STRICT", UNUM_ROUNDING_PRIORITY_STRICT);
INSTALL_CONSTANTS_TYPE(UNumberTrailingZeroDisplay, m);
INSTALL_ENUM(UNumberRoundingPriority, "AUTO", UNUM_TRAILING_ZERO_AUTO);
INSTALL_ENUM(UNumberRoundingPriority, "HIDE_IF_WHOLE", UNUM_TRAILING_ZERO_HIDE_IF_WHOLE);
#endif
INSTALL_CONSTANTS_TYPE(UNumberFormatStyle, m);
INSTALL_ENUM(UNumberFormatStyle, "PATTERN_DECIMAL", UNUM_PATTERN_DECIMAL);
INSTALL_ENUM(UNumberFormatStyle, "DECIMAL", UNUM_DECIMAL);
......
......@@ -9,7 +9,7 @@ except ImportError:
from distutils.spawn import find_executable
VERSION = '2.8.1'
ICU_MAX_MAJOR_VERSION = '70' # max supported major version of ICU
ICU_MAX_MAJOR_VERSION = '71' # max supported major version of ICU
try:
from subprocess import check_output as subprocess_check_output
......
......@@ -47,7 +47,7 @@ class TestDateTimePatternGenerator(TestCase):
sdf = SimpleDateFormat(dtpg.getBestPattern('MMMMddHmm'), locale)
sdf.setTimeZone(self.tz)
if ICU_VERSION < '68.0':
if ICU_VERSION < '68.0' or ICU_VERSION > '71.0':
self.assertEqual(sdf.format(self.date), u'09 mai à 17:30')
self.assertEqual(sdf.toPattern(), u"dd MMMM 'à' HH:mm")
else:
......@@ -57,7 +57,7 @@ class TestDateTimePatternGenerator(TestCase):
dtpg.addPattern("dd'. von' MMMM", True)
sdf.applyPattern(dtpg.getBestPattern('MMMMddHmm'))
sdf.setTimeZone(self.tz)
if ICU_VERSION < '68.0':
if ICU_VERSION < '68.0' or ICU_VERSION > '71.0':
self.assertEqual(sdf.format(self.date), u'09. von mai à 17:30')
self.assertEqual(sdf.toPattern(), u"dd'. von' MMMM 'à' HH:mm")
else:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment