From 83677fc927fdf65bb4bca5ed3257a2997f847db2 Mon Sep 17 00:00:00 2001
From: Lonami Exo <totufals@hotmail.com>
Date: Sun, 8 Oct 2017 13:45:14 +0200
Subject: [PATCH] Enhance and use .get_input_photo on the generated code

---
 telethon/utils.py                  | 7 +++++--
 telethon_generator/tl_generator.py | 4 +++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/telethon/utils.py b/telethon/utils.py
index c4c3182c..9c3ee2fe 100644
--- a/telethon/utils.py
+++ b/telethon/utils.py
@@ -20,8 +20,8 @@ from .tl.types import (
     GeoPointEmpty, InputGeoPointEmpty, Photo, InputPhoto, PhotoEmpty,
     InputPhotoEmpty, FileLocation, ChatPhotoEmpty, UserProfilePhotoEmpty,
     FileLocationUnavailable, InputMediaUploadedDocument,
-    InputMediaUploadedPhoto,
-    DocumentAttributeFilename)
+    InputMediaUploadedPhoto, DocumentAttributeFilename, photos
+)
 
 
 def get_display_name(entity):
@@ -188,6 +188,9 @@ def get_input_photo(photo):
     if type(photo).SUBCLASS_OF_ID == 0x846363e0:  # crc32(b'InputPhoto')
         return photo
 
+    if isinstance(photo, photos.Photo):
+        photo = photo.photo
+
     if isinstance(photo, Photo):
         return InputPhoto(id=photo.id, access_hash=photo.access_hash)
 
diff --git a/telethon_generator/tl_generator.py b/telethon_generator/tl_generator.py
index 0fb2c1ed..0e4f0013 100644
--- a/telethon_generator/tl_generator.py
+++ b/telethon_generator/tl_generator.py
@@ -143,7 +143,7 @@ class TLGenerator:
                     builder.writeln(
                         'from {}.utils import get_input_peer, '
                         'get_input_channel, get_input_user, '
-                        'get_input_media'.format('.' * depth)
+                        'get_input_media, get_input_photo'.format('.' * depth)
                     )
 
                 # Import 'os' for those needing access to 'os.urandom()'
@@ -402,6 +402,8 @@ class TLGenerator:
             TLGenerator.write_get_input(builder, arg, 'get_input_user')
         elif arg.type == 'InputMedia' and tlobject.is_function:
             TLGenerator.write_get_input(builder, arg, 'get_input_media')
+        elif arg.type == 'InputPhoto' and tlobject.is_function:
+            TLGenerator.write_get_input(builder, arg, 'get_input_photo')
 
         else:
             builder.writeln('self.{0} = {0}'.format(arg.name))