diff --git a/lib/ucoinpy/documents/__init__.py b/lib/ucoinpy/documents/__init__.py index 198b62b474c770b7440a0ac72c8d2d8d14eb61f7..9763c366155f445dd55be9022f8d2cacf381036a 100644 --- a/lib/ucoinpy/documents/__init__.py +++ b/lib/ucoinpy/documents/__init__.py @@ -1,8 +1,8 @@ -''' +""" Created on 3 déc. 2014 @author: inso -''' +""" import base58 import base64 import re @@ -23,10 +23,10 @@ class Document: self.signatures = [] def sign(self, keys): - ''' + """ Sign the current document. Warning : current signatures will be replaced with the new ones. - ''' + """ self.signatures = [] for key in keys: signing = base64.b64encode(key.signature(bytes(self.raw(), 'ascii'))) @@ -34,10 +34,10 @@ class Document: self.signatures.append(signing.decode("ascii")) def signed_raw(self): - ''' + """ If keys are None, returns the raw + current signatures If keys are present, returns the raw signed by these keys - ''' + """ raw = self.raw() signed = "\n".join(self.signatures) signed_raw = raw + signed + "\n" diff --git a/lib/ucoinpy/documents/block.py b/lib/ucoinpy/documents/block.py index dd17cb2f7e52f772c422eb4b93a3618943ddb29a..a02a550dac8f71302bf3140503ceae7c98a40bd6 100644 --- a/lib/ucoinpy/documents/block.py +++ b/lib/ucoinpy/documents/block.py @@ -1,8 +1,8 @@ -''' +""" Created on 2 déc. 2014 @author: inso -''' +""" from .. import PROTOCOL_VERSION from . import Document @@ -15,7 +15,7 @@ import logging class Block(Document): - ''' + """ Version: VERSION Type: Block Currency: CURRENCY @@ -52,7 +52,7 @@ Transactions: COMPACT_TRANSACTION ... BOTTOM_SIGNATURE - ''' + """ re_type = re.compile("Type: (Block)\n") re_noonce = re.compile("Nonce: ([0-9]+)\n") @@ -82,9 +82,9 @@ BOTTOM_SIGNATURE parameters, members_count, identities, joiners, actives, leavers, excluded, certifications, transactions, signature): - ''' + """ Constructor - ''' + """ super().__init__(version, currency, [signature]) self.noonce = noonce self.number = number diff --git a/lib/ucoinpy/documents/certification.py b/lib/ucoinpy/documents/certification.py index 3792839e593b9f46c2078b91fe867bad586192ac..d7e79adb550dcc1ce15c10dc20fa7e0629c40758 100644 --- a/lib/ucoinpy/documents/certification.py +++ b/lib/ucoinpy/documents/certification.py @@ -1,8 +1,8 @@ -''' +""" Created on 2 déc. 2014 @author: inso -''' +""" import re import base64 import logging @@ -11,9 +11,9 @@ from . import Document class SelfCertification(Document): - ''' + """ A document discribing a self certification. - ''' + """ re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([A-Za-z0-9+/]+(?:=|==)?):([0-9]+):([^\n]+)\n") re_uid = re.compile("UID:([^\n]+)\n") @@ -48,9 +48,9 @@ META:TS:{1} class Certification(Document): - ''' + """ A document describing a certification. - ''' + """ re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):\ ([1-9A-Za-z][^OIl]{42,45}):([0-9]+):([A-Za-z0-9+/]+(?:=|==)?)\n") @@ -58,9 +58,9 @@ class Certification(Document): def __init__(self, version, currency, pubkey_from, pubkey_to, blocknumber, blockhash, signature): - ''' + """ Constructor - ''' + """ super().__init__(version, currency, [signature]) self.pubkey_from = pubkey_from self.pubkey_to = pubkey_to @@ -85,10 +85,10 @@ class Certification(Document): def sign(self, selfcert, keys): - ''' + """ Sign the current document. Warning : current signatures will be replaced with the new ones. - ''' + """ self.signatures = [] for key in keys: signing = base64.b64encode(key.signature(bytes(self.raw(selfcert), 'ascii'))) @@ -107,13 +107,13 @@ class Certification(Document): class Revocation(Document): - ''' + """ A document describing a self-revocation. - ''' + """ def __init__(self, version, currency, signature): - ''' + """ Constructor - ''' + """ super().__init__(version, currency, [signature]) def raw(self, selfcert): @@ -121,10 +121,10 @@ class Revocation(Document): """.format(selfcert.signed_raw()) def sign(self, selfcert, keys): - ''' + """ Sign the current document. Warning : current signatures will be replaced with the new ones. - ''' + """ self.signatures = [] for key in keys: signing = base64.b64encode(key.signature(bytes(self.raw(selfcert), 'ascii'))) diff --git a/lib/ucoinpy/documents/membership.py b/lib/ucoinpy/documents/membership.py index af71a3a0e07c381decd50e6207a5513ac63f935a..570110e29772f1ed473f02a5c788cc4505cbe2ca 100644 --- a/lib/ucoinpy/documents/membership.py +++ b/lib/ucoinpy/documents/membership.py @@ -1,8 +1,8 @@ -''' +""" Created on 2 déc. 2014 @author: inso -''' +""" from .. import PROTOCOL_VERSION from . import Document @@ -10,7 +10,7 @@ import re class Membership(Document): - ''' + """ This is a utility class to generate membership documents : Version: VERSION Type: Membership @@ -20,7 +20,7 @@ class Membership(Document): Membership: MEMBERSHIP_TYPE UserID: USER_ID CertTS: CERTIFICATION_TS - ''' + """ # PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([A-Za-z0-9+/]+(?:=|==)?):\ @@ -36,9 +36,9 @@ class Membership(Document): def __init__(self, version, currency, issuer, block_number, block_hash, membership_type, uid, cert_ts, signature): - ''' + """ Constructor - ''' + """ super().__init__(version, currency, [signature]) self.issuer = issuer self.block_number = block_number diff --git a/lib/ucoinpy/documents/peer.py b/lib/ucoinpy/documents/peer.py index 6b437a6d3f72f05fcf65292075fac474dc273402..6ca7606c6429b7521318720b0336649676a70dd6 100644 --- a/lib/ucoinpy/documents/peer.py +++ b/lib/ucoinpy/documents/peer.py @@ -1,8 +1,8 @@ -''' +""" Created on 2 déc. 2014 @author: inso -''' +""" import re diff --git a/lib/ucoinpy/documents/status.py b/lib/ucoinpy/documents/status.py index 2ba47ea89c585d9af302c7272a68943f103b0460..f11e7542c338f57831f6972f11a260a10d0d0254 100644 --- a/lib/ucoinpy/documents/status.py +++ b/lib/ucoinpy/documents/status.py @@ -1,15 +1,15 @@ -''' +""" Created on 2 déc. 2014 @author: inso -''' +""" import re from . import Document class Status(Document): - ''' + """ Version: VERSION Type: Status Currency: CURRENCY_NAME @@ -17,7 +17,7 @@ class Status(Document): Block: BLOCK From: SENDER To: RECIPIENT - ''' + """ re_type = re.compile("Type: (Status)") re_status = re.compile("Status: (NEW|NEW_BACK|UP|UP_BACK|DOWN)") @@ -27,9 +27,9 @@ class Status(Document): def __init__(self, version, currency, status, blockid, sender, recipient, signature): - ''' + """ Constructor - ''' + """ super().__init__(version, currency, [signature]) self.status = status @@ -70,12 +70,12 @@ class Status(Document): sender, recipient, signature) def raw(self): - return '''Version: {0} + return """Version: {0} Type: Status Currency: {1} Status: {2} Block: {3} From: {4} To: {5} -'''.format(self.version, self.currency, self.status, +""".format(self.version, self.currency, self.status, self.blockid, self.sender, self.recipient) diff --git a/lib/ucoinpy/documents/transaction.py b/lib/ucoinpy/documents/transaction.py index e84313f8c27a002eb5e4fd12fb69b7eafe1c9736..0a9d40d21b797cd1dfd7f35bcaac230c73170c6a 100644 --- a/lib/ucoinpy/documents/transaction.py +++ b/lib/ucoinpy/documents/transaction.py @@ -1,15 +1,15 @@ -''' +""" Created on 2 déc. 2014 @author: inso -''' +""" from . import Document import re import logging class Transaction(Document): - ''' + """ Document format : Version: VERSION Type: Transaction @@ -38,7 +38,7 @@ PUBLIC_KEY:AMOUNT COMMENT SIGNATURE ... - ''' + """ re_type = re.compile("Type: (Transaction)\n") re_header = re.compile("TX:([0-9]+):([0-9]+):([0-9]+):([0-9]+):(0|1)\n") @@ -51,9 +51,9 @@ SIGNATURE def __init__(self, version, currency, issuers, inputs, outputs, comment, signatures): - ''' + """ Constructor - ''' + """ super().__init__(version, currency, signatures) self.issuers = issuers @@ -181,9 +181,9 @@ Issuers: return doc def compact(self): - ''' + """ Return a transaction in its compact format. - ''' + """ """TX:VERSION:NB_ISSUERS:NB_INPUTS:NB_OUTPUTS:HAS_COMMENT PUBLIC_KEY:INDEX ... @@ -213,26 +213,26 @@ COMMENT class SimpleTransaction(Transaction): - ''' + """ As transaction class, but for only one issuer. ... - ''' + """ def __init__(self, version, currency, issuer, single_input, outputs, comment, signature): - ''' + """ Constructor - ''' + """ super().__init__(version, currency, [issuer], [single_input], outputs, comment, [signature]) class InputSource(): - ''' + """ A Transaction INPUT Compact : INDEX:SOURCE:FINGERPRINT:AMOUNT - ''' + """ re_inline = re.compile("([0-9]+):(D|T):([0-9]+):\ ([0-9a-fA-F]{5,40}):([0-9]+)\n") re_compact = re.compile("([0-9]+):(D|T):([0-9a-fA-F]{5,40}):([0-9]+)\n") @@ -278,9 +278,9 @@ class InputSource(): class OutputSource(): - ''' + """ A Transaction OUTPUT - ''' + """ re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([0-9]+)") def __init__(self, pubkey, amount): diff --git a/lib/ucoinpy/key/__init__.py b/lib/ucoinpy/key/__init__.py index 191bf3786c47f93b4fa9daaf4f10f58874063482..f0813ef87b1962e027593dd312548c61d78c2f5d 100644 --- a/lib/ucoinpy/key/__init__.py +++ b/lib/ucoinpy/key/__init__.py @@ -1,8 +1,8 @@ -''' +""" Ucoin public and private keys @author: inso -''' +""" import base58 import base64 diff --git a/lib/ucoinpy/key/hdwallet.py b/lib/ucoinpy/key/hdwallet.py index dffb5fffa8515b8d8433e9af2b965bf16ae3b459..1a135d7da916fb4155d1fb8116859ec753d2e91d 100644 --- a/lib/ucoinpy/key/hdwallet.py +++ b/lib/ucoinpy/key/hdwallet.py @@ -1,9 +1,9 @@ -''' +""" HD Wallet inspired from Bip32 wallets. @author: inso -''' -''' +""" +""" import os import hmac import hashlib @@ -375,4 +375,4 @@ if __name__ == "__main__": print "* [Chain m/0/2147483647h/1/2147483646h/2]" m = m.ChildKey(2) m.dump() -''' \ No newline at end of file +""" \ No newline at end of file diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index c14a42751ce454f1debba8c6b48d26f28cfc5725..e8b0152d1f9ddbd15e24b77becd66dd242f54e1f 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -130,7 +130,7 @@ class Account(QObject): broadcast_error = pyqtSignal(int, str) def __init__(self, salt, pubkey, name, communities, wallets, contacts, identities_registry): - ''' + """ Create an account :param str salt: The root key salt @@ -144,7 +144,7 @@ class Account(QObject): :param cutecoin.core.registry.IdentitiesRegistry: The identities registry intance .. warnings:: The class methods create and load should be used to create an account - ''' + """ super().__init__() self.salt = salt self.pubkey = pubkey @@ -158,7 +158,7 @@ class Account(QObject): @classmethod def create(cls, name, identities_registry): - ''' + """ Factory method to create an empty account object This new account doesn't have any key and it should be given one later @@ -168,20 +168,20 @@ class Account(QObject): :param str name: The account name, same as network identity uid :return: A new empty account object - ''' + """ account = cls(None, None, name, [], [], [], identities_registry) return account @classmethod def load(cls, json_data, network_manager, identities_registry): - ''' + """ Factory method to create an Account object from its json view. :rtype : cutecoin.core.account.Account :param dict json_data: The account view as a json dict :param PyQt5.QtNetwork import QNetworkManager: network_manager :param cutecoin.core.registry.self._identities_registry: identities_registry :return: A new account object created from the json datas - ''' + """ salt = json_data['salt'] pubkey = json_data['pubkey'] @@ -205,22 +205,22 @@ class Account(QObject): return account def __eq__(self, other): - ''' + """ :return: True if account.pubkey == other.pubkey - ''' + """ if other is not None: return other.pubkey == self.pubkey else: return False def check_password(self, password): - ''' + """ Method to verify the key password validity :param str password: The key password :return: True if the generated pubkey is the same as the account .. warnings:: Generates a new temporary SigningKey - ''' + """ key = SigningKey(self.salt, password) return (key.pubkey == self.pubkey) @@ -233,11 +233,11 @@ class Account(QObject): self.contacts.append(new_contact) def add_community(self, community): - ''' + """ Add a community to the account :param community: A community object to add - ''' + """ self.communities.append(community) return community @@ -324,12 +324,12 @@ class Account(QObject): return Account.referentials[self.referential][5] def set_walletpool_size(self, size, password): - ''' + """ Change the size of the wallet pool :param int size: The new size of the wallet pool :param str password: The password of the account, same for all wallets - ''' + """ logging.debug("Defining wallet pool size") if len(self.wallets) < size: for i in range(len(self.wallets), size): @@ -341,13 +341,13 @@ class Account(QObject): self.wallets_changed.emit() def transfers(self, community): - ''' + """ Get all transfers done in a community by all the wallets owned by this account :param community: The target community of this request :return: All account wallets transfers - ''' + """ sent = [] for w in self.wallets: sent.extend(w.transfers(community)) @@ -355,13 +355,13 @@ class Account(QObject): @asyncio.coroutine def future_amount(self, community): - ''' + """ Get amount of money owned in a community by all the wallets owned by this account :param community: The target community of this request :return: The value of all wallets values accumulated - ''' + """ value = 0 for w in self.wallets: val = yield from w.future_value(community) @@ -369,13 +369,13 @@ class Account(QObject): return value def amount(self, community): - ''' + """ Get amount of money owned in a community by all the wallets owned by this account :param community: The target community of this request :return: The value of all wallets values accumulated - ''' + """ value = 0 for w in self.wallets: val = w.value(community) @@ -384,12 +384,12 @@ class Account(QObject): @asyncio.coroutine def send_selfcert(self, password, community): - ''' + """ Send our self certification to a target community :param str password: The account SigningKey password :param community: The community target of the self certification - ''' + """ selfcert = SelfCertification(PROTOCOL_VERSION, community.currency, self.pubkey, @@ -432,14 +432,14 @@ class Account(QObject): @asyncio.coroutine def send_membership(self, password, community, mstype): - ''' + """ Send a membership document to a target community. Signal "document_broadcasted" is emitted at the end. :param str password: The account SigningKey password :param community: The community target of the membership document :param str mstype: The type of membership demand. "IN" to join, "OUT" to leave - ''' + """ logging.debug("Send membership") blockid = yield from community.blockid() @@ -600,11 +600,11 @@ class Account(QObject): w.stop_coroutines() def jsonify(self): - ''' + """ Get the account in a json format. :return: A dict view of the account to be saved as json - ''' + """ data_communities = [] for c in self.communities: data_communities.append(c.jsonify()) diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py index d410e53a16fe264e19cad8d52f42159c013ac9f1..75f7961242e97649a5933e46069c8794fae82bce 100644 --- a/src/cutecoin/core/app.py +++ b/src/cutecoin/core/app.py @@ -1,8 +1,8 @@ -''' +""" Created on 1 févr. 2014 @author: inso -''' +""" import os import logging @@ -25,20 +25,20 @@ from ..tools.exceptions import NameAlreadyExists, BadAccountFile class Application(QObject): - ''' + """ Managing core application datas : Accounts list and general configuration Saving and loading the application state - ''' + """ version_requested = pyqtSignal() def __init__(self, argv, qapp, loop): - ''' + """ Create a new "cutecoin" application :param argv: The argv parameters of the call - ''' + """ super().__init__() self.accounts = {} self.current_account = None @@ -68,12 +68,12 @@ class Application(QObject): logging.debug("Couldn't load translation") def get_account(self, name): - ''' + """ Load an account then return it :param str name: The account name :return: The loaded account if it's a success, else return None - ''' + """ self.load_account(name) if name in self.accounts.keys(): return self.accounts[name] @@ -81,13 +81,13 @@ class Application(QObject): return None def create_account(self, name): - ''' + """ Create a new account from its name :param str name: The account name :return: The new account :raise: NameAlreadyExists if the account name is already used locally - ''' + """ for a in self.accounts: if a == name: raise NameAlreadyExists(a) @@ -104,10 +104,10 @@ class Application(QObject): self.accounts[account.name] = account def delete_account(self, account): - ''' + """ Delete an account. Current account changes to None if it is deleted. - ''' + """ self.accounts.pop(account.name) if self.current_account == account: self.current_account = None @@ -158,10 +158,10 @@ class Application(QObject): pass def load_registries(self): - ''' + """ Load the Person instances of the person module. Each instance is unique, and can be find by its public key. - ''' + """ try: identities_path = os.path.join(config.parameters['home'], '__identities__') @@ -311,11 +311,11 @@ class Application(QObject): json.dump(data, outfile, indent=4, sort_keys=True) def save_cache(self, account): - ''' + """ Save the cache of an account :param account: The account object to save the cache - ''' + """ if not os.path.exists(os.path.join(config.parameters['home'], account.name, '__cache__')): os.makedirs(os.path.join(config.parameters['home'], @@ -344,12 +344,12 @@ class Application(QObject): json.dump(data, outfile, indent=4, sort_keys=True) def import_account(self, file, name): - ''' + """ Import an account from a tar file and open it :param str file: The file path of the tar file :param str name: The account name - ''' + """ with tarfile.open(file, "r") as tar: path = os.path.join(config.parameters['home'], name) @@ -371,12 +371,12 @@ class Application(QObject): self.change_current_account(account) def export_account(self, file, account): - ''' + """ Export an account to a tar file :param str file: The filepath of the tar file :param account: The account object to export - ''' + """ with tarfile.open(file, "w") as tar: for file in ["properties"]: path = os.path.join(config.parameters['home'], @@ -384,11 +384,11 @@ class Application(QObject): tar.add(path, file) def jsonify_accounts(self): - ''' + """ Jsonify an account :return: The account as a dict to format as json - ''' + """ data = [] logging.debug("{0}".format(self.accounts)) for account in self.accounts: @@ -396,11 +396,11 @@ class Application(QObject): return data def jsonify(self): - ''' + """ Jsonify the app datas :return: The accounts of the app to format as json - ''' + """ data = {'local_accounts': self.jsonify_accounts()} return data diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index 7a612d09dfeb4bb937e3d7fd224de0bcec6985d1..23409733a5db1285e368547be381fdf099a628f2 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -1,8 +1,8 @@ -''' +""" Created on 1 févr. 2014 @author: inso -''' +""" import logging import hashlib @@ -207,33 +207,33 @@ class Community(QObject): return self.bma_access.get(self, qtbma.blockchain.Parameters) def certification_expired(self, certtime): - ''' + """ Return True if the certificaton time is too old - ''' + """ return time.time() - certtime > self.parameters['sigValidity'] def add_node(self, node): - ''' + """ Add a peer to the community. :param peer: The new peer as a ucoinpy Peer object. - ''' + """ self._network.add_root_node(node) def remove_node(self, index): - ''' + """ Remove a node from the community. :param index: The index of the removed node. - ''' + """ self._network.remove_root_node(index) def get_block(self, number=None): - ''' + """ Get a block :param int number: The block number. If none, returns current block. - ''' + """ if number is None: data = self.bma_access.get(self, qtbma.blockchain.Current) else: @@ -244,11 +244,11 @@ class Community(QObject): @asyncio.coroutine def blockid(self): - ''' + """ Get the block id. :return: The current block ID as [NUMBER-HASH] format. - ''' + """ block = yield from self.bma_access.future_request(qtbma.blockchain.Current) signed_raw = "{0}{1}\n".format(block['raw'], block['signature']) block_hash = hashlib.sha1(signed_raw.encode("ascii")).hexdigest().upper() @@ -256,11 +256,11 @@ class Community(QObject): return {'number': block_number, 'hash': block_hash} def members_pubkeys(self): - ''' + """ Listing members pubkeys of a community :return: All members pubkeys. - ''' + """ memberships = self.bma_access.get(self, qtbma.wot.Members) return [m['pubkey'] for m in memberships["results"]] @@ -268,11 +268,11 @@ class Community(QObject): self.network.stop_coroutines() def jsonify(self): - ''' + """ Jsonify the community datas. :return: The community as a dict in json format. - ''' + """ nodes_data = [] for node in self._network.root_nodes: diff --git a/src/cutecoin/core/config.py b/src/cutecoin/core/config.py index 3f35a2550146a95f62a0ac582008859d25aeb341..8a4202d20e3481342de0b88d55335eebc5ff3808 100644 --- a/src/cutecoin/core/config.py +++ b/src/cutecoin/core/config.py @@ -1,8 +1,8 @@ -''' +""" Created on 7 févr. 2014 @author: inso -''' +""" import logging from logging import FileHandler diff --git a/src/cutecoin/core/net/api/bma/access.py b/src/cutecoin/core/net/api/bma/access.py index 06f2eeb3f8c721947ff8ec07e8217937a8329399..3c6aeffd14365e83e53717652b948001456a56b5 100644 --- a/src/cutecoin/core/net/api/bma/access.py +++ b/src/cutecoin/core/net/api/bma/access.py @@ -8,9 +8,9 @@ import asyncio import random class BmaAccess(QObject): - ''' + """ This class is used to access BMA API. - ''' + """ __saved_requests = [str(blockchain.Block), str(blockchain.Parameters)] @@ -28,13 +28,13 @@ class BmaAccess(QObject): @classmethod def create(cls, network): - ''' + """ Initialize a new BMAAccess object with empty data. :param cutecoin.core.net.network.Network network: :return: A new BmaAccess object :rtype: cutecoin.core.net.api.bma.access.BmaAccess - ''' + """ return cls({}, network) @property @@ -42,11 +42,11 @@ class BmaAccess(QObject): return self._data.copy() def load_from_json(self, json_data): - ''' + """ Put data in the cache from json datas. :param dict data: The cache in json format - ''' + """ data = {} for entry in json_data: key = entry['key'] @@ -55,11 +55,11 @@ class BmaAccess(QObject): self._data = data def jsonify(self): - ''' + """ Get the cache in json format :return: The cache as a dict in json format - ''' + """ data = {k: self._data[k] for k in self._data.keys()} entries = [] for d in data: @@ -226,7 +226,7 @@ class BmaAccess(QObject): logging.debug("{0} is not present anymore in pending requests".format(cache_key)) def future_request(self, request, req_args={}, get_args={}): - ''' + """ Start a request to the network and returns a future. :param class request: A bma request class calling for data @@ -234,7 +234,7 @@ class BmaAccess(QObject): :param dict get_args: Arguments to pass to the request __get__ method :return: The future data :rtype: dict - ''' + """ def handle_future_reply(reply): if reply.error() == QNetworkReply.NoError: strdata = bytes(reply.readAll()).decode('utf-8') @@ -265,14 +265,14 @@ class BmaAccess(QObject): return future_data def simple_request(self, request, req_args={}, get_args={}): - ''' + """ Start a request to the network but don't cache its result. :param class request: A bma request class calling for data :param dict req_args: Arguments to pass to the request constructor :param dict get_args: Arguments to pass to the request __get__ method :return: The returned data if cached = True else return the QNetworkReply - ''' + """ nodes = self._network.synced_nodes if len(nodes) > 0: node = random.choice(nodes) @@ -286,7 +286,7 @@ class BmaAccess(QObject): raise NoPeerAvailable(self.currency, len(nodes)) def broadcast(self, request, req_args={}, post_args={}): - ''' + """ Broadcast data to a network. Sends the data to all knew nodes. @@ -298,7 +298,7 @@ class BmaAccess(QObject): .. note:: If one node accept the requests (returns 200), the broadcast should be considered accepted by the network. - ''' + """ nodes = self._network.online_nodes replies = [] for node in nodes: diff --git a/src/cutecoin/core/net/network.py b/src/cutecoin/core/net/network.py index 7646ff120cab1f338cee05141407aab53ec1fe1a..f483db38b2bb6a992ec36f7b32196f7ae89e5694 100644 --- a/src/cutecoin/core/net/network.py +++ b/src/cutecoin/core/net/network.py @@ -1,8 +1,8 @@ -''' +""" Created on 24 févr. 2015 @author: inso -''' +""" from cutecoin.core.net.node import Node import logging @@ -14,20 +14,20 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QCoreApplication, QTimer class Network(QObject): - ''' + """ A network is managing nodes polling and crawling of a given community. - ''' + """ nodes_changed = pyqtSignal() new_block_mined = pyqtSignal(int) def __init__(self, network_manager, currency, nodes): - ''' + """ Constructor of a network :param str currency: The currency name of the community :param list nodes: The root nodes of the network - ''' + """ super().__init__() self._root_nodes = nodes self._nodes = [] @@ -41,24 +41,24 @@ class Network(QObject): @classmethod def create(cls, network_manager, node): - ''' + """ Create a new network with one knew node Crawls the nodes from the first node to build the community network :param node: The first knew node of the network - ''' + """ nodes = [node] network = cls(network_manager, node.currency, nodes) return network def merge_with_json(self, json_data): - ''' + """ We merge with knew nodes when we last stopped cutecoin :param dict json_data: Nodes in json format - ''' + """ for data in json_data: node = Node.from_json(self.network_manager, self.currency, data) if node.pubkey not in [n.pubkey for n in self.nodes]: @@ -73,12 +73,12 @@ class Network(QObject): @classmethod def from_json(cls, network_manager, currency, json_data): - ''' + """ Load a network from a configured community :param str currency: The currency name of a community :param dict json_data: A json_data view of a network - ''' + """ nodes = [] for data in json_data: node = Node.from_json(network_manager, currency, data) @@ -87,11 +87,11 @@ class Network(QObject): return network def jsonify(self): - ''' + """ Get the network in json format. :return: The network as a dict in json format. - ''' + """ data = [] for node in self.nodes: data.append(node.jsonify()) @@ -99,18 +99,18 @@ class Network(QObject): @property def quality(self): - ''' + """ Get a ratio of the synced nodes vs the rest - ''' + """ synced = len(self.synced_nodes) total = len(self.nodes) ratio_synced = synced / total return ratio_synced def stop_coroutines(self): - ''' + """ Stop network nodes crawling. - ''' + """ self._must_crawl = False def continue_crawling(self): @@ -118,80 +118,80 @@ class Network(QObject): @property def synced_nodes(self): - ''' + """ Get nodes which are in the ONLINE state. - ''' + """ return [n for n in self.nodes if n.state == Node.ONLINE] @property def online_nodes(self): - ''' + """ Get nodes which are in the ONLINE state. - ''' + """ return [n for n in self.nodes if n.state in (Node.ONLINE, Node.DESYNCED)] @property def nodes(self): - ''' + """ Get all knew nodes. - ''' + """ return self._nodes @property def root_nodes(self): - ''' + """ Get root nodes. - ''' + """ return self._root_nodes @property def latest_block(self): - ''' + """ Get latest block known - ''' + """ return max([n.block for n in self.nodes]) def add_node(self, node): - ''' + """ Add a node to the network. - ''' + """ self._nodes.append(node) node.changed.connect(self.handle_change) node.neighbour_found.connect(self.handle_new_node) logging.debug("{:} connected".format(node.pubkey[:5])) def add_root_node(self, node): - ''' + """ Add a node to the root nodes list - ''' + """ self._root_nodes.append(node) def remove_root_node(self, index): - ''' + """ Remove a node from the root nodes list - ''' + """ self._root_nodes.pop(index) def is_root_node(self, node): - ''' + """ Check if this node is in the root nodes - ''' + """ return node in self._root_nodes def root_node_index(self, index): - ''' + """ Get the index of a root node from its index in all nodes list - ''' + """ node = self.nodes[index] return self._root_nodes.index(node) @asyncio.coroutine def discover_network(self): - ''' + """ Start crawling which never stops. To stop this crawling, call "stop_crawling" method. - ''' + """ self._must_crawl = True while self.continue_crawling(): for node in self.nodes: diff --git a/src/cutecoin/core/net/node.py b/src/cutecoin/core/net/node.py index f37776ae03fc9838748afaa4b789a4fd047427a9..ef8bd443286882e96801d53c3b6ffaf79d81d08e 100644 --- a/src/cutecoin/core/net/node.py +++ b/src/cutecoin/core/net/node.py @@ -1,8 +1,8 @@ -''' +""" Created on 21 févr. 2015 @author: inso -''' +""" from ucoinpy.documents.peer import Peer, BMAEndpoint, Endpoint from requests.exceptions import RequestException, ConnectionError @@ -21,14 +21,14 @@ from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest class Node(QObject): - ''' + """ A node is a peer seend from the client point of view. This node can have multiple states : - ONLINE : The node is available for requests - OFFLINE: The node is disconnected - DESYNCED : The node is online but is desynced from the network - CORRUPTED : The node is corrupted, some weird behaviour is going on - ''' + """ ONLINE = 1 OFFLINE = 2 @@ -40,9 +40,9 @@ class Node(QObject): def __init__(self, network_manager, currency, endpoints, uid, pubkey, block, state, last_change, last_merkle, software, version): - ''' + """ Constructor - ''' + """ super().__init__() self.network_manager = network_manager self._endpoints = endpoints @@ -59,14 +59,14 @@ class Node(QObject): @classmethod def from_address(cls, network_manager, currency, address, port): - ''' + """ Factory method to get a node from a given address :param str currency: The node currency. None if we don't know\ the currency it should have, for example if its the first one we add :param str address: The node address :param int port: The node port - ''' + """ peer_data = qtbma.network.Peering(ConnectionHandler(network_manager, address, port)).get() peer = Peer.from_signed_raw("{0}{1}\n".format(peer_data['raw'], @@ -84,13 +84,13 @@ class Node(QObject): @classmethod def from_peer(cls, network_manager, currency, peer): - ''' + """ Factory method to get a node from a peer document. :param str currency: The node currency. None if we don't know\ the currency it should have, for example if its the first one we add :param peer: The peer document - ''' + """ if currency is not None: if peer.currency != currency: raise InvalidNodeCurrency(peer.currency, currency) diff --git a/src/cutecoin/core/registry/identity.py b/src/cutecoin/core/registry/identity.py index ad26e014a25719491ab1a6a08f9f40bd289cf5f9..23d35a1c509ec6522d204ebf15fe5b7a1e53c3db 100644 --- a/src/cutecoin/core/registry/identity.py +++ b/src/cutecoin/core/registry/identity.py @@ -1,8 +1,8 @@ -''' +""" Created on 11 févr. 2014 @author: inso -''' +""" import logging import time @@ -173,12 +173,12 @@ class Identity(QObject): return False def is_member(self, community): - ''' + """ Check if the person is a member of a community :param cutecoin.core.community.Community community: The community target to request the join date :return: True if the person is a member of a community - ''' + """ certifiers = community.bma_access.get(self, qtbma.wot.CertifiersOf, {'search': self.pubkey}) if certifiers != qtbma.wot.CertifiersOf.null_value: return certifiers['isMember'] @@ -241,12 +241,12 @@ class Identity(QObject): return unique_valid def certified_by(self, community): - ''' + """ Get the list of persons certified by this person :param cutecoin.core.community.Community community: The community target to request the join date :return: The list of the certified persons of this community in BMA json format - ''' + """ certified_list = community.bma_access.get(self, qtbma.wot.CertifiedBy, {'search': self.pubkey}) if certified_list == qtbma.wot.CertifiedBy.null_value: logging.debug('bma.wot.CertifiersOf request error') @@ -295,10 +295,10 @@ class Identity(QObject): return expiration_date - current_time def jsonify(self): - ''' + """ Get the community as dict in json format. :return: The community as a dict in json format - ''' + """ data = {'uid': self.uid, 'pubkey': self.pubkey, 'status': self.status} diff --git a/src/cutecoin/core/transfer.py b/src/cutecoin/core/transfer.py index c7edf796b642f4c3d0141c874de5c94897ac9c43..95b316a6014e56a584801ea7ade6535e954b899e 100644 --- a/src/cutecoin/core/transfer.py +++ b/src/cutecoin/core/transfer.py @@ -1,8 +1,8 @@ -''' +""" Created on 31 janv. 2015 @author: inso -''' +""" import logging import asyncio from .net.api import bma as qtbma @@ -11,7 +11,7 @@ from PyQt5.QtNetwork import QNetworkReply import hashlib class Transfer(QObject): - ''' + """ A transfer is the lifecycle of a transaction. TO_SEND means the transaction wasn't sent yet AWAITING means the transaction is waiting for a blockchain validation @@ -20,7 +20,7 @@ class Transfer(QObject): therefore it is considered as refused DROPPED means the transaction was canceled locally. It can still be validated in the blockchain if it was sent, if the guy is unlucky ;) - ''' + """ TO_SEND = 0 AWAITING = 1 VALIDATED = 2 @@ -31,7 +31,7 @@ class Transfer(QObject): broadcast_error = pyqtSignal(int, str) def __init__(self, hash, state, metadata): - ''' + """ The constructor of a transfer. Check for metadata keys which must be present : - receiver @@ -44,7 +44,7 @@ class Transfer(QObject): :param txdoc: The Transaction ucoinpy object :param state: The state of the Transfer (TO_SEND, AWAITING, VALIDATED, REFUSED or DROPPED) :param metadata: The transfer metadata - ''' + """ assert('receiver' in metadata) assert('block' in metadata) assert('time' in metadata) @@ -62,50 +62,50 @@ class Transfer(QObject): @classmethod def initiate(cls, metadata): - ''' + """ Create a new transfer in a "TO_SEND" state. - ''' + """ return cls(None, Transfer.TO_SEND, metadata) @classmethod def create_validated(cls, hash, metadata): - ''' + """ Create a new transfer in a "VALIDATED" state. - ''' + """ return cls(hash, Transfer.VALIDATED, metadata) @classmethod def load(cls, data): - ''' + """ Create a new transfer from a dict in json format. - ''' + """ return cls(data['hash'], data['state'], data['metadata']) @property def metadata(self): - ''' + """ :return: this transfer metadata - ''' + """ return self._metadata def jsonify(self): - ''' + """ :return: The transfer as a dict in json format - ''' + """ return {'hash': self.hash, 'state': self.state, 'metadata': self._metadata} @asyncio.coroutine def send(self, txdoc, community): - ''' + """ Send a transaction and update the transfer state to AWAITING if accepted. If the transaction was refused (return code != 200), state becomes REFUSED The txdoc is saved as the transfer txdoc. :param txdoc: A transaction ucoinpy object :param community: The community target of the transaction - ''' + """ replies = community.bma_access.broadcast(qtbma.tx.Process, post_args={'transaction': txdoc.signed_raw()}) for r in replies: @@ -135,53 +135,53 @@ class Transfer(QObject): self.broadcast_error.emit(r.error(), strdata) def check_registered(self, tx, block, time): - ''' + """ Check if the transfer was registered in a block. Update the transfer state to VALIDATED if it was registered. :param tx: A transaction ucoinpy object found in the block :param int block: The block number checked :param int time: The time of the block - ''' + """ if tx.signed_raw() == self.txdoc.signed_raw(): self.state = Transfer.VALIDATED self._metadata['block'] = block self._metadata['time'] = time def check_refused(self, block): - ''' + """ Check if the transfer was refused If more than 15 blocks were mined since the transaction transfer, it is considered as refused. :param int block: The current block number - ''' + """ if block > self._metadata['block'] + 15: self.state = Transfer.REFUSED def drop(self): - ''' + """ Cancel the transfer locally. The transfer state becomes "DROPPED". - ''' + """ self.state = Transfer.DROPPED class Received(Transfer): def __init__(self, hash, metadata): - ''' + """ A transfer were the receiver is the local user. :param txdoc: The transaction document of the received transfer :param metadata: The metadata of the transfer - ''' + """ super().__init__(hash, Transfer.VALIDATED, metadata) @classmethod def load(cls, data): - ''' + """ Create a transfer from a dict in json format. :param data: The transfer as a dict in json format - ''' + """ return cls(data['hash'], data['metadata']) diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 0d76ee22ad0be423ff42815a64891fc91fc458de..3d996beef8d0d8378ccd1699cca50180fbac6e15 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -1,8 +1,8 @@ -''' +""" Created on 1 févr. 2014 @author: inso -''' +""" from ucoinpy.documents.transaction import InputSource, OutputSource, Transaction from ucoinpy.key import SigningKey @@ -21,9 +21,9 @@ import asyncio class Wallet(QObject): - ''' + """ A wallet is used to manage money with a unique key. - ''' + """ inner_data_changed = pyqtSignal(str) refresh_progressed = pyqtSignal(int, int, str) @@ -32,13 +32,13 @@ class Wallet(QObject): broadcast_error = pyqtSignal(int, str) def __init__(self, walletid, pubkey, name, identities_registry): - ''' + """ Constructor of a wallet object :param int walletid: The wallet number, unique between all wallets :param str pubkey: The wallet pubkey :param str name: The wallet name - ''' + """ super().__init__() self.coins = [] self.walletid = walletid @@ -49,14 +49,14 @@ class Wallet(QObject): @classmethod def create(cls, walletid, salt, password, name, identities_registry): - ''' + """ Factory method to create a new wallet :param int walletid: The wallet number, unique between all wallets :param str salt: The account salt :param str password: The account password :param str name: The account name - ''' + """ if walletid == 0: key = SigningKey(salt, password) else: @@ -65,66 +65,66 @@ class Wallet(QObject): @classmethod def load(cls, json_data, identities_registry): - ''' + """ Factory method to load a saved wallet. :param dict json_data: The wallet as a dict in json format - ''' + """ walletid = json_data['walletid'] pubkey = json_data['pubkey'] name = json_data['name'] return cls(walletid, pubkey, name, identities_registry) def load_caches(self, json_data): - ''' + """ Load this wallet caches. Each cache correspond to one different community. :param dict json_data: The caches as a dict in json format - ''' + """ for currency in json_data: if currency != 'version': self.caches[currency] = TxHistory(self) self.caches[currency].load_from_json(json_data[currency]) def jsonify_caches(self): - ''' + """ Get this wallet caches as json. :return: The wallet caches as a dict in json format - ''' + """ data = {} for currency in self.caches: data[currency] = self.caches[currency].jsonify() return data def init_cache(self, community): - ''' + """ Init the cache of this wallet for the specified community. :param community: The community to refresh its cache - ''' + """ if community.currency not in self.caches: self.caches[community.currency] = TxHistory(self) def refresh_transactions(self, community, received_list): - ''' + """ Refresh the cache of this wallet for the specified community. :param community: The community to refresh its cache - ''' + """ logging.debug("Refresh transactions for {0}".format(self.pubkey)) asyncio.async(self.caches[community.currency].refresh(community, received_list)) def check_password(self, salt, password): - ''' + """ Check if wallet password is ok. :param salt: The account salt :param password: The given password :return: True if (salt, password) generates the good public key .. warning:: Generates a new temporary SigningKey from salt and password - ''' + """ key = None if self.walletid == 0: key = SigningKey(salt, password) @@ -133,12 +133,12 @@ class Wallet(QObject): return (key.pubkey == self.pubkey) def relative_value(self, community): - ''' + """ Get wallet value relative to last generated UD :param community: The community to get value :return: The wallet relative value - ''' + """ value = self.value(community) ud = community.dividend relative_value = value / float(ud) @@ -146,12 +146,12 @@ class Wallet(QObject): @asyncio.coroutine def future_value(self, community): - ''' + """ Get wallet absolute value :param community: The community to get value :return: The wallet absolute value - ''' + """ value = 0 sources = yield from self.future_sources(community) for s in sources: @@ -159,12 +159,12 @@ class Wallet(QObject): return value def value(self, community): - ''' + """ Get wallet absolute value :param community: The community to get value :return: The wallet absolute value - ''' + """ value = 0 sources = self.sources(community) for s in sources: @@ -172,14 +172,14 @@ class Wallet(QObject): return value def tx_inputs(self, amount, community): - ''' + """ Get inputs to generate a transaction with a given amount of money :param int amount: The amount target value :param community: The community target of the transaction :return: The list of inputs to use in the transaction document - ''' + """ value = 0 inputs = [] cache = self.caches[community.currency] @@ -198,7 +198,7 @@ class Wallet(QObject): len(inputs), amount) def tx_outputs(self, pubkey, amount, inputs): - ''' + """ Get outputs to generate a transaction with a given amount of money :param str pubkey: The target pubkey of the transaction @@ -206,7 +206,7 @@ class Wallet(QObject): :param list inputs: The inputs used to send the given amount of money :return: The list of outputs to use in the transaction document - ''' + """ outputs = [] inputs_value = 0 for i in inputs: @@ -222,7 +222,7 @@ class Wallet(QObject): @asyncio.coroutine def send_money(self, salt, password, community, recipient, amount, message): - ''' + """ Send money to a given recipient in a specified community :param str salt: The account salt @@ -231,7 +231,7 @@ class Wallet(QObject): :param str recipient: The pubkey of the recipient :param int amount: The amount of money to transfer :param str message: The message to send with the transfer - ''' + """ blockid = yield from community.blockid() block_number = blockid['number'] block = yield from community.bma_access.future_request(qtbma.blockchain.Block, @@ -292,12 +292,12 @@ class Wallet(QObject): @asyncio.coroutine def future_sources(self, community): - ''' + """ Get available sources in a given community :param cutecoin.core.community.Community community: The community where we want available sources :return: List of InputSource ucoinpy objects - ''' + """ data = yield from community.bma_access.future_request(qtbma.tx.Sources, req_args={'pubkey': self.pubkey}) tx = [] @@ -306,12 +306,12 @@ class Wallet(QObject): return tx def sources(self, community): - ''' + """ Get available sources in a given community :param cutecoin.core.community.Community community: The community where we want available sources :return: List of InputSource ucoinpy objects - ''' + """ data = community.bma_access.get(self, qtbma.tx.Sources, req_args={'pubkey': self.pubkey}) tx = [] @@ -320,12 +320,12 @@ class Wallet(QObject): return tx def transfers(self, community): - ''' + """ Get all transfers objects of this wallet :param community: The community we want to get the executed transfers :return: A list of Transfer objects - ''' + """ if community.currency in self.caches: return self.caches[community.currency].transfers else: @@ -336,11 +336,11 @@ class Wallet(QObject): c.stop_coroutines() def jsonify(self): - ''' + """ Get the wallet as json format. :return: The wallet as a dict in json format. - ''' + """ return {'walletid': self.walletid, 'pubkey': self.pubkey, 'name': self.name} diff --git a/src/cutecoin/gen_resources/__init__.py b/src/cutecoin/gen_resources/__init__.py index 82d70b56cad15bed8a6accdacfde0024af7e40a8..260b8d64fc04e27477f54b75e0ced47834eb159f 100644 --- a/src/cutecoin/gen_resources/__init__.py +++ b/src/cutecoin/gen_resources/__init__.py @@ -1,5 +1,5 @@ -''' +""" Created on 11 mars 2014 @author: inso -''' +""" diff --git a/src/cutecoin/gui/__init__.py b/src/cutecoin/gui/__init__.py index 19560381f7b99b47389d0bd8d6fddad655d596eb..3d5bba2e32c7b314ba23fc09e9d0566c0319d4c8 100644 --- a/src/cutecoin/gui/__init__.py +++ b/src/cutecoin/gui/__init__.py @@ -1,6 +1,6 @@ -''' +""" Created on 11 mars 2014 @author: inso -''' +""" from PyQt5 import QtSvg \ No newline at end of file diff --git a/src/cutecoin/gui/certification.py b/src/cutecoin/gui/certification.py index 9de66b8fd2d86333b2a9feb339b39c801dd77b6b..25f860710127a02bf4cc545a0fcf874d251efae9 100644 --- a/src/cutecoin/gui/certification.py +++ b/src/cutecoin/gui/certification.py @@ -1,8 +1,8 @@ -''' +""" Created on 24 dec. 2014 @author: inso -''' +""" from PyQt5.QtWidgets import QDialog, QMessageBox, QDialogButtonBox, QApplication from PyQt5.QtCore import Qt, pyqtSlot import quamash @@ -13,14 +13,14 @@ import asyncio class CertificationDialog(QDialog, Ui_CertificationDialog): - ''' + """ classdocs - ''' + """ def __init__(self, certifier, app, password_asker): - ''' + """ Constructor - ''' + """ super().__init__() self.setupUi(self) self.app = app diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py index 38f7cdd81a358dffd8cd311a373150fb695e2951..1096583e991852deecf572c9bccabdcc47afb8cd 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/community_tab.py @@ -1,8 +1,8 @@ -''' +""" Created on 2 févr. 2014 @author: inso -''' +""" import logging from PyQt5.QtCore import Qt, pyqtSlot @@ -24,9 +24,9 @@ from ..core.net.api import bma as qtbma class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): - ''' + """ classdocs - ''' + """ def __init__(self, app, account, community, password_asker, parent): """ @@ -325,10 +325,10 @@ Revoking your UID can only success if it is not already validated by the network self.refresh(identities) def refresh(self, identities): - ''' + """ Refresh the table with specified identities. If no identities is passed, use the account connections. - ''' + """ self.table_identities.model().sourceModel().refresh_identities(identities) self.table_identities.resizeColumnsToContents() diff --git a/src/cutecoin/gui/contact.py b/src/cutecoin/gui/contact.py index 59e2f0042f4c7a8341caf5123a32c78d604d3ce4..8e26de9708940be7b1212853d6e42f004d327564 100644 --- a/src/cutecoin/gui/contact.py +++ b/src/cutecoin/gui/contact.py @@ -1,8 +1,8 @@ -''' +""" Created on 2 févr. 2014 @author: inso -''' +""" import re import logging @@ -14,14 +14,14 @@ from ..gen_resources.contact_uic import Ui_ConfigureContactDialog class ConfigureContactDialog(QDialog, Ui_ConfigureContactDialog): - ''' + """ classdocs - ''' + """ def __init__(self, account, parent=None, contact=None, index_edit=None): - ''' + """ Constructor - ''' + """ super().__init__() self.setupUi(self) self.account = account diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 603d3e027c886147d99efc07b3f254e58b823db2..2c687842bc6d461c30bd2756f646960184f7c323 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -1,8 +1,8 @@ -''' +""" Created on 2 févr. 2014 @author: inso -''' +""" import time import logging @@ -24,14 +24,14 @@ from ..core.registry import IdentitiesRegistry class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): - ''' + """ classdocs - ''' + """ def __init__(self, app, community, password_asker, status_label): - ''' + """ Constructor - ''' + """ super().__init__() self.setupUi(self) self.app = app @@ -121,10 +121,10 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): @pyqtSlot(int) def refresh_block(self, block_number): - ''' + """ When a new block is found, start handling data. @param: block_number: The number of the block mined - ''' + """ logging.debug("Refresh block") self.status_info.clear() try: @@ -156,9 +156,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.refresh_data() def refresh_data(self): - ''' + """ Refresh data when the blockchain watcher finished handling datas - ''' + """ if self.tab_wallets: self.tab_wallets.refresh() @@ -167,9 +167,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): @pyqtSlot() def refresh_status(self): - ''' + """ Refresh status bar - ''' + """ logging.debug("Refresh status") text = self.tr(" Block {0}").format(self.community.network.latest_block) if self.community.network.quality > 0.66: diff --git a/src/cutecoin/gui/import_account.py b/src/cutecoin/gui/import_account.py index dae6192c02afc00e3fddef31ab2e000ebedf5be4..bd3c0a52eea9d20f6fe0e5edb6059bf58a8713de 100644 --- a/src/cutecoin/gui/import_account.py +++ b/src/cutecoin/gui/import_account.py @@ -1,8 +1,8 @@ -''' +""" Created on 22 mai 2014 @author: inso -''' +""" import re from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox, QFileDialog @@ -12,14 +12,14 @@ from cutecoin.gen_resources.import_account_uic import Ui_ImportAccountDialog class ImportAccountDialog(QDialog, Ui_ImportAccountDialog): - ''' + """ classdocs - ''' + """ def __init__(self, app, parent=None): - ''' + """ Constructor - ''' + """ super().__init__() self.setupUi(self) self.app = app diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index 8cb5815e537a2f32d763de607a36f78c0a15bfbc..8caaeb1b35d9b2fbaa58edbbfcf009b8603e716d 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -1,8 +1,8 @@ -''' +""" Created on 1 févr. 2014 @author: inso -''' +""" from ..gen_resources.mainwindow_uic import Ui_MainWindow from ..gen_resources.about_uic import Ui_AboutPopup @@ -29,9 +29,9 @@ import logging class MainWindow(QMainWindow, Ui_MainWindow): - ''' + """ classdocs - ''' + """ def __init__(self, app): """ @@ -296,11 +296,11 @@ class MainWindow(QMainWindow, Ui_MainWindow): delete_action.triggered.connect(self.delete_contact) def refresh(self): - ''' + """ Refresh main window When the selected account changes, all the widgets in the window have to be refreshed - ''' + """ logging.debug("Refresh started") self.refresh_accounts() diff --git a/src/cutecoin/gui/network_tab.py b/src/cutecoin/gui/network_tab.py index bd97eda945c8d2e48e7f0d1c6fa2f923870b7237..1816942cc45a17b3c4b64616cdb860c3f1dd25bd 100644 --- a/src/cutecoin/gui/network_tab.py +++ b/src/cutecoin/gui/network_tab.py @@ -1,8 +1,8 @@ -''' +""" Created on 20 févr. 2015 @author: inso -''' +""" import logging from PyQt5.QtGui import QCursor @@ -13,14 +13,14 @@ from ..gen_resources.network_tab_uic import Ui_NetworkTabWidget class NetworkTabWidget(QWidget, Ui_NetworkTabWidget): - ''' + """ classdocs - ''' + """ def __init__(self, community): - ''' + """ Constructor - ''' + """ super().__init__() self.setupUi(self) model = NetworkTableModel(community) diff --git a/src/cutecoin/gui/password_asker.py b/src/cutecoin/gui/password_asker.py index 2009f8720f92613fed576275609968eddfba08b6..dcb65ddd1851dab1c0ae2cd21365f3a06a2979a8 100644 --- a/src/cutecoin/gui/password_asker.py +++ b/src/cutecoin/gui/password_asker.py @@ -1,8 +1,8 @@ -''' +""" Created on 24 dec. 2014 @author: inso -''' +""" import logging import re @@ -14,14 +14,14 @@ from ..gen_resources.password_asker_uic import Ui_PasswordAskerDialog class PasswordAskerDialog(QDialog, Ui_PasswordAskerDialog): - ''' + """ A dialog to get password. - ''' + """ def __init__(self, account): - ''' + """ Constructor - ''' + """ super().__init__() self.setupUi(self) self.account = account diff --git a/src/cutecoin/gui/preferences.py b/src/cutecoin/gui/preferences.py index 91f0026efef99365da97c6b115bc59a7aea559c1..c674625c1a8fe27d58cfe6f39e4dfdb9a874dc36 100644 --- a/src/cutecoin/gui/preferences.py +++ b/src/cutecoin/gui/preferences.py @@ -1,8 +1,8 @@ -''' +""" Created on 11 mai 2015 @author: inso -''' +""" from PyQt5.QtCore import QCoreApplication @@ -15,14 +15,14 @@ from ..gen_resources.preferences_uic import Ui_PreferencesDialog class PreferencesDialog(QDialog, Ui_PreferencesDialog): - ''' + """ A dialog to get password. - ''' + """ def __init__(self, app): - ''' + """ Constructor - ''' + """ super().__init__() self.setupUi(self) self.app = app diff --git a/src/cutecoin/gui/process_cfg_account.py b/src/cutecoin/gui/process_cfg_account.py index 50b1bc7271b5708a95131ee8a63d779084cf9212..a13516f607710098b66ddb82d1f0e451b8b20794 100644 --- a/src/cutecoin/gui/process_cfg_account.py +++ b/src/cutecoin/gui/process_cfg_account.py @@ -1,8 +1,8 @@ -''' +""" Created on 6 mars 2014 @author: inso -''' +""" import logging import requests from ucoinpy.documents.peer import Peer @@ -24,9 +24,9 @@ class Step(): class StepPageInit(Step): - ''' + """ First step when adding a community - ''' + """ def __init__(self, config_dialog): super().__init__(config_dialog) @@ -59,9 +59,9 @@ class StepPageInit(Step): class StepPageKey(Step): - ''' + """ First step when adding a community - ''' + """ def __init__(self, config_dialog): super().__init__(config_dialog) @@ -107,9 +107,9 @@ class StepPageKey(Step): class StepPageCommunities(Step): - ''' + """ First step when adding a community - ''' + """ def __init__(self, config_dialog): super().__init__(config_dialog) @@ -140,14 +140,14 @@ class StepPageCommunities(Step): class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog): - ''' + """ classdocs - ''' + """ def __init__(self, app, account): - ''' + """ Constructor - ''' + """ # Set up the user interface from Designer. super().__init__() self.setupUi(self) diff --git a/src/cutecoin/gui/process_cfg_community.py b/src/cutecoin/gui/process_cfg_community.py index eb6d49ac2bb429b263093321be6cb23dd25ee6f8..05e16fdc3b9fa7e9dd5107476ebf7b32e95234c9 100644 --- a/src/cutecoin/gui/process_cfg_community.py +++ b/src/cutecoin/gui/process_cfg_community.py @@ -1,8 +1,8 @@ -''' +""" Created on 8 mars 2014 @author: inso -''' +""" import logging import requests @@ -25,9 +25,9 @@ class Step(): class StepPageInit(Step): - ''' + """ First step when adding a community - ''' + """ def __init__(self, config_dialog): super().__init__(config_dialog) self.node = None @@ -47,9 +47,9 @@ class StepPageInit(Step): return True def process_next(self): - ''' + """ We create the community - ''' + """ account = self.config_dialog.account logging.debug("Account : {0}".format(account)) self.config_dialog.community = Community.create(self.node) @@ -59,9 +59,9 @@ class StepPageInit(Step): class StepPageAddpeers(Step): - ''' + """ The step where the user add peers - ''' + """ def __init__(self, config_dialog): super().__init__(config_dialog) @@ -85,14 +85,14 @@ class StepPageAddpeers(Step): class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): - ''' + """ Dialog to configure or add a community - ''' + """ def __init__(self, account, community, password_asker, default_node=None): - ''' + """ Constructor - ''' + """ super().__init__() self.setupUi(self) self.community = community @@ -143,9 +143,9 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): self.step.display_page() def add_node(self): - ''' + """ Add node slot - ''' + """ server = self.lineedit_add_address.text() port = self.spinbox_add_port.value() @@ -158,9 +158,9 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): self.tree_peers.setModel(PeeringTreeModel(self.community)) def remove_node(self): - ''' + """ Remove node slot - ''' + """ logging.debug("Remove node") index = self.sender().data() self.community.remove_node(index) @@ -188,7 +188,7 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): def accept(self): try: - Person.lookup(self.account.pubkey, self.community, cached=False) + yield from Person.lookup(self.account.pubkey, self.community, cached=False) except LookupFailureError as e: reply = QMessageBox.question(self, self.tr("Pubkey not found"), self.tr("""The public key of your account wasn't found in the community. :\n diff --git a/src/cutecoin/gui/toast.py b/src/cutecoin/gui/toast.py index 52fddab8a7e2cc0d868553a1bfe281c21e55095f..a259e9e9acbe78a7163f379bbd6d23925caf42c5 100644 --- a/src/cutecoin/gui/toast.py +++ b/src/cutecoin/gui/toast.py @@ -1,8 +1,8 @@ -''' +""" Created on 1 mai 2015 @author: inso -''' +""" import sys, time import logging from PyQt5.QtCore import Qt, QThread diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py index 9fe89882ed519c95e3fb16d6fa20007a614dcf82..b62f1e7acc0764a6330f875515816704b7abfab1 100644 --- a/src/cutecoin/gui/transfer.py +++ b/src/cutecoin/gui/transfer.py @@ -1,8 +1,8 @@ -''' +""" Created on 2 févr. 2014 @author: inso -''' +""" from PyQt5.QtWidgets import QDialog, QMessageBox, QApplication from PyQt5.QtCore import QRegExp, Qt, QLocale, pyqtSlot from PyQt5.QtGui import QRegExpValidator @@ -14,14 +14,14 @@ import asyncio class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): - ''' + """ classdocs - ''' + """ def __init__(self, sender, password_asker): - ''' + """ Constructor - ''' + """ super().__init__() self.setupUi(self) self.account = sender diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py index cb39c8f937cdba08a203dbffa90478d2618061e8..b386a743e435da984f48e5f3b35dafdf5455366b 100644 --- a/src/cutecoin/gui/wallets_tab.py +++ b/src/cutecoin/gui/wallets_tab.py @@ -1,8 +1,8 @@ -''' +""" Created on 15 févr. 2015 @author: inso -''' +""" import logging from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication, QDialog @@ -18,9 +18,9 @@ from ..gen_resources.wallets_tab_uic import Ui_WalletsTab class WalletsTabWidget(QWidget, Ui_WalletsTab): - ''' + """ classdocs - ''' + """ def __init__(self, app, account, community, password_asker): """ diff --git a/src/cutecoin/models/communities.py b/src/cutecoin/models/communities.py index 2e1479b5de3da5939c4829066f25f8c7ff4ad911..d782ad461a4bcf380af6bbb6dbff24a3f624089d 100644 --- a/src/cutecoin/models/communities.py +++ b/src/cutecoin/models/communities.py @@ -1,22 +1,22 @@ -''' +""" Created on 5 févr. 2014 @author: inso -''' +""" from PyQt5.QtCore import QAbstractListModel, Qt class CommunitiesListModel(QAbstractListModel): - ''' + """ A Qt abstract item model to display communities in a tree - ''' + """ def __init__(self, account, parent=None): - ''' + """ Constructor - ''' + """ super(CommunitiesListModel, self).__init__(parent) self.communities = account.communities diff --git a/src/cutecoin/models/community.py b/src/cutecoin/models/community.py index 61a239b902c28a67a99101cff5eefdeeb3914094..16babb17f50b415a760af1d68a148f18bcd8ab4d 100644 --- a/src/cutecoin/models/community.py +++ b/src/cutecoin/models/community.py @@ -1,8 +1,8 @@ -''' +""" Created on 5 fevr. 2014 @author: inso -''' +""" class CommunityItemModel(object): diff --git a/src/cutecoin/models/identities.py b/src/cutecoin/models/identities.py index e30af70dfb8389267fc3110e730d21d1db6e17c6..7e32c77ce057d733d79efe9859aaf0daabd3742f 100644 --- a/src/cutecoin/models/identities.py +++ b/src/cutecoin/models/identities.py @@ -1,8 +1,8 @@ -''' +""" Created on 5 févr. 2014 @author: inso -''' +""" from ..core.net.api import bma as qtbma from ..tools.exceptions import NoPeerAvailable, MembershipNotFoundError @@ -69,14 +69,14 @@ class IdentitiesFilterProxyModel(QSortFilterProxyModel): class IdentitiesTableModel(QAbstractTableModel): - ''' + """ A Qt abstract item model to display communities in a tree - ''' + """ def __init__(self, community, parent=None): - ''' + """ Constructor - ''' + """ super().__init__(parent) self.community = community self.columns_titles = { @@ -91,9 +91,9 @@ class IdentitiesTableModel(QAbstractTableModel): @property def pubkeys(self): - ''' + """ Get pubkeys of displayed identities - ''' + """ return [i[1] for i in self.identities_data] def identity_data(self, identity): diff --git a/src/cutecoin/models/network.py b/src/cutecoin/models/network.py index 31c801ab12c9be818a69aa0e1bcbeea4d3fc05a3..6056a9feeb6d16b072d8d05e9e25f6cc2aaaefc5 100644 --- a/src/cutecoin/models/network.py +++ b/src/cutecoin/models/network.py @@ -1,8 +1,8 @@ -''' +""" Created on 5 févr. 2014 @author: inso -''' +""" import logging @@ -83,14 +83,14 @@ class NetworkFilterProxyModel(QSortFilterProxyModel): class NetworkTableModel(QAbstractTableModel): - ''' + """ A Qt abstract item model to display - ''' + """ def __init__(self, community, parent=None): - ''' + """ Constructor - ''' + """ super().__init__(parent) self.community = community self.columns_types = ( diff --git a/src/cutecoin/models/peering.py b/src/cutecoin/models/peering.py index 307949da2ec871d6cbfc70105420d6d6f45169be..4b2e48c2b4a5a4c2f2041d5eb9836a81751d6b56 100644 --- a/src/cutecoin/models/peering.py +++ b/src/cutecoin/models/peering.py @@ -1,8 +1,8 @@ -''' +""" Created on 5 févr. 2014 @author: inso -''' +""" from PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt import logging @@ -84,14 +84,14 @@ class NodeItem(object): class PeeringTreeModel(QAbstractItemModel): - ''' + """ A Qt abstract item model to display nodes of a community - ''' + """ def __init__(self, community): - ''' + """ Constructor - ''' + """ super().__init__(None) self.nodes = community._network.root_nodes self.root_item = RootItem(community.currency) diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py index 328f94a7eb98b952bd0712f035f81c144eba1f41..c34c231ff9639662fd769cf634d8f20f9112e39f 100644 --- a/src/cutecoin/models/txhistory.py +++ b/src/cutecoin/models/txhistory.py @@ -1,8 +1,8 @@ -''' +""" Created on 5 févr. 2014 @author: inso -''' +""" import datetime import logging @@ -150,14 +150,14 @@ class TxFilterProxyModel(QSortFilterProxyModel): class HistoryTableModel(QAbstractTableModel): - ''' + """ A Qt abstract item model to display communities in a tree - ''' + """ def __init__(self, account, community, parent=None): - ''' + """ Constructor - ''' + """ super().__init__(parent) self.account = account self.community = community diff --git a/src/cutecoin/models/wallets.py b/src/cutecoin/models/wallets.py index cb7de68bb83e65ed21704a3f50c5693b8b3549e6..1d4f1cad813aac12e9677b57dfdecec638bd90ff 100644 --- a/src/cutecoin/models/wallets.py +++ b/src/cutecoin/models/wallets.py @@ -1,8 +1,8 @@ -''' +""" Created on 8 févr. 2014 @author: inso -''' +""" import asyncio from PyQt5.QtCore import QAbstractTableModel, QSortFilterProxyModel, Qt, QLocale, pyqtSlot @@ -56,9 +56,9 @@ class WalletsFilterProxyModel(QSortFilterProxyModel): class WalletsTableModel(QAbstractTableModel): - ''' + """ A Qt list model to display wallets and edit their names - ''' + """ def __init__(self, account, community, parent=None): """ diff --git a/src/cutecoin/tools/exceptions.py b/src/cutecoin/tools/exceptions.py index 9f2da1cc73e1cf1d79bb9dd270eb4eb94c0cd8d7..8821d1c8ed90662e22ae4c5f57bc47a6b78581f2 100644 --- a/src/cutecoin/tools/exceptions.py +++ b/src/cutecoin/tools/exceptions.py @@ -1,16 +1,16 @@ -''' +""" Created on 9 févr. 2014 @author: inso -''' +""" class Error(Exception): def __init__(self, message): - ''' + """ Constructor - ''' + """ self.message = "Error : " + message def __str__(self): @@ -19,44 +19,44 @@ class Error(Exception): class NotMemberOfCommunityError(Error): - ''' + """ Exception raised when adding a community the account is not a member of - ''' + """ def __init__(self, account, community): - ''' + """ Constructor - ''' + """ super() \ .__init__(account + " is not a member of " + community) class LookupFailureError(Error): - ''' + """ Exception raised when looking for a person in a community who isnt present in key list - ''' + """ def __init__(self, value, community): - ''' + """ Constructor - ''' + """ super() .__init__( "Person looked by {0} in {1} not found ".format(value, community)) class MembershipNotFoundError(Error): - ''' + """ Exception raised when looking for a person in a community who isnt present in key list - ''' + """ def __init__(self, value, community): - ''' + """ Constructor - ''' + """ super() .__init__( "Membership searched by " + value + @@ -67,29 +67,29 @@ class MembershipNotFoundError(Error): class AlgorithmNotImplemented(Error): - ''' + """ Exception raised when a coin uses an algorithm not known - ''' + """ def __init__(self, algo_name): - ''' + """ Constructor - ''' + """ super() \ .__init__("Algorithm " + algo_name + " not implemented.") class KeyAlreadyUsed(Error): - ''' + """ Exception raised trying to add an account using a key already used for another account. - ''' + """ def __init__(self, new_account, keyid, found_account): - ''' + """ Constructor - ''' + """ super() .__init__( """Cannot add account {0} : the key {1} is already used by {2}""".format(new_account, @@ -100,15 +100,15 @@ the key {1} is already used by {2}""".format(new_account, class NameAlreadyExists(Error): - ''' + """ Exception raised trying to add an account using a key already used for another account. - ''' + """ def __init__(self, account_name): - ''' + """ Constructor - ''' + """ super() .__init__( "Cannot add account " + account_name + @@ -117,30 +117,30 @@ class NameAlreadyExists(Error): class BadAccountFile(Error): - ''' + """ Exception raised trying to add an account using a key already used for another account. - ''' + """ def __init__(self, path): - ''' + """ Constructor - ''' + """ super() .__init__( "File " + path + " is not an account file") class NotEnoughMoneyError(Error): - ''' + """ Exception raised trying to add an account using a key already used for another account. - ''' + """ def __init__(self, available, currency, nb_inputs, requested): - ''' + """ Constructor - ''' + """ super() .__init__( "Only {0} {1} available in {2} sources, needs {3}" .format(available, @@ -150,41 +150,41 @@ class NotEnoughMoneyError(Error): class NoPeerAvailable(Error): - ''' + """ Exception raised when a community doesn't have any peer available. - ''' + """ def __init__(self, currency, peers): - ''' + """ Constructor - ''' + """ super() .__init__( "No peer answered in {0} community ({1} peers available)" .format(currency, peers)) class InvalidNodeCurrency(Error): - ''' + """ Exception raised when a node doesn't use the intended currency - ''' + """ def __init__(self, currency, node_currency): - ''' + """ Constructor - ''' + """ super() .__init__( "Node is working for {0} currency, but should be {1}" .format(node_currency, currency)) class ContactAlreadyExists(Error): - ''' + """ Exception raised when a community doesn't have any peer available. - ''' + """ def __init__(self, new_contact, already_contact): - ''' + """ Constructor - ''' + """ super() .__init__( "Cannot add {0}, he/she has the same pubkey as {1} contact" .format(new_contact, already_contact))