Enforce pre-summary newline in docstrings

This commit is contained in:
Dominik Muhs
2019-10-24 20:10:45 +02:00
parent 87ed98d7af
commit bafdd8512d
52 changed files with 349 additions and 199 deletions

View File

@ -11,7 +11,8 @@ class SpiderCrawl:
"""Crawl the network and look for given 160-bit keys."""
def __init__(self, protocol, node, peers, ksize, alpha):
"""Create a new C{SpiderCrawl}er.
"""
Create a new C{SpiderCrawl}er.
Args:
protocol: A :class:`~kademlia.protocol.KademliaProtocol` instance.
@ -32,7 +33,8 @@ class SpiderCrawl:
self.nearest.push(peers)
async def _find(self, rpcmethod):
"""Get either a value or list of nodes.
"""
Get either a value or list of nodes.
Args:
rpcmethod: The protocol's callfindValue or call_find_node.
@ -98,7 +100,8 @@ class ValueSpiderCrawl(SpiderCrawl):
return await self.find()
async def _handle_found_values(self, values):
"""We got some values!
"""
We got some values!
Exciting. But let's make sure they're all the same or freak out
a little bit. Also, make sure we tell the nearest node that
@ -140,7 +143,8 @@ class NodeSpiderCrawl(SpiderCrawl):
class RPCFindResponse:
def __init__(self, response):
"""A wrapper for the result of a RPC find.
"""
A wrapper for the result of a RPC find.
Args:
response: This will be a tuple of (<response received>, <value>)
@ -160,7 +164,8 @@ class RPCFindResponse:
return self.response[1]["value"]
def get_node_list(self):
"""Get the node list in the response.
"""
Get the node list in the response.
If there's no value, this should be set.
"""

View File

@ -57,7 +57,8 @@ class KadPeerHeap:
"""A heap of peers ordered by distance to a given node."""
def __init__(self, node, maxsize):
"""Constructor.
"""
Constructor.
@param node: The node to measure all distnaces from.
@param maxsize: The maximum size that this heap can grow to.
@ -68,7 +69,8 @@ class KadPeerHeap:
self.maxsize = maxsize
def remove(self, peers):
"""Remove a list of peer ids from this heap.
"""
Remove a list of peer ids from this heap.
Note that while this heap retains a constant visible size (based
on the iterator), it's actual size may be quite a bit larger
@ -104,7 +106,8 @@ class KadPeerHeap:
return heapq.heappop(self.heap)[1] if self else None
def push(self, nodes):
"""Push nodes onto heap.
"""
Push nodes onto heap.
@param nodes: This can be a single item or a C{list}.
"""

View File

@ -13,7 +13,8 @@ log = logging.getLogger(__name__)
class KademliaServer:
"""High level view of a node instance.
"""
High level view of a node instance.
This is the object that should be created to start listening as an
active node on the network.
@ -22,8 +23,8 @@ class KademliaServer:
protocol_class = KademliaProtocol
def __init__(self, ksize=20, alpha=3, node_id=None, storage=None):
"""Create a server instance. This will start listening on the given
port.
"""
Create a server instance. This will start listening on the given port.
Args:
ksize (int): The k parameter from the paper
@ -55,7 +56,8 @@ class KademliaServer:
return self.protocol_class(self.node, self.storage, self.ksize)
async def listen(self, port, interface="0.0.0.0"):
"""Start listening on the given port.
"""
Start listening on the given port.
Provide interface="::" to accept ipv6 address
"""
@ -94,8 +96,9 @@ class KademliaServer:
await self.set_digest(dkey, value)
def bootstrappable_neighbors(self):
"""Get a :class:`list` of (ip, port) :class:`tuple` pairs suitable for
use as an argument to the bootstrap method.
"""
Get a :class:`list` of (ip, port) :class:`tuple` pairs suitable for use
as an argument to the bootstrap method.
The server should have been bootstrapped
already - this is just a utility for getting some neighbors and then
@ -106,8 +109,8 @@ class KademliaServer:
return [tuple(n)[-2:] for n in neighbors]
async def bootstrap(self, addrs):
"""Bootstrap the server by connecting to other known nodes in the
network.
"""
Bootstrap the server by connecting to other known nodes in the network.
Args:
addrs: A `list` of (ip, port) `tuple` pairs. Note that only IP
@ -127,7 +130,8 @@ class KademliaServer:
return create_kad_peerinfo(result[1], addr[0], addr[1]) if result[0] else None
async def get(self, key):
"""Get a key if the network has it.
"""
Get a key if the network has it.
Returns:
:class:`None` if not found, the value otherwise.
@ -218,8 +222,8 @@ class KademliaServer:
return svr
def save_state_regularly(self, fname, frequency=600):
"""Save the state of node with a given regularity to the given
filename.
"""
Save the state of node with a given regularity to the given filename.
Args:
fname: File name to save retularly to

View File

@ -137,7 +137,8 @@ class KademliaProtocol(RPCProtocol):
return self.handle_call_response(result, node_to_ask)
def welcome_if_new(self, node):
"""Given a new node, send it all the keys/values it should be storing,
"""
Given a new node, send it all the keys/values it should be storing,
then add it to the routing table.
@param node: A new node that just joined (or that we just found out
@ -166,7 +167,8 @@ class KademliaProtocol(RPCProtocol):
self.router.add_contact(node)
def handle_call_response(self, result, node):
"""If we get a response, add the node to the routing table.
"""
If we get a response, add the node to the routing table.
If we get no response, make sure it's removed from the routing
table.

View File

@ -52,8 +52,9 @@ class KBucket:
return node.peer_id_bytes not in self.nodes
def add_node(self, node):
"""Add a C{Node} to the C{KBucket}. Return True if successful, False
if the bucket is full.
"""
Add a C{Node} to the C{KBucket}. Return True if successful, False if
the bucket is full.
If the bucket is full, keep track of node in a replacement list,
per section 4.1 of the paper.

View File

@ -6,7 +6,8 @@ import time
class IStorage(ABC):
"""Local storage for this node.
"""
Local storage for this node.
IStorage implementations of get must return the same type as put in
by set
@ -18,14 +19,16 @@ class IStorage(ABC):
@abstractmethod
def __getitem__(self, key):
"""Get the given key.
"""
Get the given key.
If item doesn't exist, raises C{KeyError}
"""
@abstractmethod
def get(self, key, default=None):
"""Get given key.
"""
Get given key.
If not found, return default.
"""

View File

@ -17,7 +17,8 @@ def digest(string):
class OrderedSet(list):
"""Acts like a list in all ways, except in the behavior of the.
"""
Acts like a list in all ways, except in the behavior of the.
:meth:`push` method.
"""
@ -33,7 +34,8 @@ class OrderedSet(list):
def shared_prefix(args):
"""Find the shared prefix between the strings.
"""
Find the shared prefix between the strings.
For instance: