From bee6ced5c2590dad9f5e0827e8a8972ce14bf7f8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 19 Sep 2018 18:52:02 +0200 Subject: [PATCH 1/6] Fix Telegram API missing on readthedocs --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 10789e98..78d01fa8 100644 --- a/setup.py +++ b/setup.py @@ -130,6 +130,7 @@ class Generate(Command): if len(argv) > 1 and argv[1] in ["bdist_wheel", "install"]: error_compiler.start() api_compiler.start() + docs_compiler.start() setup( name="Pyrogram", From 61a2ad812ef5b01f4022d868971a5d625711b880 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 20 Sep 2018 16:33:36 +0200 Subject: [PATCH 2/6] Add missing docstrings for edit_message_media --- .../methods/messages/edit_message_media.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 7bf66d5e..74778865 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -36,6 +36,28 @@ class EditMessageMedia(BaseClient): message_id: int, media, reply_markup=None): + """Use this method to edit audio, document, photo, or video messages. + + If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, + message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. + Use previously uploaded file via its file_id or specify a URL. On success, if the edited message was sent + by the bot, the edited Message is returned, otherwise True is returned. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For your personal cloud (Saved Messages) you can simply use "me" or "self". + For a contact that exists in your Telegram address book you can use his phone number (str). + + message_id (``int``): + Message identifier in the chat specified in chat_id. + + media (:obj:`InputMediaAnimation` | :obj:`InputMediaAudio` | :obj:`InputMediaDocument` | :obj:`InputMediaPhoto` | :obj:`InputMediaVideo`) + One of the InputMedia objects describing an animation, audio, document, photo or video. + + reply_markup (:obj:`InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + """ style = self.html if media.parse_mode.lower() == "html" else self.markdown caption = media.caption From ab560dc292c64ca97c506aa9a2d0d67e0a546448 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 20 Sep 2018 16:35:43 +0200 Subject: [PATCH 3/6] Small documentation fix --- docs/source/start/Usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/start/Usage.rst b/docs/source/start/Usage.rst index 6c560f90..6eac5cd1 100644 --- a/docs/source/start/Usage.rst +++ b/docs/source/start/Usage.rst @@ -33,7 +33,7 @@ Examples (more on `GitHub ` and :mod:`types ` exposed by the ``pyrogram.api`` package and call any Telegram API method you wish using the :meth:`send() ` method provided by the Client class. From 6a89c7ea02001c28df37e00eb0c7fc97cc055082 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 22 Sep 2018 14:21:55 +0200 Subject: [PATCH 4/6] Add missing ipv6 docstrings --- pyrogram/client/client.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 3d8911a7..ade4fc50 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -90,6 +90,10 @@ class Client(Methods, BaseClient): Code of the language used on the client, in ISO 639-1 standard. Defaults to "en". This is an alternative way to set it if you don't want to use the *config.ini* file. + ipv6 (``bool``, *optional*): + Pass True to connect to Telegram using IPv6. + Defaults to False (IPv4). + proxy (``dict``, *optional*): Your SOCKS5 Proxy settings as dict, e.g.: *dict(hostname="11.22.33.44", port=1080, username="user", password="pass")*. From 28abcaac50a760aff1ac2922db784a5632122473 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 22 Sep 2018 14:31:28 +0200 Subject: [PATCH 5/6] Fix ipv6 with ipv4 proxies --- pyrogram/connection/transport/tcp/tcp.py | 29 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 8560604f..ee29b960 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -34,24 +34,33 @@ log = logging.getLogger(__name__) class TCP(socks.socksocket): def __init__(self, ipv6: bool, proxy: dict): - super().__init__(family=socket.AF_INET6 if ipv6 else socket.AF_INET) + if proxy.get("enabled", False): + hostname = proxy.get("hostname", None) + port = proxy.get("port", None) - self.settimeout(10) - self.proxy_enabled = proxy.get("enabled", False) + try: + socket.inet_aton(hostname) + except socket.error: + super().__init__(socket.AF_INET6) + else: + super().__init__(socket.AF_INET) - if proxy and self.proxy_enabled: self.set_proxy( proxy_type=socks.SOCKS5, - addr=proxy.get("hostname", None), - port=proxy.get("port", None), + addr=hostname, + port=port, username=proxy.get("username", None), password=proxy.get("password", None) ) - log.info("Using proxy {}:{}".format( - proxy.get("hostname", None), - proxy.get("port", None) - )) + log.info("Using proxy {}:{}".format(hostname, port)) + else: + super().__init__( + socket.AF_INET6 if ipv6 + else socket.AF_INET + ) + + self.settimeout(10) def close(self): try: From 8ea556b65fbc2440f81408ee52179ce1586e68ac Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 22 Sep 2018 14:44:12 +0200 Subject: [PATCH 6/6] Fix handling proxies with domain names --- pyrogram/connection/transport/tcp/tcp.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index ee29b960..2ee08d09 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -18,6 +18,7 @@ import logging import socket +import ipaddress try: import socks @@ -39,11 +40,14 @@ class TCP(socks.socksocket): port = proxy.get("port", None) try: - socket.inet_aton(hostname) - except socket.error: - super().__init__(socket.AF_INET6) - else: + ip_address = ipaddress.ip_address(hostname) + except ValueError: super().__init__(socket.AF_INET) + else: + if isinstance(ip_address, ipaddress.IPv6Address): + super().__init__(socket.AF_INET6) + else: + super().__init__(socket.AF_INET) self.set_proxy( proxy_type=socks.SOCKS5,