Ñò  ÑXc@szdZddkZddkZeidƒZeidƒZeidƒZdefd„ƒYZde fd „ƒYZ de d „Z dd „Zdd „Zdd „Zd„Zd„Zd„Zd„Zd„ZhZd„Zeidjo>eZZdZddkZddkZeiZeiZnCddk Z e iZdZd„Zddk!Z!e!iZe!iZdS(s± pygments.util ~~~~~~~~~~~~~ Utility functions. :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. iÿÿÿÿNs[/\\ ]sƒ(?smx) (<\?.*?\?>)?\s* ]*> s<(.+?)(\s.*?)?>.*?(?uism)t ClassNotFoundcBseZdZRS(sJ If one of the get_*_by_* functions didn't find a matching class. (t__name__t __module__t__doc__(((s1/usr/lib/python2.6/site-packages/pygments/util.pyRst OptionErrorcBseZRS((RR(((s1/usr/lib/python2.6/site-packages/pygments/util.pyR!scCsf|i||ƒ}|o|iƒ}n||jo,td|ditt|ƒƒfƒ‚n|S(Ns%Value for option %s must be one of %ss, (tgettlowerRtjointmaptstr(toptionstoptnametallowedtdefaulttnormcasetstring((s1/usr/lib/python2.6/site-packages/pygments/util.pytget_choice_opt%s &cCs¶|i||ƒ}t|tƒo|St|tƒo t|ƒSt|tƒptd||fƒ‚nG|iƒd jotS|iƒd jotStd ||fƒ‚dS( NsBInvalid type %r for option %s; use 1/0, yes/no, true/false, on/offt1tyesttruetont0tnotfalsetoffsCInvalid value %r for option %s; use 1/0, yes/no, true/false, on/off(RRRR(RRRR( Rt isinstancetbooltintt basestringRRtTruetFalse(R R R R((s1/usr/lib/python2.6/site-packages/pygments/util.pyt get_bool_opt/s cCsx|i||ƒ}yt|ƒSWnQtj otd||fƒ‚n*tj otd||fƒ‚nXdS(Ns=Invalid type %r for option %s; you must give an integer values>Invalid value %r for option %s; you must give an integer value(RRt TypeErrorRt ValueError(R R R R((s1/usr/lib/python2.6/site-packages/pygments/util.pyt get_int_optCscCsh|i||ƒ}t|tƒo |iƒSt|ttfƒo t|ƒStd||fƒ‚dS(Ns9Invalid type %r for option %s; you must give a list value(RRRtsplittlistttupleR(R R R tval((s1/usr/lib/python2.6/site-packages/pygments/util.pyt get_list_optQs  cCsq|ipdSg}xF|iiƒiƒD]/}|iƒo|id|iƒƒq+Pq+Wdi|ƒiƒS(Ntt (Rtstript splitlinestappendRtlstrip(tobjtrestline((s1/usr/lib/python2.6/site-packages/pygments/util.pytdocstring_headline]s  cs%‡fd†}ˆi|_t|ƒS(sR Return a static text analysation function that returns float values. c styˆ|ƒ}Wntj odSX|pdSy tdtdt|ƒƒƒSWnttfj odSXdS(Nggð?(t ExceptiontmintmaxtfloatR!R (ttexttrv(tf(s1/usr/lib/python2.6/site-packages/pygments/util.pyt text_analysens (Rt staticmethod(R8R9((R8s1/usr/lib/python2.6/site-packages/pygments/util.pytmake_analysatoris c Cs÷|idƒ}|djo|| iƒ}n |iƒ}|idƒo§yXg}ti|diƒƒD])}|o|idƒ o ||qmqm~d}Wntj otSXti d|ti ƒ}|i |ƒdj ot SntS( sõ Check if the given regular expression matches the last part of the shebang if one exists. >>> from pygments.util import shebang_matches >>> shebang_matches('#!/usr/bin/env python', r'python(2\.\d)?') True >>> shebang_matches('#!/usr/bin/python2.4', r'python(2\.\d)?') True >>> shebang_matches('#!/usr/bin/python-ruby', r'python(2\.\d)?') False >>> shebang_matches('#!/usr/bin/python/ruby', r'python(2\.\d)?') False >>> shebang_matches('#!/usr/bin/startsomethingwith python', ... r'python(2\.\d)?') True It also checks for common windows executable file extensions:: >>> shebang_matches('#!C:\Python2.4\Python.exe', r'python(2\.\d)?') True Parameters (``'-f'`` or ``'--foo'`` are ignored so ``'perl'`` does the same as ``'perl -e'``) Note that this method automatically searches the whole string (eg: the regular expression is wrapped in ``'^$'``) s is#!it-iÿÿÿÿs^%s(\.(exe|cmd|bat|bin))?$N(tfindRt startswitht split_path_reR#R*t IndexErrorRtretcompilet IGNORECASEtsearchtNoneR(R6tregextindext first_linet_[1]txtfound((s1/usr/lib/python2.6/site-packages/pygments/util.pytshebang_matches}s  $4 cCsRti|ƒ}|djotS|idƒ}ti|ƒi|iƒƒdj S(sÅ Check if the doctype matches a regular expression (if present). Note that this method only checks the first part of a DOCTYPE. eg: 'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' iN(tdoctype_lookup_retmatchRERtgroupRARBR*(R6RFtmtdoctype((s1/usr/lib/python2.6/site-packages/pygments/util.pytdoctype_matches«s  cCs t|dƒS(s= Check if the file looks like it has a html doctype. s%html\s+PUBLIC\s+"-//W3C//DTD X?HTML.*(RR(R6((s1/usr/lib/python2.6/site-packages/pygments/util.pythtml_doctype_matches¸scCswt|ƒ}y t|SWnXtj oLti|ƒ}|dj otSti|d ƒdj }|t|<|SXdS(s< Check if a doctype exists or if we have some tags. ièN( thasht_looks_like_xml_cachetKeyErrorRMRNRERttag_reRD(R6tkeyRPR7((s1/usr/lib/python2.6/site-packages/pygments/util.pytlooks_like_xmlÀs    iituR(cCsPt|tƒottt|ƒƒSt|tƒo|Std|fƒ‚dS(NsInvalid argument %r for b()(RR tbytesRtordR (ts((s1/usr/lib/python2.6/site-packages/pygments/util.pytbÛs (ii("RRAtsysRBR?RMRWR!RR2RRERRRR"R'R1R;RLRRRSRURYt version_infoR R^R[tu_prefixtStringIOt cStringIOtBytesIOtbuiltinstio(((s1/usr/lib/python2.6/site-packages/pygments/util.pyt s@       .