Replace a custom implementation of an ordered dict in the file orderedmapping.py by collections.OrderedDict (#131)

This commit is contained in:
Ernesto Rodriguez Ortiz
2017-11-01 09:55:24 -04:00
committed by GitHub
parent f9d8868794
commit c326d59b2d
2 changed files with 3 additions and 39 deletions

View File

@@ -17,14 +17,14 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import math import math
from collections import OrderedDict
from .compat import to_s from .compat import to_s
from .orderedmapping import OrderedMapping
class Num2Word_Base(object): class Num2Word_Base(object):
def __init__(self): def __init__(self):
self.cards = OrderedMapping() self.cards = OrderedDict()
self.is_title = False self.is_title = False
self.precision = 2 self.precision = 2
self.exclude_title = [] self.exclude_title = []
@@ -39,7 +39,7 @@ class Num2Word_Base(object):
self.setup() self.setup()
self.set_numwords() self.set_numwords()
self.MAXVAL = 1000 * self.cards.order[0] self.MAXVAL = 1000 * list(self.cards.keys())[0]
def set_numwords(self): def set_numwords(self):
self.set_high_numwords(self.high_numwords) self.set_high_numwords(self.high_numwords)

View File

@@ -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