ó Z-Qc@s¨dZddlZddlZddlZejdƒZejdƒZejdƒZdefd„ƒYZ de fd „ƒYZ de d „Zdd „Zdd „Zdd „Zd„Zd„Zd„Zd„Zd„ZiZd„Zd„Zd„ZejdkrYeZZdZddl Z ddl!Z!e!j Z"e j Z ej#Z$nKddl%Z%e%jZdZd„Zddl&Z&e&j"Z"e&j Z e%j#Z$dS(s± pygments.util ~~~~~~~~~~~~~ Utility functions. :copyright: Copyright 2006-2013 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__(((s7/usr/local/lib/python2.7/site-packages/pygments/util.pyRst OptionErrorcBseZRS((RR(((s7/usr/local/lib/python2.7/site-packages/pygments/util.pyR#scCsb|j||ƒ}|r'|jƒ}n||kr^td|djtt|ƒƒfƒ‚n|S(Ns%Value for option %s must be one of %ss, (tgettlowerRtjointmaptstr(toptionstoptnametallowedtdefaulttnormcasetstring((s7/usr/local/lib/python2.7/site-packages/pygments/util.pytget_choice_opt's %cCs¬|j||ƒ}t|tƒr%|St|tƒr>t|ƒSt|tƒsftd||fƒ‚nB|jƒd kr|tS|jƒd kr’tStd ||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(Rsyesstrueson(Rsnosfalsesoff( Rt isinstancetbooltintt basestringRRtTruetFalse(R R R R((s7/usr/local/lib/python2.7/site-packages/pygments/util.pyt get_bool_opt1s cCst|j||ƒ}yt|ƒSWnMtk rItd||fƒ‚n'tk rotd||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((s7/usr/local/lib/python2.7/site-packages/pygments/util.pyt get_int_optEs  cCsd|j||ƒ}t|tƒr+|jƒSt|ttfƒrJt|ƒStd||fƒ‚dS(Ns9Invalid type %r for option %s; you must give a list value(RRRtsplittlistttupleR(R R R tval((s7/usr/local/lib/python2.7/site-packages/pygments/util.pyt get_list_optSs  cCsm|js dSg}xD|jjƒjƒD]-}|jƒrU|jd|jƒƒq)Pq)Wdj|ƒjƒS(Ntt (Rtstript splitlinestappendRtlstrip(tobjtrestline((s7/usr/local/lib/python2.7/site-packages/pygments/util.pytdocstring_headline_s  cs%‡fd†}ˆj|_t|ƒS(sR Return a static text analysation function that returns float values. csnyˆ|ƒ}Wntk r$dSX|s/dSy tdtdt|ƒƒƒSWnttfk ridSXdS(Nggð?(t ExceptiontmintmaxtfloatR!R (ttexttrv(tf(s7/usr/local/lib/python2.7/site-packages/pygments/util.pyt text_analyseps  (Rt staticmethod(R8R9((R8s7/usr/local/lib/python2.7/site-packages/pygments/util.pytmake_analysatorks cCsá|jdƒ}|dkr.|| jƒ}n |jƒ}|jdƒrÝyJgtj|djƒƒD]"}|rf|jdƒ rf|^qfd}Wntk r§tSXtj d|tj ƒ}|j |ƒdk rÝt 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_linetxtfound((s7/usr/local/lib/python2.7/site-packages/pygments/util.pytshebang_matchess   * cCsPtj|ƒ}|dkrtS|jdƒ}tj|ƒj|jƒƒdk 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((s7/usr/local/lib/python2.7/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.*(RQ(R6((s7/usr/local/lib/python2.7/site-packages/pygments/util.pythtml_doctype_matchesºscCsst|ƒ}y t|SWnTtk rntj|ƒ}|dk rGtStj|d ƒdk }|t|<|SXdS(s< Check if a doctype exists or if we have some tags. ièN( thasht_looks_like_xml_cachetKeyErrorRLRMRERttag_reRD(R6tkeyROR7((s7/usr/local/lib/python2.7/site-packages/pygments/util.pytlooks_like_xmlÂs     cCsd|d?d|d@fS(NiÀ×i iÜiÿ((tc((s7/usr/local/lib/python2.7/site-packages/pygments/util.pyt_surrogatepairÓscCs©||krtdƒ‚n|dks3|dkrBtdƒ‚ntjdkrkdt|ƒt|ƒfSt|ƒ\}}t|ƒ\}}||kr¾dt|ƒt|ƒt|ƒfSg}|jdt|ƒt|ƒ||kr÷t|ƒptdƒfƒ||d krU|jd t|d ƒt|d ƒtd ƒtdƒƒn||kr|jdt|ƒtd ƒt|ƒfƒnd d j|ƒdSdS(sO Returns a regular expression string to match the given non-BMP range. sBad character rangeis+unirange is only defined for non-BMP rangesiÿÿu[%s-%s]u (?:%s[%s-%s])u %s[%s-%s]iÿßiu[%s-%s][%s-%s]iÜu(?:u|u)N(R!tsyst maxunicodetunichrRZR,R(tatbtahtaltbhtbltbuf((s7/usr/local/lib/python2.7/site-packages/pygments/util.pytunirangeÖs*   # ) 4  &iituR(cCsLt|tƒr"ttt|ƒƒSt|tƒr5|Std|fƒ‚dS(NsInvalid argument %r for b()(RR tbytesRtordR (ts((s7/usr/local/lib/python2.7/site-packages/pygments/util.pyR_ s (ii('RRAR[tcodecsRBR?RLRVR!RR2RRERRRR"R'R1R;RKRQRRRTRXRZRet version_infoR R_Rgtu_prefixtStringIOt cStringIOtBytesIOtopentuni_opentbuiltinstio(((s7/usr/local/lib/python2.7/site-packages/pygments/util.pyt sJ        .    *