~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Andrew Bennetts
  • Date: 2008-04-07 08:17:38 UTC
  • mto: This revision was merged to the branch mainline in revision 3349.
  • Revision ID: andrew.bennetts@canonical.com-20080407081738-yx4c53pvqfif313d
SmartClientRequestProtocol*.read_response_tuple can now raise UnknownSmartMethod.  Callers no longer need to do their own ad hoc unknown smart method error detection.

Show diffs side-by-side

added added

removed removed

Lines of Context:
150
150
    def open_repository(self):
151
151
        path = self._path_for_remote_call(self._client)
152
152
        verb = 'BzrDir.find_repositoryV2'
153
 
        response = self._client.call(verb, path)
154
 
        if (response == ('error', "Generic bzr smart protocol error: "
155
 
                "bad request '%s'" % verb) or
156
 
              response == ('error', "Generic bzr smart protocol error: "
157
 
                "bad request u'%s'" % verb)):
 
153
        try:
 
154
            response = self._client.call(verb, path)
 
155
        except errors.UnknownSmartMethod:
158
156
            verb = 'BzrDir.find_repository'
159
157
            response = self._client.call(verb, path)
160
158
        assert response[0] in ('ok', 'norepository'), \
630
628
        """
631
629
        import tempfile
632
630
        path = self.bzrdir._path_for_remote_call(self._client)
633
 
        response, protocol = self._client.call_expecting_body(
634
 
            'Repository.tarball', path, compression)
 
631
        try:
 
632
            response, protocol = self._client.call_expecting_body(
 
633
                'Repository.tarball', path, compression)
 
634
        except errors.UnknownSmartMethod:
 
635
            protocol.cancel_read_body()
 
636
            return None
635
637
        if response[0] == 'ok':
636
638
            # Extract the tarball and return it
637
639
            t = tempfile.NamedTemporaryFile()
639
641
            t.write(protocol.read_body_bytes())
640
642
            t.seek(0)
641
643
            return t
642
 
        if (response == ('error', "Generic bzr smart protocol error: "
643
 
                "bad request 'Repository.tarball'") or
644
 
              response == ('error', "Generic bzr smart protocol error: "
645
 
                "bad request u'Repository.tarball'")):
646
 
            protocol.cancel_read_body()
647
 
            return None
648
644
        raise errors.UnexpectedSmartServerResponse(response)
649
645
 
650
646
    def sprout(self, to_bzrdir, revision_id=None):
811
807
                100.0 * len(self._requested_parents) / len(ancestry))
812
808
        return dict((k, ancestry[k]) for k in present_keys)
813
809
 
814
 
    def _response_is_unknown_method(self, response, verb):
815
 
        """Return True if response is an unknonwn method response to verb.
816
 
        
817
 
        :param response: The response from a smart client call_expecting_body
818
 
            call.
819
 
        :param verb: The verb used in that call.
820
 
        :return: True if an unknown method was encountered.
821
 
        """
822
 
        # This might live better on
823
 
        # bzrlib.smart.protocol.SmartClientRequestProtocolOne
824
 
        if (response[0] == ('error', "Generic bzr smart protocol error: "
825
 
                "bad request '%s'" % verb) or
826
 
              response[0] == ('error', "Generic bzr smart protocol error: "
827
 
                "bad request u'%s'" % verb)):
828
 
           response[1].cancel_read_body()
829
 
           return True
830
 
        return False
831
 
 
832
810
    def _get_parent_map(self, keys):
833
811
        """Helper for get_parent_map that performs the RPC."""
834
812
        medium = self._client.get_smart_medium()
875
853
            assert type(key) is str
876
854
        verb = 'Repository.get_parent_map'
877
855
        args = (path,) + tuple(keys)
878
 
        response = self._client.call_with_body_bytes_expecting_body(
879
 
            verb, args, self._serialise_search_recipe(recipe))
880
 
        if self._response_is_unknown_method(response, verb):
 
856
        try:
 
857
            response = self._client.call_with_body_bytes_expecting_body(
 
858
                verb, args, self._serialise_search_recipe(recipe))
 
859
        except errors.UnknownSmartMethod:
881
860
            # Server does not support this method, so get the whole graph.
882
861
            # Worse, we have to force a disconnection, because the server now
883
862
            # doesn't realise it has a body on the wire to consume, so the
890
869
            # fact the server doesn't understand remote methods added in 1.2.
891
870
            medium._remote_is_at_least_1_2 = False
892
871
            return self.get_revision_graph()
893
 
        elif response[0][0] not in ['ok']:
 
872
        if response[0][0] not in ['ok']:
894
873
            response[1].cancel_read_body()
895
874
            raise errors.UnexpectedSmartServerResponse(response[0])
896
875
        if response[0][0] == 'ok':
1053
1032
        REQUEST_NAME = 'Repository.stream_revisions_chunked'
1054
1033
        path = self.bzrdir._path_for_remote_call(self._client)
1055
1034
        body = self._serialise_search_recipe(search.get_recipe())
1056
 
        response, protocol = self._client.call_with_body_bytes_expecting_body(
1057
 
            REQUEST_NAME, (path,), body)
1058
 
 
1059
 
        if self._response_is_unknown_method((response, protocol), REQUEST_NAME):
 
1035
        try:
 
1036
            result = self._client.call_with_body_bytes_expecting_body(
 
1037
                REQUEST_NAME, (path,), body)
 
1038
            response, protocol = result
 
1039
        except errors.UnknownSmartMethod:
1060
1040
            # Server does not support this method, so fall back to VFS.
1061
1041
            # Worse, we have to force a disconnection, because the server now
1062
1042
            # doesn't realise it has a body on the wire to consume, so the