Commit Graph

182 Commits

Author SHA1 Message Date
Lonami Exo
1e3120b0b6 Bring back report_errors to the constructor 2018-03-15 10:22:21 +01:00
Lonami Exo
d5bc3c1a6c Fix misleading documentation regarding report_errors 2018-03-14 21:05:50 +01:00
Lonami Exo
d0bdb7ea3f Lower message severity when retrying invoke the first time 2018-03-07 11:13:55 +01:00
Tulir Asokan
47cdcda9e2 Move device info out of Session 2018-03-02 21:05:09 +02:00
Tulir Asokan
c5e6f7e265 Split Session into three parts and make a module for sessions 2018-03-01 23:40:28 +02:00
Joscha Götzer
835ff51e25 Multiple small changes/fixed typos to docs/error messages (#623) 2018-03-01 13:21:28 +01:00
Lonami Exo
b93e1b5f50 Add add_event_handler and deprecate add_update_handler 2018-02-18 13:29:05 +01:00
Lonami Exo
178643d3a1 Periodically send getState even without disconnect (341fb38)
After some more tests, even if the server doesn't drop the
connection, it might also just stop sending updates at all.
2018-02-15 11:41:32 +01:00
Lonami Exo
80f918956a Revert "official apps must be obfuscated" (29471f3)
It didn't really make any sense and @danog keeps changing it.
2018-02-15 10:02:12 +01:00
Lonami Exo
341fb38136 Invoke getState after the server kicks us idling for updates
For some reason, the server seems to kick us after 1024 items from
the network are received. Tested with the following code, 1022
updates were received, after BadServerSalt, NewSessionCreated and
MsgsAck:

    client = TelegramClient(..., spawn_read_thread=False)
    client.connect(_sync_updates=False)
    sender = client._sender
    client = None
    while True:
        try:
            sender.receive(None)
        except TimeoutError:
            pass
        except ConnectionResetError:
            sender.connect()

If one were to run this code after being kicked no further items
will be retrieved and it will always timeout. Invoking a ping has
no effect either. Invoking some "high level" request like getState
seems to do the trick.
2018-02-03 15:39:37 +01:00
Lonami Exo
eefd37c2d7 Stop calling .disconnect() from .__del__()
It was causing some strange behaviour with the synchronized Queue
used by the UpdateState class. Calling .get() with any timeout
would block forever. Perhaps something else got released when
the script ended and then any call would block forever, thus the
thread never joining.
2018-02-03 12:15:38 +01:00
Lonami Exo
43a3f40527 Properly close the sqlite3 connection (#560) 2018-01-26 09:59:49 +01:00
Lonami Exo
5c2dfc17a8 Make timeout logging message debug to scare people less 2018-01-25 18:44:21 +01:00
Lonami Exo
db698858e0 Except TypeNotFoundError on ._invoke() 2018-01-23 22:26:19 +01:00
Lonami Exo
4d4e81e609 Fix cyclic imports on Python 3.4 by moving Session one level up 2018-01-19 22:55:28 +01:00
Lonami Exo
f6d98a61cf Add stub .get_input_entity() to TelegramBareClient
.resolve() calls should now work even if the subclass isn't in use.
2018-01-19 11:52:44 +01:00
Lonami Exo
1c9fa76ede Add new method to .resolve() parameters instead on init
TLObject's __init__ used to call utils.get_input_* methods and
similar to auto-cast things like User into InputPeerUser as
required. Now there's a custom .resolve() method for this purpose
with several advantages:
- Old behaviour still works, autocasts work like usual.

- A request can be constructed and later modified, before the
  autocast only occured on the constructor but now while invoking.

- This allows us to not only use the utils module but also the
  client, so it's even possible to use usernames or phone numbers
  for things that require an InputPeer. This actually assumes
  the TelegramClient subclass is being used and not the bare version
  which would fail when calling .get_input_peer().
2018-01-19 11:47:45 +01:00
Lonami Exo
1a3feec481 Move upload/download file methods to the TelegramClient 2018-01-18 13:55:03 +01:00
Lonami Exo
55efb2b104 Use a different schema for file cache which actually persists
Caching the inputFile values would not persist accross several
days so the cache was nearly unnecessary. Saving the id/hash of
the actual inputMedia sent is a much better/persistent idea.
2018-01-18 09:52:39 +01:00
Lonami Exo
494c90af69 Fix uploaded files cache may have expired 2018-01-15 12:36:46 +01:00
Lonami Exo
8be7e76b74 Use the idling state instead checking if read thread is present
This caused some multithreading bugs, for instance, when there was
no read thread and the main thread was idling, and there were some
update workers. Several threads would try to read from the socket
at the same time (since there's no lock for reading), causing
reads to be corrupted and receiving "invalid packet lengths"
from the network. Closes #538.
2018-01-14 21:20:22 +01:00
Lonami Exo
77ef659cbf Clearer error when invoking without calling .connect() (#532) 2018-01-11 15:42:27 +01:00
Lonami Exo
eaef392a9b Add and except missing FLOOD_TEST_PHONE_WAIT_X error 2018-01-10 17:34:34 +01:00
Lonami Exo
c12af5e412 Remove references to the wiki 2018-01-08 14:04:04 +01:00
Lonami Exo
d81dd055e6 Remove temporary connections and use a lock again
These seem to be the reason for missing some updates (#237)
2018-01-06 23:45:22 +01:00
Lonami Exo
c4e26c95f5 Always cache files smaller than 10MB, now in the database
This removes the need for a .clear_cache() method as now files
are identified by their MD5 (which needs to be calculated
always) and their file size (to make collisions even more
unlikely) instead using the file path (which can now change).
2018-01-05 15:33:25 +01:00
Lonami Exo
6cb5931e7a Call .disconnect() on client.__del__ for convenience 2018-01-04 23:37:47 +01:00
Lonami Exo
b45b63d71d Assert ._first_request is True with None auth_key (#517) 2018-01-04 21:07:29 +01:00
Lonami Exo
4fba27dee9 Accept InputFile/InputFileBig on .upload_file for 2c437c51
Now an input file thumbnail can also be specified, instead
needing to reupload the file every time.
2018-01-04 15:33:48 +01:00
Lonami Exo
52a4ef82f4 Merge branch 'master' of github.com:LonamiWebs/Telethon 2017-12-28 01:17:30 +01:00
Lonami Exo
b35fc075e0 Merge branch 'sqlite-session' 2017-12-28 01:15:12 +01:00
Lonami Exo
2a10f31511 Always wrap init connection for first call
Ping @delivrance.
See https://core.telegram.org/api/invoking#saving-client-info.
2017-12-28 01:13:24 +01:00
Lonami Exo
ab07f0220a Save dc_id instead layer and salt in the session file
Server salts change every 30 minutes after all, so keeping them
in the long-term storage session file doesn't make much sense.

Saving the layer doesn't make sense either, as it was only used
to know whether to init connection or not, but it should be done
always.
2017-12-28 01:06:27 +01:00
Dmitry D. Chernov
6ec6967ff9 Make exception types correspond to Python docs 2017-12-28 09:48:02 +10:00
Dmitry D. Chernov
b252468ca2 TelegramBareClient: Add set_proxy() method
This allows to change proxy without recreation of the client instance.
2017-12-28 09:48:01 +10:00
Lonami Exo
b1b3610c1f Add missing self to .set_proxy (fa64a5f) 2017-12-28 00:09:29 +01:00
Dmitry D. Chernov
fa64a5f7b8 TelegramBareClient: Add set_proxy() method
This allows to change proxy without recreation of the client instance.
2017-12-28 07:50:49 +10:00
Dmitry D. Chernov
a5b1457eee TelegramBareClient: Fix lost #region 2017-12-28 07:33:25 +10:00
Lonami Exo
f8745155ac Stop joining read thread on disconnect, as it may be None 2017-12-27 12:37:07 +01:00
Lonami Exo
664417b409 Use sqlite3 instead JSON for the session files 2017-12-26 16:45:47 +01:00
Tanuj
c218df87d7 Remove reference to README.rst (#504) 2017-12-25 17:26:29 +01:00
Lonami Exo
5842d3741b Make a proper use of the logging module 2017-12-20 12:47:39 +01:00
Lonami Exo
edd73ed69a Allow switching from IPv4 to IPv6 and vice versa 2017-11-16 13:40:25 +01:00
Vladislav Kolesnichenko
ee5915e86d Add support for connecting through IPv6 (#425 for #112) 2017-11-16 13:30:18 +01:00
Lonami Exo
959e824c1c Reduce indent level to simplify flow on __call__ 2017-11-16 13:26:49 +01:00
Lonami Exo
778c844a64 Use logger.exception instead logger.error on ReadThread 2017-11-16 13:25:13 +01:00
Lonami Exo
4ac88a1505 Use ._logger.exception when .connect fails (#373) 2017-11-13 10:58:10 +01:00
Lonami Exo
07cb001854 Attempt at cleaning up reconnection logic 2017-11-13 10:31:32 +01:00
Lonami Exo
99512875a2 Reconnect if invoking failed (#270) 2017-11-12 16:25:56 +01:00
Andrei Fokau
ef794bf75d Fix importing dependencies during installing (#384) 2017-10-28 12:21:07 +02:00