From 789b0263b845f587ad0e5d3c96eff4e39debe2d6 Mon Sep 17 00:00:00 2001
From: Caner Candan <caner@candan.fr>
Date: Fri, 3 Oct 2014 23:56:57 +0200
Subject: [PATCH] * compatible with python2, added Hardship service

---
 __init__.py                 |  4 ++--
 blockchain/__init__.py      | 29 +++++++++++++++++++++++++++--
 network/__init__.py         |  2 +-
 network/peering/__init__.py |  2 +-
 tx/__init__.py              |  2 +-
 5 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/__init__.py b/__init__.py
index e5a04939..c5884005 100644
--- a/__init__.py
+++ b/__init__.py
@@ -27,7 +27,7 @@ import requests, logging, json
 
 logger = logging.getLogger("ucoin")
 
-class ConnectionHandler:
+class ConnectionHandler(object):
     """Helper class used by other API classes to ease passing server connection information."""
 
     def __init__(self, server, port):
@@ -43,7 +43,7 @@ class ConnectionHandler:
     def __str__(self):
         return 'connection info: %s:%d' % (self.server, self.port)
 
-class API:
+class API(object):
     """APIRequest is a class used as an interface. The intermediate derivated classes are the modules and the leaf classes are the API requests."""
 
     def __init__(self, connection_handler, module):
diff --git a/blockchain/__init__.py b/blockchain/__init__.py
index 46a8bed0..3e108c65 100644
--- a/blockchain/__init__.py
+++ b/blockchain/__init__.py
@@ -22,7 +22,7 @@ logger = logging.getLogger("ucoin/blockchain")
 
 class Blockchain(API):
     def __init__(self, connection_handler, module='blockchain'):
-        super().__init__(connection_handler, module)
+        super(Blockchain, self).__init__(connection_handler, module)
 
 class Parameters(Blockchain):
     """GET the blockchain parameters used by this node."""
@@ -49,7 +49,7 @@ class Block(Blockchain):
         - `number`: block number to select
         """
 
-        super().__init__(connection_handler)
+        super(Block, self).__init__(connection_handler)
 
         self.number = number
 
@@ -62,3 +62,28 @@ class Block(Blockchain):
         assert 'signature' in kwargs
 
         return self.requests_post('/block', **kwargs).json()
+
+class Current(Blockchain):
+    """GET, same as block/[number], but return last accepted block."""
+
+    def __get__(self, **kwargs):
+        return self.requests_get('/current', **kwargs).json()
+
+class Hardship(Blockchain):
+    """GET hardship level for given member's fingerprint for writing next block."""
+
+    def __init__(self, connection_handler, fingerprint):
+        """
+        Use the number parameter in order to select a block number.
+
+        Arguments:
+        - `fingerprint`: member fingerprint
+        """
+
+        super(Hardship, self).__init__(connection_handler)
+
+        self.fingerprint = fingerprint
+
+    def __get__(self, **kwargs):
+        assert self.fingerprint is not None
+        return self.requests_get('/hardship/%s' % self.fingerprint.upper(), **kwargs).json()
diff --git a/network/__init__.py b/network/__init__.py
index c133c7ea..7d267815 100644
--- a/network/__init__.py
+++ b/network/__init__.py
@@ -22,7 +22,7 @@ logger = logging.getLogger("ucoin/network")
 
 class Network(API):
     def __init__(self, connection_handler, module='network'):
-        super().__init__(connection_handler, module)
+        super(Network, self).__init__(connection_handler, module)
 
 class Peering(Network):
     """GET peering information about a peer."""
diff --git a/network/peering/__init__.py b/network/peering/__init__.py
index 637f9d83..2971c1da 100644
--- a/network/peering/__init__.py
+++ b/network/peering/__init__.py
@@ -22,7 +22,7 @@ logger = logging.getLogger("ucoin/network/peering")
 
 class Base(Network):
     def __init__(self, connection_handler):
-        super().__init__(connection_handler, 'network/peering')
+        super(Base, self).__init__(connection_handler, 'network/peering')
 
 class Peers(Base):
     """GET peering entries of every node inside the currency network."""
diff --git a/tx/__init__.py b/tx/__init__.py
index 9d9c0694..fc9582c5 100644
--- a/tx/__init__.py
+++ b/tx/__init__.py
@@ -22,7 +22,7 @@ logger = logging.getLogger("ucoin/tx")
 
 class Tx(API):
     def __init__(self, connection_handler, module='tx'):
-        super().__init__(connection_handler, module)
+        super(Tx, self).__init__(connection_handler, module)
 
 class Process(Tx):
     """POST a transaction."""
-- 
GitLab