~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/request.py

Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
 
67
67
    def do_body(self, body_bytes):
68
68
        """Called if the client sends a body with the request.
 
69
 
 
70
        The do() method is still called, and must have returned None.
69
71
        
70
72
        Must return a SmartServerResponse.
71
73
        """
83
85
    SuccessfulSmartServerResponse and FailedSmartServerResponse as appropriate.
84
86
    """
85
87
 
86
 
    def __init__(self, args, body=None):
 
88
    def __init__(self, args, body=None, body_stream=None):
 
89
        """Constructor.
 
90
 
 
91
        :param args: tuple of response arguments.
 
92
        :param body: string of a response body.
 
93
        :param body_stream: iterable of bytestrings to be streamed to the
 
94
            client.
 
95
        """
87
96
        self.args = args
 
97
        if body is not None and body_stream is not None:
 
98
            raise errors.BzrError(
 
99
                "'body' and 'body_stream' are mutually exclusive.")
88
100
        self.body = body
 
101
        self.body_stream = body_stream
89
102
 
90
103
    def __eq__(self, other):
91
104
        if other is None:
92
105
            return False
93
 
        return other.args == self.args and other.body == self.body
 
106
        return (other.args == self.args and
 
107
                other.body == self.body and
 
108
                other.body_stream is self.body_stream)
94
109
 
95
110
    def __repr__(self):
96
 
        return "<SmartServerResponse args=%r body=%r>" % (self.is_successful(), 
97
 
            self.args, self.body)
 
111
        return ("<SmartServerResponse successful=%s args=%r body=%r>"
 
112
                % (self.is_successful(), self.args, self.body))
98
113
 
99
114
 
100
115
class FailedSmartServerResponse(SmartServerResponse):
271
286
request_handlers.register_lazy(
272
287
    'Branch.unlock', 'bzrlib.smart.branch', 'SmartServerBranchRequestUnlock')
273
288
request_handlers.register_lazy(
274
 
    'BzrDir.find_repository', 'bzrlib.smart.bzrdir', 'SmartServerRequestFindRepository')
 
289
    'BzrDir.find_repository', 'bzrlib.smart.bzrdir', 'SmartServerRequestFindRepositoryV1')
 
290
request_handlers.register_lazy(
 
291
    'BzrDir.find_repositoryV2', 'bzrlib.smart.bzrdir', 'SmartServerRequestFindRepositoryV2')
275
292
request_handlers.register_lazy(
276
293
    'BzrDirFormat.initialize', 'bzrlib.smart.bzrdir', 'SmartServerRequestInitializeBzrDir')
277
294
request_handlers.register_lazy(
305
322
request_handlers.register_lazy('Repository.gather_stats',
306
323
                               'bzrlib.smart.repository',
307
324
                               'SmartServerRepositoryGatherStats')
 
325
request_handlers.register_lazy('Repository.get_parent_map',
 
326
                               'bzrlib.smart.repository',
 
327
                               'SmartServerRepositoryGetParentMap')
 
328
request_handlers.register_lazy(
 
329
    'Repository.stream_knit_data_for_revisions',
 
330
    'bzrlib.smart.repository',
 
331
    'SmartServerRepositoryStreamKnitDataForRevisions')
 
332
request_handlers.register_lazy(
 
333
    'Repository.stream_revisions_chunked',
 
334
    'bzrlib.smart.repository',
 
335
    'SmartServerRepositoryStreamRevisionsChunked')
308
336
request_handlers.register_lazy(
309
337
    'Repository.get_revision_graph', 'bzrlib.smart.repository', 'SmartServerRepositoryGetRevisionGraph')
310
338
request_handlers.register_lazy(