Ñò ÑXc @ sz d Z d d k Z d d k Z e i d ƒ Z e i d ƒ Z e i d ƒ Z d e f d „ ƒ YZ d e f d „ ƒ YZ d e d „ Z d d „ Z d d „ Z d d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z h Z d „ Z e i d j o> e Z Z d Z d d k Z d d k Z e i Z e i Z nC d d k Z e i Z d Z d „ Z d d k! Z! e! i Z e! i Z d S( 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 ClassNotFoundc B s e Z d Z RS( 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.pyR s t OptionErrorc B s e Z RS( ( R R ( ( ( s1 /usr/lib/python2.6/site-packages/pygments/util.pyR ! s c C sf | i | | ƒ } | o | i ƒ } n | | j o, t d | d i t t | ƒ ƒ f ƒ ‚ n | S( Ns% Value for option %s must be one of %ss , ( t gett lowerR t joint mapt str( t optionst optnamet allowedt defaultt normcaset string( ( s1 /usr/lib/python2.6/site-packages/pygments/util.pyt get_choice_opt% s &c C s¶ | i | | ƒ } t | t ƒ o | St | t ƒ o t | ƒ St | t ƒ p t d | | f ƒ ‚ nG | i ƒ d j o t S| i ƒ d j o t St d | | f ƒ ‚ d S( NsB Invalid type %r for option %s; use 1/0, yes/no, true/false, on/offt 1t yest truet ont 0t not falset offsC Invalid value %r for option %s; use 1/0, yes/no, true/false, on/off( R R R R ( R R R R ( R t isinstancet boolt intt basestringR R t Truet False( R R R R ( ( s1 /usr/lib/python2.6/site-packages/pygments/util.pyt get_bool_opt/ s c C sx | i | | ƒ } y t | ƒ SWnQ t j o t d | | f ƒ ‚ n* t j o t d | | f ƒ ‚ n Xd S( 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( R R t TypeErrorR t ValueError( R R R R ( ( s1 /usr/lib/python2.6/site-packages/pygments/util.pyt get_int_optC s c C sh | i | | ƒ } t | t ƒ o | i ƒ St | t t f ƒ o t | ƒ St d | | f ƒ ‚ d S( Ns9 Invalid type %r for option %s; you must give a list value( R R R t splitt listt tupleR ( R R R t val( ( s1 /usr/lib/python2.6/site-packages/pygments/util.pyt get_list_optQ s c C sq | i p d Sg } xF | i i ƒ i ƒ D]/ } | i ƒ o | i d | i ƒ ƒ q+ Pq+ Wd i | ƒ i ƒ S( Nt t ( R t stript splitlinest appendR t lstrip( t objt rest line( ( s1 /usr/lib/python2.6/site-packages/pygments/util.pyt docstring_headline] s c s% ‡ f d † } ˆ i | _ t | ƒ S( sR Return a static text analysation function that returns float values. c st y ˆ | ƒ } Wn t j o d SX| p d Sy t d t d t | ƒ ƒ ƒ SWn t t f j o d SXd S( Ng g ð?( t Exceptiont mint maxt floatR! R ( t textt rv( t f( s1 /usr/lib/python2.6/site-packages/pygments/util.pyt text_analysen s ( R t staticmethod( R8 R9 ( ( R8 s1 /usr/lib/python2.6/site-packages/pygments/util.pyt make_analysatori s c C s÷ | i d ƒ } | d j o | | i ƒ } n | i ƒ } | i d ƒ o§ yX g } t i | d i ƒ ƒ D]) } | o | i d ƒ o | | qm qm ~ d } Wn t j o t SXt i d | t i ƒ } | i | ƒ d j o t Sn t S( 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 i s #!i t -iÿÿÿÿs ^%s(\.(exe|cmd|bat|bin))?$N( t findR t startswitht split_path_reR# R* t IndexErrorR t ret compilet IGNORECASEt searcht NoneR ( R6 t regext indext first_linet _[1]t xt found( ( s1 /usr/lib/python2.6/site-packages/pygments/util.pyt shebang_matches} s $4 c C sR t i | ƒ } | d j o t S| i d ƒ } t i | ƒ i | i ƒ ƒ d j 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"' i N( t doctype_lookup_ret matchRE R t groupRA RB R* ( R6 RF t mt doctype( ( s1 /usr/lib/python2.6/site-packages/pygments/util.pyt doctype_matches« s c C s 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.pyt html_doctype_matches¸ s c C sw t | ƒ } y t | SWnX t j oL t i | ƒ } | d j o t St i | d ƒ d j } | t | <| SXd S( s<