gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-bank] 03/09: linting


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] 03/09: linting
Date: Tue, 05 Dec 2017 13:21:45 +0100

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

marcello pushed a commit to branch master
in repository bank.

commit 9dd4af1f6451fa161cd4b9c0a7c5b9e44bd24cb9
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Dec 4 18:20:55 2017 +0100

    linting
---
 talerbank/__init__.py   |  4 ++--
 talerbank/app/amount.py | 41 ++++++++++++++++++++---------------------
 talerbank/jinja2.py     | 40 +++++++++++++++++++---------------------
 3 files changed, 41 insertions(+), 44 deletions(-)

diff --git a/talerbank/__init__.py b/talerbank/__init__.py
index 4efb025..914d55d 100644
--- a/talerbank/__init__.py
+++ b/talerbank/__init__.py
@@ -1,8 +1,8 @@
 import logging
 
-log_conf = {
+LOG_CONF = {
     'format': '%(asctime)-15s %(module)s %(levelname)s %(message)s',
     'level': logging.INFO
 }
 
-logging.basicConfig(**log_conf)
+logging.basicConfig(**LOG_CONF)
diff --git a/talerbank/app/amount.py b/talerbank/app/amount.py
index 2edf1cb..46e3446 100644
--- a/talerbank/app/amount.py
+++ b/talerbank/app/amount.py
@@ -23,26 +23,24 @@
 #  which might need it.
 
 class CurrencyMismatch(Exception):
-    def __init__(self, msg):
-        self.msg = msg
-    def __str__(self):
-        return self.msg
+    def __init__(self, curr1, curr2):
+        super(CurrencyMismatch, self).__init__(
+            "%s vs %s" % (curr1, curr2))
 
 class BadFormatAmount(Exception):
     def __init__(self, faulty_str):
-        self.faulty_str = faulty_str
-    def __str__(self):
-        return self.faulty_str
+        super(BadFormatAmount, self).__init__(
+            "Bad format amount: " + faulty_str)
 
 class Amount:
     # How many "fraction" units make one "value" unit of currency
     # (Taler requires 10^8).  Do not change this 'constant'.
     @staticmethod
-    def FRACTION():
+    def _fraction():
         return 10 ** 8
 
     @staticmethod
-    def MAX_VALUE():
+    def _max_value():
         return (2 ** 53) - 1
 
     def __init__(self, currency, value=0, fraction=0):
@@ -52,13 +50,13 @@ class Amount:
         self.fraction = fraction
         self.currency = currency
         self.__normalize()
-        assert self.value <= Amount.MAX_VALUE()
+        assert self.value <= Amount._max_value()
 
     # Normalize amount
     def __normalize(self):
-        if self.fraction >= Amount.FRACTION():
-            self.value += int(self.fraction / Amount.FRACTION())
-            self.fraction = self.fraction % Amount.FRACTION()
+        if self.fraction >= Amount._fraction():
+            self.value += int(self.fraction / Amount._fraction())
+            self.fraction = self.fraction % Amount._fraction()
 
     # Parse a string matching the format "A:B.C"
     # instantiating an amount object.
@@ -72,7 +70,7 @@ class Amount:
         value = int(parsed.group(2))
         fraction = 0
         for i, digit in enumerate(parsed.group(3)):
-            fraction += int(int(digit) * (Amount.FRACTION() / 10 ** (i+1)))
+            fraction += int(int(digit) * (Amount._fraction() / 10 ** (i+1)))
         return cls(parsed.group(1), value, fraction)
 
     # Comare two amounts, return:
@@ -82,7 +80,7 @@ class Amount:
     @staticmethod
     def cmp(am1, am2):
         if am1.currency != am2.currency:
-            raise CurrencyMismatch("%s vs %s" % (am1.currency, am2.currency))
+            raise CurrencyMismatch(am1.currency, am2.currency)
         if am1.value == am2.value:
             if am1.fraction < am2.fraction:
                 return -1
@@ -101,7 +99,7 @@ class Amount:
     # Add the given amount to this one
     def add(self, amount):
         if self.currency != amount.currency:
-            raise CurrencyMismatch("%s vs %s" % (am1.currency, am2.currency))
+            raise CurrencyMismatch(self.currency, amount.currency)
         self.value += amount.value
         self.fraction += amount.fraction
         self.__normalize()
@@ -109,9 +107,9 @@ class Amount:
     # Subtract passed amount from this one
     def subtract(self, amount):
         if self.currency != amount.currency:
-            raise CurrencyMismatch("%s vs %s" % (am1.currency, am2.currency))
+            raise CurrencyMismatch(self.currency, amount.currency)
         if self.fraction < amount.fraction:
-            self.fraction += Amount.FRACTION()
+            self.fraction += Amount._fraction()
             self.value -= 1
         if self.value < amount.value:
             raise ValueError('self is lesser than amount to be subtracted')
@@ -124,9 +122,10 @@ class Amount:
         assert ndigits > 0
         ret = '%s:%s.' % (self.currency, str(self.value))
         fraction = self.fraction
-        for i in range(0, ndigits):
-            ret += str(int(fraction / (Amount.FRACTION() / 10)))
-            fraction = (fraction * 10) % (Amount.FRACTION())
+        while ndigits > 0:
+            ret += str(int(fraction / (Amount._fraction() / 10)))
+            fraction = (fraction * 10) % (Amount._fraction())
+            ndigits -= 1
         return ret
 
     # Dump the Taler-compliant 'dict' amount
diff --git a/talerbank/jinja2.py b/talerbank/jinja2.py
index c6688c7..713e613 100644
--- a/talerbank/jinja2.py
+++ b/talerbank/jinja2.py
@@ -14,36 +14,35 @@
 #
 #  @author Florian Dold
 
-from django.contrib.staticfiles.storage import staticfiles_storage
+import os
+from urllib.parse import urlparse
 from django.urls import reverse, get_script_prefix
 from django.conf import settings
-from urllib.parse import urlparse
 from jinja2 import Environment
-import os
 
 
-def is_absolute(url):
-    return bool(urlparse(url).netloc)
+def is_absolute(urloc):
+    return bool(urlparse(urloc).netloc)
 
 
 def join_urlparts(*parts):
-    s = ""
-    i = 0
-    while i < len(parts):
-        n = parts[i]
-        i += 1
-        if s.endswith("/"):
-            n = n.lstrip("/")
-        elif s and  not n.startswith("/"):
-            n = "/" + n
-        s += n
-    return s
+    ret = ""
+    part = 0
+    while part < len(parts):
+        buf = parts[part]
+        part += 1
+        if ret.endswith("/"):
+            buf = buf.lstrip("/")
+        elif ret and not buf.startswith("/"):
+            buf = "/" + buf
+        ret += buf
+    return ret
 
 
-def static(url):
-    if is_absolute(url):
-        return url
-    return join_urlparts(get_script_prefix(), settings.STATIC_URL, url)
+def static(urloc):
+    if is_absolute(urloc):
+        return urloc
+    return join_urlparts(get_script_prefix(), settings.STATIC_URL, urloc)
 
 
 def settings_value(name):
@@ -70,4 +69,3 @@ def environment(**options):
         'env': env_get,
     })
     return env
-

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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