mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-17 21:22:40 +00:00
Merge branch 'develop' into asyncio
This commit is contained in:
commit
654a432d99
@ -4,18 +4,18 @@ Error Handling
|
||||
Errors are inevitable when working with the API, and they must be correctly handled with ``try..except`` blocks.
|
||||
|
||||
There are many errors that Telegram could return, but they all fall in one of these categories
|
||||
(which are in turn children of the :obj:`pyrogram.Error` superclass)
|
||||
(which are in turn children of the :obj:`RPCError <pyrogram.RPCError>` superclass)
|
||||
|
||||
- :obj:`303 - See Other <pyrogram.api.errors.SeeOther>`
|
||||
- :obj:`400 - Bad Request <pyrogram.api.errors.BadRequest>`
|
||||
- :obj:`401 - Unauthorized <pyrogram.api.errors.Unauthorized>`
|
||||
- :obj:`403 - Forbidden <pyrogram.api.errors.Forbidden>`
|
||||
- :obj:`406 - Not Acceptable <pyrogram.api.errors.NotAcceptable>`
|
||||
- :obj:`420 - Flood <pyrogram.api.errors.Flood>`
|
||||
- :obj:`500 - Internal Server Error <pyrogram.api.errors.InternalServerError>`
|
||||
- :obj:`303 - See Other <pyrogram.errors.SeeOther>`
|
||||
- :obj:`400 - Bad Request <pyrogram.errors.BadRequest>`
|
||||
- :obj:`401 - Unauthorized <pyrogram.errors.Unauthorized>`
|
||||
- :obj:`403 - Forbidden <pyrogram.errors.Forbidden>`
|
||||
- :obj:`406 - Not Acceptable <pyrogram.errors.NotAcceptable>`
|
||||
- :obj:`420 - Flood <pyrogram.errors.Flood>`
|
||||
- :obj:`500 - Internal Server Error <pyrogram.errors.InternalServerError>`
|
||||
|
||||
As stated above, there are really many (too many) errors, and in case Pyrogram does not know anything yet about a
|
||||
specific one, it raises a special :obj:`520 Unknown Error <pyrogram.api.errors.UnknownError>` exception and logs it
|
||||
specific one, it raises a special :obj:`520 Unknown Error <pyrogram.errors.UnknownError>` exception and logs it
|
||||
in the ``unknown_errors.txt`` file. Users are invited to report these unknown errors; in later versions of Pyrogram
|
||||
some kind of automatic error reporting module might be implemented.
|
||||
|
||||
@ -24,7 +24,7 @@ Examples
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pyrogram.api.errors import (
|
||||
from pyrogram.errors import (
|
||||
BadRequest, Flood, InternalServerError,
|
||||
SeeOther, Unauthorized, UnknownError
|
||||
)
|
||||
@ -45,13 +45,13 @@ Examples
|
||||
pass
|
||||
|
||||
Exception objects may also contain some informative values.
|
||||
E.g.: :obj:`FloodWait <pyrogram.api.errors.exceptions.flood_420.FloodWait>` holds the amount of seconds you have to wait
|
||||
E.g.: :obj:`FloodWait <pyrogram.errors.exceptions.flood_420.FloodWait>` holds the amount of seconds you have to wait
|
||||
before you can try again. The value is always stored in the ``x`` field of the returned exception object:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import time
|
||||
from pyrogram.api.errors import FloodWait
|
||||
from pyrogram.errors import FloodWait
|
||||
|
||||
try:
|
||||
...
|
||||
|
@ -80,8 +80,8 @@ class BaseClient:
|
||||
self.peers_by_username = {}
|
||||
self.peers_by_phone = {}
|
||||
|
||||
self.markdown = Markdown(self.peers_by_id)
|
||||
self.html = HTML(self.peers_by_id)
|
||||
self.markdown = Markdown(self)
|
||||
self.html = HTML(self)
|
||||
|
||||
self.session = None
|
||||
self.media_sessions = {}
|
||||
|
@ -19,6 +19,7 @@
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api.types import (
|
||||
MessageEntityBold as Bold,
|
||||
MessageEntityItalic as Italic,
|
||||
@ -28,6 +29,7 @@ from pyrogram.api.types import (
|
||||
MessageEntityMentionName as MentionInvalid,
|
||||
InputMessageEntityMentionName as Mention,
|
||||
)
|
||||
from pyrogram.errors import PeerIdInvalid
|
||||
from . import utils
|
||||
|
||||
|
||||
@ -35,8 +37,8 @@ class HTML:
|
||||
HTML_RE = re.compile(r"<(\w+)(?: href=([\"'])([^<]+)\2)?>([^>]+)</\1>")
|
||||
MENTION_RE = re.compile(r"tg://user\?id=(\d+)")
|
||||
|
||||
def __init__(self, peers_by_id: dict = None):
|
||||
self.peers_by_id = peers_by_id or {}
|
||||
def __init__(self, client: "pyrogram.BaseClient" = None):
|
||||
self.client = client
|
||||
|
||||
def parse(self, message: str):
|
||||
entities = []
|
||||
@ -52,7 +54,11 @@ class HTML:
|
||||
|
||||
if mention:
|
||||
user_id = int(mention.group(1))
|
||||
input_user = self.peers_by_id.get(user_id, None)
|
||||
|
||||
try:
|
||||
input_user = self.client.resolve_peer(user_id)
|
||||
except PeerIdInvalid:
|
||||
input_user = None
|
||||
|
||||
entity = (
|
||||
Mention(offset=start, length=len(body), user_id=input_user)
|
||||
|
@ -19,6 +19,7 @@
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api.types import (
|
||||
MessageEntityBold as Bold,
|
||||
MessageEntityItalic as Italic,
|
||||
@ -28,6 +29,7 @@ from pyrogram.api.types import (
|
||||
MessageEntityMentionName as MentionInvalid,
|
||||
InputMessageEntityMentionName as Mention
|
||||
)
|
||||
from pyrogram.errors import PeerIdInvalid
|
||||
from . import utils
|
||||
|
||||
|
||||
@ -52,8 +54,8 @@ class Markdown:
|
||||
))
|
||||
MENTION_RE = re.compile(r"tg://user\?id=(\d+)")
|
||||
|
||||
def __init__(self, peers_by_id: dict = None):
|
||||
self.peers_by_id = peers_by_id or {}
|
||||
def __init__(self, client: "pyrogram.BaseClient" = None):
|
||||
self.client = client
|
||||
|
||||
def parse(self, message: str):
|
||||
message = utils.add_surrogates(str(message or "")).strip()
|
||||
@ -69,12 +71,15 @@ class Markdown:
|
||||
|
||||
if mention:
|
||||
user_id = int(mention.group(1))
|
||||
input_user = self.peers_by_id.get(user_id, None)
|
||||
|
||||
try:
|
||||
input_user = self.client.resolve_peer(user_id)
|
||||
except PeerIdInvalid:
|
||||
input_user = None
|
||||
|
||||
entity = (
|
||||
Mention(offset=start, length=len(text), user_id=input_user)
|
||||
if input_user
|
||||
else MentionInvalid(offset=start, length=len(text), user_id=user_id)
|
||||
if input_user else MentionInvalid(offset=start, length=len(text), user_id=user_id)
|
||||
)
|
||||
else:
|
||||
entity = Url(offset=start, length=len(text), url=url)
|
||||
|
@ -29,6 +29,7 @@ class PollOption(PyrogramType):
|
||||
|
||||
voters (``int``):
|
||||
The number of users who voted this option.
|
||||
It will be 0 until you vote for the poll.
|
||||
|
||||
data (``bytes``):
|
||||
Unique data that identifies this option among all the other options in a poll.
|
||||
|
Loading…
Reference in New Issue
Block a user