Merge branch 'develop' into asyncio

# Conflicts:
#	pyrogram/__init__.py
This commit is contained in:
Dan 2018-08-26 19:28:32 +02:00
commit 00f0051bd6
4 changed files with 138 additions and 20 deletions

View File

@ -31,7 +31,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance
"e" if sys.getfilesystemencoding() != "utf-8" else "\xe8" "e" if sys.getfilesystemencoding() != "utf-8" else "\xe8"
) )
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)" __license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
__version__ = "0.8.0async1" __version__ = "0.8.0.async1"
from .api.errors import Error from .api.errors import Error
from .client.types import ( from .client.types import (

View File

@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import logging
from collections import OrderedDict from collections import OrderedDict
from datetime import datetime from datetime import datetime
from io import BytesIO from io import BytesIO
@ -23,13 +24,23 @@ from json import JSONEncoder, dumps
from ..all import objects from ..all import objects
log = logging.getLogger(__name__)
class Object: class Object:
all = {} all = {}
@staticmethod @staticmethod
def read(b: BytesIO, *args): def read(b: BytesIO, *args):
return Object.all[int.from_bytes(b.read(4), "little")].read(b, *args) constructor_id = int.from_bytes(b.read(4), "little")
try:
return Object.all[constructor_id].read(b, *args)
except KeyError:
log.error("Unknown constructor found: {}. Full data: {}".format(
hex(constructor_id),
b.getvalue().hex())
)
def write(self, *args) -> bytes: def write(self, *args) -> bytes:
pass pass

View File

@ -26,9 +26,9 @@ class MessageEntity(Object):
Args: Args:
type (``str``): type (``str``):
Type of the entity. Type of the entity.
Can be "mention" (@username), "hashtag", "cashtag", "bot_command", "url", "email", "bold" (bold text), Can be "mention" (@username), "hashtag", "cashtag", "bot_command", "url", "email", "phone_number", "bold"
italic (italic text), "code" (monowidth string), "pre" (monowidth block), "text_link" (for clickable text (bold text), italic (italic text), "code" (monowidth string), "pre" (monowidth block), "text_link"
URLs), "text_mention" (for users without usernames). (for clickable text URLs), "text_mention" (for users without usernames).
offset (``int``): offset (``int``):
Offset in UTF-16 code units to the start of the entity. Offset in UTF-16 code units to the start of the entity.

133
setup.py
View File

@ -16,10 +16,12 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import os
import re import re
import shutil
from sys import argv from sys import argv
from setuptools import setup, find_packages from setuptools import setup, find_packages, Command
from compiler.api import compiler as api_compiler from compiler.api import compiler as api_compiler
from compiler.docs import compiler as docs_compiler from compiler.docs import compiler as docs_compiler
@ -31,24 +33,125 @@ def read(file: str) -> list:
return [i.strip() for i in r] return [i.strip() for i in r]
if len(argv) > 1 and argv[1] != "sdist": def get_version():
api_compiler.start() with open("pyrogram/__init__.py", encoding="utf-8") as f:
docs_compiler.start() return re.findall(r"__version__ = \"(.+)\"", f.read())[0]
error_compiler.start()
with open("pyrogram/__init__.py", encoding="utf-8") as f:
version = re.findall(r"__version__ = \"(.+)\"", f.read())[0]
# PyPI doesn't like raw html def get_readme():
with open("README.rst", encoding="utf-8") as f: # PyPI doesn"t like raw html
with open("README.rst", encoding="utf-8") as f:
readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read()) readme = re.sub(r"\.\. \|.+\| raw:: html(?:\s{4}.+)+\n\n", "", f.read())
readme = re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme) return re.sub(r"\|header\|", "|logo|\n\n|description|\n\n|scheme| |tgcrypto|", readme)
class Clean(Command):
DIST = [
"./build",
"./dist",
"./Pyrogram.egg-info"
]
API = [
"pyrogram/api/errors/exceptions",
"pyrogram/api/functions",
"pyrogram/api/types",
"pyrogram/api/all.py",
]
DOCS = [
"docs/source/functions",
"docs/source/types",
"docs/build"
]
ALL = DIST + API + DOCS
description = "Clean generated files"
user_options = [
("dist", None, "Clean distribution files"),
("api", None, "Clean generated API files"),
("docs", None, "Clean generated docs files"),
("all", None, "Clean all generated files"),
]
def __init__(self, dist, **kw):
super().__init__(dist, **kw)
self.dist = None
self.api = None
self.docs = None
self.all = None
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
paths = set()
if self.dist:
paths.update(Clean.DIST)
if self.api:
paths.update(Clean.API)
if self.docs:
paths.update(Clean.DOCS)
if self.all:
paths.update(Clean.ALL)
for path in sorted(list(paths)):
try:
shutil.rmtree(path) if os.path.isdir(path) else os.remove(path)
except OSError:
print("skipping {}".format(path))
else:
print("removing {}".format(path))
class Build(Command):
description = "Build Pyrogram files"
user_options = [
("api", None, "Build API files"),
("docs", None, "Build docs files"),
]
def __init__(self, dist, **kw):
super().__init__(dist, **kw)
self.api = None
self.docs = None
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
if self.api:
error_compiler.start()
api_compiler.start()
if self.docs:
docs_compiler.start()
if len(argv) > 1 and argv[1] in ["bdist_wheel", "install"]:
error_compiler.start()
api_compiler.start()
setup( setup(
name="Pyrogram", name="Pyrogram",
version=version, version=get_version(),
description="Telegram MTProto API Client Library for Python", description="Telegram MTProto API Client Library for Python",
long_description=readme, long_description=get_readme(),
url="https://github.com/pyrogram", url="https://github.com/pyrogram",
download_url="https://github.com/pyrogram/pyrogram/releases/latest", download_url="https://github.com/pyrogram/pyrogram/releases/latest",
author="Dan Tès", author="Dan Tès",
@ -85,5 +188,9 @@ setup(
packages=find_packages(exclude=["compiler*"]), packages=find_packages(exclude=["compiler*"]),
zip_safe=False, zip_safe=False,
install_requires=read("requirements.txt"), install_requires=read("requirements.txt"),
extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]} extras_require={"tgcrypto": ["tgcrypto>=1.0.4"]},
cmdclass={
"clean": Clean,
"build": Build,
}
) )