Skip to content

Commit 52b3f09

Browse files
SpEcHiDedeus-developergautamajay52wulan17
authored
Update Pyrogram to v2.1.33.9
*Experimental Changes (#98) * (1): Experimental Change * (2): Experimental Change * Revert some of the changes by deus-developer. This reverts commit 20f4f3c and 983d396 * Add Python 3.13 support Co-authored-by: Artem Ukolov <[email protected]> Co-authored-by: GautamKumar <[email protected]> Co-authored-by: wulan17 <[email protected]>
1 parent 0b7bd9f commit 52b3f09

File tree

16 files changed

+219
-308
lines changed

16 files changed

+219
-308
lines changed

.github/workflows/build-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ jobs:
99
name: build-doc
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
with:
1414
fetch-depth: 1
1515
- name: Set up Python
16-
uses: actions/setup-python@v3
16+
uses: actions/setup-python@v5
1717
with:
1818
python-version: '3.11'
1919

.github/workflows/publish.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ permissions:
1919

2020
jobs:
2121
deploy:
22-
2322
runs-on: ubuntu-latest
2423

24+
environment: release
25+
permissions:
26+
id-token: write
27+
2528
steps:
26-
- uses: actions/checkout@v3
29+
- uses: actions/checkout@v4
2730
- name: Set up Python
28-
uses: actions/setup-python@v3
31+
uses: actions/setup-python@v5
2932
with:
3033
python-version: '3.10'
3134
- name: Install dependencies
@@ -38,8 +41,5 @@ jobs:
3841
- name: Build package
3942
run: hatch build
4043
- name: Publish package
41-
env:
42-
HATCH_INDEX_USER: __token__
43-
HATCH_INDEX_AUTH: ${{ secrets.PYPI_API_TOKEN }}
44-
run: |
45-
hatch publish
44+
uses: pypa/gh-action-pypi-publish@release/v1
45+

.github/workflows/python.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: [ubuntu-22.04, macos-12]
16-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
16+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1717

1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
2020

2121
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v2
22+
uses: actions/setup-python@v5
2323
with:
2424
python-version: ${{ matrix.python-version }}
2525

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ classifiers = [
2121
"Programming Language :: Python :: 3.10",
2222
"Programming Language :: Python :: 3.11",
2323
"Programming Language :: Python :: 3.12",
24+
"Programming Language :: Python :: 3.13",
2425
"Programming Language :: Python :: Implementation",
2526
"Programming Language :: Python :: Implementation :: CPython",
2627
"Programming Language :: Python :: Implementation :: PyPy",

pyrogram/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
__fork_name__ = "pyrotgfork"
20-
__version__ = "2.1.33.8"
20+
__version__ = "2.1.33.9"
2121
__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
2222
__copyright__ = "Copyright (C) 2017-present Dan <https://github.com/delivrance>"
2323

pyrogram/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
from pyrogram.types import User, TermsOfService
5656
from pyrogram.utils import ainput
5757
from .connection import Connection
58-
from .connection.transport import TCP, TCPAbridged
58+
from .connection.transport import TCP, TCPAbridged, TCPFull
5959
from .dispatcher import Dispatcher
6060
from .file_id import FileId, FileType, ThumbnailSource
6161
from .mime_types import mime_types
@@ -339,7 +339,7 @@ def __init__(
339339
self.storage = FileStorage(self.name, self.WORKDIR)
340340

341341
self.connection_factory = Connection
342-
self.protocol_factory = TCPAbridged
342+
self.protocol_factory = TCPFull
343343

344344
self.dispatcher = Dispatcher(self)
345345

pyrogram/connection/connection.py

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,64 +18,69 @@
1818

1919
import asyncio
2020
import logging
21-
from typing import Optional, Type
21+
from typing import Optional
2222

23-
from .transport import TCP, TCPAbridged
23+
from .transport import *
2424
from ..session.internals import DataCenter
2525

2626
log = logging.getLogger(__name__)
2727

2828

2929
class Connection:
30-
MAX_CONNECTION_ATTEMPTS = 3
30+
MAX_RETRIES = 3
3131

32-
def __init__(
33-
self,
34-
dc_id: int,
35-
test_mode: bool,
36-
ipv6: bool,
37-
proxy: dict,
38-
media: bool = False,
39-
protocol_factory: Type[TCP] = TCPAbridged
40-
) -> None:
32+
MODES = {
33+
0: TCPFull,
34+
1: TCPAbridged,
35+
2: TCPIntermediate,
36+
3: TCPAbridgedO,
37+
4: TCPIntermediateO
38+
}
39+
40+
def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False, mode: int = 3):
4141
self.dc_id = dc_id
4242
self.test_mode = test_mode
4343
self.ipv6 = ipv6
4444
self.proxy = proxy
4545
self.media = media
46-
self.protocol_factory = protocol_factory
47-
4846
self.address = DataCenter(dc_id, test_mode, ipv6, media)
49-
self.protocol: Optional[TCP] = None
47+
self.mode = self.MODES.get(mode, TCPAbridged)
48+
49+
self.protocol = None # type: TCP
5050

51-
async def connect(self) -> None:
52-
for i in range(Connection.MAX_CONNECTION_ATTEMPTS):
53-
self.protocol = self.protocol_factory(ipv6=self.ipv6, proxy=self.proxy)
51+
async def connect(self):
52+
for i in range(Connection.MAX_RETRIES):
53+
self.protocol = self.mode(self.ipv6, self.proxy)
5454

5555
try:
5656
log.info("Connecting...")
5757
await self.protocol.connect(self.address)
5858
except OSError as e:
59-
log.warning("Unable to connect due to network issues: %s", e)
60-
await self.protocol.close()
59+
log.warning(f"Unable to connect due to network issues: {e}")
60+
self.protocol.close()
6161
await asyncio.sleep(1)
6262
else:
63-
log.info("Connected! %s DC%s%s - IPv%s",
64-
"Test" if self.test_mode else "Production",
65-
self.dc_id,
66-
" (media)" if self.media else "",
67-
"6" if self.ipv6 else "4")
63+
log.info("Connected! {} DC{}{} - IPv{} - {}".format(
64+
"Test" if self.test_mode else "Production",
65+
self.dc_id,
66+
" (media)" if self.media else "",
67+
"6" if self.ipv6 else "4",
68+
self.mode.__name__,
69+
))
6870
break
6971
else:
7072
log.warning("Connection failed! Trying again...")
71-
raise ConnectionError
73+
raise TimeoutError
7274

73-
async def close(self) -> None:
74-
await self.protocol.close()
75+
def close(self):
76+
self.protocol.close()
7577
log.info("Disconnected")
7678

77-
async def send(self, data: bytes) -> None:
78-
await self.protocol.send(data)
79+
async def send(self, data: bytes):
80+
try:
81+
await self.protocol.send(data)
82+
except Exception as e:
83+
raise OSError(e)
7984

8085
async def recv(self) -> Optional[bytes]:
8186
return await self.protocol.recv()

pyrogram/connection/transport/tcp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from .tcp import TCP, Proxy
19+
from .tcp import TCP
2020
from .tcp_abridged import TCPAbridged
2121
from .tcp_abridged_o import TCPAbridgedO
2222
from .tcp_full import TCPFull

0 commit comments

Comments
 (0)