Skip to content

Commit 41acdd4

Browse files
committed
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/connection/transport/tcp/tcp.py
2 parents df8bc62 + 8ea556b commit 41acdd4

5 files changed

Lines changed: 55 additions & 15 deletions

File tree

docs/source/start/Usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Examples (more on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/exa
3333
Raw Functions
3434
-------------
3535

36-
If you can't find a high-level method for your needs or if want complete, low-level access to the whole Telegram API,
36+
If you can't find a high-level method for your needs or if you want complete, low-level access to the whole Telegram API,
3737
you have to use the raw :mod:`functions <pyrogram.api.functions>` and :mod:`types <pyrogram.api.types>` exposed by the
3838
``pyrogram.api`` package and call any Telegram API method you wish using the :meth:`send() <pyrogram.Client.send>`
3939
method provided by the Client class.

pyrogram/client/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class Client(Methods, BaseClient):
9090
Code of the language used on the client, in ISO 639-1 standard. Defaults to "en".
9191
This is an alternative way to set it if you don't want to use the *config.ini* file.
9292
93+
ipv6 (``bool``, *optional*):
94+
Pass True to connect to Telegram using IPv6.
95+
Defaults to False (IPv4).
96+
9397
proxy (``dict``, *optional*):
9498
Your SOCKS5 Proxy settings as dict,
9599
e.g.: *dict(hostname="11.22.33.44", port=1080, username="user", password="pass")*.

pyrogram/client/methods/messages/edit_message_media.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ async def edit_message_media(self,
3636
message_id: int,
3737
media,
3838
reply_markup=None):
39+
"""Use this method to edit audio, document, photo, or video messages.
40+
41+
If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise,
42+
message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded.
43+
Use previously uploaded file via its file_id or specify a URL. On success, if the edited message was sent
44+
by the bot, the edited Message is returned, otherwise True is returned.
45+
46+
Args:
47+
chat_id (``int`` | ``str``):
48+
Unique identifier (int) or username (str) of the target chat.
49+
For your personal cloud (Saved Messages) you can simply use "me" or "self".
50+
For a contact that exists in your Telegram address book you can use his phone number (str).
51+
52+
message_id (``int``):
53+
Message identifier in the chat specified in chat_id.
54+
55+
media (:obj:`InputMediaAnimation` | :obj:`InputMediaAudio` | :obj:`InputMediaDocument` | :obj:`InputMediaPhoto` | :obj:`InputMediaVideo`)
56+
One of the InputMedia objects describing an animation, audio, document, photo or video.
57+
58+
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
59+
An InlineKeyboardMarkup object.
60+
"""
3961
style = self.html if media.parse_mode.lower() == "html" else self.markdown
4062
caption = media.caption
4163

pyrogram/connection/transport/tcp/tcp.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import asyncio
2020
import logging
2121
import socket
22+
import ipaddress
2223

2324
try:
2425
import socks
@@ -37,31 +38,43 @@ class TCP:
3738
TIMEOUT = 10
3839

3940
def __init__(self, ipv6: bool, proxy: dict):
40-
self.proxy = proxy
41+
self.socket = None
42+
43+
self.reader = None # type: asyncio.StreamReader
44+
self.writer = None # type: asyncio.StreamWriter
4145

4246
self.lock = asyncio.Lock()
4347

44-
self.socket = socks.socksocket(family=socket.AF_INET6 if ipv6 else socket.AF_INET)
48+
if proxy.get("enabled", False):
49+
hostname = proxy.get("hostname", None)
50+
port = proxy.get("port", None)
4551

46-
self.socket.settimeout(TCP.TIMEOUT)
47-
48-
self.reader = None # type: asyncio.StreamReader
49-
self.writer = None # type: asyncio.StreamWriter
50-
self.proxy_enabled = proxy.get("enabled", False)
52+
try:
53+
ip_address = ipaddress.ip_address(hostname)
54+
except ValueError:
55+
self.socket = socks.socksocket(socket.AF_INET)
56+
else:
57+
if isinstance(ip_address, ipaddress.IPv6Address):
58+
self.socket = socks.socksocket(socket.AF_INET6)
59+
else:
60+
self.socket = socks.socksocket(socket.AF_INET)
5161

52-
if proxy and self.proxy_enabled:
5362
self.socket.set_proxy(
5463
proxy_type=socks.SOCKS5,
55-
addr=proxy.get("hostname", None),
56-
port=proxy.get("port", None),
64+
addr=hostname,
65+
port=port,
5766
username=proxy.get("username", None),
5867
password=proxy.get("password", None)
5968
)
6069

61-
log.info("Using proxy {}:{}".format(
62-
proxy.get("hostname", None),
63-
proxy.get("port", None)
64-
))
70+
log.info("Using proxy {}:{}".format(hostname, port))
71+
else:
72+
super().__init__(
73+
socket.AF_INET6 if ipv6
74+
else socket.AF_INET
75+
)
76+
77+
self.socket.settimeout(TCP.TIMEOUT)
6578

6679
async def connect(self, address: tuple):
6780
self.socket.connect(address)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def run(self):
130130
if len(argv) > 1 and argv[1] in ["bdist_wheel", "install"]:
131131
error_compiler.start()
132132
api_compiler.start()
133+
docs_compiler.start()
133134

134135
setup(
135136
name="Pyrogram",

0 commit comments

Comments
 (0)