~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/remote.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""RemoteTransport client for the smart-server.
18
18
 
34
34
    urlutils,
35
35
    )
36
36
from bzrlib.smart import client, medium
37
 
from bzrlib.symbol_versioning import (deprecated_method, one_four)
 
37
from bzrlib.symbol_versioning import (
 
38
    deprecated_method,
 
39
    )
38
40
 
39
41
 
40
42
class _SmartStat(object):
52
54
 
53
55
    The connection has a notion of the current directory to which it's
54
56
    connected; this is incorporated in filenames passed to the server.
55
 
    
56
 
    This supports some higher-level RPC operations and can also be treated 
 
57
 
 
58
    This supports some higher-level RPC operations and can also be treated
57
59
    like a Transport to do file-like operations.
58
60
 
59
61
    The connection can be made over a tcp socket, an ssh pipe or a series of
67
69
    # IMPORTANT FOR IMPLEMENTORS: RemoteTransport MUST NOT be given encoding
68
70
    # responsibilities: Put those on SmartClient or similar. This is vital for
69
71
    # the ability to support multiple versions of the smart protocol over time:
70
 
    # RemoteTransport is an adapter from the Transport object model to the 
 
72
    # RemoteTransport is an adapter from the Transport object model to the
71
73
    # SmartClient model, not an encoder.
72
74
 
73
75
    # FIXME: the medium parameter should be private, only the tests requires
90
92
            should only be used for testing purposes; normally this is
91
93
            determined from the medium.
92
94
        """
93
 
        super(RemoteTransport, self).__init__(url,
94
 
                                              _from_transport=_from_transport)
 
95
        super(RemoteTransport, self).__init__(
 
96
            url, _from_transport=_from_transport)
95
97
 
96
98
        # The medium is the connection, except when we need to share it with
97
99
        # other objects (RemoteBzrDir, RemoteRepository etc). In these cases
98
100
        # what we want to share is really the shared connection.
99
101
 
100
 
        if _from_transport is None:
 
102
        if (_from_transport is not None
 
103
            and isinstance(_from_transport, RemoteTransport)):
 
104
            _client = _from_transport._client
 
105
        elif _from_transport is None:
101
106
            # If no _from_transport is specified, we need to intialize the
102
107
            # shared medium.
103
108
            credentials = None
133
138
        # No credentials
134
139
        return None, None
135
140
 
 
141
    def _report_activity(self, bytes, direction):
 
142
        """See Transport._report_activity.
 
143
 
 
144
        Does nothing; the smart medium will report activity triggered by a
 
145
        RemoteTransport.
 
146
        """
 
147
        pass
 
148
 
136
149
    def is_readonly(self):
137
150
        """Smart server transport can do read/write file operations."""
138
151
        try:
155
168
    def get_smart_medium(self):
156
169
        return self._get_connection()
157
170
 
158
 
    @deprecated_method(one_four)
159
 
    def get_shared_medium(self):
160
 
        return self._get_shared_connection()
161
 
 
162
171
    def _remote_path(self, relpath):
163
172
        """Returns the Unicode version of the absolute path for relpath."""
164
173
        return self._combine_paths(self._path, relpath)
206
215
 
207
216
    def get(self, relpath):
208
217
        """Return file-like object reading the contents of a remote file.
209
 
        
 
218
 
210
219
        :see: Transport.get_bytes()/get_file()
211
220
        """
212
221
        return StringIO(self.get_bytes(relpath))
291
300
 
292
301
    def append_file(self, relpath, from_file, mode=None):
293
302
        return self.append_bytes(relpath, from_file.read(), mode)
294
 
        
 
303
 
295
304
    def append_bytes(self, relpath, bytes, mode=None):
296
305
        resp = self._call_with_body_bytes(
297
306
            'append',
313
322
    def recommended_page_size(self):
314
323
        """Return the recommended page size for this transport."""
315
324
        return 64 * 1024
316
 
        
 
325
 
317
326
    def _readv(self, relpath, offsets):
318
327
        if not offsets:
319
328
            return
421
430
    def _ensure_ok(self, resp):
422
431
        if resp[0] != 'ok':
423
432
            raise errors.UnexpectedSmartServerResponse(resp)
424
 
        
 
433
 
425
434
    def _translate_error(self, err, relpath=None):
426
435
        remote._translate_error(err, path=relpath)
427
436
 
465
474
 
466
475
class RemoteTCPTransport(RemoteTransport):
467
476
    """Connection to smart server over plain tcp.
468
 
    
 
477
 
469
478
    This is essentially just a factory to get 'RemoteTransport(url,
470
479
        SmartTCPClientMedium).
471
480
    """
513
522
 
514
523
class RemoteHTTPTransport(RemoteTransport):
515
524
    """Just a way to connect between a bzr+http:// url and http://.
516
 
    
 
525
 
517
526
    This connection operates slightly differently than the RemoteSSHTransport.
518
527
    It uses a plain http:// transport underneath, which defines what remote
519
528
    .bzr/smart URL we are connected to. From there, all paths that are sent are
584
593
    """Simple transport that handles ssh:// and points out bzr+ssh://."""
585
594
 
586
595
    def __init__(self, url):
587
 
        raise errors.UnsupportedProtocol(url, 
 
596
        raise errors.UnsupportedProtocol(url,
588
597
            'bzr supports bzr+ssh to operate over ssh, use "bzr+%s".' % url)
589
598
 
590
599