From c326d59b2dbc2b16ea1711383d79f5ac252bd5da Mon Sep 17 00:00:00 2001 From: Ernesto Rodriguez Ortiz Date: Wed, 1 Nov 2017 09:55:24 -0400 Subject: [PATCH] Replace a custom implementation of an ordered dict in the file orderedmapping.py by collections.OrderedDict (#131) --- num2words/base.py | 6 +++--- num2words/orderedmapping.py | 36 ------------------------------------ 2 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 num2words/orderedmapping.py diff --git a/num2words/base.py b/num2words/base.py index caafcef..96d1912 100644 --- a/num2words/base.py +++ b/num2words/base.py @@ -17,14 +17,14 @@ from __future__ import unicode_literals import math +from collections import OrderedDict from .compat import to_s -from .orderedmapping import OrderedMapping class Num2Word_Base(object): def __init__(self): - self.cards = OrderedMapping() + self.cards = OrderedDict() self.is_title = False self.precision = 2 self.exclude_title = [] @@ -39,7 +39,7 @@ class Num2Word_Base(object): self.setup() self.set_numwords() - self.MAXVAL = 1000 * self.cards.order[0] + self.MAXVAL = 1000 * list(self.cards.keys())[0] def set_numwords(self): self.set_high_numwords(self.high_numwords) diff --git a/num2words/orderedmapping.py b/num2words/orderedmapping.py deleted file mode 100644 index 7481e7c..0000000 --- a/num2words/orderedmapping.py +++ /dev/null @@ -1,36 +0,0 @@ -# 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