From f87aae1dbdf9b9062310b77e2b89f22621e7b7d4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Aug 2019 13:16:48 +0200 Subject: [PATCH 1/2] Add FAQ about "database is locked" error --- docs/source/faq.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/source/faq.rst b/docs/source/faq.rst index 5d4823c8..203dde8a 100644 --- a/docs/source/faq.rst +++ b/docs/source/faq.rst @@ -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 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! ----------------------------------------- From 2aefbfd531d05ab70b5dd48faa18e69233648bff Mon Sep 17 00:00:00 2001 From: Mario A Date: Wed, 7 Aug 2019 13:48:21 +0200 Subject: [PATCH 2/2] Add better support for nested entities (both for HTML and Markdown) (#297) * Added better support for nested entities, both for HTML and Markdown * Tiny style fix * Make use of pre-defined constants --- pyrogram/client/parser/html.py | 55 ++++++++++++-------------- pyrogram/client/parser/markdown.py | 62 +++++++++++++++--------------- 2 files changed, 56 insertions(+), 61 deletions(-) diff --git a/pyrogram/client/parser/html.py b/pyrogram/client/parser/html.py index 41efe3b3..82499cb3 100644 --- a/pyrogram/client/parser/html.py +++ b/pyrogram/client/parser/html.py @@ -147,43 +147,38 @@ class HTML: @staticmethod def unparse(text: str, entities: list): text = utils.add_surrogates(text) - copy = text + + entities_offsets = [] for entity in entities: + entity_type = entity.type start = entity.offset end = start + entity.length - type = entity.type - - url = entity.url - user = entity.user - - sub = copy[start:end] - - if type == "bold": - style = "b" - elif type == "italic": - style = "i" - elif type == "underline": - style = "u" - elif type == "strike": - 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, '{}'.format(url, sub), 1) - continue - elif type == "text_mention": - text = text[:start] + text[start:].replace( - sub, '{}'.format(user.id, sub), 1) - continue + if entity_type in ("bold", "italic", "underline", "strike"): + start_tag = "<{}>".format(entity_type[0]) + end_tag = "".format(entity_type[0]) + elif entity_type in ("code", "pre", "blockquote"): + start_tag = "<{}>".format(entity_type) + end_tag = "".format(entity_type) + elif entity_type == "text_link": + url = entity.url + start_tag = ''.format(url) + end_tag = "" + elif entity_type == "text_mention": + user = entity.user + start_tag = ''.format(user.id) + end_tag = "" else: continue - text = text[:start] + text[start:].replace(sub, "<{0}>{1}".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) diff --git a/pyrogram/client/parser/markdown.py b/pyrogram/client/parser/markdown.py index 74d06e97..1319f6df 100644 --- a/pyrogram/client/parser/markdown.py +++ b/pyrogram/client/parser/markdown.py @@ -107,44 +107,44 @@ class Markdown: @staticmethod def unparse(text: str, entities: list): text = utils.add_surrogates(text) - copy = text + + entities_offsets = [] for entity in entities: + entity_type = entity.type start = entity.offset end = start + entity.length - type = entity.type - - url = entity.url - user = entity.user - - sub = copy[start:end] - - if type == "bold": - style = BOLD_DELIM - elif type == "italic": - style = ITALIC_DELIM - elif type == "underline": - style = UNDERLINE_DELIM - elif type == "strike": - style = STRIKE_DELIM - elif type == "code": - style = CODE_DELIM - elif type == "pre": - style = PRE_DELIM - # TODO: Blockquote for MD - # 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 + if entity_type == "bold": + start_tag = end_tag = BOLD_DELIM + elif entity_type == "italic": + start_tag = end_tag = ITALIC_DELIM + elif entity_type == "underline": + start_tag = end_tag = UNDERLINE_DELIM + elif entity_type == "strike": + start_tag = end_tag = STRIKE_DELIM + elif entity_type == "code": + start_tag = end_tag = CODE_DELIM + elif entity_type in ("pre", "blockquote"): + start_tag = end_tag = PRE_DELIM + elif entity_type == "text_link": + url = entity.url + start_tag = "[" + end_tag = "]({})".format(url) + elif entity_type == "text_mention": + user = entity.user + start_tag = "[" + end_tag = "](tg://user?id={})".format(user.id) else: 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)