[misc] Improve docstrings

Mostly by removing whitespace before and after the docstring
This commit is contained in:
Martin Rey 2020-10-13 11:38:33 +02:00 committed by Maike
parent 2954f3700b
commit 4146cb89b5
13 changed files with 32 additions and 41 deletions

View file

@ -4,7 +4,7 @@
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
""" Configuration file and command line argument parser. """Configuration file and command line argument parser.
Gives a dictionary named `config` with configuration parsed either from Gives a dictionary named `config` with configuration parsed either from
`/etc/kibicara.conf` or from a file given by command line argument `-f`. `/etc/kibicara.conf` or from a file given by command line argument `-f`.
@ -38,7 +38,7 @@ config = {
'root_url': 'http://localhost:8000', # url of backend 'root_url': 'http://localhost:8000', # url of backend
'cors_allow_origin': 'http://127.0.0.1:4200', 'cors_allow_origin': 'http://127.0.0.1:4200',
} }
""" Default configuration. """Default configuration.
The default configuration gets overwritten by a configuration file if one exists. The default configuration gets overwritten by a configuration file if one exists.
""" """

View file

@ -4,7 +4,7 @@
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
""" E-Mail handling. """ """E-Mail handling."""
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText

View file

@ -4,7 +4,7 @@
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
""" Entrypoint of Kibicara. """ """Entrypoint of Kibicara."""
from asyncio import run as asyncio_run from asyncio import run as asyncio_run
from logging import DEBUG, INFO, WARNING, basicConfig, getLogger from logging import DEBUG, INFO, WARNING, basicConfig, getLogger

View file

@ -4,7 +4,7 @@
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
""" ORM Models for core. """ """ORM Models for core."""
from databases import Database from databases import Database
from ormantic import Boolean, ForeignKey, Integer, Model, Text from ormantic import Boolean, ForeignKey, Integer, Model, Text

View file

@ -4,7 +4,7 @@
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
""" API classes for implementing bots for platforms. """ """API classes for implementing bots for platforms."""
from asyncio import Queue, create_task from asyncio import Queue, create_task
from enum import Enum, auto from enum import Enum, auto
@ -24,10 +24,6 @@ class Message:
message = Message('Message sent from platform xyz', xyz_message_id=123) message = Message('Message sent from platform xyz', xyz_message_id=123)
``` ```
Args:
text (str): The message text
**kwargs (object, optional): Other platform-specific data.
Attributes: Attributes:
text (str): The message text text (str): The message text
**kwargs (object, optional): Other platform-specific data. **kwargs (object, optional): Other platform-specific data.
@ -71,9 +67,6 @@ class Censor:
# XXX send message.text to platform xyz # XXX send message.text to platform xyz
``` ```
Args:
hood (Hood): A Hood Model object
Attributes: Attributes:
hood (Hood): A Hood Model object hood (Hood): A Hood Model object
""" """
@ -90,12 +83,12 @@ class Censor:
self.status = BotStatus.INSTANTIATED self.status = BotStatus.INSTANTIATED
def start(self): def start(self):
""" Start the bot. """ """Start the bot."""
if self.__task is None: if self.__task is None:
self.__task = create_task(self.__run()) self.__task = create_task(self.__run())
def stop(self): def stop(self):
""" Stop the bot. """ """Stop the bot."""
if self.__task is not None: if self.__task is not None:
self.__task.cancel() self.__task.cancel()
@ -120,7 +113,7 @@ class Censor:
@classmethod @classmethod
async def destroy_hood(cls, hood): async def destroy_hood(cls, hood):
"""Removes all its database entries. """Remove all of its database entries.
Note: Override this in the derived bot class. Note: Override this in the derived bot class.
""" """
@ -176,10 +169,6 @@ class Spawner:
spawner = Spawner(XYZ, XYZPlatform) spawner = Spawner(XYZ, XYZPlatform)
``` ```
Args:
ORMClass (ORM Model subclass): A Bot Model object
BotClass (Censor subclass): A Bot Class object
Attributes: Attributes:
ORMClass (ORM Model subclass): A Hood Model object ORMClass (ORM Model subclass): A Hood Model object
BotClass (Censor subclass): A Bot Class object BotClass (Censor subclass): A Bot Class object

View file

