Skip to content

Commit

Permalink
Remove non-python files
Browse files Browse the repository at this point in the history
  • Loading branch information
delivrance committed Dec 20, 2020
1 parent 18b3ca1 commit d82ecf0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 63 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## Include
include README.md COPYING COPYING.lesser NOTICE requirements.txt
recursive-include compiler *.py *.tl *.tsv *.txt
recursive-include pyrogram mime.types schema.sql

## Exclude
prune pyrogram/errors/exceptions
Expand Down
25 changes: 24 additions & 1 deletion pyrogram/mime.types → pyrogram/mime_types.py
Original file line number Diff line number Diff line change
@@ -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).
# Although created for httpd, this file is used by many software systems
# and has been placed in the public domain for unlimited redistribution.
Expand Down Expand Up @@ -1855,4 +1876,6 @@
x-conference/x-cooltalk ice
# Telegram animated stickers
application/x-tgsticker tgs
application/x-bad-tgsticker tgs
application/x-tgsticker tgs
"""
5 changes: 4 additions & 1 deletion pyrogram/scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import platform
import re
import sys
from io import StringIO
from mimetypes import MimeTypes
from pathlib import Path

import pyrogram
from pyrogram import __version__
from pyrogram.parser import Parser
from pyrogram.session.internals import MsgId
from .mime_types import mime_types


class Scaffold:
Expand All @@ -46,7 +48,8 @@ class Scaffold:

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):
try:
Expand Down
57 changes: 0 additions & 57 deletions pyrogram/storage/schema.sql

This file was deleted.

45 changes: 42 additions & 3 deletions pyrogram/storage/sqlite_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,54 @@
import inspect
import sqlite3
import time
from pathlib import Path
from threading import Lock
from typing import List, Tuple, Any

from pyrogram import raw
from .storage import Storage
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):
if peer_type in ["user", "bot"]:
Expand Down Expand Up @@ -61,8 +101,7 @@ def __init__(self, name: str):

def create(self):
with self.lock, self.conn:
with open(str(Path(__file__).parent / "schema.sql"), "r") as schema:
self.conn.executescript(schema.read())
self.conn.executescript(SCHEMA)

self.conn.execute(
"INSERT INTO version VALUES (?)",
Expand Down

0 comments on commit d82ecf0

Please sign in to comment.