Skip to content

Commit

Permalink
Update Pyrogram to v2.1.33.9
Browse files Browse the repository at this point in the history
*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]>
  • Loading branch information
4 people authored Oct 12, 2024
1 parent 0b7bd9f commit 52b3f09
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 308 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
name: build-doc
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ permissions:

jobs:
deploy:

runs-on: ubuntu-latest

environment: release
permissions:
id-token: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
Expand All @@ -38,8 +41,5 @@ jobs:
- name: Build package
run: hatch build
- name: Publish package
env:
HATCH_INDEX_USER: __token__
HATCH_INDEX_AUTH: ${{ secrets.PYPI_API_TOKEN }}
run: |
hatch publish
uses: pypa/gh-action-pypi-publish@release/v1

6 changes: 3 additions & 3 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04, macos-12]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
Expand Down
2 changes: 1 addition & 1 deletion pyrogram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

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

Expand Down
4 changes: 2 additions & 2 deletions pyrogram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from pyrogram.types import User, TermsOfService
from pyrogram.utils import ainput
from .connection import Connection
from .connection.transport import TCP, TCPAbridged
from .connection.transport import TCP, TCPAbridged, TCPFull
from .dispatcher import Dispatcher
from .file_id import FileId, FileType, ThumbnailSource
from .mime_types import mime_types
Expand Down Expand Up @@ -339,7 +339,7 @@ def __init__(
self.storage = FileStorage(self.name, self.WORKDIR)

self.connection_factory = Connection
self.protocol_factory = TCPAbridged
self.protocol_factory = TCPFull

self.dispatcher = Dispatcher(self)

Expand Down
65 changes: 35 additions & 30 deletions pyrogram/connection/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,69 @@

import asyncio
import logging
from typing import Optional, Type
from typing import Optional

from .transport import TCP, TCPAbridged
from .transport import *
from ..session.internals import DataCenter

log = logging.getLogger(__name__)


class Connection:
MAX_CONNECTION_ATTEMPTS = 3
MAX_RETRIES = 3

def __init__(
self,
dc_id: int,
test_mode: bool,
ipv6: bool,
proxy: dict,
media: bool = False,
protocol_factory: Type[TCP] = TCPAbridged
) -> None:
MODES = {
0: TCPFull,
1: TCPAbridged,
2: TCPIntermediate,
3: TCPAbridgedO,
4: TCPIntermediateO
}

def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False, mode: int = 3):
self.dc_id = dc_id
self.test_mode = test_mode
self.ipv6 = ipv6
self.proxy = proxy
self.media = media
self.protocol_factory = protocol_factory

self.address = DataCenter(dc_id, test_mode, ipv6, media)
self.protocol: Optional[TCP] = None
self.mode = self.MODES.get(mode, TCPAbridged)

self.protocol = None # type: TCP

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

try:
log.info("Connecting...")
await self.protocol.connect(self.address)
except OSError as e:
log.warning("Unable to connect due to network issues: %s", e)
await self.protocol.close()
log.warning(f"Unable to connect due to network issues: {e}")
self.protocol.close()
await asyncio.sleep(1)
else:
log.info("Connected! %s DC%s%s - IPv%s",
"Test" if self.test_mode else "Production",
self.dc_id,
" (media)" if self.media else "",
"6" if self.ipv6 else "4")
log.info("Connected! {} DC{}{} - IPv{} - {}".format(
"Test" if self.test_mode else "Production",
self.dc_id,
" (media)" if self.media else "",
"6" if self.ipv6 else "4",
self.mode.__name__,
))
break
else:
log.warning("Connection failed! Trying again...")
raise ConnectionError
raise TimeoutError

async def close(self) -> None:
await self.protocol.close()
def close(self):
self.protocol.close()
log.info("Disconnected")

async def send(self, data: bytes) -> None:
await self.protocol.send(data)
async def send(self, data: bytes):
try:
await self.protocol.send(data)
except Exception as e:
raise OSError(e)

async def recv(self) -> Optional[bytes]:
return await self.protocol.recv()
2 changes: 1 addition & 1 deletion pyrogram/connection/transport/tcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from .tcp import TCP, Proxy
from .tcp import TCP
from .tcp_abridged import TCPAbridged
from .tcp_abridged_o import TCPAbridgedO
from .tcp_full import TCPFull
Expand Down
Loading

0 comments on commit 52b3f09

Please sign in to comment.