Skip to content

Commit 1de6e55

Browse files
authored
Merge pull request #23 from NonProjects/indev
Merge Indev (0.4) to Main
2 parents 6840d20 + b0f047b commit 1de6e55

16 files changed

+1156
-559
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131-
# Vim
132-
*.swp
133-
*.swo
131+
# VIM
132+
*.sw*
134133

135134
# User defined
136135
*.hidden

README.rst

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
TGBOX: encrypted cloud storage based on Telegram API
22
====================================================
3+
.. image:: https://readthedocs.org/projects/tgbox/badge/?version=latest
34

45
.. code-block:: python
56
6-
from tgbox import loop
7-
87
from tgbox.api import (
98
TelegramAccount,
109
make_remote_box,
1110
make_local_box
1211
)
13-
from tgbox.keys import make_basekey
12+
from tgbox.keys import make_basekey, Phrase
13+
from asyncio import get_event_loop
1414
from getpass import getpass
1515
16+
PHONE_NUMBER = input('Your phone number: ')
17+
18+
API_ID = 1234567 # https://my.telegram.org
19+
API_HASH = '00000000000000000000000000000000'
20+
21+
# We will use it to encrypt all data in Box
22+
box_phrase = Phrase.generate()
23+
print(box_phrase, '- phrase to your Box')
1624
1725
async def main():
1826
ta = TelegramAccount(
19-
phone_number = input('Phone: ')
27+
phone_number = PHONE_NUMBER,
28+
api_id = API_ID,
29+
api_hash = API_HASH
2030
)
2131
await ta.connect()
2232
await ta.send_code_request()
@@ -25,7 +35,7 @@ TGBOX: encrypted cloud storage based on Telegram API
2535
code = int(input('Code: ')),
2636
password = getpass('Pass: ')
2737
)
28-
basekey = make_basekey(b'very_bad_phrase')
38+
basekey = make_basekey(box_phrase)
2939
3040
erb = await make_remote_box(ta)
3141
dlb = await make_local_box(erb, ta, basekey)
@@ -37,9 +47,10 @@ TGBOX: encrypted cloud storage based on Telegram API
3747
comment = b'Cats are cool B-)',
3848
foldername = b'Pictures/Kitties'
3949
)
40-
drbfi = await drb.push_file(ff)
41-
await drbfi.download()
42-
50+
drbfi = await drb.push_file(ff) # Upload file
51+
await drbfi.download() # Download it back
52+
53+
loop = get_event_loop()
4354
loop.run_until_complete(main())
4455
4556
Motivation
@@ -55,7 +66,7 @@ This library targets to be a PoC of **encrypted file storage** inside Telegram,
5566
Abstract
5667
--------
5768

58-
We name *"encrypted cloud storage"* as **Box** and the API to it as **Tgbox**. There is **two** of boxes: the **RemoteBox** and the **LocalBox**. They define a basic primitives. You can share your Box and separate Files with other people absolutely secure - only You and someone you want will have decryption key, even through insecure communication canals (`e2e <https://en.wikipedia.org/wiki/End-to-end_encryption>`_). You can make unlimited amount of Boxes, upload speed equals to vanilla Telegram and maximum filesize is ``~2GB-2MB``.
69+
We name *"encrypted cloud storage"* as **Box** and the API to it as **Tgbox**. There is **two** of boxes: the **RemoteBox** and the **LocalBox**. They define a basic primitives. You can share your Box and separate Files with other people absolutely secure - only You and someone you want will have decryption key, even through insecure communication canals (`e2e <https://en.wikipedia.org/wiki/End-to-end_encryption>`_). You can make unlimited amount of Boxes, Upload & Download speed is **faster** than in official Telegram clients and maximum filesize is around **2GB** *minus* **2MB**.
5970

6071
Documentation
6172
-------------
@@ -67,8 +78,8 @@ You can also build docs from the source
6778
.. code-block:: console
6879
6980
git clone https://github.com/NonProject/tgbox --branch=main
70-
cd tgbox; python3 -m pip install -r requirements.txt
71-
cd docs; make html; <your-browser> _build/html/index.html
81+
cd tgbox & python3 -m pip install .[fast] # Install TGBOX
82+
cd docs & make html & <your-browser> _build/html/index.html
7283
7384
Third party & thanks to
7485
-----------------------
@@ -81,5 +92,3 @@ Third party & thanks to
8192
- `Filetype <https://github.com/h2non/filetype.py>`_ (`MIT <https://github.com/h2non/filetype.py/blob/master/LICENSE>`_)
8293
- `Cryptg <https://github.com/cher-nov/cryptg>`_ (`LICENSE <https://github.com/cher-nov/cryptg/blob/master/LICENSE.txt>`_)
8394
- `Pycryptodome <https://github.com/Legrandin/pycryptodome>`_ (`LICENSE <https://github.com/Legrandin/pycryptodome/blob/master/LICENSE.rst>`_)
84-
- `Uvloop <https://github.com/MagicStack/uvloop>`_ (`LICENSE <https://github.com/MagicStack/uvloop/blob/master/LICENSE-APACHE>`_)
85-

