diff options
author | ng0 <ng0@n0.is> | 2019-09-27 16:18:36 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-27 16:18:36 +0000 |
commit | 180232cfa78ae0ee539da11cafd9c588590994d3 (patch) | |
tree | 137cd92cef8eb2e4968531dd908136221c3af2e8 | |
parent | a7d7fb4332c4a17ea9cc265b87a620a0d2eb523b (diff) | |
download | merchant-frontend-examples-180232cfa78ae0ee539da11cafd9c588590994d3.tar.gz merchant-frontend-examples-180232cfa78ae0ee539da11cafd9c588590994d3.tar.bz2 merchant-frontend-examples-180232cfa78ae0ee539da11cafd9c588590994d3.zip |
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | python/example/example.py | 6 | ||||
-rw-r--r-- | python/example/setup.py | 12 | ||||
-rw-r--r-- | python/lib/Makefile | 5 | ||||
-rw-r--r-- | python/lib/pytaler/__init__.py | 0 | ||||
-rw-r--r-- | python/lib/pytaler/amount.py | 72 | ||||
-rw-r--r-- | python/lib/pytaler/test_amount.py | 32 | ||||
-rwxr-xr-x | python/lib/setup.py | 11 |
8 files changed, 21 insertions, 123 deletions
@@ -15,3 +15,9 @@ python/doc/tutorial.html python/doc/tutorial.log python/doc/tutorial.pdf python/doc/tutorial.toc + +__pycache__ +dist +*.egg-info +test-env + diff --git a/python/example/example.py b/python/example/example.py index 2f90392..505144c 100644 --- a/python/example/example.py +++ b/python/example/example.py @@ -1,7 +1,7 @@ import flask import requests from urllib.parse import urljoin, urlencode -from pytaler import amount +import taler.util.amount import base64 import os import logging @@ -47,8 +47,8 @@ def donate(): @app.route("/generate-proposal") def generate_proposal(): - DONATION = amount.string_to_amount("0.1:%s" % CURRENCY) - MAX_FEE = amount.string_to_amount("0.05:%s" % CURRENCY) + DONATION = amount.string_to_amount("0.1:%s" % CURRENCY) + MAX_FEE = amount.string_to_amount("0.05:%s" % CURRENCY) ORDER_ID = "tutorial-%X-%s" % (randint(0, 0xFFFFFFFF), datetime.today().strftime("%H_%M_%S")) order = dict( order_id=ORDER_ID, diff --git a/python/example/setup.py b/python/example/setup.py new file mode 100644 index 0000000..4dedfc4 --- /dev/null +++ b/python/example/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup, find_packages + +setup( + name='example', + version='0.6.0rc0', + long_description=__doc__, + packages=find_packages(), + include_package_data=True, + zip_safe=False, + install_requires=['Flask', + 'taler-util'] + ) diff --git a/python/lib/Makefile b/python/lib/Makefile deleted file mode 100644 index cf3cacc..0000000 --- a/python/lib/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -install: - pip3 install . --install-option="--prefix=$(TALER_PREFIX)" --upgrade - -check: - python3 pytaler/tests.py diff --git a/python/lib/pytaler/__init__.py b/python/lib/pytaler/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/python/lib/pytaler/__init__.py +++ /dev/null diff --git a/python/lib/pytaler/amount.py b/python/lib/pytaler/amount.py deleted file mode 100644 index e15e623..0000000 --- a/python/lib/pytaler/amount.py +++ /dev/null @@ -1,72 +0,0 @@ -# This file is part of GNU TALER. -# Copyright (C) 2014-2017 INRIA -# -# TALER 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, or (at your option) any later version. -# -# TALER 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 -# GNU TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -# -# @author Marcello Stanisci - -import re - -FRACTION = 100000000 - -def amount_get_zero(currency): - return dict(value=0, fraction=0, currency=currency) - -def string_to_amount(fmt): - pattern = re.compile("^[0-9]+\.[0-9]+:[A-Z]+$") - assert(pattern.match(fmt)) - split = fmt.split(":") - num = split[0] - currency = split[1] - split = num.split(".") - value = int(split[0]) - fraction = float("0." + split[1]) * FRACTION - return dict(value=value, fraction=int(fraction), currency=currency) - - -def amount_sum(a1, a2): - assert(a1['currency'] == a2['currency']) - fractions = a1['fraction'] + a2['fraction'] - ret = {"value": a1["value"] + a2["value"] + int(fractions / FRACTION), - "fraction": fractions % FRACTION, - "currency": a1["currency"]} - return ret - -# True if a1 == a2 -def same_amount(a1, a2): - return a1["value"] == a2["value"] and a1["fraction"] == a2["fraction"] and a1["currency"] == a2["currency"] - -# Computes a1 - a2 -def amount_sub(a1, a2): - assert(a1["currency"] == a2["currency"]) - - # Normalize - a1["value"] += int(a1["fraction"] / FRACTION) - a2["value"] += int(a2["fraction"] / FRACTION) - a1["fraction"] = a1["fraction"] % FRACTION - a2["fraction"] = a2["fraction"] % FRACTION - - # Extra care for fraction - if a1["fraction"] < a2["fraction"]: - a1["fraction"] += FRACTION - a1["value"] -= 1 - assert(a1["value"] >= 0) - - # Sub - ret = amount_get_zero(a1["currency"]) - ret["value"] = a1["value"] - a2["value"] - ret["fraction"] = a1["fraction"] - a2["fraction"] - - assert(ret["value"] >= 0) - assert(ret["fraction"] >= 0) - - return ret diff --git a/python/lib/pytaler/test_amount.py b/python/lib/pytaler/test_amount.py deleted file mode 100644 index ffc8cba..0000000 --- a/python/lib/pytaler/test_amount.py +++ /dev/null @@ -1,32 +0,0 @@ -import unittest -import amounts -from random import randint - -CURRENCY = "KUDOS" - -class AmountsTest(unittest.TestCase): - - def test_sum_sub(self): - a1 = amounts.amount_get_zero(CURRENCY) - a2 = amounts.amount_get_zero(CURRENCY) - v1 = randint(1, 200) - v2 = randint(1, 200) - f1 = randint(10000000, 100000000) - f2 = randint(10000000, 100000000) - a1['value'] = v1 - a2['value'] = v2 - a1['fraction'] = f1 - a2['fraction'] = f2 - res1 = amounts.amount_sum(a1, a2) - res2 = amounts.amount_sub(res1, a1) - self.assertTrue(amounts.same_amount(res2, a2)) - - - def test_string_to_amount(self): - model = dict(value=1, fraction=0, currency=CURRENCY) - amount = amounts.string_to_amount("1.0:%s" % CURRENCY) - self.assertTrue(amounts.same_amount(model, amount)) - - -if __name__ == '__main__': - unittest.main() diff --git a/python/lib/setup.py b/python/lib/setup.py deleted file mode 100755 index 5727698..0000000 --- a/python/lib/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -from setuptools import setup, find_packages - -setup(name='pytaler', - version='0.0', - description='Helper functions for Taler amounts', - url='git://taler.net/merchant-frontend-examples', - author='Marcello Stanisci', - author_email='marcello.stanisci@inria.fr', - license='GPL', - packages=find_packages(), - zip_safe=False) |