99# Copyright © 2013 Bernard Blackham <bernard@largestprime.net>
1010# Copyright © 2014 Artem Iglikov <artem.iglikov@gmail.com>
1111# Copyright © 2014 Fabian Gundlach <320pointsguy@gmail.com>
12+ # Copyright © 2015 William Di Luigi <williamdiluigi@gmail.com>
1213#
1314# This program is free software: you can redistribute it and/or modify
1415# it under the terms of the GNU Affero General Public License as
5354import re
5455import socket
5556import struct
56- import tempfile
5757import traceback
5858from datetime import timedelta
5959from urllib import quote
7272from cms .db .filecacher import FileCacher
7373from cms .grading .tasktypes import get_task_type
7474from cms .grading .scoretypes import get_score_type
75- from cms .server import file_handler_gen , extract_archive , \
76- actual_phase_required , get_url_root , filter_ascii , \
77- CommonRequestHandler , format_size , compute_actual_phase
75+ from cms .server import file_handler_gen , actual_phase_required , \
76+ get_url_root , filter_ascii , CommonRequestHandler , format_size , \
77+ compute_actual_phase
7878from cmscommon .isocodes import is_language_code , translate_language_code , \
7979 is_country_code , translate_country_code , \
8080 is_language_country_code , translate_language_country_code
8181from cmscommon .crypto import encrypt_number
8282from cmscommon .datetime import make_datetime , make_timestamp , get_timezone
8383from cmscommon .mimetypes import get_type_for_file_name
84+ from cmscommon .archive import Archive
8485
8586
8687logger = logging .getLogger (__name__ )
@@ -979,16 +980,10 @@ def post(self, task_name):
979980 archive_data = self .request .files ["submission" ][0 ]
980981 del self .request .files ["submission" ]
981982
982- # Extract the files from the archive.
983- temp_archive_file , temp_archive_filename = \
984- tempfile .mkstemp (dir = config .temp_dir )
985- with os .fdopen (temp_archive_file , "w" ) as temp_archive_file :
986- temp_archive_file .write (archive_data ["body" ])
983+ # Create the archive.
984+ archive = Archive .from_raw_data (archive_data ["body" ])
987985
988- archive_contents = extract_archive (temp_archive_filename ,
989- archive_data ["filename" ])
990-
991- if archive_contents is None :
986+ if archive is None :
992987 self .application .service .add_notification (
993988 self .current_user .username ,
994989 self .timestamp ,
@@ -999,8 +994,17 @@ def post(self, task_name):
999994 safe = '' ))
1000995 return
1001996
1002- for item in archive_contents :
1003- self .request .files [item ["filename" ]] = [item ]
997+ # Extract the archive.
998+ unpacked_dir = archive .unpack ()
999+ for name in archive .namelist ():
1000+ filename = os .path .basename (name )
1001+ body = open (os .path .join (unpacked_dir , filename ), "r" ).read ()
1002+ self .request .files [filename ] = [{
1003+ 'filename' : filename ,
1004+ 'body' : body
1005+ }]
1006+
1007+ archive .cleanup ()
10041008
10051009 # This ensure that the user sent one file for every name in
10061010 # submission format and no more. Less is acceptable if task
@@ -1518,16 +1522,10 @@ def post(self, task_name):
15181522 archive_data = self .request .files ["submission" ][0 ]
15191523 del self .request .files ["submission" ]
15201524
1521- # Extract the files from the archive.
1522- temp_archive_file , temp_archive_filename = \
1523- tempfile .mkstemp (dir = config .temp_dir )
1524- with os .fdopen (temp_archive_file , "w" ) as temp_archive_file :
1525- temp_archive_file .write (archive_data ["body" ])
1526-
1527- archive_contents = extract_archive (temp_archive_filename ,
1528- archive_data ["filename" ])
1525+ # Create the archive.
1526+ archive = Archive .from_raw_data (archive_data ["body" ])
15291527
1530- if archive_contents is None :
1528+ if archive is None :
15311529 self .application .service .add_notification (
15321530 self .current_user .username ,
15331531 self .timestamp ,
@@ -1537,8 +1535,17 @@ def post(self, task_name):
15371535 self .redirect ("/testing?%s" % quote (task .name , safe = '' ))
15381536 return
15391537
1540- for item in archive_contents :
1541- self .request .files [item ["filename" ]] = [item ]
1538+ # Extract the archive.
1539+ unpacked_dir = archive .unpack ()
1540+ for name in archive .namelist ():
1541+ filename = os .path .basename (name )
1542+ body = open (os .path .join (unpacked_dir , filename ), "r" ).read ()
1543+ self .request .files [filename ] = [{
1544+ 'filename' : filename ,
1545+ 'body' : body
1546+ }]
1547+
1548+ archive .cleanup ()
15421549
15431550 # This ensure that the user sent one file for every name in
15441551 # submission format and no more. Less is acceptable if task
0 commit comments