[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-copylib] branch master updated: amount version 0.1.
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-copylib] branch master updated: amount version 0.1. Basically has some new exceptions |
Date: |
Tue, 31 Oct 2017 15:10:00 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository copylib.
The following commit(s) were added to refs/heads/master by this push:
new 3ef2200 amount version 0.1. Basically has some new exceptions
3ef2200 is described below
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [taler-copylib] branch master updated: amount version 0.1. Basically has some new exceptions,
gnunet <=