Commit 3640bbe6 authored by inso's avatar inso

Rename to duniter

parent e3effe1e
......@@ -9,6 +9,6 @@ install:
- pip install -r requirements.txt
# command to run tests
script:
- coverage run --source=ucoinpy setup.py test
- coverage run --source=duniterpy setup.py test
after_success:
- coveralls
\ No newline at end of file
#ucoin-python-api
[![Build Status](https://travis-ci.org/ucoin-io/ucoin-python-api.svg)](https://travis-ci.org/ucoin-io/ucoin-python-api) [![Coverage Status](https://coveralls.io/repos/ucoin-io/ucoin-python-api/badge.svg?branch=master&service=github)](https://coveralls.io/github/ucoin-io/ucoin-python-api?branch=master)
#duniter-python-api
[![Build Status](https://travis-ci.org/duniter-io/duniter-python-api.svg)](https://travis-ci.org/duniter-io/duniter-python-api) [![Coverage Status](https://coveralls.io/repos/duniter-io/duniter-python-api/badge.svg?branch=master&service=github)](https://coveralls.io/github/duniter-io/duniter-python-api?branch=master)
A python implementation of [uCoin](https://github.com/ucoin-io/ucoin) API
A python implementation of [duniter](https://github.com/duniter-io/duniter) API
## Features
* Supports uCoin's Basic Merkle Api
* Supports duniter's Basic Merkle Api
* Asynchronous
* uCoin signing key
* duniter signing key
## Requirements
* Python >= 3.5
......@@ -16,7 +16,7 @@ A python implementation of [uCoin](https://github.com/ucoin-io/ucoin) API
* [base58](https://pypi.python.org/pypi/base58 "base58")
##Installation
You can install ucoin-python-api and all its dependencies via the following pip install :
`pip install ucoinpy`
You can install duniter-python-api and all its dependencies via the following pip install :
`pip install duniterpy`
Please take a look at the document [HTTP API](https://github.com/ucoin-io/ucoin/blob/master/doc/HTTP_API.md) to learn about the API.
Please take a look at the document [HTTP API](https://github.com/duniter-io/duniter/blob/master/doc/HTTP_API.md) to learn about the API.
......@@ -87,9 +87,9 @@ qthelp:
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ucoinpy.qhcp"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/duniterpy.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ucoinpy.qhc"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/duniterpy.qhc"
applehelp:
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
......@@ -104,8 +104,8 @@ devhelp:
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/ucoinpy"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/ucoinpy"
@echo "# mkdir -p $$HOME/.local/share/devhelp/duniterpy"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/duniterpy"
@echo "# devhelp"
epub:
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# ucoinpy documentation build configuration file, created by
# duniterpy documentation build configuration file, created by
# sphinx-quickstart on Tue Oct 6 16:34:46 2015.
#
# This file is execfile()d with the current directory set to its
......@@ -62,7 +62,7 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = 'ucoinpy'
project = 'duniterpy'
copyright = '2015, caner & inso'
author = 'caner & inso'
......@@ -216,7 +216,7 @@ html_static_path = ['_static']
#html_search_scorer = 'scorer.js'
# Output file base name for HTML help builder.
htmlhelp_basename = 'ucoinpydoc'
htmlhelp_basename = 'duniterpydoc'
# -- Options for LaTeX output ---------------------------------------------
......@@ -238,7 +238,7 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'ucoinpy.tex', 'ucoinpy Documentation',
(master_doc, 'duniterpy.tex', 'duniterpy Documentation',
'caner \\& inso', 'manual'),
]
......@@ -268,7 +268,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'ucoinpy', 'ucoinpy Documentation',
(master_doc, 'duniterpy', 'duniterpy Documentation',
[author], 1)
]
......@@ -282,8 +282,8 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'ucoinpy', 'ucoinpy Documentation',
author, 'ucoinpy', 'One line description of project.',
(master_doc, 'duniterpy', 'duniterpy Documentation',
author, 'duniterpy', 'One line description of project.',
'Miscellaneous'),
]
......
Documents methods
=================
.. automodule:: ucoinpy.documents.block
.. automodule:: duniterpy.documents.block
:members:
:special-members:
:exclude-members: __dict__,__weakref__
.. automodule:: ucoinpy.documents.certification
.. automodule:: duniterpy.documents.certification
:members:
:special-members:
:exclude-members: __dict__,__weakref__
.. automodule:: ucoinpy.documents.document
.. automodule:: duniterpy.documents.document
:members:
:special-members:
:exclude-members: __dict__,__weakref__
.. automodule:: ucoinpy.documents.membership
.. automodule:: duniterpy.documents.membership
:members:
:special-members:
:exclude-members: __dict__,__weakref__
.. automodule:: ucoinpy.documents.peer
.. automodule:: duniterpy.documents.peer
:members:
:special-members:
:exclude-members: __dict__,__weakref__
.. automodule:: ucoinpy.documents.status
.. automodule:: duniterpy.documents.status
:members:
:special-members:
:exclude-members: __dict__,__weakref__
.. automodule:: ucoinpy.documents.transaction
.. automodule:: duniterpy.documents.transaction
:members:
:special-members:
:exclude-members: __dict__,__weakref__
\ No newline at end of file
.. ucoinpy documentation master file, created by
.. duniterpy documentation master file, created by
sphinx-quickstart on Tue Oct 6 16:34:46 2015.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
ucoinpy : A python implementation of uCoin API
duniterpy : A python implementation of duniter API
==============================================
ucoinpy is a library to develop an application for uCoin.
ucoinpy helps to handle the following problem :
* Request Basic Merkle API provided by ucoin nodes
duniterpy is a library to develop an application for duniter.
duniterpy helps to handle the following problem :
* Request Basic Merkle API provided by duniter nodes
* Request nodes in a non-blocking way
* Handle ucoin signing keys
* Handle duniter signing keys
Installation
------------
Simply type::
$ pip install ucoinpy
$ pip install duniterpy
Source code
-----------
Sources can be found at https://github.com/ucoin-io/ucoin-python-api
Sources can be found at https://github.com/duniter-io/duniter-python-api
Contributions are welcome.
......
......@@ -127,9 +127,9 @@ if "%1" == "qthelp" (
echo.
echo.Build finished; now you can run "qcollectiongenerator" with the ^
.qhcp project file in %BUILDDIR%/qthelp, like this:
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\ucoinpy.qhcp
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\duniterpy.qhcp
echo.To view the help file:
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\ucoinpy.ghc
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\duniterpy.ghc
goto end
)
......
from setuptools import setup, find_packages
import ucoinpy
import duniterpy
import os
import re
......@@ -39,9 +39,9 @@ for requirement in (l.strip() for l in open('requirements.txt')):
install_requires.append(requirement)
setup(
name='ucoinpy',
name='duniterpy',
version=ucoinpy.__version__,
version=duniterpy.__version__,
packages=find_packages(),
......@@ -49,13 +49,13 @@ setup(
author_email="insomniak.fr@gmail.com",
description="A python implementation of [uCoin](https://github.com/ucoin-io/ucoin) API",
description="A python implementation of [duniter](https://github.com/duniter-io/duniter) API",
long_description=open('README.md').read(),
# Active la prise en compte du fichier MANIFEST.in
include_package_data=True,
url='https://github.com/ucoin-io/ucoin-python-api',
url='https://github.com/duniter-io/duniter-python-api',
test_suite="tests",
classifiers=[
......
......@@ -2,7 +2,7 @@ import unittest
import jsonschema
import aiohttp
from tests.api.webserver import WebFunctionalSetupMixin, web, asyncio
from ucoinpy.api.bma.blockchain import Parameters, Block, Current, Hardship, Membership, Newcomers, \
from duniterpy.api.bma.blockchain import Parameters, Block, Current, Hardship, Membership, Newcomers, \
Certifications, Joiners, Actives, Leavers, UD, TX
......
import unittest
import jsonschema
from ucoinpy.api.bma.network import Peering
from duniterpy.api.bma.network import Peering
from tests.api.webserver import WebFunctionalSetupMixin, web, asyncio
from ucoinpy.api.bma.network.peering import Peers
from duniterpy.api.bma.network.peering import Peers
class Test_BMA_Network(WebFunctionalSetupMixin, unittest.TestCase):
......
import unittest
import jsonschema
import aiohttp
from ucoinpy.api.bma.tx import History, Sources
from duniterpy.api.bma.tx import History, Sources
from tests.api.webserver import WebFunctionalSetupMixin, web, asyncio
from ucoinpy.api.bma.tx.history import Blocks
from duniterpy.api.bma.tx.history import Blocks
class Test_BMA_TX(WebFunctionalSetupMixin, unittest.TestCase):
......
......@@ -3,7 +3,7 @@ import unittest
import jsonschema
import json
from tests.api.webserver import WebFunctionalSetupMixin, web, asyncio
from ucoinpy.api.bma.wot import Lookup, Members, CertifiedBy, CertifiersOf
from duniterpy.api.bma.wot import Lookup, Members, CertifiedBy, CertifiersOf
class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
......
import unittest
from tests.api.webserver import WebFunctionalSetupMixin
from ucoinpy.api.bma.ws import Block, Peer
from duniterpy.api.bma.ws import Block, Peer
class Test_BMA_Websocket(WebFunctionalSetupMixin, unittest.TestCase):
......
import unittest
from ucoinpy.api.bma import API
from ucoinpy.documents.peer import BMAEndpoint
from duniterpy.api.bma import API
from duniterpy.documents.peer import BMAEndpoint
class Test_BMA_API(unittest.TestCase):
......
......@@ -4,7 +4,7 @@ Created on 12 déc. 2014
@author: inso
'''
import unittest
from ucoinpy.documents.block import Block, BlockUID
from duniterpy.documents.block import Block, BlockUID
raw_block = """Version: 2
Type: Block
......
......@@ -5,8 +5,8 @@ Created on 6 déc. 2014
'''
import unittest
from ucoinpy.documents.certification import SelfCertification, Certification, Revokation
from ucoinpy.documents import Block, BlockUID
from duniterpy.documents.certification import SelfCertification, Certification, Revokation
from duniterpy.documents import Block, BlockUID
selfcert_inlines = ["HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:\
h/H8tDIEbfA4yxMQcvfOXVDQhi1sUa9qYtPKrM59Bulv97ouwbAvAsEkC1Uyit1IOpeAV+CQQs4IaAyjE8F1Cw==:\
......
......@@ -4,7 +4,7 @@ Created on 12 déc. 2014
@author: inso
'''
import unittest
from ucoinpy.documents.membership import Membership
from duniterpy.documents.membership import Membership
membership_inline = "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:\
dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==:\
......
......@@ -4,7 +4,7 @@ Created on 13 déc. 2014
@author: inso
'''
import unittest
from ucoinpy.documents.peer import Peer, BMAEndpoint, UnknownEndpoint
from duniterpy.documents.peer import Peer, BMAEndpoint, UnknownEndpoint
rawpeer = """Version: 2
......
......@@ -5,8 +5,8 @@ Created on 12 déc. 2014
'''
import unittest
import pypeg2
from ucoinpy.grammars import output
from ucoinpy.documents.transaction import Transaction, reduce_base, SimpleTransaction
from duniterpy.grammars import output
from duniterpy.documents.transaction import Transaction, reduce_base, SimpleTransaction
tx_compact = """TX:2:3:6:6:3:1:0
......
from ucoinpy.grammars import output
from duniterpy.grammars import output
import unittest
import pypeg2
......
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
PROTOCOL_VERSION="1"
MANAGED_API=["BASIC_MERKLED_API"]
__author__ = 'Caner Candan & inso'
__version__ = '0.20.1dev5'
__nonsense__ = 'uCoin'
from . import api, documents, key
\ No newline at end of file
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
# Inso <insomniak.fr at gmail.com>
__all__ = ['api']
PROTOCOL_VERSION = 2
import logging
logger = logging.getLogger("ucoin")
from .api import API, ConnectionHandler
from . import network, blockchain, tx, wot, node, ud, ws
\ No newline at end of file
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
# Inso <insomniak.fr at gmail.com>
import aiohttp, json, logging, jsonschema
from ..errors import UcoinError
logger = logging.getLogger("ucoin")
class ConnectionHandler(object):
"""Helper class used by other API classes to ease passing server connection information."""
def __init__(self, server, port):
"""
Arguments:
- `server`: server hostname
- `port`: port number
"""
self.server = server
self.port = port
def __str__(self):
return 'connection info: %s:%d' % (self.server, self.port)
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."""
error_schema = {
"type": "object",
"properties": {
"ucode": {
"type": "number"
},
"message": {
"type": "string"
}
},
"required": ["ucode", "message"]
}
def __init__(self, connection_handler, module):
"""
Asks a module in order to create the url used then by derivated classes.
Arguments:
- `module`: module name
- `connection_handler`: connection handler
"""
self.module = module
self.connection_handler = connection_handler
self.headers = {}
def reverse_url(self, scheme, path):
"""
Reverses the url using self.url and path given in parameter.
Arguments:
- `path`: the request path
"""
server, port = self.connection_handler.server, self.connection_handler.port
url = '{scheme}://{server}:{port}/{module}'.format(scheme=scheme,
server=server,
port=port,
module=self.module)
return url + path
def get(self, session, **kwargs):
"""wrapper of overloaded __get__ method."""
return self.__get__(session, **kwargs)
def post(self, session, **kwargs):
"""wrapper of overloaded __post__ method."""
logger.debug('do some work with')
data = self.__post__(session, **kwargs)
logger.debug('and send back')
return data
async def __get__(self, session, **kwargs):
"""interface purpose for GET request"""
pass
async def __post__(self, session, **kwargs):
"""interface purpose for POST request"""
pass
def parse_text(self, text):
"""
Validate and parse the BMA answer from websocket
:param str text: the bma answer
:return: the json data
"""
try:
data = json.loads(text)
jsonschema.validate(data, self.schema)
return data
except TypeError:
raise jsonschema.ValidationError("Could not parse json")
def parse_error(self, text):
"""
Validate and parse the BMA answer from websocket
:param str text: the bma error
:return: the json data
"""
try:
data = json.loads(text)
jsonschema.validate(data, self.error_schema)
return data
except TypeError:
raise jsonschema.ValidationError("Could not parse json")
async def parse_response(self, response):
"""
Validate and parse the BMA answer
:param response:
:return: the json data
"""
try:
data = await response.json()
jsonschema.validate(data, self.schema)
return data
except TypeError:
raise jsonschema.ValidationError("Could not parse json")
async def requests_get(self, session, path, **kwargs):
"""
Requests GET wrapper in order to use API parameters.
:params aiohttp.ClientSession session: the client session
:params str path: the request path
"""
logging.debug("Request : {0}".format(self.reverse_url("http", path)))
with aiohttp.Timeout(15):
response = await session.get(self.reverse_url("http", path), params=kwargs,headers=self.headers)
if response.status != 200:
try:
error_data = self.parse_error(await response.text())
raise UcoinError(error_data)
except TypeError:
raise ValueError('status code != 200 => %d (%s)' % (response.status, (await response.text())))
return response
async def requests_post(self, session, path, **kwargs):
"""
Requests POST wrapper in order to use API parameters.
:param aiohttp.ClientSession session: the request session
:param str path: the request path
"""
if 'self_' in kwargs:
kwargs['self'] = kwargs.pop('self_')
logging.debug("POST : {0}".format(kwargs))
with aiohttp.Timeout(15):
response = await session.post(self.reverse_url("http", path), data=kwargs, headers=self.headers)
return response
def connect_ws(self, session, path):
"""
Connect to a websocket in order to use API parameters
:param aiohttp.ClientSession session: the session of the connection
:param str path: the url path
:return:
"""
url = self.reverse_url("ws", path)
return session.ws_connect(url)
This diff is collapsed.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from .. import API, logging
logger = logging.getLogger("ucoin/network")
class Network(API):
def __init__(self, connection_handler, module='network'):
super(Network, self).__init__(connection_handler, module)
class Peering(Network):
"""GET peering information about a peer."""
schema = {
"type": "object",
"properties": {
"version": {
"type": ["number", "string"]
},
"currency": {
"type": "string"
},
"pubkey": {
"type": "string"
},
"endpoints": {
"type": "array",
"items": {
"type": "string"
}
},
"signature": {
"type": "string"
}
},
"required": ["version", "currency", "pubkey", "endpoints", "signature"]
}
async def __get__(self, session, **kwargs):
r = await self.requests_get(session, '/peering', **kwargs)
return (await self.parse_response(r))
from . import peering
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from ucoinpy.api.bma.network import Network, logging
logger = logging.getLogger("ucoin/network/peering")
class Base(Network):
def __init__(self, connection_handler):
super(Base, self).__init__(connection_handler, 'network/peering')
class Peers(Base):
"""GET peering entries of every node inside the currency network."""
schema = {
"type": ["object"],
"properties": {
"depth": {
"type": "number"
},