7
S'/home/dreich/lib/python/web2py/applications/pyquiz/controllers/default.py'
11
S'# -*- coding: utf-8 -*- \n\n#########################################################################\n## This is a samples controller\n## - index is the default action of any application\n## - user is required for authentication and authorization\n## - download is for downloading files uploaded in the db (does streaming)\n## - call exposes all registered services (none by default)\n######################################################################### \n\ndef index():\n\treturn dict()\n\n@auth.requires_permission(\'create\', \'quiz\')\ndef new():\n\tform = SQLFORM(db.quiz,col3={\n\t\'public_doctests\':PRE("Should be in this format, remembering to have a space between the >>> and the prompt: \\n>>> hello_world()\\nHello World!"),\n\t\'starter\':\'Code here will be given to the student to start with\',\n\t\'times_takeable\':\'Enter 0 here for unlimited tries - eg, for a practice quiz.\',\n\t})\n\tif form.accepts(request.vars,session):\n\t\t\n\t\tquiz_id = form.vars.id\n\t\t\n\t\tgroup_id = auth.user_group(auth.user_id)\n\t\tauth.add_permission(group_id, \'update\', db.quiz,quiz_id)\n\t\t\n\t\tresponse.flash = \'quiz accepted\'\n\t\tredirect(URL(r=request, f=\'index\'))\n\t\t\n\treturn dict(form=form)\n\n@auth.requires_login()\t\ndef userinfo():\n\tgroup_id = auth.id_group(auth.user_id)\n\tdb(db.auth_membership.group_id==group_id)\n\t\n@auth.requires_permission(\'update\', \'quiz\', request.args(0))\ndef edit():\n\tquiz = db(db.quiz.id==request.args(0)).select()[0]\n\tform = SQLFORM(db.quiz, quiz, quizcol3={\n\t\'public_doctests\':PRE("Should be in this format, remembering to have a space between the >>> and the prompt: \\n>>> hello_world()\\nHello World!"),\n\t\'starter\':\'Code here will be given to the student to start with\',\n\t\'times_takeable\':\'Enter 0 here for unlimited tries - eg, for a practice quiz.\',\n\t})\n\tif form.accepts(request.vars,session):\n\t\tresponse.flash = "Edit accepted"\n\t\tredirect(URL(r=request,f=\'index\'))\n\treturn dict(form=form,quiz=quiz)\t\n\t\n@auth.requires_permission(\'read\', \'attempt\', request.args(0))\ndef attempt():\n\tattempt = db(db.attempt.id==request.args(0)).select()[0]\n\tif auth.has_membership(user_id=auth.user_id,role=\'teachers\'):\n\t\treturn dict(attempt=attempt,teacher=True)\n\treturn dict(attempt=attempt,teacher=False)\n\t\ndef list():\n\tquizzes = db().select(db.quiz.ALL)\n\tif auth.has_membership(user_id=auth.user_id,role=\'teachers\'):\n\t\treturn dict(quizzes=quizzes, teacher=\'yes\')\n\telse:\n\t\treturn dict(quizzes=quizzes, teacher=\'no\')\n\t\n\n@auth.requires_login()\t\ndef take():\n\tquiz = db(db.quiz.id==request.args(0)).select()[0]\n\t\n\tattempts=[]\n\tif quiz.times_takeable != 0:\n\t\tuserid=auth.user_id\n\t\tfor attempt in db(db.attempt.user==userid).select():\n\t\t\tif int(attempt.quiz)==quiz.id:\n\t\t\t\tattempts.append(attempt)\n\t\ttakes_left=str(quiz.times_takeable - len(attempts))\n\t\tif len(attempts) >= quiz.times_takeable:\n\t\t\treturn dict(error="already_taken")\n\telse:\n\t\ttakes_left="infinite"\n\tform = SQLFORM(db.quiz, quiz, fields=["starter"],col3={\'starter\':PRE(attempts[-1].code)})\n\telse:\n\t\tform = SQLFORM(db.quiz, quiz, fields=["starter"])\n\tresults = ""\n\tif request.vars.starter:\n\t\tcode = request.vars.starter\n\t\timport applications.pyquiz.modules.pypy.pypy.translator.sandbox.pypy_interact as pypy_interact\n\t\topentests = open("applications/pyquiz/modules/pypy/pypy/translator/sandbox/virtualtmp/opentests.py","w")\n\t\topentests.write("\'\'\'\\n"+quiz.public_doctests+"\\n\'\'\'\\n"+code)\n\t\topentests.close()\n\t\thiddentests = open("applications/pyquiz/modules/pypy/pypy/translator/sandbox/virtualtmp/hiddentests.py","w")\n\t\thiddentests.write("\'\'\'\\n"+quiz.hidden_doctests+"\\n\'\'\'\\n"+code)\n\t\thiddentests.close()\n\t\tsandbox = pypy_interact.PyPySandboxedProc(\n\t\t\t\'applications/pyquiz/modules/pypy/pypy/translator/sandbox/sandbox\',\n\t\t\t["/tmp/codefile.py",],\n\t\t\t\'applications/pyquiz/modules/pypy/pypy/translator/sandbox/virtualtmp/\')\n\t\tresults = sandbox.communicate()[1]\n\t\t\n\t\t\n\t\tquasichunklist = results.split("----------------------------------------------------------------------")\n\t\tchunklist = []\n\t\tfor item in quasichunklist:\n\t\t\tchunklist+=(item.split("======================================================================"))\n\t\t\n\t\tchunklist = chunklist[1:-1]\n\t\tfor item in chunklist:\n\t\t\tif item == \'\\nTraceback (most recent call last):\\n File "/bin/lib-python/modified-2.5.2/doctest.py", line 2128, in runTest\\n raise self.failureException(self.format_failure(new.getvalue()))\\nAssertionError: Failed doctest test for opentests\\n File "/tmp/opentests.py", line 0, in opentests\\n\\n\':\n\t\t\t\tchunklist.remove(item)\n\t\t\telif item == \'\\nTraceback (most recent call last):\\n File "/bin/lib-python/modified-2.5.2/doctest.py", line 2128, in runTest\\n raise self.failureException(self.format_failure(new.getvalue()))\\nAssertionError: Failed doctest test for hiddentests\\n File "/tmp/hiddentests.py", line 0, in hiddentests\\n\\n\':\n\t\t\t\tchunklist.remove(item)\n\t\t\telif item.startswith(\'FAIL: Doctest:\'):\n\t\t\t\tchunklist.remove(item)\n\t\t\t\t\n\t\tfullresults = ""\n\t\tfor item in chunklist:\n\t\t\tfullresults+=item\n\t\t\t\n\t\t\n\t\ttry:\t\n\t\t\tdoctest_results = fullresults.split("FAIL: Doctest: hiddentests")[0][74:]\n\t\t\thidden_results = fullresults.split("FAIL: Doctest: hiddentests")[1][53:]\n\t\texcept IndexError:\n\t\t\thidden_results = "No hidden failures"\n\t\t\t\n\t\tif not \':\' in doctest_results:\n\t\t\tif not \':\' in hidden_results:\n\t\t\t\tdoctest_results = "No failed doctests, you passed the quiz!"\n\t\t\telse:\n\t\t\t\tdoctest_results = "Unspecified failure - are you actually making a generalized solution?"\n\t\t\t\n\t\tif takes_left != 0:\n\t\t\tsession.lastquiz=request.args[0]\n\t\t\tsession.lastcode=code\n\t\t\tsession.lastresults=doctest_results\n\t\t\n\t\tnewattempt = db.attempt.insert(\n\t\t\tquiz=request.args(0),\n\t\t\tuser=auth.user_id,\n\t\t\tcode=code,\n\t\t\tdoctest_results=doctest_results,\n\t\t\thidden_results=hidden_results)\n\t\t\t\n\t\tgroup_id = auth.user_group(auth.user_id)\n\t\tauth.add_permission(group_id, \'read\', db.attempt,newattempt)\n\t\tredirect(URL(r=request,f=\'attempt\',args=[newattempt]))\n\t\t\n\treturn dict(form=form,quiz=quiz,attempts=attempts,takes_left=takes_left,error="none")\n\t\n@auth.requires_login()\t\ndef history():\n\tif not request.args:\n\t\tattempts = db(db.attempt.user==auth.user_id).select()\n\t\tquizzes = []\n\t\tfor attempt in attempts:\n\t\t\tquiz = (db(db.quiz.id==attempt.quiz).select()[0])\n\t\t\tif not quiz in quizzes:\n\t\t\t\tquizzes.append(quiz)\n\t\treturn dict(quizzes=quizzes,action="quizzes")\n\telif request.args[0]=="quiz":\n\t\tattempts = db(db.attempt.user==auth.user_id).select()\n\t\toutattempts=[]\n\t\tfor attempt in attempts:\n\t\t\tif int(attempt.quiz) == int(request.args[1]):\n\t\t\t\toutattempts.append(attempt)\n\t\treturn dict(attempts=outattempts,action="attempts")\n\n@auth.requires_permission(\'read\', \'attempt\', 0)\t\ndef all_attempts():\n\tif not request.args:\n\t\tusers = db().select(db.auth_user.ALL)\n\t\treturn dict(users=users,action="users")\n\telif len(request.args)==1:\n\t\tuser = db(db.auth_user.id==int(request.args[0])).select()[0]\n\t\toutquizzes=[]\n\t\tfor attempt in db().select(db.attempt.ALL):\n\t\t\tif int(attempt.user.id) == int(user.id):\n\t\t\t\tif not attempt.quiz in outquizzes:\n\t\t\t\t\toutquizzes.append(attempt.quiz)\n\t\treturn dict(quizzes=outquizzes,user=user,action="user")\n\telif len(request.args)==2:\n\t\tuser = db(db.auth_user.id==int(request.args[0])).select()[0]\n\t\tquiz = db(db.quiz.id==int(request.args[1])).select()[0]\n\t\toutattempts=[]\n\t\tfor attempt in db().select(db.attempt.ALL):\n\t\t\tif attempt.user.id == user.id:\n\t\t\t\tif attempt.quiz.id==quiz.id:\n\t\t\t\t\toutattempts.append(attempt)\n\t\treturn dict(attempts=outattempts,user=user,quiz=quiz,action="quiz")\n\t\t\n@auth.requires_permission(\'read\', \'attempt\', 0)\t\ndef user_admin():\n\tif not request.args:\n\t\tusers = db().select(db.auth_user.ALL)\n\t\tteachers = []\n\t\tstudents = []\n\t\tfor user in users:\n\t\t\tif auth.has_membership(user_id=user.id,role=\'teachers\'):\n\t\t\t\tteachers.append(user)\n\t\t\telse: \n\t\t\t\tstudents.append(user)\n\t\treturn dict(teachers=teachers,students=students)\n\t\t\t\n\t\t\n\t\t\n@auth.requires_membership(\'teachers\')\ndef make_teacher():\t\n\ttry:\n\t\tuser = db(db.auth_user.id==int(request.args[0])).select()[0]\n\texcept:\n\t\treturn dict(user="none",message=\'Error: Invalid user\')\n\tauth.add_membership(1,user.id)\n\treturn dict(user=user,message=\'was added to teachers\')\n\t\n@auth.requires_membership(\'teachers\')\ndef remove_teacher():\t\n\ttry:\n\t\tuser = db(db.auth_user.id==int(request.args[0])).select()[0]\n\texcept:\n\t\treturn dict(user="none",message=\'Error: Invalid user\')\n\tauth.del_membership(1,user.id)\n\treturn dict(user=user,message=\'was removed from teachers\')\n\n\ndef user():\n\t"""\n\texposes:\n\thttp://..../[app]/default/user/login \n\thttp://..../[app]/default/user/logout\n\thttp://..../[app]/default/user/register\n\thttp://..../[app]/default/user/profile\n\thttp://..../[app]/default/user/retrieve_password\n\thttp://..../[app]/default/user/change_password\n\tuse @auth.requires_login()\n\t\t@auth.requires_membership(\'group name\')\n\t\t@auth.requires_permission(\'read\',\'table name\',record_id)\n\tto decorate functions that need access control\n\t"""\n\treturn dict(form=auth())\n\n\ndef download():\n\treturn response.download(request,db)\n\n\n\n\n\nresponse._vars=response._caller(list)\n'
21
S"<method-wrapper '__getslice__' of exceptions.SyntaxError object>"
29
S"<method-wrapper '__str__' of exceptions.SyntaxError object>"
33
S'<built-in method __reduce__ of exceptions.SyntaxError object>'
41
S'<built-in method __sizeof__ of exceptions.SyntaxError object>'
45
S"<method-wrapper '__init__' of exceptions.SyntaxError object>"
49
S"<method-wrapper '__setattr__' of exceptions.SyntaxError object>"
53
S'<built-in method __reduce_ex__ of exceptions.SyntaxError object>'
57
S'<built-in method __new__ of type object>'
61
S'<built-in method __format__ of exceptions.SyntaxError object>'
65
S"<type 'exceptions.SyntaxError'>"
69
S"'/home/dreich/lib/python/web2py/applications/pyquiz/controllers/default.py'"
85
S"<method-wrapper '__getitem__' of exceptions.SyntaxError object>"
89
S'<built-in method __setstate__ of exceptions.SyntaxError object>'
93
S"<method-wrapper '__getattribute__' of exceptions.SyntaxError object>"
95
sS'print_file_and_line'
101
S"('invalid syntax', ('/home/dreich/lib/python/web2py/applications/pyquiz/controllers/default.py', 82, 5, '\\telse:\\n'))"
105
S'<built-in method __subclasshook__ of type object>'
112
S'<built-in method __unicode__ of exceptions.SyntaxError object>'
116
S"<method-wrapper '__delattr__' of exceptions.SyntaxError object>"
120
S"<method-wrapper '__repr__' of exceptions.SyntaxError object>"
124
S"<method-wrapper '__hash__' of exceptions.SyntaxError object>"
128
S'invalid syntax (default.py, line 82)'
139
S'<cStringIO.StringO object>'
143
S"<Storage {'start_response': <function <lambda> a...ING': 'gzip,deflate', 'HTTP_KEEP_ALIVE': '115'}}>"
159
S"'/pyquiz/default/list'"
170
S"<SimpleCookie: session_id_admin='127-0-0-1-0f79e...'127-0-0-1-b72b09cd-4df5-400b-a52a-de767af812c8'>"
186
S"<Storage {'http_user_agent': 'Mozilla/5.0 (X11; ...ce': False, 'path_info': '/pyquiz/default/list'}>"
198
S"'/home/dreich/lib/python/web2py/applications/pyquiz/'"
202
S'datetime.datetime(2010, 8, 13, 13, 38, 36, 102389)'
214
S'/home/dreich/lib/python/web2py/gluon/restricted.py'
221
S"'# -*- coding: utf-8 -*- \\n\\n######################...t,db)\\n\\n\\n\\n\\n\\nresponse._vars=response._caller(list)\\n'"
225
S"'/home/dreich/lib/python/web2py/applications/pyquiz/controllers/default.py'"
229
S'<function compile2>'
247
S' if type(code) == types.CodeType:'
256
S' ccode = compile2(code,layer)'
261
S' exec ccode in environment'
271
S"(code='# -*- coding: utf-8 -*- \\n\\n######################...t,db)\\n\\n\\n\\n\\n\\nresponse._vars=response._caller(list)\\n', environment={'A': <class 'gluon.html.A'>, 'Auth': <class 'gluon.tools.Auth'>, 'B': <class 'gluon.html.B'>, 'BEAUTIFY': <class 'gluon.html.BEAUTIFY'>, 'BODY': <class 'gluon.html.BODY'>, 'BR': <class 'gluon.html.BR'>, 'CENTER': <class 'gluon.html.CENTER'>, 'CLEANUP': <class 'gluon.validators.CLEANUP'>, 'CODE': <class 'gluon.html.CODE'>, 'CRYPT': <class 'gluon.validators.CRYPT'>, ...}, layer='/home/dreich/lib/python/web2py/applications/pyquiz/controllers/default.py')"
279
S'/home/dreich/lib/python/web2py/gluon/restricted.py'
285
S'<built-in function compile>'
289
S"'# -*- coding: utf-8 -*- \\n\\n######################...t,db)\\n\\n\\n\\n\\n\\nresponse._vars=response._caller(list)\\n'"
293
S'<built-in method rstrip of str object>'
300
S"'/home/dreich/lib/python/web2py/applications/pyquiz/controllers/default.py'"
309
S'def compile2(code,layer):'
315
S" The +'\\n' is necessary else compile fails when code ends in a comment."
321
S" return compile(code.rstrip().replace('\\r\\n','\\n')+'\\n', layer, 'exec')"
326
S"def restricted(code, environment={}, layer='Unknown'):"
332
S' runs code in environment and returns the output. if an exception occurs'
335
S"(code='# -*- coding: utf-8 -*- \\n\\n######################...t,db)\\n\\n\\n\\n\\n\\nresponse._vars=response._caller(list)\\n', layer='/home/dreich/lib/python/web2py/applications/pyquiz/controllers/default.py')"
342
S'Python 2.6.5: /usr/bin/python'
349
S"'No failed doctests, you passed the quiz!'"
361
S"<Storage {'expiration': 3600, 'user': <Storage {..., 8, 13, 13, 38, 36, 102389), 'remember': False}>"
369
S"'76907923-c3df-48da-a12e-865e67ee396c'"
371
sS'_formkey[quiz_create]'
373
S"'cc03d533-0a60-42de-a336-a11af68f2e34'"
377
S"<type 'exceptions.SyntaxError'>"
381
S'Fri Aug 13 13:38:36 2010'
391
S'<cStringIO.StringO object>'
394
S"<SimpleCookie: session_id_pyquiz='127-0-0-1-551bff65-0c08-476c-a819-2b1685d3c115'>"
406
S"<open file '/home/dreich/lib/python/web2py/appli...51bff65-0c08-476c-a819-2b1685d3c115', mode 'rb+'>"
418
S"'127-0-0-1-551bff65-0c08-476c-a819-2b1685d3c115'"
422
S"<Storage {'Expires': 'Fri, 13 Aug 2010 17:38:36 ...he, must-revalidate, post-check=0, pre-check=0'}>"
430
S"'/home/dreich/lib/python/web2py/applications/pyqu...ns/127-0-0-1-551bff65-0c08-476c-a819-2b1685d3c115'"
438
S"[[<lazyT 'Home Page'>, False, '/pyquiz/default/index', []], [<lazyT 'New Quiz'>, False, '/pyquiz/default/new', []], [<lazyT 'List Quizzes'>, False, '/pyquiz/default/list', []], [<lazyT 'Your History'>, False, '/pyquiz/default/history', []], [<lazyT 'User Admin'>, False, '/pyquiz/default/user_admin', []]]"
440
sS'_view_environment'
442
S"{'A': <class 'gluon.html.A'>, 'Auth': <class 'gluon.tools.Auth'>, 'B': <class 'gluon.html.B'>, 'BEAUTIFY': <class 'gluon.html.BEAUTIFY'>, 'BODY': <class 'gluon.html.BODY'>, 'BR': <class 'gluon.html.BR'>, 'CENTER': <class 'gluon.html.CENTER'>, 'CLEANUP': <class 'gluon.validators.CLEANUP'>, 'CODE': <class 'gluon.html.CODE'>, 'CRYPT': <class 'gluon.validators.CRYPT'>, ...}"
446
S"<lazyT 'Quizzes in Python'>"
450
S"'session_id_pyquiz'"
458
S'<function <lambda>>'
466
S"'default/list.html'"
472
S"'/home/dreich/lib/python/web2py/applications/pyquiz/controllers/default.py'"
475
S"'# -*- coding: utf-8 -*- \\n\\n######################...t,db)\\n\\n\\n\\n\\n\\nresponse._vars=response._caller(list)\\n'"
479
S'Traceback (most recent call last):\n File "/home/dreich/lib/python/web2py/gluon/restricted.py", line 184, in restricted\n ccode = compile2(code,layer)\n File "/home/dreich/lib/python/web2py/gluon/restricted.py", line 171, in compile2\n return compile(code.rstrip().replace(\'\\r\\n\',\'\\n\')+\'\\n\', layer, \'exec\')\n File "/home/dreich/lib/python/web2py/applications/pyquiz/controllers/default.py", line 82\n else:\n ^\nSyntaxError: invalid syntax\n'
b'\\ No newline at end of file'