/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/identitymap.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-12-01 15:06:29 UTC
  • mto: (2172.3.1 bzr.73948)
  • mto: This revision was merged to the branch mainline in revision 2181.
  • Revision ID: v.ladeuil+lp@free.fr-20061201150629-zjd2an87u0r7nhhw
The tests that would have help avoid bug #73948 and all that mess :)

* bzrlib/transport/http/response.py:
(handle_response): Translate a 416 http error code into a bzr
exception.

* bzrlib/transport/http/_urllib2_wrappers.py:
(HTTPDefaultErrorHandler.http_error_default): Translate a 416 http
error code into a bzr exception.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._curl_perform): It could happen that pycrul
itself detect a short read.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase._retry_get): New method, factorizing the retry
logic.
(HttpTransportBase.readv): We can have exception during the
initial GET worth degrading the range requirements (i.e. retrying
the GET request with either single or not ranges).

* bzrlib/tests/test_transport_implementations.py:
(TransportTests.test_readv_short_read): InvalidRange can also be
raised.

* bzrlib/tests/test_http.py:
(TestRangeRequestServer.test_readv_invalid_ranges): Was named
test_readv_short_read, the new name make the intent
clearer. Depending of the code path used (urllib or pycurl), both
exceptions can be raised.

* bzrlib/tests/HttpServer.py:
(TestingHTTPRequestHandler.do_GET): If invalid ranges are
specified, returns a 416 instead of the whole file (both are valid
according to the RFC).

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
"""This module provides an IdentityMap."""
19
19
 
20
20
 
21
 
from bzrlib import (
22
 
    errors,
23
 
    )
 
21
import bzrlib.errors as errors
24
22
 
25
23
 
26
24
class IdentityMap(object):
27
25
    """An in memory map from object id to instance.
28
 
 
 
26
    
29
27
    An IdentityMap maps from keys to single instances of objects in memory.
30
28
    We have explicit calls on the map for the root of each inheritance tree
31
29
    that is store in the map. Look for find_CLASS and add_CLASS methods.
32
30
    """
33
31
 
 
32
    def add_revision_history(self, revision_history):
 
33
        """Add a revision_history object to the map.
 
34
 
 
35
        There can only be one!
 
36
        """
 
37
        if self._revision_history is not None:
 
38
            raise errors.BzrError("A revision history (%s) is already "
 
39
                                  "identity map" % self._revision_history)
 
40
        self._revision_history = revision_history
 
41
 
34
42
    def add_weave(self, id, weave):
35
43
        """Add weave to the map with a given id."""
36
44
        if self._weave_key(id) in self._map:
38
46
        self._map[self._weave_key(id)] = weave
39
47
        self._reverse_map[weave] = self._weave_key(id)
40
48
 
 
49
    def find_revision_history(self):
 
50
        return self._revision_history
 
51
 
41
52
    def find_weave(self, id):
42
53
        """Return the weave for 'id', or None if it is not present."""
43
54
        return self._map.get(self._weave_key(id), None)
46
57
        super(IdentityMap, self).__init__()
47
58
        self._map = {}
48
59
        self._reverse_map = {}
 
60
        self._revision_history = None
49
61
 
50
62
    def remove_object(self, an_object):
51
63
        """Remove object from map."""
52
64
        if isinstance(an_object, list):
53
 
            raise KeyError('%r not in identity map' % an_object)
 
65
            if self._revision_history is an_object:
 
66
                self._revision_history = None
 
67
            else:
 
68
                raise KeyError('%r not in identity map' % an_object)
54
69
        else:
55
70
            self._map.pop(self._reverse_map[an_object])
56
71
            self._reverse_map.pop(an_object)
59
74
        """Return the key for a weaves id."""
60
75
        return "weave-" + id
61
76
 
62
 
 
 
77
        
63
78
class NullIdentityMap(object):
64
79
    """A pretend in memory map from object id to instance.
65
 
 
 
80
    
66
81
    A NullIdentityMap is an Identity map that does not store anything in it.
67
82
    """
68
83
 
69
84
    def add_weave(self, id, weave):
70
85
        """See IdentityMap.add_weave."""
71
86
 
 
87
    def add_revision_history(self, revision_history):
 
88
        """See IdentityMap.add_revision_history."""
 
89
 
72
90
    def find_weave(self, id):
73
91
        """See IdentityMap.find_weave."""
74
92
        return None
 
93
 
 
94
    def find_revision_history(self):
 
95
        """See IdentityMap.find_revision_history."""