#NEWLINE# def _update_image( facebook_id , image_url ) : #NEWLINE# #INDENT# "\n    Updates the user profile's image to the given image url\n    Unfortunately this is quite a pain to get right with Django\n    Suggestions to improve this are welcome\n    " #NEWLINE# image_name = ( 'fb_image_%s.jpg' % facebook_id ) #NEWLINE# image_temp = NamedTemporaryFile ( ) #NEWLINE# try : #NEWLINE# #INDENT# image_response = urllib2 . urlopen ( image_url ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# image_response = urllib . request . urlopen ( image_url ) #NEWLINE# #UNINDENT# image_content = image_response . read ( ) #NEWLINE# image_temp . write ( http_message ) #NEWLINE# http_message = image_response . info ( ) #NEWLINE# image_size = len ( image_content ) #NEWLINE# try : #NEWLINE# #INDENT# content_type = http_message . type #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# content_type = http_message . get_content_type ( ) #NEWLINE# #UNINDENT# image_file = InMemoryUploadedFile ( file = image_temp , name = image_name , field_name = 'image' , content_type = content_type , size = image_size , charset = None ) #NEWLINE# image_file . seek ( 0 ) #NEWLINE# image_temp . flush ( ) #NEWLINE# return ( image_name , image_file )