Merge branch 'develop' into asyncio-dev

This commit is contained in:
Dan 2019-08-07 16:37:55 +02:00
commit 06f3053af8
3 changed files with 73 additions and 61 deletions

View File

@ -269,6 +269,23 @@ Telegram cloud. This error usually happens in case the provided URL is not publi
media exceeds 20 MB in size. In such cases, your only option is to download the media yourself and upload from your media exceeds 20 MB in size. In such cases, your only option is to download the media yourself and upload from your
local machine. local machine.
sqlite3.OperationalError: database is locked
--------------------------------------------
This error occurs when more than one process is using the same session file, that is, when you run two or more clients
at the same time using the same session name.
It could also occur when a background script is still running and you forgot about it. In this case, you either restart
your system or find and kill the process that is locking the database. On Unix based systems, you can do the following:
#. ``cd`` into your session file directory.
#. ``fuser my_account.session`` to find the process id.
#. ``kill 1234`` to gracefully stop the process.
#. If the last command doesn't help, use ``kill -9 1234`` instead.
If you want to run multiple clients on the same account, you must authorize your account (either user or bot)
from the beginning every time, and use different session names for each parallel client you are going to use.
My verification code expires immediately! My verification code expires immediately!
----------------------------------------- -----------------------------------------

View File

@ -147,43 +147,38 @@ class HTML:
@staticmethod @staticmethod
def unparse(text: str, entities: list): def unparse(text: str, entities: list):
text = utils.add_surrogates(text) text = utils.add_surrogates(text)
copy = text
entities_offsets = []
for entity in entities: for entity in entities:
entity_type = entity.type
start = entity.offset start = entity.offset
end = start + entity.length end = start + entity.length
type = entity.type if entity_type in ("bold", "italic", "underline", "strike"):
start_tag = "<{}>".format(entity_type[0])
url = entity.url end_tag = "</{}>".format(entity_type[0])
user = entity.user elif entity_type in ("code", "pre", "blockquote"):
start_tag = "<{}>".format(entity_type)
sub = copy[start:end] end_tag = "</{}>".format(entity_type)
elif entity_type == "text_link":
if type == "bold": url = entity.url
style = "b" start_tag = '<a href="{}">'.format(url)
elif type == "italic": end_tag = "</a>"
style = "i" elif entity_type == "text_mention":
elif type == "underline": user = entity.user
style = "u" start_tag = '<a href="tg://user?id={}">'.format(user.id)
elif type == "strike": end_tag = "</a>"
style = "s"
elif type == "code":
style = "code"
elif type == "pre":
style = "pre"
elif type == "blockquote":
style = "blockquote"
elif type == "text_link":
text = text[:start] + text[start:].replace(sub, '<a href="{}">{}</a>'.format(url, sub), 1)
continue
elif type == "text_mention":
text = text[:start] + text[start:].replace(
sub, '<a href="tg://user?id={}">{}</a>'.format(user.id, sub), 1)
continue
else: else:
continue continue
text = text[:start] + text[start:].replace(sub, "<{0}>{1}</{0}>".format(style, sub), 1) entities_offsets.append((start_tag, start,))
entities_offsets.append((end_tag, end,))
# sorting by offset (desc)
entities_offsets.sort(key=lambda x: -x[1])
for entity, offset in entities_offsets:
text = text[:offset] + entity + text[offset:]
return utils.remove_surrogates(text) return utils.remove_surrogates(text)

View File

@ -107,44 +107,44 @@ class Markdown:
@staticmethod @staticmethod
def unparse(text: str, entities: list): def unparse(text: str, entities: list):
text = utils.add_surrogates(text) text = utils.add_surrogates(text)
copy = text
entities_offsets = []
for entity in entities: for entity in entities:
entity_type = entity.type
start = entity.offset start = entity.offset
end = start + entity.length end = start + entity.length
type = entity.type if entity_type == "bold":
start_tag = end_tag = BOLD_DELIM
url = entity.url elif entity_type == "italic":
user = entity.user start_tag = end_tag = ITALIC_DELIM
elif entity_type == "underline":
sub = copy[start:end] start_tag = end_tag = UNDERLINE_DELIM
elif entity_type == "strike":
if type == "bold": start_tag = end_tag = STRIKE_DELIM
style = BOLD_DELIM elif entity_type == "code":
elif type == "italic": start_tag = end_tag = CODE_DELIM
style = ITALIC_DELIM elif entity_type in ("pre", "blockquote"):
elif type == "underline": start_tag = end_tag = PRE_DELIM
style = UNDERLINE_DELIM elif entity_type == "text_link":
elif type == "strike": url = entity.url
style = STRIKE_DELIM start_tag = "["
elif type == "code": end_tag = "]({})".format(url)
style = CODE_DELIM elif entity_type == "text_mention":
elif type == "pre": user = entity.user
style = PRE_DELIM start_tag = "["
# TODO: Blockquote for MD end_tag = "](tg://user?id={})".format(user.id)
# elif type == "blockquote":
# style = ...
elif type == "text_link":
text = text[:start] + text[start:].replace(sub, '[{1}]({0})'.format(url, sub), 1)
continue
elif type == "text_mention":
text = text[:start] + text[start:].replace(
sub, '[{1}](tg://user?id={0})'.format(user.id, sub), 1)
continue
else: else:
continue continue
text = text[:start] + text[start:].replace(sub, "{0}{1}{0}".format(style, sub), 1) entities_offsets.append((start_tag, start,))
entities_offsets.append((end_tag, end,))
# sorting by offset (desc)
entities_offsets.sort(key=lambda x: -x[1])
for entity, offset in entities_offsets:
text = text[:offset] + entity + text[offset:]
return utils.remove_surrogates(text) return utils.remove_surrogates(text)