summaryrefslogtreecommitdiff
path: root/taler/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-01-29 19:24:25 +0100
committerChristian Grothoff <christian@grothoff.org>2021-01-29 19:24:25 +0100
commit43f5f0baa0a40fa9e5c32dd76bd46b0637850f67 (patch)
treeeb1c52521caf5f4f9d4fab2a43a83331ff011220 /taler/util
parentd807b5fbeafcd730f45be0f71f8623d5f8abc807 (diff)
downloadtaler-util-43f5f0baa0a40fa9e5c32dd76bd46b0637850f67.tar.gz
taler-util-43f5f0baa0a40fa9e5c32dd76bd46b0637850f67.tar.bz2
taler-util-43f5f0baa0a40fa9e5c32dd76bd46b0637850f67.zip
move PaytoParse logic into taler-util (#6650)
Diffstat (limited to 'taler/util')
-rw-r--r--taler/util/payto.py47
1 files changed, 47 insertions, 0 deletions
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