~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/request.py

merge bzr.dev r4054

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
class SmartServerRequest(object):
45
45
    """Base class for request handlers.
46
 
    
 
46
 
47
47
    To define a new request, subclass this class and override the `do` method
48
48
    (and if appropriate, `do_body` as well).  Request implementors should take
49
49
    care to call `translate_client_path` and `transport_from_client_path` as
78
78
 
79
79
    def do(self, *args):
80
80
        """Mandatory extension point for SmartServerRequest subclasses.
81
 
        
 
81
 
82
82
        Subclasses must implement this.
83
 
        
 
83
 
84
84
        This should return a SmartServerResponse if this command expects to
85
85
        receive no body.
86
86
        """
101
101
        """Called if the client sends a body with the request.
102
102
 
103
103
        The do() method is still called, and must have returned None.
104
 
        
 
104
 
105
105
        Must return a SmartServerResponse.
106
106
        """
107
 
        raise NotImplementedError(self.do_body)
 
107
        if body_bytes != '':
 
108
            raise errors.SmartProtocolError('Request does not expect a body')
108
109
 
109
110
    def do_chunk(self, chunk_bytes):
110
111
        """Called with each body chunk if the request has a streamed body.
118
119
        body_bytes = ''.join(self._body_chunks)
119
120
        self._body_chunks = None
120
121
        return self.do_body(body_bytes)
121
 
    
 
122
 
122
123
    def translate_client_path(self, client_path):
123
124
        """Translate a path received from a network client into a local
124
125
        relpath.
157
158
 
158
159
class SmartServerResponse(object):
159
160
    """A response to a client request.
160
 
    
 
161
 
161
162
    This base class should not be used. Instead use
162
163
    SuccessfulSmartServerResponse and FailedSmartServerResponse as appropriate.
163
164
    """
207
208
 
208
209
class SmartServerRequestHandler(object):
209
210
    """Protocol logic for smart server.
210
 
    
 
211
 
211
212
    This doesn't handle serialization at all, it just processes requests and
212
213
    creates responses.
213
214
    """
239
240
    def accept_body(self, bytes):
240
241
        """Accept body data."""
241
242
        self._run_handler_code(self._command.do_chunk, (bytes,), {})
242
 
        
 
243
 
243
244
    def end_of_body(self):
244
245
        """No more body data will be received."""
245
246
        self._run_handler_code(self._command.do_end, (), {})
400
401
request_handlers.register_lazy(
401
402
    'Branch.unlock', 'bzrlib.smart.branch', 'SmartServerBranchRequestUnlock')
402
403
request_handlers.register_lazy(
 
404
    'BzrDir.create_branch', 'bzrlib.smart.bzrdir', 'SmartServerRequestCreateBranch')
 
405
request_handlers.register_lazy(
 
406
    'BzrDir.create_repository', 'bzrlib.smart.bzrdir', 'SmartServerRequestCreateRepository')
 
407
request_handlers.register_lazy(
403
408
    'BzrDir.find_repository', 'bzrlib.smart.bzrdir', 'SmartServerRequestFindRepositoryV1')
404
409
request_handlers.register_lazy(
405
410
    'BzrDir.find_repositoryV2', 'bzrlib.smart.bzrdir', 'SmartServerRequestFindRepositoryV2')
447
452
request_handlers.register_lazy(
448
453
    'Repository.has_revision', 'bzrlib.smart.repository', 'SmartServerRequestHasRevision')
449
454
request_handlers.register_lazy(
 
455
    'Repository.insert_stream', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream')
 
456
request_handlers.register_lazy(
450
457
    'Repository.is_shared', 'bzrlib.smart.repository', 'SmartServerRepositoryIsShared')
451
458
request_handlers.register_lazy(
452
459
    'Repository.lock_write', 'bzrlib.smart.repository', 'SmartServerRepositoryLockWrite')
453
460
request_handlers.register_lazy(
 
461
    'Repository.set_make_working_trees', 'bzrlib.smart.repository',
 
462
    'SmartServerRepositorySetMakeWorkingTrees')
 
463
request_handlers.register_lazy(
454
464
    'Repository.unlock', 'bzrlib.smart.repository', 'SmartServerRepositoryUnlock')
455
465
request_handlers.register_lazy(
456
466
    'Repository.tarball', 'bzrlib.smart.repository',