Optimize imports

This commit is contained in:
Lonami Exo 2017-09-04 17:18:33 +02:00
parent 97cab7347b
commit 15fd5390ae
7 changed files with 41 additions and 71 deletions

View File

@ -4,6 +4,7 @@ try:
import rsa import rsa
import rsa.core import rsa.core
except ImportError: except ImportError:
rsa = None
raise ImportError('Missing module "rsa", please install via pip.') raise ImportError('Missing module "rsa", please install via pip.')
from ..extensions import BinaryWriter from ..extensions import BinaryWriter

View File

@ -1,12 +1,8 @@
# Python rough implementation of a C# TCP client # Python rough implementation of a C# TCP client
import socket
import time
from datetime import datetime, timedelta
from io import BytesIO, BufferedWriter
from threading import Event, Lock
import errno import errno
import socket
from ..errors import ReadCancelledError from datetime import timedelta
from io import BytesIO, BufferedWriter
class TcpClient: class TcpClient:

View File

@ -118,10 +118,6 @@ class Connection:
def close(self): def close(self):
self.conn.close() self.conn.close()
def get_client_delay(self):
"""Gets the client read delay"""
return self.conn.delay
# region Receive message implementations # region Receive message implementations
def recv(self): def recv(self):

View File

@ -1,14 +1,14 @@
import gzip import gzip
from threading import RLock, Thread import logging
from threading import RLock
from .. import helpers as utils from .. import helpers as utils
from ..crypto import AES from ..crypto import AES
from ..errors import BadMessageError, InvalidDCError, rpc_message_to_error from ..errors import BadMessageError, rpc_message_to_error
from ..extensions import BinaryReader, BinaryWriter
from ..tl.all_tlobjects import tlobjects from ..tl.all_tlobjects import tlobjects
from ..tl.types import MsgsAck from ..tl.types import MsgsAck
from ..extensions import BinaryReader, BinaryWriter
import logging
logging.getLogger(__name__).addHandler(logging.NullHandler()) logging.getLogger(__name__).addHandler(logging.NullHandler())

View File

@ -1,43 +1,32 @@
import logging import logging
from time import sleep
from datetime import timedelta from datetime import timedelta
from hashlib import md5 from hashlib import md5
from os import path
from io import BytesIO from io import BytesIO
from os import path
# Import some externalized utilities to work with the Telegram types and more
from . import helpers as utils from . import helpers as utils
from .crypto import rsa, CdnDecrypter
from .errors import ( from .errors import (
RPCError, FloodWaitError, FileMigrateError, TypeNotFoundError RPCError, FloodWaitError, FileMigrateError, TypeNotFoundError
) )
from .network import authenticator, MtProtoSender, Connection, ConnectionMode from .network import authenticator, MtProtoSender, Connection, ConnectionMode
from .utils import get_appropriated_part_size
from .crypto import rsa, CdnDecrypter
# For sending and receiving requests
from .tl import TLObject, Session from .tl import TLObject, Session
from .tl.all_tlobjects import layer from .tl.all_tlobjects import layer
from .tl.functions import ( from .tl.functions import (
InitConnectionRequest, InvokeWithLayerRequest, PingRequest InitConnectionRequest, InvokeWithLayerRequest, PingRequest
) )
# Initial request
from .tl.functions.help import GetConfigRequest
from .tl.functions.auth import ( from .tl.functions.auth import (
ImportAuthorizationRequest, ExportAuthorizationRequest ImportAuthorizationRequest, ExportAuthorizationRequest
) )
from .tl.functions.help import (
# Easier access for working with media GetCdnConfigRequest, GetConfigRequest
from .tl.functions.upload import ( )
GetFileRequest, GetCdnFileRequest, ReuploadCdnFileRequest, from .tl.functions.upload import (
SaveBigFilePartRequest, SaveFilePartRequest GetFileRequest, SaveBigFilePartRequest, SaveFilePartRequest
) )
from .tl.functions.help import GetCdnConfigRequest
# All the types we need to work with
from .tl.types import InputFile, InputFileBig from .tl.types import InputFile, InputFileBig
from .tl.types.upload import FileCdnRedirect, CdnFileReuploadNeeded from .tl.types.upload import FileCdnRedirect
from .utils import get_appropriated_part_size
class TelegramBareClient: class TelegramBareClient:

