-=[ Mr. Bumblebee ]=-
_Indonesia_

Path : /usr/lib/python2.7/dist-packages/bzrlib/
File Upload :
Current File : //usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyc

ó
î:ïNc@@sVdZddlmZddlmZdefd„ƒYZdefd„ƒYZdS(	s)A simple first-in-first-out (FIFO) cache.i(tabsolute_import(tdequet	FIFOCachecB@s§eZdZddd„Zd„Zd„Zdd„Zd„Zd„Z	d„Z
d	„Zd
„Zdd„Z
d„Zdd
„Zd„Zdd„Zd„ZRS(s<A class which manages a cache of entries, removing old ones.idcC@sgtj|ƒ||_|dkr9|jdd|_nt||jƒ|_i|_tƒ|_dS(Nii
(	tdictt__init__t
_max_cachetNonet_after_cleanup_counttmint_cleanupRt_queue(tselft	max_cachetafter_cleanup_count((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyRs
		cC@s|j||ddƒdS(s<Add a value to the cache, there will be no cleanup function.tcleanupN(taddR(Rtkeytvalue((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyt__setitem__&scC@spt|jddƒ}|dk	r.||ƒn1tg|jD]}||kr;|^q;ƒ|_|j|ƒdS(Ntremove(tgetattrR
RRt_remove(RRRtk((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyt__delitem__*s

1cC@s{||kr||=n|jj|ƒtj|||ƒ|dk	rU||j|<nt|ƒ|jkrw|jƒndS(s}Add a new value to the cache.

        Also, if the entry is ever removed from the queue, call cleanup.
        Passing it the key and value being removed.

        :param key: The key to store it under
        :param value: The object to store
        :param cleanup: None or a function taking (key, value) to indicate
                        'value' should be cleaned up
        N(	R
tappendRRRR	tlenRR(RRRR((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyR8s
cC@s|jS(s(Get the number of entries we will cache.(R(R((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyt
cache_sizeNscC@smx#t|ƒ|jkr%|jƒqWt|jƒt|ƒkritdt|jƒt|ƒfƒ‚ndS(s¯Clear the cache until it shrinks to the requested size.

        This does not completely wipe the cache, just makes sure it is under
        the after_cleanup_count.
        sLThe length of the queue should always equal the length of the dict. %s != %sN(RRt_remove_oldestR
tAssertionError(R((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyRRs
cC@sx|r|jƒqWdS(sClear out all of the cache.N(R(R((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pytclear`s	cC@sG|jj|dƒ}tj||ƒ}|dk	rC|||ƒn|S(s:Remove an entry, making sure to call any cleanup function.N(R	tpopRR(RRRtval((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyRfs
cC@s |jjƒ}|j|ƒdS(sRemove the oldest entry.N(R
tpopleftR(RR((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyRpscC@sa||_|dkr)|dd|_nt||ƒ|_t|ƒ|jkr]|jƒndS(sIncrease/decrease the number of cached entries.

        :param max_cache: The maximum number of entries to cache.
        :param after_cleanup_count: After cleanup, we should have at most this
            many entries. This defaults to 80% of max_cache.
        ii
N(RRRRRR(RRR
((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pytresizeus	cC@st|jƒ‚dS(N(tNotImplementedErrortcopy(R((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyR#†scC@st|jƒ‚dS(N(R"R(RRtdefault((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyR‰scC@st|jƒ‚dS(N(R"tpopitem(R((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyR%‘scC@s"||kr||S|||<|S(ssimilar to dict.setdefault((RRt
defaultval((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyt
setdefault•s
cO@sît|ƒdkr‰|d}t|tƒr[xX|jƒD]\}}|j||ƒq8Wq´xV|dD]\}}|j||ƒqfWn+t|ƒdkr´tdt|ƒƒ‚n|rêx-|jƒD]\}}|j||ƒqÇWndS(sSimilar to dict.update()iis*update expected at most 1 argument, got %dN(Rt
isinstanceRt	iteritemsRt	TypeError(RtargstkwargstargRR((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pytupdateœs
N(t__name__t
__module__t__doc__RRRRRRRRRRR!R#RR%R'R.(((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyRs 						
			t
FIFOSizeCachecB@sSeZdZdd	d	d„Zd	d„Zd„Zd„Zd„Zd	d„Z	RS(
sÙAn FIFOCache that removes things based on the size of the values.

    This differs in that it doesn't care how many actual items there are,
    it restricts the cache to be cleaned based on the size of the data.
    icC@s‚tj|d|ƒ||_|dkr?|jdd|_nt||jƒ|_d|_||_|dkr~t|_ndS(sŠCreate a new FIFOSizeCache.

        :param max_size: The max number of bytes to store before we start
            clearing out entries.
        :param after_cleanup_size: After cleaning up, shrink everything to this
            size (defaults to 80% of max_size).
        :param compute_size: A function to compute the size of a value. If
            not supplied we default to 'len'.
        Rii
iN(	RRt	_max_sizeRt_after_cleanup_sizeRt_value_sizet
_compute_sizeR(Rtmax_sizetafter_cleanup_sizetcompute_size((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyRµs			cC@s©||kr||=n|j|ƒ}||jkr8dS|jj|ƒtj|||ƒ|dk	rw||j|<n|j|7_|j|j	kr¥|j
ƒndS(sÜAdd a new value to the cache.

        Also, if the entry is ever removed from the queue, call cleanup.
        Passing it the key and value being removed.

        :param key: The key to store it under
        :param value: The object to store, this value by itself is >=
            after_cleanup_size, then we will not store it at all.
        :param cleanup: None or a function taking (key, value) to indicate
                        'value' sohuld be cleaned up.
        N(R6R4R
RRRRR	R5R3R(RRRRt	value_len((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyRÍs
cC@s|jS(s&Get the number of bytes we will cache.(R3(R((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyRëscC@s'x |j|jkr"|jƒqWdS(s®Clear the cache until it shrinks to the requested size.

        This does not completely wipe the cache, just makes sure it is under
        the after_cleanup_size.
        N(R5R4R(R((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyRïscC@s.tj||ƒ}|j|j|ƒ8_|S(s8Remove an entry, making sure to maintain the invariants.(RRR5R6(RRR((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyRùscC@sntj||ƒ||_|dkr9|dd|_nt||ƒ|_|j|jkrj|jƒndS(sIncrease/decrease the amount of cached data.

        :param max_size: The maximum number of bytes to cache.
        :param after_cleanup_size: After cleanup, we should have at most this
            many bytes cached. This defaults to 80% of max_size.
        ii
N(RR!R3RR4RR5R(RR7R8((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyR!ÿs	iN(
R/R0R1RRRRRRR!(((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyR2®s		
	N(R1t
__future__RtcollectionsRRRR2(((s5/usr/lib/python2.7/dist-packages/bzrlib/fifo_cache.pyt<module>s–

Copyright © 2017 || Recoded By Mr.Bumblebee