~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2008 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import bzrlib
18
18
from bzrlib.smart import message, protocol
36
36
        else:
37
37
            self._headers = dict(headers)
38
38
 
 
39
    def __repr__(self):
 
40
        return '%s(%r)' % (self.__class__.__name__, self._medium)
 
41
 
39
42
    def _send_request(self, protocol_version, method, args, body=None,
40
43
                      readv_body=None, body_stream=None):
41
44
        encoder, response_handler = self._construct_protocol(
66
69
        params = CallHookParams(method, args, body, readv_body, self._medium)
67
70
        for hook in _SmartClient.hooks['call']:
68
71
            hook(params)
69
 
            
 
72
 
70
73
    def _call_and_read_response(self, method, args, body=None, readv_body=None,
71
74
            body_stream=None, expect_response_body=True):
72
75
        self._run_call_hooks(method, args, body, readv_body)
132
135
 
133
136
    def call_expecting_body(self, method, *args):
134
137
        """Call a method and return the result and the protocol object.
135
 
        
 
138
 
136
139
        The body can be read like so::
137
140
 
138
141
            result, smart_protocol = smart_client.call_expecting_body(...)
180
183
 
181
184
    def remote_path_from_transport(self, transport):
182
185
        """Convert transport into a path suitable for using in a request.
183
 
        
 
186
 
184
187
        Note that the resulting remote path doesn't encode the host name or
185
188
        anything but path, so it is only safe to use it in requests sent over
186
189
        the medium from the matching transport.
191
194
class SmartClientHooks(hooks.Hooks):
192
195
 
193
196
    def __init__(self):
194
 
        hooks.Hooks.__init__(self)
195
 
        self['call'] = []
196
 
 
197
 
        
 
197
        hooks.Hooks.__init__(self, "bzrlib.smart.client", "_SmartClient.hooks")
 
198
        self.add_hook('call',
 
199
            "Called when the smart client is submitting a request to the "
 
200
            "smart server. Called with a bzrlib.smart.client.CallHookParams "
 
201
            "object. Streaming request bodies, and responses, are not "
 
202
            "accessible.", None)
 
203
 
 
204
 
198
205
_SmartClient.hooks = SmartClientHooks()
199
206
 
200
207
 
201
208
class CallHookParams(object):
202
 
    
 
209
 
203
210
    def __init__(self, method, args, body, readv_body, medium):
204
211
        self.method = method
205
212
        self.args = args