1010
1111from ietf .utils .html import sanitize_document
1212
13- def handle_upload_file (file ,filename ,meeting ,subdir , request = None ):
13+ def handle_upload_file (file ,filename ,meeting ,subdir , request = None , encoding = None ):
1414 '''
1515 This function takes a file object, a filename and a meeting object and subdir as string.
1616 It saves the file to the appropriate directory, get_materials_path() + subdir.
@@ -37,7 +37,16 @@ def handle_upload_file(file,filename,meeting,subdir, request=None):
3737 destination = open (os .path .join (path ,filename ), 'wb+' )
3838 if extension in settings .MEETING_VALID_MIME_TYPE_EXTENSIONS ['text/html' ]:
3939 file .open ()
40- text = smart_text (file .read ())
40+ text = file .read ()
41+ if encoding :
42+ text = text .decode (encoding )
43+ else :
44+ try :
45+ text = smart_text (text )
46+ except UnicodeDecodeError as e :
47+ msg = "Failure trying to save '%s': %s..." % (filename , str (e )[:120 ])
48+ return msg
49+
4150 # Whole file sanitization; add back what's missing from a complete
4251 # document (sanitize will remove these).
4352 clean = sanitize_document (text )
@@ -56,3 +65,4 @@ def handle_upload_file(file,filename,meeting,subdir, request=None):
5665 os .chdir (path )
5766 os .system ('unzip %s' % filename )
5867
68+ return None
0 commit comments