@ -32,7 +32,7 @@ class EmailBot(Censor):
await subscriber.delete() await subscriber.delete()
async def run(self): async def run(self):
""" Loop which waits for new messages and sends emails to all subscribers. """ """Loop which waits for new messages and sends emails to all subscribers."""
while True: while True:
message = await self.receive() message = await self.receive()
logger.debug( logger.debug(

View file

@ -11,7 +11,7 @@ from kibicara.model import Hood, Mapping
class Email(Model): class Email(Model):
""" This table is used to track the names. It also stores the token secret. """ """This table is used to track the names. It also stores the token secret."""
id: Integer(primary_key=True) = None id: Integer(primary_key=True) = None
hood: ForeignKey(Hood) hood: ForeignKey(Hood)
@ -23,7 +23,7 @@ class Email(Model):
class EmailSubscribers(Model): class EmailSubscribers(Model):
""" This table stores all subscribers, who want to receive messages via email. """ """This table stores all subscribers, who want to receive messages via email."""
id: Integer(primary_key=True) = None id: Integer(primary_key=True) = None
hood: ForeignKey(Hood) hood: ForeignKey(Hood)

View file

@ -41,20 +41,21 @@ class BodyEmailPublic(BaseModel):
class BodyMessage(BaseModel): class BodyMessage(BaseModel):
""" This model shows which values are supplied by the MDA listener script. """ """This model shows which values are supplied by the MDA listener script."""
text: str text: str
secret: str secret: str
class BodySubscriber(BaseModel): class BodySubscriber(BaseModel):
""" This model holds the email address of a fresh subscriber. """ """This model holds the email address of a fresh subscriber."""
email: str email: str
async def get_email(email_id: int, hood=Depends(get_hood)): async def get_email(email_id: int, hood=Depends(get_hood)):
"""Get Email row by hood. """Get Email row by hood.
You can specify an email_id to nail it down, but it works without as well. You can specify an email_id to nail it down, but it works without as well.
:param hood: Hood the Email bot belongs to. :param hood: Hood the Email bot belongs to.
@ -168,6 +169,7 @@ async def email_read(email=Depends(get_email)):
) )
async def email_delete(email=Depends(get_email)): async def email_delete(email=Depends(get_email)):
"""Delete an Email bot. """Delete an Email bot.
Stops and deletes the Email bot. Stops and deletes the Email bot.
:param hood: Hood the Email bot belongs to. :param hood: Hood the Email bot belongs to.

View file

@ -4,7 +4,7 @@
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
""" Routing definitions for the REST API. """Routing definitions for the REST API.
A platform bot shall add its API router in this `__init__.py` A platform bot shall add its API router in this `__init__.py`
file to get included into the main application. file to get included into the main application.

View file

@ -5,7 +5,7 @@
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
""" REST API endpoints for hood admins. """ """REST API endpoints for hood admins."""
from datetime import datetime, timedelta from datetime import datetime, timedelta
from logging import getLogger from logging import getLogger
@ -230,7 +230,7 @@ async def admin_confirm_reset(reset_token: str, values: BodyPassword):
operation_id='get_hoods_admin', operation_id='get_hoods_admin',
) )
async def admin_hood_read_all(admin=Depends(get_admin)): async def admin_hood_read_all(admin=Depends(get_admin)):
""" Get a list of all hoods of a given admin. """ """Get a list of all hoods of a given admin."""
return ( return (
await AdminHoodRelation.objects.select_related('hood').filter(admin=admin).all() await AdminHoodRelation.objects.select_related('hood').filter(admin=admin).all()
) )
@ -242,7 +242,7 @@ async def admin_hood_read_all(admin=Depends(get_admin)):
operation_id='get_admin', operation_id='get_admin',
) )
async def admin_read(admin=Depends(get_admin)): async def admin_read(admin=Depends(get_admin)):
""" Get a list of all hoods of a given admin. """ """Get a list of all hoods of a given admin."""
admin = await Admin.objects.filter(email=admin.email).all() admin = await Admin.objects.filter(email=admin.email).all()
if len(admin) != 1: if len(admin) != 1:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)

View file

