38
from bzrlib.bundle.serializer import write_bundle
38
from bzrlib.lazy_import import lazy_import
39
lazy_import(globals(), """
40
from bzrlib.bundle import serializer
41
44
class SmartServerRequest(object):
179
182
other.body_stream is self.body_stream)
181
184
def __repr__(self):
182
status = {True: 'OK', False: 'ERR'}[self.is_successful()]
183
return "<SmartServerResponse status=%s args=%r body=%r>" % (status,
185
return "<%s args=%r body=%r>" % (self.__class__.__name__,
184
186
self.args, self.body)
288
290
except errors.ShortReadvError, e:
289
291
return FailedSmartServerResponse(('ShortReadvError',
290
292
e.path, str(e.offset), str(e.length), str(e.actual)))
293
except errors.UnstackableRepositoryFormat, e:
294
return FailedSmartServerResponse(('UnstackableRepositoryFormat',
295
str(e.format), e.url))
296
except errors.UnstackableBranchFormat, e:
297
return FailedSmartServerResponse(('UnstackableBranchFormat',
298
str(e.format), e.url))
299
except errors.NotStacked, e:
300
return FailedSmartServerResponse(('NotStacked',))
291
301
except UnicodeError, e:
292
302
# If it is a DecodeError, than most likely we are starting
293
303
# with a plain string
294
304
str_or_unicode = e.object
295
305
if isinstance(str_or_unicode, unicode):
296
# XXX: UTF-8 might have \x01 (our seperator byte) in it. We
297
# should escape it somehow.
306
# XXX: UTF-8 might have \x01 (our protocol v1 and v2 seperator
307
# byte) in it, so this encoding could cause broken responses.
308
# Newer clients use protocol v3, so will be fine.
298
309
val = 'u:' + str_or_unicode.encode('utf-8')
300
311
val = 's:' + str_or_unicode.encode('base64')
306
317
return FailedSmartServerResponse(('ReadOnlyError', ))
320
except errors.ReadError, e:
321
# cannot read the file
322
return FailedSmartServerResponse(('ReadError', e.path))
323
except errors.PermissionDenied, e:
324
return FailedSmartServerResponse(
325
('PermissionDenied', e.path, e.extra))
310
327
def headers_received(self, headers):
311
328
# Just a no-op at the moment.
353
370
repo = control.open_repository()
354
371
tmpf = tempfile.TemporaryFile()
355
372
base_revision = revision.NULL_REVISION
356
write_bundle(repo, revision_id, base_revision, tmpf)
373
serializer.write_bundle(repo, revision_id, base_revision, tmpf)
358
375
return SuccessfulSmartServerResponse((), tmpf.read())
375
392
request_handlers.register_lazy(
376
393
'Branch.get_config_file', 'bzrlib.smart.branch', 'SmartServerBranchGetConfigFile')
377
394
request_handlers.register_lazy(
395
'Branch.get_stacked_on_url', 'bzrlib.smart.branch', 'SmartServerBranchRequestGetStackedOnURL')
396
request_handlers.register_lazy(
378
397
'Branch.last_revision_info', 'bzrlib.smart.branch', 'SmartServerBranchRequestLastRevisionInfo')
379
398
request_handlers.register_lazy(
380
399
'Branch.lock_write', 'bzrlib.smart.branch', 'SmartServerBranchRequestLockWrite')
424
443
'readv', 'bzrlib.smart.vfs', 'ReadvRequest')
425
444
request_handlers.register_lazy(
426
445
'rename', 'bzrlib.smart.vfs', 'RenameRequest')
446
request_handlers.register_lazy(
447
'PackRepository.autopack', 'bzrlib.smart.packrepository',
448
'SmartServerPackRepositoryAutopack')
427
449
request_handlers.register_lazy('Repository.gather_stats',
428
450
'bzrlib.smart.repository',
429
451
'SmartServerRepositoryGatherStats')