def parse_number(string, locale=LC_NUMERIC): """Parse localized number string into a long integer. >>> parse_number('1,099', locale='en_US') == long_type(1099) True >>> parse_number('1.099', locale='de_DE') == long_type(1099) True When the given string cannot be parsed, a NumberFormatError is raised. :param string: the string to parse :param locale: the `Locale` object or locale identifier :return: the parsed number :rtype: `long` :raise `NumberFormatError`: if the string can not be converted to a number """ try: return long_type(string.replace(get_group_symbol(locale), '')) except ValueError: raise NumberFormatError('%r is not a valid number' % string)
:since: version 0.9 :see: `The Format of MO Files <http://www.gnu.org/software/gettext/manual/gettext.html#MO-Files>`_ """ from __future__ import unicode_literals import array import struct from babel.compat import long_type, xrange, PY3 from babel.messages.catalog import Catalog, Message __all__ = ['read_mo', 'write_mo'] __docformat__ = 'restructuredtext en' LE_MAGIC = long_type(0x950412de) BE_MAGIC = long_type(0xde120495) def read_mo(fileobj): """Read a binary MO file from the given file-like object and return a corresponding `Catalog` object. :param fileobj: the file-like object to read the MO file from :return: a catalog object representing the parsed MO file :rtype: `Catalog` :note: The implementation of this function is heavily based on the ``GNUTranslations._parse`` method of the ``gettext`` module in the standard library. """
:see: `The Format of MO Files <http://www.gnu.org/software/gettext/manual/gettext.html#MO-Files>`_ """ from __future__ import unicode_literals import array import struct from babel.compat import long_type, xrange, PY3 from babel.messages.catalog import Catalog, Message __all__ = ['read_mo', 'write_mo'] __docformat__ = 'restructuredtext en' LE_MAGIC = long_type(0x950412de) BE_MAGIC = long_type(0xde120495) def read_mo(fileobj): """Read a binary MO file from the given file-like object and return a corresponding `Catalog` object. :param fileobj: the file-like object to read the MO file from :return: a catalog object representing the parsed MO file :rtype: `Catalog` :note: The implementation of this function is heavily based on the ``GNUTranslations._parse`` method of the ``gettext`` module in the standard library. """ catalog = Catalog()