@ -4,7 +4,7 @@
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
""" REST API Endpoints for managing hoods. """ """REST API Endpoints for managing hoods."""
from sqlite3 import IntegrityError from sqlite3 import IntegrityError
@ -54,7 +54,7 @@ router = APIRouter()
tags=['hoods'], tags=['hoods'],
) )
async def hood_read_all(): async def hood_read_all():
""" Get all existing hoods. """ """Get all existing hoods."""
return await Hood.objects.all() return await Hood.objects.all()
@ -92,7 +92,7 @@ async def hood_create(values: BodyHood, response: Response, admin=Depends(get_ad
tags=['hoods'], tags=['hoods'],
) )
async def hood_read(hood=Depends(get_hood_unauthorized)): async def hood_read(hood=Depends(get_hood_unauthorized)):
""" Get hood with id **hood_id**. """ """Get hood with id **hood_id**."""
return hood return hood
@ -119,6 +119,6 @@ async def hood_update(values: BodyHood, hood=Depends(get_hood)):
tags=['hoods'], tags=['hoods'],
) )
async def hood_delete(hood=Depends(get_hood)): async def hood_delete(hood=Depends(get_hood)):
""" Deletes hood with id **hood_id**. """ """Deletes hood with id **hood_id**."""
await delete_hood(hood) await delete_hood(hood)
return Response(status_code=status.HTTP_204_NO_CONTENT) return Response(status_code=status.HTTP_204_NO_CONTENT)

View file

@ -4,7 +4,7 @@
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
""" REST API endpoints for managing badwords. """REST API endpoints for managing badwords.
Provides API endpoints for adding, removing and reading regular expressions that block a Provides API endpoints for adding, removing and reading regular expressions that block a
received message to be dropped by a censor. This provides a message filter customizable received message to be dropped by a censor. This provides a message filter customizable
@ -43,7 +43,7 @@ router = APIRouter()
operation_id='get_badwords', operation_id='get_badwords',
) )
async def badword_read_all(hood=Depends(get_hood)): async def badword_read_all(hood=Depends(get_hood)):
""" Get all badwords of hood with id **hood_id**. """ """Get all badwords of hood with id **hood_id**."""
return await BadWord.objects.filter(hood=hood).all() return await BadWord.objects.filter(hood=hood).all()
@ -77,7 +77,7 @@ async def badword_create(
operation_id='get_badword', operation_id='get_badword',
) )
async def badword_read(badword=Depends(get_badword)): async def badword_read(badword=Depends(get_badword)):
""" Reads badword with id **badword_id** for hood with id **hood_id**. """ """Reads badword with id **badword_id** for hood with id **hood_id**."""
return badword return badword
@ -101,6 +101,6 @@ async def badword_update(values: BodyBadWord, badword=Depends(get_badword)):
operation_id='delete_badword', operation_id='delete_badword',
) )
async def badword_delete(badword=Depends(get_badword)): async def badword_delete(badword=Depends(get_badword)):
""" Deletes badword with id **badword_id** for hood with id **hood_id**. """ """Deletes badword with id **badword_id** for hood with id **hood_id**."""
await badword.delete() await badword.delete()
return Response(status_code=status.HTTP_204_NO_CONTENT) return Response(status_code=status.HTTP_204_NO_CONTENT)

View file

@ -4,7 +4,7 @@
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
""" REST API endpoints for managing triggers. """REST API endpoints for managing triggers.
Provides API endpoints for adding, removing and reading regular expressions that allow a Provides API endpoints for adding, removing and reading regular expressions that allow a
message to be passed through by a censor. A published message must match one of these message to be passed through by a censor. A published message must match one of these
@ -44,7 +44,7 @@ router = APIRouter()
operation_id='get_triggers', operation_id='get_triggers',
) )
async def trigger_read_all(hood=Depends(get_hood)): async def trigger_read_all(hood=Depends(get_hood)):
""" Get all triggers of hood with id **hood_id**. """ """Get all triggers of hood with id **hood_id**."""
return await Trigger.objects.filter(hood=hood).all() return await Trigger.objects.filter(hood=hood).all()
@ -78,7 +78,7 @@ async def trigger_create(
operation_id='get_trigger', operation_id='get_trigger',
) )
async def trigger_read(trigger=Depends(get_trigger)): async def trigger_read(trigger=Depends(get_trigger)):
""" Reads trigger with id **trigger_id** for hood with id **hood_id**. """ """Reads trigger with id **trigger_id** for hood with id **hood_id**."""
return trigger return trigger
@ -102,6 +102,6 @@ async def trigger_update(values: BodyTrigger, trigger=Depends(get_trigger)):
operation_id='delete_trigger', operation_id='delete_trigger',
) )
async def trigger_delete(trigger=Depends(get_trigger)): async def trigger_delete(trigger=Depends(get_trigger)):
""" Deletes trigger with id **trigger_id** for hood with id **hood_id**. """ """Deletes trigger with id **trigger_id** for hood with id **hood_id**."""
await trigger.delete() await trigger.delete()
return Response(status_code=status.HTTP_204_NO_CONTENT) return Response(status_code=status.HTTP_204_NO_CONTENT)