[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-taler-util] 03/51: amount version 0.1. Basically has
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-taler-util] 03/51: amount version 0.1. Basically has some new exceptions |
Date: |
Mon, 23 Sep 2019 22:01:54 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository taler-util.
commit 3ef2200a2132df2db3ff785cd8cef53e9a059ab5
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Oct 31 15:09:23 2017 +0100
amount version 0.1. Basically has some new exceptions
---
python/amount/amount.py | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/python/amount/amount.py b/python/amount/amount.py
index dfe78dc..9a6318a 100644
--- a/python/amount/amount.py
+++ b/python/amount/amount.py
@@ -16,13 +16,16 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
#
# @author Marcello Stanisci
-# @version 0.0
+# @version 0.1
# @repository https://git.taler.net/copylib.git/
# This code is "copylib", it is versioned under the Git repository
# mentioned above, and it is meant to be manually copied into any project
# which might need it.
-class BadAmount(Exception):
+class CurrencyMismatch(Exception):
+ pass
+
+class BadFormatAmount(Exception):
def __init__(self, faulty_str):
self.faulty_str = faulty_str
@@ -60,7 +63,7 @@ class Amount:
import re
parsed = re.search(exp, amount_str)
if not parsed:
- raise BadAmount(amount_str)
+ raise BadFormatAmount(amount_str)
value = int(parsed.group(2))
fraction = 0
for i, digit in enumerate(parsed.group(3)):
@@ -73,7 +76,8 @@ class Amount:
# 1 if a > b
@staticmethod
def cmp(a, b):
- assert a.currency == b.currency
+ if a.currency != b.currency:
+ raise CurrencyMismatch()
if a.value == b.value:
if a.fraction < b.fraction:
return -1
@@ -84,16 +88,23 @@ class Amount:
return -1
return 1
+ def set(self, currency, value=0, fraction=0):
+ self.currency = currency
+ self.value = value
+ self.fraction = fraction
+
# Add the given amount to this one
def add(self, a):
- assert self.currency == a.currency
+ if self.currency != a.currency:
+ raise CurrencyMismatch()
self.value += a.value
self.fraction += a.fraction
self.__normalize()
# Subtract passed amount from this one
def subtract(self, a):
- assert self.currency == a.currency
+ if self.currency != a.currency:
+ raise CurrencyMismatch()
if self.fraction < a.fraction:
self.fraction += Amount.FRACTION()
self.value -= 1
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [GNUnet-SVN] [taler-taler-util] branch master created (now 3e2d0fb), gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 01/51: readme, gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 08/51: Update python config module., gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 09/51: empty module, gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 03/51: amount version 0.1. Basically has some new exceptions,
gnunet <=
- [GNUnet-SVN] [taler-taler-util] 10/51: Very first draft for solving #4453., gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 05/51: First commit for #4453., gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 02/51: adding amount lib, gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 04/51: add talerconfig and linted amount, gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 06/51: remove old config, gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 07/51: Update "config" module (with one that implements @INLINE@)., gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 14/51: log test, gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 12/51: make map static, gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 25/51: 4453. Parsing line interval., gnunet, 2019/09/23
- [GNUnet-SVN] [taler-taler-util] 11/51: Towards a usable solution for #4453., gnunet, 2019/09/23