/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 breezy/fifo_cache.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 00:06:46 UTC
  • mfrom: (6673 work)
  • mto: This revision was merged to the branch mainline in revision 6675.
  • Revision ID: jelmer@jelmer.uk-20170610000646-xj6jh277lo4xuo10
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""A simple first-in-first-out (FIFO) cache."""
18
18
 
19
 
from __future__ import absolute_import
 
19
from __future__ import absolute_import, division
20
20
 
21
21
from collections import deque
22
22
 
28
28
        dict.__init__(self)
29
29
        self._max_cache = max_cache
30
30
        if after_cleanup_count is None:
31
 
            self._after_cleanup_count = self._max_cache * 8 / 10
 
31
            self._after_cleanup_count = self._max_cache * 8 // 10
32
32
        else:
33
33
            self._after_cleanup_count = min(after_cleanup_count,
34
34
                                            self._max_cache)
123
123
        """
124
124
        self._max_cache = max_cache
125
125
        if after_cleanup_count is None:
126
 
            self._after_cleanup_count = max_cache * 8 / 10
 
126
            self._after_cleanup_count = max_cache * 8 // 10
127
127
        else:
128
128
            self._after_cleanup_count = min(max_cache, after_cleanup_count)
129
129
        if len(self) > self._max_cache:
158
158
        if len(args) == 1:
159
159
            arg = args[0]
160
160
            if isinstance(arg, dict):
161
 
                for key, val in arg.iteritems():
162
 
                    self.add(key, val)
 
161
                for key in arg:
 
162
                    self.add(key, arg[key])
163
163
            else:
164
164
                for key, val in args[0]:
165
165
                    self.add(key, val)
167
167
            raise TypeError('update expected at most 1 argument, got %d'
168
168
                            % len(args))
169
169
        if kwargs:
170
 
            for key, val in kwargs.iteritems():
171
 
                self.add(key, val)
 
170
            for key in kwargs:
 
171
                self.add(key, kwargs[key])
172
172
 
173
173
 
174
174
class FIFOSizeCache(FIFOCache):
193
193
        FIFOCache.__init__(self, max_cache=max_size)
194
194
        self._max_size = max_size
195
195
        if after_cleanup_size is None:
196
 
            self._after_cleanup_size = self._max_size * 8 / 10
 
196
            self._after_cleanup_size = self._max_size * 8 // 10
197
197
        else:
198
198
            self._after_cleanup_size = min(after_cleanup_size, self._max_size)
199
199
 
262
262
        FIFOCache.resize(self, max_size)
263
263
        self._max_size = max_size
264
264
        if after_cleanup_size is None:
265
 
            self._after_cleanup_size = max_size * 8 / 10
 
265
            self._after_cleanup_size = max_size * 8 // 10
266
266
        else:
267
267
            self._after_cleanup_size = min(max_size, after_cleanup_size)
268
268
        if self._value_size > self._max_size: