~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to services/python-console

  • Committer: William Grant
  • Date: 2010-02-25 13:53:09 UTC
  • Revision ID: grantw@unimelb.edu.au-20100225135309-nfuzipcjj9zfu4ma
Set 'secure' flag on cookies if served over a direct or proxied HTTPS connection.

Show diffs side-by-side

added added

removed removed

Lines of Context:
181
181
 
182
182
        # Handlers for each action
183
183
        actions = {
 
184
            'splash': self.handle_splash,
184
185
            'chat': self.handle_chat,
185
186
            'block': self.handle_block,
186
187
            'globals': self.handle_globals,
198
199
                response = {'error': repr(e)}
199
200
            finally:
200
201
                self.cmdQ.put(response)
201
 
                   
 
202
 
 
203
    def handle_splash(self, params):
 
204
        # Initial console splash screen
 
205
        python_version = '.'.join(str(v) for v in sys.version_info[:3])
 
206
        splash_text = ("""IVLE %s Python Console (Python %s)
 
207
Type "help", "copyright", "credits" or "license" for more information.
 
208
""" % (ivle.__version__, python_version))
 
209
        return {'output': splash_text}
 
210
 
202
211
    def handle_chat(self, params):
203
212
        # Set up the partial cmd buffer
204
213
        if self.curr_cmd == '':
208
217
 
209
218
        # Try to execute the buffer
210
219
        try:
211
 
            cmd = self.cc(self.curr_cmd, '<web session>')
 
220
            # A single trailing newline simply indicates that the line is
 
221
            # finished. Two trailing newlines indicate the end of a block.
 
222
            # Unfortunately, codeop.CommandCompiler causes even one to
 
223
            # terminate a block.
 
224
            # Thus we need to remove a trailing newline from the command,
 
225
            # unless there are *two* trailing newlines, or multi-line indented
 
226
            # blocks are impossible. See Google Code issue 105.
 
227
            cmd_text = self.curr_cmd
 
228
            if cmd_text.endswith('\n') and not cmd_text.endswith('\n\n'):
 
229
                cmd_text = cmd_text[:-1]
 
230
            cmd = self.cc(cmd_text, '<web session>')
212
231
            if cmd is None:
213
232
                # The command was incomplete, so send back a None, so the              
214
233
                # client can print a '...'
359
378
    """Handles response from signals"""
360
379
    global terminate
361
380
    if signum == signal.SIGXCPU:
362
 
        terminate = "CPU Time Limit Exceeded"
 
381
        terminate = "CPU time limit exceeded"
363
382
 
364
383
def dispatch_msg(msg):
365
384
    global terminate
366
385
    if msg['cmd'] == 'terminate':
367
 
        terminate = "User requested console be terminated"
 
386
        terminate = "User requested restart"
368
387
    if terminate:
369
388
        raise ivle.chat.Terminate({"terminate":terminate})
370
389
    expiry.ping()
389
408
    for o in object:
390
409
        try:
391
410
            flat[o] = cPickle.dumps(object[o], PICKLEVERSION)
392
 
        except TypeError:
 
411
        except (TypeError, cPickle.PicklingError):
393
412
            try:
394
413
                o_type = type(object[o]).__name__
395
414
                o_name = object[o].__name__