~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/gio_transport.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
It provides the gio+XXX:// protocols where XXX is any of the protocols
24
24
supported by gio.
25
25
"""
26
 
 
27
 
from __future__ import absolute_import
28
 
 
29
26
from cStringIO import StringIO
 
27
import getpass
30
28
import os
31
29
import random
 
30
import socket
32
31
import stat
 
32
import urllib
33
33
import time
 
34
import sys
 
35
import getpass
34
36
import urlparse
35
37
 
36
38
from bzrlib import (
47
49
    deprecated_passed,
48
50
    warn,
49
51
    )
50
 
from bzrlib.trace import mutter
 
52
from bzrlib.trace import mutter, warning
51
53
from bzrlib.transport import (
52
54
    FileStream,
53
55
    ConnectedTransport,
54
56
    _file_streams,
 
57
    Server,
55
58
    )
56
59
 
57
60
from bzrlib.tests.test_server import TestServer
168
171
        #really use bzrlib.auth get_password for this
169
172
        #or possibly better gnome-keyring?
170
173
        auth = config.AuthenticationConfig()
171
 
        parsed_url = urlutils.URL.from_string(self.url)
 
174
        (scheme, urluser, urlpassword, host, port, urlpath) = \
 
175
           urlutils.parse_url(self.url)
172
176
        user = None
173
177
        if (flags & gio.ASK_PASSWORD_NEED_USERNAME and
174
178
                flags & gio.ASK_PASSWORD_NEED_DOMAIN):
175
 
            prompt = (u'%s' % (parsed_url.scheme.upper(),) +
176
 
                      u' %(host)s DOMAIN\\username')
177
 
            user_and_domain = auth.get_user(parsed_url.scheme,
178
 
                parsed_url.host, port=parsed_url.port, ask=True,
179
 
                prompt=prompt)
 
179
            prompt = scheme.upper() + ' %(host)s DOMAIN\username'
 
180
            user_and_domain = auth.get_user(scheme, host,
 
181
                    port=port, ask=True, prompt=prompt)
180
182
            (domain, user) = user_and_domain.split('\\', 1)
181
183
            op.set_username(user)
182
184
            op.set_domain(domain)
183
185
        elif flags & gio.ASK_PASSWORD_NEED_USERNAME:
184
 
            user = auth.get_user(parsed_url.scheme, parsed_url.host,
185
 
                    port=parsed_url.port, ask=True)
 
186
            user = auth.get_user(scheme, host,
 
187
                    port=port, ask=True)
186
188
            op.set_username(user)
187
189
        elif flags & gio.ASK_PASSWORD_NEED_DOMAIN:
188
190
            #Don't know how common this case is, but anyway
189
191
            #a DOMAIN and a username prompt should be the
190
192
            #same so I will missuse the ui_factory get_username
191
193
            #a little bit here.
192
 
            prompt = (u'%s' % (parsed_url.scheme.upper(),) +
193
 
                      u' %(host)s DOMAIN')
 
194
            prompt = scheme.upper() + ' %(host)s DOMAIN'
194
195
            domain = ui.ui_factory.get_username(prompt=prompt)
195
196
            op.set_domain(domain)
196
197
 
197
198
        if flags & gio.ASK_PASSWORD_NEED_PASSWORD:
198
199
            if user is None:
199
200
                user = op.get_username()
200
 
            password = auth.get_password(parsed_url.scheme, parsed_url.host,
201
 
                    user, port=parsed_url.port)
 
201
            password = auth.get_password(scheme, host,
 
202
                    user, port=port)
202
203
            op.set_password(password)
203
204
        op.reply(gio.MOUNT_OPERATION_HANDLED)
204
205
 
212
213
 
213
214
    def _create_connection(self, credentials=None):
214
215
        if credentials is None:
215
 
            user, password = self._parsed_url.user, self._parsed_url.password
 
216
            user, password = self._user, self._password
216
217
        else:
217
218
            user, password = credentials
218
219
 
253
254
        self._set_connection(connection, credentials)
254
255
 
255
256
    def _remote_path(self, relpath):
256
 
        return self._parsed_url.clone(relpath).path
 
257
        relative = urlutils.unescape(relpath).encode('utf-8')
 
258
        remote_path = self._combine_paths(self._path, relative)
 
259
        return remote_path
257
260
 
258
261
    def has(self, relpath):
259
262
        """Does the target location exist?"""
271
274
            else:
272
275
                self._translate_gio_error(e, relpath)
273
276
 
274
 
    def get(self, relpath, retries=0):
 
277
    def get(self, relpath, decode=DEPRECATED_PARAMETER, retries=0):
275
278
        """Get the file at the given relative path.
276
279
 
277
280
        :param relpath: The relative path to the file
281
284
        We're meant to return a file-like object which bzr will
282
285
        then read from. For now we do this via the magic of StringIO
283
286
        """
 
287
        if deprecated_passed(decode):
 
288
            warn(deprecated_in((2,3,0)) %
 
289
                 '"decode" parameter to GioTransport.get()',
 
290
                 DeprecationWarning, stacklevel=2)
284
291
        try:
285
292
            if 'gio' in debug.debug_flags:
286
293
                mutter("GIO get: %s" % relpath)