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

« back to all changes in this revision

Viewing changes to lib/common/chat.py

  • Committer: wagrant
  • Date: 2008-12-23 05:23:56 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1066
Fix the console to use codeop.CommandCompiler, which remembers activated
feature flags. This lets __future__ imports work in the console.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import socket
28
28
import traceback
29
29
 
 
30
class Terminate(Exception):
 
31
    """Exception thrown when server is to be shut down. It will attempt to sned 
 
32
    the final_response to the client and then exits"""
 
33
    def __init__(self, final_response=None):
 
34
        self.final_response = final_response
 
35
 
 
36
    def __str__(self):
 
37
        return repr(self.final_response)
 
38
 
 
39
 
30
40
def start_server(port, magic, daemon_mode, handler, initializer = None):
31
41
    # Attempt to open the socket.
32
42
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
76
86
            conn.sendall(cjson.encode(response))
77
87
 
78
88
            conn.close()
 
89
 
 
90
        except Terminate, t:
 
91
            # Try and send final response and then terminate
 
92
            if t.final_response:
 
93
                conn.sendall(cjson.encode(t.final_response))
 
94
            conn.close()
 
95
            sys.exit(0)
79
96
        except Exception:
80
97
            # Make a JSON object full of exceptional goodness
81
98
            tb_dump = cStringIO.StringIO()
103
120
    while blk:
104
121
        buf.write(blk)
105
122
        try:
106
 
            blk = conn.recv(1024, socket.MSG_DONTWAIT)
107
 
        except:
 
123
            blk = sok.recv(1024, socket.MSG_DONTWAIT)
 
124
        except socket.error, e:
 
125
            if e[0] != 11:
 
126
                raise
108
127
            # Exception thrown if it WOULD block (but we
109
128
            # told it not to wait) - ie. we are done
110
129
            blk = None