Minor aiogram/utils/* typos fixes

+ PEP8 formatting fixes
+ super minor code change
This commit is contained in:
Suren Khorenyan 2018-01-23 15:48:21 +03:00
parent f68629f68b
commit 72db167fa3
5 changed files with 22 additions and 15 deletions

View file

@ -1,5 +1,5 @@
"""
Need setup task factory:
You need to setup task factory:
>>> from aiogram.utils import context
>>> loop = asyncio.get_event_loop()
>>> loop.set_task_factory(context.task_factory)

View file

@ -51,7 +51,8 @@ def start_pooling(*args, **kwargs):
return start_polling(*args, **kwargs)
def start_polling(dispatcher, *, loop=None, skip_updates=False, on_startup=None, on_shutdown=None):
def start_polling(dispatcher, *, loop=None, skip_updates=False,
on_startup=None, on_shutdown=None):
log.warning('Start bot with long-polling.')
if loop is None:
loop = dispatcher.loop
@ -59,7 +60,7 @@ def start_polling(dispatcher, *, loop=None, skip_updates=False, on_startup=None,
loop.set_task_factory(context.task_factory)
try:
loop.run_until_complete(_startup(dispatcher, skip_updates=skip_updates, callback=on_startup))
loop.run_until_complete(_startup(dispatcher, skip_updates, on_startup))
loop.create_task(dispatcher.start_polling(reset_webhook=True))
loop.run_forever()
except (KeyboardInterrupt, SystemExit):
@ -69,8 +70,8 @@ def start_polling(dispatcher, *, loop=None, skip_updates=False, on_startup=None,
log.warning("Goodbye!")
def start_webhook(dispatcher, webhook_path, *, loop=None, skip_updates=None, on_startup=None, on_shutdown=None,
check_ip=False, **kwargs):
def start_webhook(dispatcher, webhook_path, *, loop=None, skip_updates=None,
on_startup=None, on_shutdown=None, check_ip=False, **kwargs):
log.warning('Start bot with webhook.')
if loop is None:
loop = dispatcher.loop

View file

@ -137,7 +137,8 @@ class Item:
"""
Helper item
If value is not configured it will be generated automatically based on variable name
If a value is not provided,
it will be automatically generated based on a variable's name
"""
def __init__(self, value=None):
@ -156,7 +157,7 @@ class Item:
class ListItem(Item):
"""
This item always is list
This item is always a list
You can use &, | and + operators for that.
"""
@ -179,7 +180,7 @@ class ItemsList(list):
"""
Patch for default list
This class provide +, &, |, +=, &=, |= operators for extending the list
This class provides +, &, |, +=, &=, |= operators for extending the list
"""
def __init__(self, *seq):

View file

@ -18,6 +18,8 @@ HTML_QUOTES_MAP = {
'"': '"'
}
_HQS = HTML_QUOTES_MAP.keys() # HQS for HTML QUOTES SYMBOLS
def _join(*content, sep=' '):
return sep.join(map(str, content))
@ -38,21 +40,22 @@ def quote_html(content):
"""
Quote HTML symbols
All <, > and & symbols that are not a part of a tag or an HTML entity
must be replaced with the corresponding HTML entities (< with &lt;, > with &gt; and & with &amp;).
All <, >, & and " symbols that are not a part of a tag or
an HTML entity must be replaced with the corresponding HTML entities
(< with &lt; > with &gt; & with &amp and " with &quot).
:param content: str
:return: str
"""
new_content = ''
for symbol in content:
new_content += HTML_QUOTES_MAP[symbol] if symbol in '<>&"' else symbol
new_content += HTML_QUOTES_MAP[symbol] if symbol in _HQS else symbol
return new_content
def text(*content, sep=' '):
"""
Join all elements with separator
Join all elements with a separator
:param content:
:param sep:
@ -168,7 +171,7 @@ def hlink(title, url):
:param url:
:return:
"""
return "<a href=\"{0}\">{1}</a>".format(url, quote_html(title))
return '<a href="{0}">{1}</a>'.format(url, quote_html(title))
def escape_md(*content, sep=' '):

View file

@ -9,7 +9,8 @@ from .helper import Helper, HelperMode, Item
class Version:
def __init__(self, major=0, minor=0, maintenance=0, stage='final', build=0):
def __init__(self, major=0, minor=0,
maintenance=0, stage='final', build=0):
self.__raw_version = None
self.__version = None
@ -86,7 +87,8 @@ class Version:
if git_changeset:
sub = '.dev{0}'.format(git_changeset)
elif version[3] != Stage.FINAL:
mapping = {Stage.ALPHA: 'a', Stage.BETA: 'b', Stage.RC: 'rc', Stage.DEV: 'dev'}
mapping = {Stage.ALPHA: 'a', Stage.BETA: 'b',
Stage.RC: 'rc', Stage.DEV: 'dev'}
sub = mapping[version[3]] + str(version[4])
return str(main + sub)