gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-util] 01/02: move PaytoParse logic into taler-util (#6650)


From: gnunet
Subject: [taler-taler-util] 01/02: move PaytoParse logic into taler-util (#6650)
Date: Fri, 29 Jan 2021 19:24:58 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository taler-util.

commit 43f5f0baa0a40fa9e5c32dd76bd46b0637850f67
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Jan 29 19:24:25 2021 +0100

    move PaytoParse logic into taler-util (#6650)
---
 setup.py            |  2 +-
 taler/util/payto.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 6794a14..c49b972 100644
--- a/setup.py
+++ b/setup.py
@@ -25,7 +25,7 @@ with open('README', 'r') as f:
 
 setup(
         name='taler-util',
-        version='0.6.4',
+        version='0.6.5',
         license='LGPL3+',
         platforms='any',
         author='Taler Systems SA',
diff --git a/taler/util/payto.py b/taler/util/payto.py
new file mode 100644
index 0000000..a208028
--- /dev/null
+++ b/taler/util/payto.py
@@ -0,0 +1,47 @@
+# This file is part of GNU Taler
+# (C) 2017-2020 Taler Systems SA
+#
+# 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 3 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
+#
+# @author Marcello Stanisci
+# @version 0.1
+# @repository https://git.taler.net/taler-util.git/
+
+import re
+from urllib.parse import urlparse, parse_qsl
+from .amount import Amount
+
+class PaytoFormatError(Exception):
+    def __init__(self, msg):
+        super(PaytoFormatError, self).__init__(msg)
+        self.msg = msg
+
+class PaytoParse:
+    def __init__(self, payto_uri):
+        obj = urlparse(payto_uri)
+        path = obj.path.split("/")
+        if obj.scheme != "payto" or \
+                len(path) != 3 or \
+                not obj.netloc or \
+                not re.match("^payto://", payto_uri):
+            raise PaytoFormatError(f"Bad Payto URI: {payto_uri}")
+        self.target = path.pop()
+        self.bank = path.pop()
+        self.authority = obj.netloc
+        params = dict(parse_qsl(obj.query))
+        self.message = params.get("message")
+        self.amount = Amount.parse(params.get("amount")) if "amount" in params 
else None

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]