Ñò ûãtHc@sÄdZddkZddkZyeWn3ej o'ddklZddklZnXdZ de fd„ƒYZ d„Z e d „Zeid ƒZed „Zeid ƒZd „ZdS(s&Various utility classes and functions.iÿÿÿÿN(t ImmutableSet(tSetsrestructuredtext entLRUCachecBs~eZdZdefd„ƒYZd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „ZRS( sdA dictionary-like object that stores only a certain number of items, and discards its least recently used item when full. >>> cache = LRUCache(3) >>> cache['A'] = 0 >>> cache['B'] = 1 >>> cache['C'] = 2 >>> len(cache) 3 >>> cache['A'] 0 Adding new items to the cache does not increase its size. Instead, the least recently used item is dropped: >>> cache['D'] = 3 >>> len(cache) 3 >>> 'B' in cache False Iterating over the cache returns the keys, starting with the most recently used: >>> for key in cache: ... print key D A C This code is based on the LRUCache class from ``myghtyutils.util``, written by Mike Bayer and released under the MIT license. See: http://svn.myghty.org/myghtyutils/trunk/lib/myghtyutils/util.py t_ItemcBseZd„Zd„ZRS(cCs&d|_|_||_||_dS(N(tNonetprevioustnexttkeytvalue(tselfRR((s1/usr/lib64/python2.6/site-packages/genshi/util.pyt__init__Bs cCs t|iƒS(N(treprR(R ((s1/usr/lib64/python2.6/site-packages/genshi/util.pyt__repr__Fs(t__name__t __module__R R (((s1/usr/lib64/python2.6/site-packages/genshi/util.pyRAs cCs+tƒ|_||_d|_d|_dS(N(tdictt_dicttcapacityRtheadttail(R R((s1/usr/lib64/python2.6/site-packages/genshi/util.pyR Is   cCs ||ijS(N(R(R R((s1/usr/lib64/python2.6/site-packages/genshi/util.pyt __contains__Osccs-|i}x|o|iV|i}q WdS(N(RRR(R tcur((s1/usr/lib64/python2.6/site-packages/genshi/util.pyt__iter__Rs  cCs t|iƒS(N(tlenR(R ((s1/usr/lib64/python2.6/site-packages/genshi/util.pyt__len__XscCs!|i|}|i|ƒ|iS(N(Rt _update_itemR(R Rtitem((s1/usr/lib64/python2.6/site-packages/genshi/util.pyt __getitem__[s  cCss|ii|ƒ}|djo0|i||ƒ}||i|<|i|ƒn!||_|i|ƒ|iƒdS(N(RtgetRRt _insert_itemRRt _manage_size(R RRR((s1/usr/lib64/python2.6/site-packages/genshi/util.pyt __setitem__`s    cCs t|iƒS(N(R R(R ((s1/usr/lib64/python2.6/site-packages/genshi/util.pyR kscCsUd|_|i|_|idj o||i_n ||_||_|iƒdS(N(RRRRRR(R R((s1/usr/lib64/python2.6/site-packages/genshi/util.pyRns    cCsŠxƒt|iƒ|ijoi|i|ii}|i|ii=|i|ijo|ii|_d|i_qd|_|_qWdS(N( RRRRRRRRR(R tolditem((s1/usr/lib64/python2.6/site-packages/genshi/util.pyRxscCs|i|jodS|i}|i|_|idj o||i_n ||_d|_|i|_||i_|_dS(N(RRRRR(R RR((s1/usr/lib64/python2.6/site-packages/genshi/util.pyR‚s     (R Rt__doc__tobjectRR RRRRRR RRR(((s1/usr/lib64/python2.6/site-packages/genshi/util.pyRs$       cCsXg}xK|D]C}t|ttttfƒo|t|ƒ7}q |i|ƒq W|S(sþFlattens a potentially nested sequence into a flat list. :param items: the sequence to flatten >>> flatten((1, 2)) [1, 2] >>> flatten([1, (2, 3), 4]) [1, 2, 3, 4] >>> flatten([1, (2, [3, 4]), 5]) [1, 2, 3, 4, 5] (t isinstancet frozensettlisttsetttupletflattentappend(titemstretvalR((s1/usr/lib64/python2.6/site-packages/genshi/util.pyR(’s cCs3tt|ƒƒ}|p|iddƒ}n|S(sReturns the text as a `unicode` string with all entities and tags removed. >>> plaintext('1 < 2') u'1 < 2' The `keeplinebreaks` parameter can be set to ``False`` to replace any line breaks by simple spaces: >>> plaintext('''1 ... < ... 2''', keeplinebreaks=False) u'1 < 2' :param text: the text to convert to plain text :param keeplinebreaks: whether line breaks in the text should be kept intact :return: the text with tags and entities removed u u (t stripentitiest striptagstreplace(ttexttkeeplinebreaks((s1/usr/lib64/python2.6/site-packages/genshi/util.pyt plaintext¦ss-&(?:#((?:\d+)|(?:[xX][0-9a-fA-F]+));?|(\w+);)cs‡fd†}ti||ƒS(sBReturn a copy of the given text with any character or numeric entities replaced by the equivalent UTF-8 characters. >>> stripentities('1 < 2') u'1 < 2' >>> stripentities('more …') u'more \u2026' >>> stripentities('…') u'\u2026' >>> stripentities('…') u'\u2026' If the `keepxmlentities` parameter is provided and is a truth value, the core XML entities (&, ', >, < and ") are left intact. >>> stripentities('1 < 2 …', keepxmlentities=True) u'1 < 2 \u2026' csÏ|idƒoP|idƒ}|idƒot|ddƒ}nt|dƒ}t|ƒS|idƒ}ˆo|d jo d |Sytti|ƒSWn'tj oˆo d |S|SnXdS(Nitxii itamptapostgttlttquotu&%s;u&%s;(R3R4R5R6R7(tgroupt startswithtinttunichrthtmlentitydefstname2codepointtKeyError(tmatchtref(tkeepxmlentities(s1/usr/lib64/python2.6/site-packages/genshi/util.pyt_replace_entityÒs   (t_STRIPENTITIES_REtsub(R/RARB((RAs1/usr/lib64/python2.6/site-packages/genshi/util.pyR,¿ss(|<[^>]*>)cCstid|ƒS(s¯Return a copy of the text with any XML/HTML tags removed. >>> striptags('Foo bar') 'Foo bar' >>> striptags('Foo') 'Foo' >>> striptags('Foo
') 'Foo' HTML/XML comments are stripped, too: >>> striptags('test') 'test' :param text: the string to remove tags from :return: the text with tags removed t(t _STRIPTAGS_RERD(R/((s1/usr/lib64/python2.6/site-packages/genshi/util.pyR-ès(R!R<treR&t NameErrortsetsRR$Rt __docformat__RRR(tTrueR1tcompileRCtFalseR,RFR-(((s1/usr/lib64/python2.6/site-packages/genshi/util.pyts  w   (