<s> import urlparse <EOL> import codecs <EOL> import os <EOL> import StringIO <EOL> import zipfile <EOL> from flask import Response , render_template , flash <EOL> def get_scorm_object ( authenticate = True , laboratory_identifier = '<STR_LIT>' , lms_path = '<STR_LIT:/>' , lms_extension = '<STR_LIT:/>' , html_body = '''<STR_LIT>''' ) : <EOL> import labmanager <EOL> base_dir = os . path . dirname ( labmanager . __file__ ) <EOL> base_scorm_dir = os . path . join ( base_dir , '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> if not os . path . exists ( base_scorm_dir ) : <EOL> flash ( "<STR_LIT>" % base_scorm_dir ) <EOL> return render_template ( "<STR_LIT>" ) <EOL> sio = StringIO . StringIO ( '<STR_LIT>' ) <EOL> zf = zipfile . ZipFile ( sio , '<STR_LIT:w>' ) <EOL> for root , dir , files in os . walk ( base_scorm_dir ) : <EOL> for f in files : <EOL> file_name = os . path . join ( root , f ) <EOL> arc_name = os . path . join ( root [ len ( base_scorm_dir ) + <NUM_LIT:1> : ] , f ) <EOL> content = codecs . open ( file_name , '<STR_LIT:rb>' , encoding = '<STR_LIT:utf-8>' ) . read ( ) <EOL> if f == '<STR_LIT>' and root == base_scorm_dir : <EOL> content = content % { <EOL> u'<STR_LIT>' : '<STR_LIT>' if authenticate else '<STR_LIT>' , <EOL> u'<STR_LIT>' : '<STR_LIT>' if not authenticate else '<STR_LIT>' , <EOL> u'<STR_LIT>' : unicode ( laboratory_identifier ) , <EOL> u'<STR_LIT>' : unicode ( lms_path ) , <EOL> u'<STR_LIT>' : unicode ( lms_extension ) , <EOL> u'<STR_LIT>' : unicode ( html_body ) , <EOL> } <EOL> zf . writestr ( arc_name , content . encode ( '<STR_LIT:utf-8>' ) ) <EOL> zf . close ( ) <EOL> return sio . getvalue ( ) <EOL> def get_authentication_scorm ( lms_url ) : <EOL> lms_path = urlparse . urlparse ( lms_url ) . path or '<STR_LIT:/>' <EOL> extension = '<STR_LIT:/>' <EOL> if '<STR_LIT>' in lms_path : <EOL> extension = lms_path [ lms_path . rfind ( '<STR_LIT>' ) + len ( '<STR_LIT>' ) : ] <EOL> lms_path = lms_path [ : lms_path . rfind ( '<STR_LIT>' ) ] <EOL> content = get_scorm_object ( True , lms_path = lms_path , lms_extension = extension ) <EOL> return Response ( content , headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) </s>
