~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Robert Collins
  • Date: 2005-10-20 03:06:20 UTC
  • mfrom: (1185.16.80)
  • Revision ID: robertc@robertcollins.net-20051020030620-3fa3160be265c585
mergeĀ fromĀ Martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
354
354
    # which has a lookup of None
355
355
    return _protocol_handlers[None](base)
356
356
 
357
 
# Local transport should always be initialized
358
 
import bzrlib.transport.local
359
357
 
360
358
def urlescape(relpath):
361
359
    """Escape relpath to be a valid url."""
364
362
    return urllib.quote(relpath)
365
363
 
366
364
 
367
 
def register_builtin_transports():
368
 
    """Register all builtin transport modules.
369
 
    
370
 
    This happens as a sideeffect of importing the modules.
 
365
def register_lazy_transport(scheme, module, classname):
 
366
    """Register lazy-loaded transport class.
 
367
 
 
368
    When opening a URL with the given scheme, load the module and then
 
369
    instantiate the particular class.  
371
370
    """
372
 
    import bzrlib.transport.local, \
373
 
           bzrlib.transport.http, \
374
 
           bzrlib.transport.sftp
 
371
    def _loader(base):
 
372
        mod = __import__(module, globals(), locals(), [classname])
 
373
        klass = getattr(mod, classname)
 
374
        return klass(base)
 
375
    register_transport(scheme, _loader)
 
376
 
 
377
 
 
378
# If nothing else matches, try the LocalTransport
 
379
register_lazy_transport(None, 'bzrlib.transport.local', 'LocalTransport')
 
380
register_lazy_transport('file://', 'bzrlib.transport.local', 'LocalTransport')
 
381
register_lazy_transport('sftp://', 'bzrlib.transport.sftp', 'SFTPTransport')
 
382
register_lazy_transport('http://', 'bzrlib.transport.http', 'HttpTransport')
 
383
register_lazy_transport('https://', 'bzrlib.transport.http', 'HttpTransport')