~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
27
"""
28
28
 
29
29
from cStringIO import StringIO
30
 
import re
31
30
import sys
32
31
 
33
32
from bzrlib.lazy_import import lazy_import
47
46
""")
48
47
 
49
48
from bzrlib.symbol_versioning import (
50
 
        DEPRECATED_PARAMETER,
51
 
        )
 
49
    DEPRECATED_PARAMETER,
 
50
    )
52
51
from bzrlib.trace import (
53
52
    mutter,
54
53
    )
84
83
    modules = set()
85
84
    for prefix, factory_list in transport_list_registry.items():
86
85
        for factory in factory_list:
87
 
            if hasattr(factory, "_module_name"):
88
 
                modules.add(factory._module_name)
89
 
            else:
90
 
                modules.add(factory._obj.__module__)
 
86
            modules.add(factory.get_module())
91
87
    # Add chroot and pathfilter directly, because there is no handler
92
88
    # registered for it.
93
89
    modules.add('bzrlib.transport.chroot')
676
672
 
677
673
        This uses _coalesce_offsets to issue larger reads and fewer seeks.
678
674
 
679
 
        :param fp: A file-like object that supports seek() and read(size)
 
675
        :param fp: A file-like object that supports seek() and read(size).
 
676
            Note that implementations are allowed to call .close() on this file
 
677
            handle, so don't trust that you can use it for other work.
680
678
        :param offsets: A list of offsets to be read from the given file.
681
679
        :return: yield (pos, data) tuples for each request
682
680
        """
693
691
 
694
692
        # Cache the results, but only until they have been fulfilled
695
693
        data_map = {}
696
 
        for c_offset in coalesced:
697
 
            # TODO: jam 20060724 it might be faster to not issue seek if
698
 
            #       we are already at the right location. This should be
699
 
            #       benchmarked.
700
 
            fp.seek(c_offset.start)
701
 
            data = fp.read(c_offset.length)
702
 
            if len(data) < c_offset.length:
703
 
                raise errors.ShortReadvError(relpath, c_offset.start,
704
 
                            c_offset.length, actual=len(data))
705
 
            for suboffset, subsize in c_offset.ranges:
706
 
                key = (c_offset.start+suboffset, subsize)
707
 
                data_map[key] = data[suboffset:suboffset+subsize]
 
694
        try:
 
695
            for c_offset in coalesced:
 
696
                # TODO: jam 20060724 it might be faster to not issue seek if
 
697
                #       we are already at the right location. This should be
 
698
                #       benchmarked.
 
699
                fp.seek(c_offset.start)
 
700
                data = fp.read(c_offset.length)
 
701
                if len(data) < c_offset.length:
 
702
                    raise errors.ShortReadvError(relpath, c_offset.start,
 
703
                                c_offset.length, actual=len(data))
 
704
                for suboffset, subsize in c_offset.ranges:
 
705
                    key = (c_offset.start+suboffset, subsize)
 
706
                    data_map[key] = data[suboffset:suboffset+subsize]
708
707
 
709
 
            # Now that we've read some data, see if we can yield anything back
710
 
            while cur_offset_and_size in data_map:
711
 
                this_data = data_map.pop(cur_offset_and_size)
712
 
                this_offset = cur_offset_and_size[0]
713
 
                try:
714
 
                    cur_offset_and_size = offset_stack.next()
715
 
                except StopIteration:
716
 
                    # Close the file handle as there will be no more data
717
 
                    # The handle would normally be cleaned up as this code goes
718
 
                    # out of scope, but as we are a generator, not all code
719
 
                    # will re-enter once we have consumed all the expected
720
 
                    # data. For example:
721
 
                    #   zip(range(len(requests)), readv(foo, requests))
722
 
                    # Will stop because the range is done, and not run the
723
 
                    # cleanup code for the readv().
724
 
                    fp.close()
725
 
                    cur_offset_and_size = None
726
 
                yield this_offset, this_data
 
708
                # Now that we've read some data, see if we can yield anything back
 
709
                while cur_offset_and_size in data_map:
 
710
                    this_data = data_map.pop(cur_offset_and_size)
 
711
                    this_offset = cur_offset_and_size[0]
 
712
                    try:
 
713
                        cur_offset_and_size = offset_stack.next()
 
714
                    except StopIteration:
 
715
                        cur_offset_and_size = None
 
716
                    yield this_offset, this_data
 
717
        except:
 
718
            fp.close()
 
719
            raise
 
720
        fp.close()
727
721
 
728
722
    def _sort_expand_and_combine(self, offsets, upper_limit):
729
723
        """Helper for readv.
1776
1770
register_lazy_transport('memory://', 'bzrlib.transport.memory',
1777
1771
                        'MemoryTransport')
1778
1772
 
1779
 
# chroots cannot be implicitly accessed, they must be explicitly created:
1780
 
register_transport_proto('chroot+')
1781
 
 
1782
1773
register_transport_proto('readonly+',
1783
1774
#              help="This modifier converts any transport to be readonly."
1784
1775
            )
1813
1804
register_lazy_transport('nosmart+', 'bzrlib.transport.nosmart',
1814
1805
                        'NoSmartTransportDecorator')
1815
1806
 
1816
 
# These two schemes were registered, but don't seem to have an actual transport
1817
 
# protocol registered
1818
 
for scheme in ['ssh', 'bzr+loopback']:
1819
 
    register_urlparse_netloc_protocol(scheme)
1820
 
del scheme
1821
 
 
1822
1807
register_transport_proto('bzr://',
1823
1808
            help="Fast access using the Bazaar smart server.",
1824
1809
                         register_netloc=True)