docs/examples.rst

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@ Logging in & Box creation
66

77
.. code-block:: python
88
9-
# This is global Tgbox loop.
10-
# You should use it if you
11-
# want to add coroutines to
12-
# the event loop.
13-
from tgbox import loop
14-
159
from tgbox.api import (
1610
TelegramAccount,
1711
make_remote_box,
1812
make_local_box
1913
)
14+
from asyncio import get_event_loop
2015
from tgbox.keys import Phrase, make_basekey
2116
from getpass import getpass # For hidden input
17+
18+
PHONE_NUMBER = input('Your phone number: ')
2219
20+
API_ID = 1234567 # https://my.telegram.org
21+
API_HASH = '00000000000000000000000000000000'
2322
2423
async def main():
2524
ta = TelegramAccount(
26-
phone_number = input('Phone: ')
25+
phone_number = PHONE_NUMBER,
26+
api_id = API_ID,
27+
api_hash = API_HASH
2728
)
2829
await ta.connect()
2930
await ta.send_code_request()
@@ -44,7 +45,8 @@ Logging in & Box creation
4445
erb = await make_remote_box(ta)
4546
# Make DecryptedLocalBox
4647
dlb = await make_local_box(erb, ta, basekey)
47-
48+
49+
loop = get_event_loop()
4850
loop.run_until_complete(main())
4951
5052
@@ -56,7 +58,7 @@ Synchronous
5658

5759
.. code-block:: python
5860
59-
from tgbox import loop
61+
from asyncio import get_event_loop
6062
from tgbox.api import get_local_box, get_remote_box
6163
from tgbox.keys import Phrase, make_basekey
6264
@@ -92,7 +94,8 @@ Synchronous
9294
9395
# Download it back.
9496
await drbfi.download()
95-
97+
98+
loop = get_event_loop()
9699
loop.run_until_complete(main())
97100
98101
.. note::
@@ -103,8 +106,6 @@ Asynchronous
103106

104107
.. code-block:: python
105108
106-
# We use gather() here, but
107-
# there is also tgbox.loop.create_task
108109
from asyncio import gather
109110
110111
... # some code omitted
@@ -207,12 +208,11 @@ Box clone
207208
208209
.. code-block:: python
209210
210-
from tgbox import loop
211-
212211
from tgbox.api import (
213212
TelegramAccount,
214213
get_remote_box
215214
)
215+
from asyncio import get_event_loop
216216
from tgbox.keys import make_basekey
217217
from getpass import getpass
218218
@@ -257,7 +257,8 @@ Box clone
257257
drb = await erb.decrypt(key=mainkey)
258258
# Clone and retreive DecryptedLocalBox
259259
dlb = await drb.clone(basekey)
260-
260+
261+
loop = get_event_loop()
261262
loop.run_until_complete(main())
262263
263264

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This library targets to be a PoC of **encrypted file storage**, but can be used
1414
Abstract
1515
--------
1616

17-
We name *"encrypted cloud storage"* as **Box** and the API to it as **Tgbox**. There is **two** of boxes: the **RemoteBox** and the **LocalBox**. They define a basic primitives. You can share your Box and separate Files with other people absolutely secure - only You and someone you want will have decryption key, even through insecure communication canals (`e2e <https://en.wikipedia.org/wiki/End-to-end_encryption>`_). You can make unlimited amount of Boxes, upload speed equals to vanilla Telegram and maximum filesize is ``~2GB-2MB``.
17+
We name *"encrypted cloud storage"* as **Box** and the API to it as **Tgbox**. There is **two** of boxes: the **RemoteBox** and the **LocalBox**. They define a basic primitives. You can share your Box and separate Files with other people absolutely secure - only You and someone you want will have decryption key, even through insecure communication canals (`e2e <https://en.wikipedia.org/wiki/End-to-end_encryption>`_). You can make unlimited amount of Boxes, Upload & Download speed is **faster** than in official Telegram clients and maximum filesize is around **2GB** *minus* **2MB**.
1818

1919

2020
.. toctree::

docs/installation.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ PyPI (pip)
66

77
.. code-block:: console
88
9-
python3 -m pip install tgbox
10-
9+
python3 -m pip install tgbox # Pure Python (very slow)
10+
python3 -m pip install tgbox[fast] # With C libraries
1111
1212
Clone from GitHub
1313
-----------------
1414

1515
.. code-block:: console
1616
17-
git clone https://github.com/NonProject/tgbox --branch=<branch>
18-
cd tgbox; python3 -m pip install -r requirements.txt
17+
git clone https://github.com/NonProjects/tgbox --branch=main
18+
cd tgbox & python3 -m pip install .[fast]
1919
2020
Optional dependencies
2121
---------------------

requirements.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

setup.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
from sys import version_info, platform
21
from setuptools import setup
32

4-
requirements = [
5-
'aiosqlite==0.17.0',
6-
'telethon==1.24.0',
7-
'ecdsa==0.16.1',
8-
'filetype==1.0.8',
9-
'cryptg==0.2.post2',
10-
'pycryptodome==3.10.1',
11-
'sphinx-rtd-theme==1.0.0',
12-
'regex==2021.11.10'
13-
]
14-
if version_info > (3, 7) and platform not in ('win32', 'cygwin', 'cli'):
15-
requirements.append('uvloop==0.16.0')
16-
173
setup(
184
name = 'tgbox',
195
packages = ['tgbox'],
20-
version = '0.3.3',
6+
version = '0.4',
217
license = 'LGPL-2.1',
228
description = 'Encrypted cloud storage based on Telegram API',
239
author = 'NonProjects',
10+
author_email = 'thenonproton@pm.me',
2411
url = 'https://github.com/NonProjects/tgbox',
25-
download_url = 'https://github.com/NonProjects/tgbox/archive/refs/tags/indev%230.3.2.tar.gz',
12+
download_url = 'https://github.com/NonProjects/tgbox/archive/refs/tags/main%23{VERSION}.tar.gz',
2613

2714
package_data = {
2815
'tgbox': ['tgbox/other'],
2916
},
3017
include_package_data = True,
31-
install_requires = requirements,
32-
18+
19+
install_requires = [
20+
'aiosqlite==0.17.0',
21+
'telethon==1.24.0',
22+
'ecdsa==0.16.1',
23+
'filetype==1.0.8',
24+
'sphinx-rtd-theme==1.0.0'
25+
],
3326
keywords = [
34-
'Telegram', 'Cloud-Storage',
27+
'Telegram', 'Cloud-Storage', 'Cloud',
3528
'API', 'Asyncio', 'Non-official'
3629
],
30+
extras_require = {
31+
'fast': [
32+
'pycryptodome==3.12.0',
33+
'cryptg==0.2.post4',
34+
'regex==2021.11.10'
35+
]
36+
},
3737
classifiers = [
3838
'Development Status :: 4 - Beta',
3939
'Intended Audience :: Developers',
@@ -42,8 +42,6 @@
4242
'Topic :: Software Development :: Libraries :: Python Modules',
4343
'Topic :: System :: Archiving :: Backup',
4444
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
45-
'Programming Language :: Python :: 3',
46-
'Programming Language :: Python :: 3.6',
4745
'Programming Language :: Python :: 3.7',
4846
'Programming Language :: Python :: 3.8',
4947
'Programming Language :: Python :: 3.9'

tgbox/__init__.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
from asyncio import (
2-
new_event_loop,
3-
set_event_loop
4-
)
5-
try:
6-
# We can use uvloop as event loop
7-
# on Linux systems, it's around 2x
8-
# faster than Python's default.
9-
from uvloop import new_event_loop
10-
FAST_EVENT_LOOP = True
11-
except ModuleNotFoundError:
12-
FAST_EVENT_LOOP = False
1+
__version__ = '0.4'
132

14-
# Define and set global event loop
15-
loop = new_event_loop()
16-
set_event_loop(loop)
3+
from asyncio import get_event_loop
4+
from typing import Coroutine
175

186
from . import api
197
from . import constants
@@ -23,7 +11,6 @@
2311
from . import keys
2412
from . import tools
2513

26-
from typing import Coroutine
2714

2815
__all__ = [
2916
'api',
@@ -33,15 +20,12 @@
3320
'errors',
3421
'keys',
3522
'tools',
36-
'loop',
3723
'sync',
38-
'new_event_loop',
39-
'FAST_EVENT_LOOP'
4024
]
41-
4225
def sync(coroutine: Coroutine):
4326
"""
44-
Will call asynchronous function
45-
in ``tgbox.loop`` and return result.
27+
Will call asynchronous function in
28+
current asyncio loop and return result.
4629
"""
30+
loop = get_event_loop()
4731
return loop.run_until_complete(coroutine)

0 commit comments

Comments
 (0)