~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/request.py

  • Committer: Andrew Bennetts
  • Date: 2008-02-12 01:56:09 UTC
  • mto: (3245.4.1 Version 3 implementation.)
  • mto: This revision was merged to the branch mainline in revision 3428.
  • Revision ID: andrew.bennetts@canonical.com-20080212015609-loaxv5te0eb6uot8
Make the general request handler dispatch version 3 events to the specific request handler (i.e. to the SmartServerRequest instance).

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
"""Basic server-side logic for dealing with requests."""
18
 
 
 
17
"""Basic server-side logic for dealing with requests.
 
18
 
 
19
**XXX**:
 
20
 
 
21
The class names are a little confusing: the protocol will instantiate a
 
22
SmartServerRequestHandler, whose dispatch_command method creates an instance of
 
23
a SmartServerRequest subclass.
 
24
 
 
25
The request_handlers registry tracks SmartServerRequest classes (rather than
 
26
SmartServerRequestHandler).
 
27
"""
19
28
 
20
29
import tempfile
21
30
 
73
82
        
74
83
        Must return a SmartServerResponse.
75
84
        """
76
 
        # TODO: if a client erroneously sends a request that shouldn't have a
77
 
        # body, what to do?  Probably SmartServerRequestHandler should catch
78
 
        # this NotImplementedError and translate it into a 'bad request' error
79
 
        # to send to the client.
80
85
        raise NotImplementedError(self.do_body)
81
86
 
 
87
    def do_chunk(self, chunk_bytes):
 
88
        """Called with each body chunk if the request has a streamed body.
 
89
 
 
90
        The do() method is still called, and must have returned None.
 
91
        """
 
92
        raise NotImplementedError(self.do_chunk)
 
93
 
 
94
    def do_end(self):
 
95
        """Called when the end of the request has been received."""
 
96
        pass
 
97
 
82
98
 
83
99
class SmartServerResponse(object):
84
100
    """A response to a client request.
241
257
        pass
242
258
 
243
259
    def args_received(self, args):
244
 
        # XXX
245
 
        pass
 
260
        cmd = args[0]
 
261
        args = args[1:]
 
262
        try:
 
263
            command = self._commands.get(cmd)
 
264
        except LookupError:
 
265
            raise errors.SmartProtocolError("bad request %r" % (cmd,))
 
266
        self._command = command(self._backing_transport)
 
267
        self._run_handler_code(self._command.execute, args, {})
246
268
 
247
269
    def no_body_received(self):
248
270
        # XXX
249
271
        pass
250
272
 
251
273
    def prefixed_body_received(self, body_bytes):
252
 
        # XXX
253
 
        pass
 
274
        """No more body data will be received."""
 
275
        self._run_handler_code(self._command.do_body, (body_bytes,), {})
 
276
        # cannot read after this.
 
277
        self.finished_reading = True
254
278
 
255
279
    def body_chunk_received(self, chunk_bytes):
256
 
        # XXX
257
 
        pass
 
280
        self._run_handler_code(self._command.do_chunk, (chunk_bytes,), {})
258
281
 
 
282
    def end_received(self):
 
283
        self._run_handler_code(self._command.do_end, (), {})
259
284
 
260
285
 
261
286
class HelloRequest(SmartServerRequest):