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

« back to all changes in this revision

Viewing changes to lib/common/chat.py

  • Committer: wagrant
  • Date: 2008-07-21 07:03:14 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:922
userdb: Add a migration for the change before we moved to migrations.

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
 
 
40
30
def start_server(port, magic, daemon_mode, handler, initializer = None):
41
31
    # Attempt to open the socket.
42
32
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
86
76
            conn.sendall(cjson.encode(response))
87
77
 
88
78
            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)
96
79
        except Exception:
97
80
            # Make a JSON object full of exceptional goodness
98
81
            tb_dump = cStringIO.StringIO()
120
103
    while blk:
121
104
        buf.write(blk)
122
105
        try:
123
 
            blk = sok.recv(1024, socket.MSG_DONTWAIT)
124
 
        except socket.error, e:
125
 
            if e[0] != 11:
126
 
                raise
 
106
            blk = conn.recv(1024, socket.MSG_DONTWAIT)
 
107
        except:
127
108
            # Exception thrown if it WOULD block (but we
128
109
            # told it not to wait) - ie. we are done
129
110
            blk = None