Remove non-python files

This commit is contained in:
Dan 2020-12-20 18:28:21 +01:00
parent 18b3ca1892
commit d82ecf048a
5 changed files with 70 additions and 63 deletions

View File

@ -1,7 +1,6 @@
## Include ## Include
include README.md COPYING COPYING.lesser NOTICE requirements.txt include README.md COPYING COPYING.lesser NOTICE requirements.txt
recursive-include compiler *.py *.tl *.tsv *.txt recursive-include compiler *.py *.tl *.tsv *.txt
recursive-include pyrogram mime.types schema.sql
## Exclude ## Exclude
prune pyrogram/errors/exceptions prune pyrogram/errors/exceptions

View File

@ -1,3 +1,24 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2020 Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# 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 https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types.
# Extended with extra mime types specific to Telegram.
mime_types = """
# This file maps Internet media types to unique file extension(s). # This file maps Internet media types to unique file extension(s).
# Although created for httpd, this file is used by many software systems # Although created for httpd, this file is used by many software systems
# and has been placed in the public domain for unlimited redistribution. # and has been placed in the public domain for unlimited redistribution.
@ -1855,4 +1876,6 @@ video/x-smv smv
x-conference/x-cooltalk ice x-conference/x-cooltalk ice
# Telegram animated stickers # Telegram animated stickers
application/x-tgsticker tgs application/x-bad-tgsticker tgs
application/x-tgsticker tgs
"""

View File

@ -21,6 +21,7 @@ import os
import platform import platform
import re import re
import sys import sys
from io import StringIO
from mimetypes import MimeTypes from mimetypes import MimeTypes
from pathlib import Path from pathlib import Path
@ -28,6 +29,7 @@ import pyrogram
from pyrogram import __version__ from pyrogram import __version__
from pyrogram.parser import Parser from pyrogram.parser import Parser
from pyrogram.session.internals import MsgId from pyrogram.session.internals import MsgId
from .mime_types import mime_types
class Scaffold: class Scaffold:
@ -46,7 +48,8 @@ class Scaffold:
PARSE_MODES = ["combined", "markdown", "md", "html", None] PARSE_MODES = ["combined", "markdown", "md", "html", None]
mimetypes = MimeTypes((f"{os.path.dirname(__file__)}/mime.types",)) mimetypes = MimeTypes()
mimetypes.readfp(StringIO(mime_types))
def __init__(self): def __init__(self):
try: try:

View File

@ -1,57 +0,0 @@
/*
* Pyrogram - Telegram MTProto API Client Library for Python
* Copyright (C) 2017-2020 Dan <https://github.com/delivrance>
*
* This file is part of Pyrogram.
*
* Pyrogram is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pyrogram is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
*/
CREATE TABLE sessions
(
dc_id INTEGER PRIMARY KEY,
test_mode INTEGER,
auth_key BLOB,
date INTEGER NOT NULL,
user_id INTEGER,
is_bot INTEGER
);
CREATE TABLE peers
(
id INTEGER PRIMARY KEY,
access_hash INTEGER,
type INTEGER NOT NULL,
username TEXT,
phone_number TEXT,
last_update_on INTEGER NOT NULL DEFAULT (CAST(STRFTIME('%s', 'now') AS INTEGER))
);
CREATE TABLE version
(
number INTEGER PRIMARY KEY
);
CREATE INDEX idx_peers_id ON peers (id);
CREATE INDEX idx_peers_username ON peers (username);
CREATE INDEX idx_peers_phone_number ON peers (phone_number);
CREATE TRIGGER trg_peers_last_update_on
AFTER UPDATE
ON peers
BEGIN
UPDATE peers
SET last_update_on = CAST(STRFTIME('%s', 'now') AS INTEGER)
WHERE id = NEW.id;
END;

View File

@ -19,7 +19,6 @@
import inspect import inspect
import sqlite3 import sqlite3
import time import time
from pathlib import Path
from threading import Lock from threading import Lock
from typing import List, Tuple, Any from typing import List, Tuple, Any
@ -27,6 +26,47 @@ from pyrogram import raw
from .storage import Storage from .storage import Storage
from .. import utils from .. import utils
# language=SQLite
SCHEMA = """
CREATE TABLE sessions
(
dc_id INTEGER PRIMARY KEY,
test_mode INTEGER,
auth_key BLOB,
date INTEGER NOT NULL,
user_id INTEGER,
is_bot INTEGER
);
CREATE TABLE peers
(
id INTEGER PRIMARY KEY,
access_hash INTEGER,
type INTEGER NOT NULL,
username TEXT,
phone_number TEXT,
last_update_on INTEGER NOT NULL DEFAULT (CAST(STRFTIME('%s', 'now') AS INTEGER))
);
CREATE TABLE version
(
number INTEGER PRIMARY KEY
);
CREATE INDEX idx_peers_id ON peers (id);
CREATE INDEX idx_peers_username ON peers (username);
CREATE INDEX idx_peers_phone_number ON peers (phone_number);
CREATE TRIGGER trg_peers_last_update_on
AFTER UPDATE
ON peers
BEGIN
UPDATE peers
SET last_update_on = CAST(STRFTIME('%s', 'now') AS INTEGER)
WHERE id = NEW.id;
END;
"""
def get_input_peer(peer_id: int, access_hash: int, peer_type: str): def get_input_peer(peer_id: int, access_hash: int, peer_type: str):
if peer_type in ["user", "bot"]: if peer_type in ["user", "bot"]:
@ -61,8 +101,7 @@ class SQLiteStorage(Storage):
def create(self): def create(self):
with self.lock, self.conn: with self.lock, self.conn:
with open(str(Path(__file__).parent / "schema.sql"), "r") as schema: self.conn.executescript(SCHEMA)
self.conn.executescript(schema.read())
self.conn.execute( self.conn.execute(
"INSERT INTO version VALUES (?)", "INSERT INTO version VALUES (?)",