mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-10-31 16:07:44 +03:00 
			
		
		
		
	Make sync.syncify a public function for user types
This commit is contained in:
		
							parent
							
								
									044e6e8a85
								
							
						
					
					
						commit
						f295ea668a
					
				|  | @ -18,7 +18,7 @@ from .client.telegramclient import TelegramClient | |||
| from .tl.custom import Draft, Dialog, MessageButton, Forward, Message | ||||
| 
 | ||||
| 
 | ||||
| def syncify(t, method_name): | ||||
| def _syncify(t, method_name): | ||||
|     method = getattr(t, method_name) | ||||
| 
 | ||||
|     @functools.wraps(method) | ||||
|  | @ -32,9 +32,17 @@ def syncify(t, method_name): | |||
|     setattr(t, method_name, syncified) | ||||
| 
 | ||||
| 
 | ||||
| for t in [TelegramClient, | ||||
|           Draft, Dialog, MessageButton, Forward, Message]: | ||||
|     for method_name in dir(t): | ||||
|         if not method_name.startswith('_') or method_name == '__call__': | ||||
|             if inspect.iscoroutinefunction(getattr(t, method_name)): | ||||
|                 syncify(t, method_name) | ||||
| def syncify(*types): | ||||
|     """ | ||||
|     Converts all the methods in the given types (class definitions) | ||||
|     into synchronous, which return either the coroutine or the result | ||||
|     based on whether ``asyncio's`` event loop is running. | ||||
|     """ | ||||
|     for t in types: | ||||
|         for method_name in dir(t): | ||||
|             if not method_name.startswith('_') or method_name == '__call__': | ||||
|                 if inspect.iscoroutinefunction(getattr(t, method_name)): | ||||
|                     _syncify(t, method_name) | ||||
| 
 | ||||
| 
 | ||||
| syncify(TelegramClient, Draft, Dialog, MessageButton, Forward, Message) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user