View File

@ -1,52 +1,41 @@
import os import os
from datetime import datetime, timedelta from datetime import datetime, timedelta
from mimetypes import guess_type from mimetypes import guess_type
from threading import Event, RLock, Thread from threading import RLock, Thread
from time import sleep, time
from . import TelegramBareClient from . import TelegramBareClient
from .network import ConnectionMode
# Import some externalized utilities to work with the Telegram types and more
from . import helpers as utils from . import helpers as utils
from .errors import (RPCError, UnauthorizedError, InvalidParameterError, from .errors import (
ReadCancelledError, PhoneCodeEmptyError, RPCError, UnauthorizedError, InvalidParameterError, PhoneCodeEmptyError,
PhoneMigrateError, NetworkMigrateError, UserMigrateError, PhoneMigrateError, NetworkMigrateError, UserMigrateError,
PhoneCodeExpiredError, PhoneCodeHashEmptyError, PhoneCodeExpiredError, PhoneCodeHashEmptyError, PhoneCodeInvalidError
PhoneCodeInvalidError, InvalidChecksumError) )
from .network import ConnectionMode
# For sending and receiving requests
from .tl import Session, TLObject from .tl import Session, TLObject
from .tl.functions.account import (
# Required to get the password salt GetPasswordRequest
from .tl.functions.account import GetPasswordRequest )
from .tl.functions.auth import (
# Logging in and out CheckPasswordRequest, LogOutRequest, SendCodeRequest, SignInRequest,
from .tl.functions.auth import (CheckPasswordRequest, LogOutRequest, SignUpRequest, ImportBotAuthorizationRequest
SendCodeRequest, SignInRequest, )
SignUpRequest, ImportBotAuthorizationRequest) from .tl.functions.contacts import (
GetContactsRequest, ResolveUsernameRequest
# Easier access to common methods )
from .tl.functions.messages import ( from .tl.functions.messages import (
GetDialogsRequest, GetHistoryRequest, ReadHistoryRequest, SendMediaRequest, GetDialogsRequest, GetHistoryRequest, ReadHistoryRequest, SendMediaRequest,
SendMessageRequest) SendMessageRequest
)
from .tl.functions.contacts import GetContactsRequest, ResolveUsernameRequest from .tl.functions.users import (
GetUsersRequest
# For .get_me() and ensuring we're authorized )
from .tl.functions.users import GetUsersRequest
# So the server doesn't stop sending updates to us
from .tl.functions import PingRequest
# All the types we need to work with
from .tl.types import ( from .tl.types import (
DocumentAttributeAudio, DocumentAttributeFilename, DocumentAttributeAudio, DocumentAttributeFilename,
InputDocumentFileLocation, InputFileLocation, InputDocumentFileLocation, InputFileLocation,
InputMediaUploadedDocument, InputMediaUploadedPhoto, InputPeerEmpty, InputMediaUploadedDocument, InputMediaUploadedPhoto, InputPeerEmpty,
Message, MessageMediaContact, MessageMediaDocument, MessageMediaPhoto, Message, MessageMediaContact, MessageMediaDocument, MessageMediaPhoto,
InputUserSelf, UserProfilePhoto, ChatPhoto) InputUserSelf, UserProfilePhoto, ChatPhoto
)
from .utils import find_user_or_chat, get_extension from .utils import find_user_or_chat, get_extension

View File

@ -1,4 +1,3 @@
from datetime import datetime, timedelta
from threading import Event from threading import Event