Ñò <0¯Hc @sºdZddkZddkZddkZddkZddklZddklZe d„Z d„Z d„Z de fd „ƒYZd efd „ƒYZd efd „ƒYZdS(suUtility functions used by various web helpers This module is such a mess that no new helpers should be added to it. iÿÿÿÿN(t DictMixin(t XMLGeneratorcCsŠd|jo|iddƒ}nd|jo|iddƒ}nd|jo|iddƒ}n|o|iddƒ}n|S( sÃReplace special characters '&', '<' and '>' by SGML entities. This is a slightly more efficient version of the cgi.escape by using 'in' membership to test if the replace is needed. t&s&ts>t"s"(treplace(tstquote((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyt cgi_escape s   cCs‹|djodSt|tƒp0t|dƒot|ƒ}qRt|ƒ}nt|tƒ}t|tƒo|iddƒ}n|S(sGHTML-escape a string or object. This converts any non-string objects passed into it to strings (actually, using ``unicode()``). All values returned are non-unicode strings (using ``&#num;`` entities for all non-ASCII characters). None is treated specially, and returns the empty string. tt __unicode__tasciitxmlcharrefreplaceN( tNonet isinstancet basestringthasattrtunicodetstrR tTruetencode(R((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyt html_escapes cCs%|djo|Sti|ddƒS(s‘ Convert an IRI portion to a URI portion suitable for inclusion in a URL. (An IRI is an Internationalized Resource Identifier.) This is the algorithm from section 3.1 of RFC 3987. However, since we are assuming input is either UTF-8 or unicode already, we can simplify things a little from the full method. Returns an ASCII string containing the encoded result. tsafes/#%[]=:;$&()+,!?N(RturllibR(tiri((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyt iri_to_uri5s tPartialcBs eZdZd„Zd„ZRS(s+Partial object, which will be in Python 2.5cOs3|d}|d|d||_|_|_dS(Niii(tfntargstkw(RRtself((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyt__init__Ns cOsX|o*|io |iiƒ}|i|ƒn|p|i}|i|i||ŽS(N(RtcopytupdateRR(RRRtd((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyt__call__Rs (t__name__t __module__t__doc__R R$(((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyRJs tSimplerXMLGeneratorcBseZddd„ZRS(cCsV|djo h}n|i||ƒ|dj o|i|ƒn|i|ƒdS(s Add an element with no children.N(Rt startElementt characterst endElement(Rtnametcontentstattrs((s3/usr/lib/python2.6/site-packages/webhelpers/util.pytaddQuickElement[s    N(R%R&RR/(((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyR(ZstUnicodeMultiDictcBs eZdZddded„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z d „Z d „Zd „Zd „ZeZd„Zd„Zdd„Zd„Zd„Zd„Zd„Zd„Zd„ZeZd„Zd„Zd„Zd„ZRS(s' A MultiDict wrapper that decodes returned values to unicode on the fly. Decoding is not applied to assigned values. The key/value contents are assumed to be ``str``/``strs`` or ``str``/``FieldStorages`` (as is returned by the :func:`paste.request.parse` functions). Can optionally also decode keys when the ``decode_keys`` argument is True. ``FieldStorage`` instances are cloned, and the clone's ``filename`` variable is decoded. Its ``name`` variable is decoded when ``decode_keys`` is enabled. tstrictcCsE||_|djotiƒ}n||_||_||_dS(N(tmultiRtsystgetdefaultencodingtencodingterrorst decode_keys(RR2R5R6R7((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyR xs     cCs*|io|i|i|iƒ}n|S(N(R7tdecodeR5R6(Rtkey((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyt _decode_keys cCs¦t|tiƒo]ti|ƒ}|io"|ii|i|iƒ|_n|i i|i|iƒ|_ n3y|i|i|iƒ}Wnt j onX|S(s  Decode the specified (``str`` or `FieldStorage``) value to unicode. ``FieldStorage`` objects are specially handled. ( Rtcgit FieldStorageR!R7R,R8R5R6tfilenametAttributeError(Rtvalue((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyt _decode_value†s ""cCs|i|ii|ƒƒS(N(R@R2t __getitem__(RR9((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyRAšscCs|ii||ƒdS(N(R2t __setitem__(RR9R?((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyRBscCs|ii||ƒdS(s:Add the key and value, not overwriting any previous value.N(R2tadd(RR9R?((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyRC scCs4g}|ii|ƒD]}||i|ƒq~S(sBReturn list of all values matching the key (may be an empty list).(R2tgetallR@(RR9t_[1]tv((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyRD¤scCs|i|ii|ƒƒS(sCReturn one value matching key. Raise KeyError if multiple matches.(R@R2tgetone(RR9((s3/usr/lib/python2.6/site-packages/webhelpers/util.pyRG¨scCsh}xƒ|iiƒiƒD]l\}}t|tƒo.g}|D]}||i|ƒqC~}n|i|ƒ}|||i|ƒs