[Checkins] SVN: zope.i18n/trunk/ * Fixed another number formatting
bug.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Thu Jul 19 13:40:34 EDT 2007
Log message for revision 78179:
* Fixed another number formatting bug.
* Provide better package meta-data.
Changed:
U zope.i18n/trunk/CHANGES.txt
U zope.i18n/trunk/setup.py
U zope.i18n/trunk/src/zope/i18n/format.py
U zope.i18n/trunk/src/zope/i18n/tests/test_formats.py
-=-
Modified: zope.i18n/trunk/CHANGES.txt
===================================================================
--- zope.i18n/trunk/CHANGES.txt 2007-07-19 17:04:08 UTC (rev 78178)
+++ zope.i18n/trunk/CHANGES.txt 2007-07-19 17:40:33 UTC (rev 78179)
@@ -4,23 +4,30 @@
After 3.4.0b3
-------------
+3.4.0b4 - (7/19/2007)
+---------------------
+
+- Bug: Number parsing was too forgiving, allowing non-numerical and/or
+ formatting characters before, after and within the number. The parsing is
+ more strict now.
+
3.4.0b3 - (6/28/2007)
---------------------
-- Bug: There was a bug in the parser that if no decimal place is given
- you still had to type the decimal symbol. Corrected this problem (one
+- Bug: There was a bug in the parser that if no decimal place is given
+ you still had to type the decimal symbol. Corrected this problem (one
character ;-) and provided a test.
3.4.0b2 - (6/25/2007)
---------------------
-- Feature: Added ability to change the output type when parsing a
+- Feature: Added ability to change the output type when parsing a
number.
3.4.0b1
-------
-- Bug: Fixed dependency on ``zope.security`` to require a version that
+- Bug: Fixed dependency on ``zope.security`` to require a version that
does not have the hidden dependency on ``zope.testing``.
@@ -48,5 +55,5 @@
3.0.0 - 2004/11/07
------------------
-- Corresponds to the version of the zope.i18n package shipped as part of
+- Corresponds to the version of the zope.i18n package shipped as part of
the Zope X3.0.0 release.
Modified: zope.i18n/trunk/setup.py
===================================================================
--- zope.i18n/trunk/setup.py 2007-07-19 17:04:08 UTC (rev 78178)
+++ zope.i18n/trunk/setup.py 2007-07-19 17:40:33 UTC (rev 78179)
@@ -15,30 +15,48 @@
$Id$
"""
-
import os
-
from setuptools import setup, find_packages
-setup(name='zope.i18n',
- version = '3.4.0b3',
- url='http://svn.zope.org/zope.i18n',
- license='ZPL 2.1',
- description='Zope3 Internationalization Support',
- keywords=('zope3 internationalization localization i18n l10n '
- 'gettext ICU locale'),
- author='Zope Corporation and Contributors',
- author_email='zope3-dev at zope.org',
- packages=find_packages('src'),
- package_dir = {'': 'src'},
- namespace_packages=['zope',],
- install_requires=['setuptools',
- 'pytz',
- 'zope.i18nmessageid',
- 'zope.component',
- 'zope.configuration',
- 'zope.security>=3.4.0b1',
- ],
- include_package_data = True,
- zip_safe = False,
+def read(*rnames):
+ text = open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+ return text
+
+setup(
+ name='zope.i18n',
+ version = '3.4.0b4',
+ author='Zope Corporation and Contributors',
+ author_email='zope3-dev at zope.org',
+ description='Zope3 Internationalization Support',
+ long_description=(
+ read('README.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
+ license='ZPL 2.1',
+ keywords=('zope3 internationalization localization i18n l10n '
+ 'gettext ICU locale'),
+ classifiers = [
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3'],
+ url='http://svn.zope.org/zope.i18n',
+ packages=find_packages('src'),
+ package_dir = {'': 'src'},
+ namespace_packages=['zope',],
+ install_requires=['setuptools',
+ 'pytz',
+ 'zope.i18nmessageid',
+ 'zope.component',
+ 'zope.configuration',
+ 'zope.security>=3.4.0b1',
+ ],
+ include_package_data = True,
+ zip_safe = False,
)
Modified: zope.i18n/trunk/src/zope/i18n/format.py
===================================================================
--- zope.i18n/trunk/src/zope/i18n/format.py 2007-07-19 17:04:08 UTC (rev 78178)
+++ zope.i18n/trunk/src/zope/i18n/format.py 2007-07-19 17:40:33 UTC (rev 78179)
@@ -248,7 +248,7 @@
# Determine sign
num_res = [None, None]
for sign in (0, 1):
- regex = ''
+ regex = '^'
if bin_pattern[sign][PADDING1] is not None:
regex += '[' + bin_pattern[sign][PADDING1] + ']+'
if bin_pattern[sign][PREFIX] != '':
@@ -280,6 +280,7 @@
regex += '[' + bin_pattern[sign][SUFFIX] + ']'
if bin_pattern[sign][PADDING4] is not None:
regex += '[' + bin_pattern[sign][PADDING4] + ']+'
+ regex += '$'
num_res[sign] = re.match(regex, text)
if num_res[0] is not None:
Modified: zope.i18n/trunk/src/zope/i18n/tests/test_formats.py
===================================================================
--- zope.i18n/trunk/src/zope/i18n/tests/test_formats.py 2007-07-19 17:04:08 UTC (rev 78178)
+++ zope.i18n/trunk/src/zope/i18n/tests/test_formats.py 2007-07-19 17:40:33 UTC (rev 78179)
@@ -28,7 +28,7 @@
from zope.i18n.format import DateTimePatternParseError, DateTimeParseError
from zope.i18n.interfaces import INumberFormat
-from zope.i18n.format import NumberFormat
+from zope.i18n.format import NumberFormat, NumberParseError
from zope.i18n.format import parseNumberPattern
class LocaleStub(object):
@@ -532,68 +532,68 @@
'dd.MM.yy h:mm:ss a'),
'02.01.03 2:00:00 vorm.')
self.assertEqual(
- self.format.format(datetime.time(0, 15), 'h:mm a'),
+ self.format.format(datetime.time(0, 15), 'h:mm a'),
'12:15 vorm.')
self.assertEqual(
- self.format.format(datetime.time(1, 15), 'h:mm a'),
+ self.format.format(datetime.time(1, 15), 'h:mm a'),
'1:15 vorm.')
self.assertEqual(
- self.format.format(datetime.time(12, 15), 'h:mm a'),
+ self.format.format(datetime.time(12, 15), 'h:mm a'),
'12:15 nachm.')
self.assertEqual(
- self.format.format(datetime.time(13, 15), 'h:mm a'),
+ self.format.format(datetime.time(13, 15), 'h:mm a'),
'1:15 nachm.')
def testFormatDayInYear(self):
self.assertEqual(
- self.format.format(datetime.date(2003, 1, 3), 'D'),
+ self.format.format(datetime.date(2003, 1, 3), 'D'),
u'3')
self.assertEqual(
- self.format.format(datetime.date(2003, 1, 3), 'DD'),
+ self.format.format(datetime.date(2003, 1, 3), 'DD'),
u'03')
self.assertEqual(
- self.format.format(datetime.date(2003, 1, 3), 'DDD'),
+ self.format.format(datetime.date(2003, 1, 3), 'DDD'),
u'003')
self.assertEqual(
- self.format.format(datetime.date(2003, 12, 31), 'D'),
+ self.format.format(datetime.date(2003, 12, 31), 'D'),
u'365')
self.assertEqual(
- self.format.format(datetime.date(2003, 12, 31), 'DD'),
+ self.format.format(datetime.date(2003, 12, 31), 'DD'),
u'365')
self.assertEqual(
- self.format.format(datetime.date(2003, 12, 31), 'DDD'),
+ self.format.format(datetime.date(2003, 12, 31), 'DDD'),
u'365')
self.assertEqual(
- self.format.format(datetime.date(2004, 12, 31), 'DDD'),
+ self.format.format(datetime.date(2004, 12, 31), 'DDD'),
u'366')
def testFormatDayOfWeekInMOnth(self):
self.assertEqual(
- self.format.format(datetime.date(2003, 1, 3), 'F'),
+ self.format.format(datetime.date(2003, 1, 3), 'F'),
u'1')
self.assertEqual(
- self.format.format(datetime.date(2003, 1, 10), 'F'),
+ self.format.format(datetime.date(2003, 1, 10), 'F'),
u'2')
self.assertEqual(
- self.format.format(datetime.date(2003, 1, 17), 'F'),
+ self.format.format(datetime.date(2003, 1, 17), 'F'),
u'3')
self.assertEqual(
- self.format.format(datetime.date(2003, 1, 24), 'F'),
+ self.format.format(datetime.date(2003, 1, 24), 'F'),
u'4')
self.assertEqual(
- self.format.format(datetime.date(2003, 1, 31), 'F'),
+ self.format.format(datetime.date(2003, 1, 31), 'F'),
u'5')
self.assertEqual(
- self.format.format(datetime.date(2003, 1, 6), 'F'),
+ self.format.format(datetime.date(2003, 1, 6), 'F'),
u'1')
def testFormatUnusualFormats(self):
self.assertEqual(
- self.format.format(datetime.date(2003, 1, 3), 'DDD-yyyy'),
+ self.format.format(datetime.date(2003, 1, 3), 'DDD-yyyy'),
u'003-2003')
self.assertEqual(
self.format.format(datetime.date(2003, 1, 10),
- "F. EEEE 'im' MMMM, yyyy"),
+ "F. EEEE 'im' MMMM, yyyy"),
u'2. Freitag im Januar, 2003')
@@ -844,7 +844,7 @@
self.assertEqual(self.format.parse('0E0', '0E0'),
0)
# This is a special case I found not working, but is used frequently
- # in the new LDML Locale files.
+ # in the new LDML Locale files.
self.assertEqual(self.format.parse('2.3341E+04', '0.000###E+00'),
23341)
@@ -989,6 +989,22 @@
symbols={'decimal': '.', 'group': ',', 'exponential': 'X'})
self.assertEqual(format.parse('1.2X11', '#.#E0'), 1.2e11)
+ def testParseFailWithInvalidCharacters(self):
+ self.assertRaises(
+ NumberParseError,self.format.parse, '123xx', '###0.0#')
+ self.assertRaises(
+ NumberParseError, self.format.parse, 'xx123', '###0.0#')
+ self.assertRaises(
+ NumberParseError, self.format.parse, '1xx23', '###0.0#')
+
+ def testParseFailWithInvalidGroupCharacterPosition(self):
+ self.assertRaises(
+ NumberParseError,self.format.parse, '123,00', '###0.0#')
+ self.assertRaises(
+ NumberParseError, self.format.parse, ',123', '###0.0#')
+ self.assertRaises(
+ NumberParseError, self.format.parse, '1,23.00', '###0.0#')
+
def testChangeOutputType(self):
format = NumberFormat()
format.type = decimal.Decimal
@@ -1013,7 +1029,7 @@
self.assertEqual(self.format.format(1, '0.00E00'),
'1.00E00')
# This is a special case I found not working, but is used frequently
- # in the new LDML Locale files.
+ # in the new LDML Locale files.
self.assertEqual(self.format.format(23341, '0.000###E+00'),
'2.3341E+04')
@@ -1078,7 +1094,7 @@
'23341.0236')
self.assertEqual(self.format.format(23341.02, '###0.000#'),
'23341.020')
-
+
def testRounding(self):
self.assertEqual(self.format.format(0.5, '#'), '1')
self.assertEqual(self.format.format(0.49, '#'), '0')
@@ -1087,8 +1103,8 @@
self.assertEqual(self.format.format(149, '0E0'), '1E2')
self.assertEqual(self.format.format(1.9999, '0.000'), '2.000')
self.assertEqual(self.format.format(1.9999, '0.0000'), '1.9999')
-
+
def testFormatScientificDecimal(self):
self.assertEqual(self.format.format(23341.02357, '0.00####E00'),
'2.334102E04')
More information about the Checkins
mailing list