635
636
return SmartServerResponse(('ok', '1'))
637
638
def do_has(self, relpath):
639
relpath = relpath.encode('utf-8')
638
640
r = self._backing_transport.has(relpath) and 'yes' or 'no'
639
641
return SmartServerResponse((r,))
641
643
def do_get(self, relpath):
644
relpath = relpath.encode('utf-8')
642
645
backing_bytes = self._backing_transport.get_bytes(relpath)
643
646
return SmartServerResponse(('ok',), backing_bytes)
652
655
def do_append(self, relpath, mode):
653
656
self._converted_command = True
654
self._relpath = relpath
657
self._relpath = relpath.encode('utf-8')
655
658
self._mode = self._deserialise_optional_mode(mode)
656
659
self._end_of_body_handler = self._handle_do_append_end
661
664
self.response = SmartServerResponse(('appended', '%d' % old_length))
663
666
def do_delete(self, relpath):
667
relpath = relpath.encode('utf-8')
664
668
self._backing_transport.delete(relpath)
666
def do_iter_files_recursive(self, abspath):
667
# XXX: the path handling needs some thought.
668
#relpath = self._backing_transport.relpath(abspath)
669
transport = self._backing_transport.clone(abspath)
670
def do_iter_files_recursive(self, relpath):
671
relpath = relpath.encode('utf-8')
672
transport = self._backing_transport.clone(relpath)
670
673
filenames = transport.iter_files_recursive()
671
674
return SmartServerResponse(('names',) + tuple(filenames))
673
676
def do_list_dir(self, relpath):
677
relpath = relpath.encode('utf-8')
674
678
filenames = self._backing_transport.list_dir(relpath)
675
679
return SmartServerResponse(('names',) + tuple(filenames))
677
681
def do_mkdir(self, relpath, mode):
682
relpath = relpath.encode('utf-8')
678
683
self._backing_transport.mkdir(relpath,
679
684
self._deserialise_optional_mode(mode))
681
686
def do_move(self, rel_from, rel_to):
687
rel_from = rel_from.encode('utf-8')
688
rel_to = rel_to.encode('utf-8')
682
689
self._backing_transport.move(rel_from, rel_to)
684
691
def do_put(self, relpath, mode):
685
692
self._converted_command = True
686
self._relpath = relpath
693
self._relpath = relpath.encode('utf-8')
687
694
self._mode = self._deserialise_optional_mode(mode)
688
695
self._end_of_body_handler = self._handle_do_put
705
712
def do_put_non_atomic(self, relpath, mode, create_parent, dir_mode):
706
713
self._converted_command = True
707
714
self._end_of_body_handler = self._handle_put_non_atomic
708
self._relpath = relpath
715
self._relpath = relpath.encode('utf-8')
709
716
self._dir_mode = self._deserialise_optional_mode(dir_mode)
710
717
self._mode = self._deserialise_optional_mode(mode)
711
718
# a boolean would be nicer XXX
722
729
def do_readv(self, relpath):
723
730
self._converted_command = True
724
731
self._end_of_body_handler = self._handle_readv_offsets
725
self._relpath = relpath
732
self._relpath = relpath.encode('utf-8')
727
734
def end_of_body(self):
728
735
"""No more body data will be received."""
738
745
self.response = SmartServerResponse(('readv',), backing_bytes)
740
747
def do_rename(self, rel_from, rel_to):
748
rel_from = rel_from.encode('utf-8')
749
rel_to = rel_to.encode('utf-8')
741
750
self._backing_transport.rename(rel_from, rel_to)
743
752
def do_rmdir(self, relpath):
753
relpath = relpath.encode('utf-8')
744
754
self._backing_transport.rmdir(relpath)
746
756
def do_stat(self, relpath):
757
relpath = relpath.encode('utf-8')
747
758
stat = self._backing_transport.stat(relpath)
748
759
return SmartServerResponse(('stat', str(stat.st_size), oct(stat.st_mode)))