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

« back to all changes in this revision

Viewing changes to services/python-console

  • Committer: David Coles
  • Date: 2009-08-06 04:04:37 UTC
  • Revision ID: coles.david@gmail.com-20090806040437-a8k5jhkkf2ixud5a
Add a rather lenient RLIMIT_NPROC that will prevent simple fork bombs (hopefully accidental...) from taking down a server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import traceback
17
17
from threading import Thread
18
18
 
19
 
import common.chat
20
 
import common.util
 
19
import ivle.chat
 
20
import ivle.util
21
21
 
22
22
# This version must be supported by both the local and remote code
23
23
PICKLEVERSION = 0
67
67
        '''Trim an incomplete UTF-8 character from the end of a string.
68
68
           Returns (trimmed_string, count_of_trimmed_bytes).
69
69
        '''
70
 
        tokill = common.util.incomplete_utf8_sequence(stuff)
 
70
        tokill = ivle.util.incomplete_utf8_sequence(stuff)
71
71
        if tokill == 0:
72
72
            return (stuff, tokill)
73
73
        else:
208
208
 
209
209
        # Try to execute the buffer
210
210
        try:
211
 
            cmd = self.cc(self.curr_cmd, '<web session>')
 
211
            # A single trailing newline simply indicates that the line is
 
212
            # finished. Two trailing newlines indicate the end of a block.
 
213
            # Unfortunately, codeop.CommandCompiler causes even one to
 
214
            # terminate a block.
 
215
            # Thus we need to remove a trailing newline from the command,
 
216
            # unless there are *two* trailing newlines, or multi-line indented
 
217
            # blocks are impossible. See Google Code issue 105.
 
218
            cmd_text = self.curr_cmd
 
219
            if cmd_text.endswith('\n') and not cmd_text.endswith('\n\n'):
 
220
                cmd_text = cmd_text[:-1]
 
221
            cmd = self.cc(cmd_text, '<web session>')
212
222
            if cmd is None:
213
223
                # The command was incomplete, so send back a None, so the              
214
224
                # client can print a '...'
366
376
    if msg['cmd'] == 'terminate':
367
377
        terminate = "User requested console be terminated"
368
378
    if terminate:
369
 
        raise common.chat.Terminate({"terminate":terminate})
 
379
        raise ivle.chat.Terminate({"terminate":terminate})
370
380
    expiry.ping()
371
381
    lineQ.put((msg['cmd'],msg['text']))
372
382
    response = cmdQ.get()
373
383
    if terminate:
374
 
        raise common.chat.Terminate({"terminate":terminate})
 
384
        raise ivle.chat.Terminate({"terminate":terminate})
375
385
    return response
376
386
 
377
387
def format_exc_start(start=0):
393
403
            try:
394
404
                o_type = type(object[o]).__name__
395
405
                o_name = object[o].__name__
396
 
                fake_o = common.util.FakeObject(o_type, o_name)
 
406
                fake_o = ivle.util.FakeObject(o_type, o_name)
397
407
                flat[o] = cPickle.dumps(fake_o, PICKLEVERSION)
398
408
            except AttributeError:
399
409
                pass
415
425
    # Make python's search path follow the cwd
416
426
    sys.path[0] = ''
417
427
 
418
 
    common.chat.start_server(port, magic, True, dispatch_msg, initializer)
 
428
    ivle.chat.start_server(port, magic, True, dispatch_msg, initializer)