From 6e2b0eeda2bc3d979598ff171e23062416352e3a Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 28 May 2013 11:50:48 -0400 Subject: [PATCH] Big unit reorganisation * Renamed pynum2word to num2word * Renamed num2word_* to lang_* * Re-organised all unit headers * Made imports relative --- num2words/__init__.py | 46 ++++++++++++++ .../num2word_base.py => num2words/base.py | 34 +++++------ .../num2word_DE.py => num2words/lang_DE.py | 45 +++++--------- .../num2word_EN.py => num2words/lang_EN.py | 55 +++++------------ .../lang_EN_EUR.py | 47 +++++---------- .../lang_EN_GB.py | 48 +++++---------- .../lang_EN_GB_old.py | 42 +++++-------- .../num2word_ES.py => num2words/lang_ES.py | 44 +++++--------- .../num2word_EU.py => num2words/lang_EU.py | 36 +++++------ .../num2word_FR.py => num2words/lang_FR.py | 46 +++++--------- .../num2word_LT.py => num2words/lang_LT.py | 15 +++++ num2words/orderedmapping.py | 35 +++++++++++ pynum2word/__init__.py | 0 pynum2word/num2word.py | 60 ------------------- pynum2word/orderedmapping.py | 35 ----------- 15 files changed, 232 insertions(+), 356 deletions(-) create mode 100644 num2words/__init__.py rename pynum2word/num2word_base.py => num2words/base.py (88%) rename pynum2word/num2word_DE.py => num2words/lang_DE.py (83%) rename pynum2word/num2word_EN.py => num2words/lang_EN.py (77%) rename pynum2word/num2word_EN_EUR.py => num2words/lang_EN_EUR.py (56%) rename pynum2word/num2word_EN_GB.py => num2words/lang_EN_GB.py (54%) rename pynum2word/num2word_EN_GB_old.py => num2words/lang_EN_GB_old.py (53%) rename pynum2word/num2word_ES.py => num2words/lang_ES.py (82%) rename pynum2word/num2word_EU.py => num2words/lang_EU.py (51%) rename pynum2word/num2word_FR.py => num2words/lang_FR.py (77%) rename pynum2word/num2word_LT.py => num2words/lang_LT.py (88%) create mode 100644 num2words/orderedmapping.py delete mode 100644 pynum2word/__init__.py delete mode 100644 pynum2word/num2word.py delete mode 100644 pynum2word/orderedmapping.py diff --git a/num2words/__init__.py b/num2words/__init__.py new file mode 100644 index 0000000..cdb3519 --- /dev/null +++ b/num2words/__init__.py @@ -0,0 +1,46 @@ +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA + +from __future__ import unicode_literals + +from . import lang_EN +from . import lang_EN_GB +from . import lang_FR +from . import lang_DE +from . import lang_ES +from . import lang_LT + +CONVERTER_CLASSES = { + 'en': lang_EN.Num2Word_EN(), + 'en_GB': lang_EN_GB.Num2Word_EN_GB(), + 'fr': lang_FR.Num2Word_FR(), + 'de': lang_DE.Num2Word_DE(), + 'es': lang_ES.Num2Word_ES(), + 'lt': lang_LT.Num2Word_LT(), +} + +def num2words(number, ordinal=False, lang='en'): + # We try the full language first + if lang not in CONVERTER_CLASSES: + # ... and then try only the first 2 letters + lang = lang[:2] + if lang not in CONVERTER_CLASSES: + raise NotImplementedError() + converter = CONVERTER_CLASSES[lang] + if ordinal: + return converter.to_ordinal(number) + else: + return converter.to_cardinal(number) diff --git a/pynum2word/num2word_base.py b/num2words/base.py similarity index 88% rename from pynum2word/num2word_base.py rename to num2words/base.py index a311527..f892d42 100644 --- a/pynum2word/num2word_base.py +++ b/num2words/base.py @@ -1,25 +1,21 @@ -''' -Module: num2word_base.py -Version: 1.0 +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. -Author: - Taro Ogawa (tso@users.sourceforge.org) - -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. - -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php - -History: - 1.1: add to_splitnum() and inflect() - add to_year() and to_currency() stubs -''' +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA from __future__ import unicode_literals -from orderedmapping import OrderedMapping +from .orderedmapping import OrderedMapping class Num2Word_Base(object): diff --git a/pynum2word/num2word_DE.py b/num2words/lang_DE.py similarity index 83% rename from pynum2word/num2word_DE.py rename to num2words/lang_DE.py index 8eb7312..8f4517a 100644 --- a/pynum2word/num2word_DE.py +++ b/num2words/lang_DE.py @@ -1,36 +1,21 @@ -''' -Module: num2word_DE.py -Requires: num2word_base.py -Version: 0.4 +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. -Author: - Taro Ogawa (tso@users.sourceforge.org) +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. - -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php - -Data from: - - http://german4u2know.tripod.com/nouns/10.html - - http://www.uni-bonn.de/~manfear/large.php - -Usage: - from num2word_DE import to_card, to_ord, to_ordnum - to_card(1234567890) - to_ord(1234567890) - to_ordnum(12) - -History - 0.4: Use high ascii characters instead of low ascii approximations - add to_currency() and to_year() - -''' from __future__ import unicode_literals -from num2word_EU import Num2Word_EU +from .lang_EU import Num2Word_EU #//TODO: Use German error messages class Num2Word_DE(Num2Word_EU): diff --git a/pynum2word/num2word_EN.py b/num2words/lang_EN.py similarity index 77% rename from pynum2word/num2word_EN.py rename to num2words/lang_EN.py index 700db24..a73c893 100644 --- a/pynum2word/num2word_EN.py +++ b/num2words/lang_EN.py @@ -1,46 +1,23 @@ -''' -Module: num2word_EN.py -Requires: num2word_EU.py -Version: 1.2 +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. -Author: - Taro Ogawa (tso@users.sourceforge.org) - -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php - -Data from: - http://www.uni-bonn.de/~manfear/large.php - -Usage: - from num2word_EN import n2w, to_card, to_ord, to_ordnum - to_card(1234567890) - n2w.is_title = True - to_card(1234567890) - to_ord(1234567890) - to_ordnum(1234567890) - to_year(1976) - to_currency(dollars*100 + cents, longval=False) - to_currency((dollars, cents)) - - -History: - 1.2: to_ordinal_num() made shorter and simpler (but slower) - strings in merge() now interpolated - to_year() and to_currency() added - - 1.1: to_ordinal_num() fixed for 11,12,13 -''' from __future__ import division, unicode_literals -import num2word_EU +from . import lang_EU - -class Num2Word_EN(num2word_EU.Num2Word_EU): +class Num2Word_EN(lang_EU.Num2Word_EU): def set_high_numwords(self, high): max = 3 + 3*len(high) for word, n in zip(high, range(max, 3, -3)): diff --git a/pynum2word/num2word_EN_EUR.py b/num2words/lang_EN_EUR.py similarity index 56% rename from pynum2word/num2word_EN_EUR.py rename to num2words/lang_EN_EUR.py index 1d847c6..503484b 100644 --- a/pynum2word/num2word_EN_EUR.py +++ b/num2words/lang_EN_EUR.py @@ -1,38 +1,21 @@ -''' -Module: num2word_EN_EUR.py -Requires: num2word_EN.py -Version: 1.0 +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. -Author: - Taro Ogawa (tso@users.sourceforge.org) - -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php - -Data from: - http://www.uni-bonn.de/~manfear/large.php - -Usage: - from num2word_EN import n2w, to_card, to_ord, to_ordnum - to_card(1234567890) - n2w.is_title = True - to_card(1234567890) - to_ord(1234567890) - to_ordnum(1234567890) - to_year(1976) - to_currency(euros*100 + cents) - to_currency((euros,cents)) - - -''' from __future__ import unicode_literals -from num2word_EN import Num2Word_EN - +from .lang_EN import Num2Word_EN class Num2Word_EN_EUR(Num2Word_EN): def to_currency(self, val, longval=True, cents=True, jointxt="and"): diff --git a/pynum2word/num2word_EN_GB.py b/num2words/lang_EN_GB.py similarity index 54% rename from pynum2word/num2word_EN_GB.py rename to num2words/lang_EN_GB.py index 1502004..568594d 100644 --- a/pynum2word/num2word_EN_GB.py +++ b/num2words/lang_EN_GB.py @@ -1,39 +1,21 @@ -''' -Module: num2word_EN_GB.py -Requires: num2word_EN.py -Version: 1.0 +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. -Author: - Taro Ogawa (tso@users.sourceforge.org) - -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php - -Data from: - http://www.uni-bonn.de/~manfear/large.php - -Usage: - from num2word_EN import n2w, to_card, to_ord, to_ordnum - to_card(1234567890) - n2w.is_title = True - to_card(1234567890) - to_ord(1234567890) - to_ordnum(1234567890) - to_year(1976) - to_currency(pounds*100 + pence) - to_currency((pounds,pence)) - - -History: - 1.0: Split from num2word_EN with the addition of to_currency() -''' from __future__ import unicode_literals -from num2word_EN import Num2Word_EN +from .lang_EN import Num2Word_EN class Num2Word_EN_GB(Num2Word_EN): diff --git a/pynum2word/num2word_EN_GB_old.py b/num2words/lang_EN_GB_old.py similarity index 53% rename from pynum2word/num2word_EN_GB_old.py rename to num2words/lang_EN_GB_old.py index b33bde3..34a86fc 100644 --- a/pynum2word/num2word_EN_GB_old.py +++ b/num2words/lang_EN_GB_old.py @@ -1,33 +1,21 @@ -''' -Module: num2word_EN_GB_old.py -Requires: num2word_EN_GB_old.py -Version: 0.3 +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. -Author: - Taro Ogawa (tso@users.sourceforge.org) - -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php - -Usage: - from num2word_EN_old import to_card, to_ord, to_ordnum - to_card(1234567890) - to_ord(1234567890) - to_ordnum(12) - -History: - 0.3: Rename from num2word_EN_old - -Todo: - Currency (pounds/shillings/pence) -''' from __future__ import unicode_literals -from num2word_EN_GB import Num2Word_EN_GB +from .lang_EN_GB import Num2Word_EN_GB class Num2Word_EN_GB_old(Num2Word_EN_GB): def base_setup(self): diff --git a/pynum2word/num2word_ES.py b/num2words/lang_ES.py similarity index 82% rename from pynum2word/num2word_ES.py rename to num2words/lang_ES.py index e10946e..4bcf938 100644 --- a/pynum2word/num2word_ES.py +++ b/num2words/lang_ES.py @@ -1,35 +1,21 @@ -''' -Module: num2word_ES.py -Requires: num2word_EU.py -Version: 0.3 +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. -Author: - Taro Ogawa (tso@users.sourceforge.org) - -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php - -Data from: - http://www.smartphrase.com/Spanish/sp_numbers_voc.shtml - -Usage: - from num2word_ES import to_card, to_ord, to_ordnum - to_card(1234567890) - to_ord(1234567890) - to_ordnum(12) - -History: - 0.3: Use high ascii characters instead of low ascii approximations - String interpolation where it makes things clearer - add to_currency() -''' from __future__ import unicode_literals -from num2word_EU import Num2Word_EU +from .lang_EU import Num2Word_EU #//TODO: correct orthographics #//TODO: error messages diff --git a/pynum2word/num2word_EU.py b/num2words/lang_EU.py similarity index 51% rename from pynum2word/num2word_EU.py rename to num2words/lang_EU.py index e319268..bdb2d32 100644 --- a/pynum2word/num2word_EU.py +++ b/num2words/lang_EU.py @@ -1,27 +1,21 @@ -''' -Module: num2word_EU.py -Requires: num2word_base.py -Version: 1.1 +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. -Author: - Taro Ogawa (tso@users.sourceforge.org) - -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php - -Data from: - http://www.uni-bonn.de/~manfear/large.php - -History: - 1.1: add to_currency() -''' from __future__ import unicode_literals -from num2word_base import Num2Word_Base +from .base import Num2Word_Base class Num2Word_EU(Num2Word_Base): def set_high_numwords(self, high): diff --git a/pynum2word/num2word_FR.py b/num2words/lang_FR.py similarity index 77% rename from pynum2word/num2word_FR.py rename to num2words/lang_FR.py index 2506a82..39b0e8b 100644 --- a/pynum2word/num2word_FR.py +++ b/num2words/lang_FR.py @@ -1,38 +1,22 @@ # -*- encoding: utf-8 -*- -''' -Module: num2word_FR.py -Requires: num2word_EU.py -Version: 0.5 +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. -Author: - Taro Ogawa (tso@users.sourceforge.org) - -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php - -Data from: - http://www.ouc.bc.ca/mola/fr/handouts/numbers.doc - http://www.realfrench.net/units/Interunit_63.html - http://www.sover.net/~daxtell/france/Euro/euro.htm - -Usage: - from num2word_FR import to_card, to_ord, to_ordnum - to_card(1234567890) - to_ord(1234567890) - to_ordnum(12) - -History: - 0.5: Use high ascii characters instead of low ascii approximations - String interpolation where it makes things clearer - to_currency() added [to_year works by default] -''' from __future__ import unicode_literals -from num2word_EU import Num2Word_EU +from .lang_EU import Num2Word_EU #//TODO: error messages in French #//TODO: ords diff --git a/pynum2word/num2word_LT.py b/num2words/lang_LT.py similarity index 88% rename from pynum2word/num2word_LT.py rename to num2words/lang_LT.py index 76d7e2b..38767aa 100644 --- a/pynum2word/num2word_LT.py +++ b/num2words/lang_LT.py @@ -1,4 +1,19 @@ # -*- encoding: utf-8 -*- +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA u""" >>> from textwrap import fill diff --git a/num2words/orderedmapping.py b/num2words/orderedmapping.py new file mode 100644 index 0000000..cf5b0c0 --- /dev/null +++ b/num2words/orderedmapping.py @@ -0,0 +1,35 @@ +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA + +class OrderedMapping(dict): + def __init__(self, *pairs): + self.order = [] + for key, val in pairs: + self[key] = val + + def __setitem__(self, key, val): + if key not in self: + self.order.append(key) + super(OrderedMapping, self).__setitem__(key, val) + + def __iter__(self): + for item in self.order: + yield item + + def __repr__(self): + out = ["%s: %s"%(repr(item), repr(self[item])) for item in self] + out = ", ".join(out) + return "{%s}"%out diff --git a/pynum2word/__init__.py b/pynum2word/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/pynum2word/num2word.py b/pynum2word/num2word.py deleted file mode 100644 index 2a34f71..0000000 --- a/pynum2word/num2word.py +++ /dev/null @@ -1,60 +0,0 @@ -''' -Module: num2word.py -Requires: num2word_*.py -Version: 0.2 - -Author: - Taro Ogawa (tso@users.sourceforge.org) - -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. - -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php - -Usage: - from num2word import to_card, to_ord, to_ordnum - to_card(1234567890) - to_ord(1234567890) - to_ordnum(12) - -Notes: - The module is a wrapper for language-specific modules. It imports the - appropriate modules as defined by locale settings. If unable to - load an appropriate module, an ImportError is raised. - -History: - 0.2: n2w, to_card, to_ord, to_ordnum now imported correctly -''' -from __future__ import unicode_literals - -import num2word_EN -import num2word_EN_GB -import num2word_FR -import num2word_DE -import num2word_ES -import num2word_LT - -CONVERTER_CLASSES = { - 'en': num2word_EN.Num2Word_EN(), - 'en_GB': num2word_EN_GB.Num2Word_EN_GB(), - 'fr': num2word_FR.Num2Word_FR(), - 'de': num2word_DE.Num2Word_DE(), - 'es': num2word_ES.Num2Word_ES(), - 'lt': num2word_LT.Num2Word_LT(), -} - -def num2words(number, ordinal=False, lang='en'): - # We try the full language first - if lang not in CONVERTER_CLASSES: - # ... and then try only the first 2 letters - lang = lang[:2] - if lang not in CONVERTER_CLASSES: - raise NotImplementedError() - converter = CONVERTER_CLASSES[lang] - if ordinal: - return converter.to_ordinal(number) - else: - return converter.to_cardinal(number) diff --git a/pynum2word/orderedmapping.py b/pynum2word/orderedmapping.py deleted file mode 100644 index 341aa1f..0000000 --- a/pynum2word/orderedmapping.py +++ /dev/null @@ -1,35 +0,0 @@ -''' -Module: orderedmapping.py -Version: 1.0 - -Author: - Taro Ogawa (tso@users.sourceforge.org) - -Copyright: - Copyright (c) 2003, Taro Ogawa. All Rights Reserved. - Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. - -Licence: - This module is distributed under the Lesser General Public Licence. - http://www.opensource.org/licenses/lgpl-license.php -''' -from __future__ import generators -class OrderedMapping(dict): - def __init__(self, *pairs): - self.order = [] - for key, val in pairs: - self[key] = val - - def __setitem__(self, key, val): - if key not in self: - self.order.append(key) - super(OrderedMapping, self).__setitem__(key, val) - - def __iter__(self): - for item in self.order: - yield item - - def __repr__(self): - out = ["%s: %s"%(repr(item), repr(self[item])) for item in self] - out = ", ".join(out) - return "{%s}"%out