;ò
­_p@c           @   s°  d  Z  d k Z d k Z d k Z d k Z d k Z d k Z d k Z h  d d <d d <d d <d d	 <d
 d <d d <d d <d d <d d <d d <d d <d d <d d <Z h  Z	 x4 e i
 ƒ  D]& \ Z Z e e	 e <e e	 e e ƒ <qÓ We	 i ƒ  e i ƒ  Z e i d ƒ Z d e i f d „  ƒ  YZ d f  d  „  ƒ  YZ d! „  Z d" d# d$ d# d% „ Z d& „  Z d' „  Z d( „  Z d) „  Z d* d+ d, „ Z d- „  d. „  e d/ „ Z d0 „  Z d1 „  Z e i  d2 j oC d k! Z! d k" Z" d k# Z# e! i$ Z% d# Z& e! i' Z( e# i) ƒ  Z* nE e i  d3 j o( d k+ Z+ e+ i% Z% e+ i& Z& e+ i( Z( n e, d4 ƒ ‚ e i  d2 j o d5 „  Z- d6 „  Z. n' e i  d3 j o d7 „  Z- d8 „  Z. n d S(9   sG  
Tools module

The swiss army knife for all things pyblosxom

@var month2num: A dict of literal months to its number format
@var num2month: A dict of number month format to its literal format
@var MONTHS: A list of valid literal and numeral months
@var VAR_REGEXP: Regular expression for detection and substituion of variables
Ns   nils   00s   Jans   01s   Febs   02s   Mars   03s   Aprs   04s   Mays   05s   Juns   06s   Juls   07s   Augs   08s   Seps   09s   Octs   10s   Novs   11s   Decs   12u-   (?<!\\)\$((?:\w|\-|::\w)+(?:\(.*?(?<!\\)\))?)s   Stripperc           B   s;   t  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sL   
    Strips HTML
    
    An C{SGMLParser} subclass to strip away HTMLs
    c         C   s   g  |  _ t i i |  ƒ d  S(   N(   s   selfs   datas   sgmllibs
   SGMLParsers   __init__(   s   self(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   __init__0   s    	c         C   s   |  i i d ƒ d  S(   Ns    (   s   selfs   datas   append(   s   selfs   tags   attrs(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   unknown_starttag3   s    c         C   s   |  i i d ƒ d  S(   Ns    (   s   selfs   datas   append(   s   selfs   tag(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   unknown_endtag4   s    c         C   s   |  i i | ƒ d  S(   N(   s   selfs   datas   append(   s   selfs   data(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   handle_data5   s    c         C   s   t  i |  i d ƒ } | Sd  S(   Ns    (   s   strings   joins   selfs   datas   text(   s   selfs   text(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   gettext6   s    (   s   __name__s
   __module__s   __doc__s   __init__s   unknown_starttags   unknown_endtags   handle_datas   gettext(    (    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   Stripper*   s    				s   Replacerc           B   s    t  Z d  Z d „  Z d „  Z RS(   s®   
    Class for replacing variables in a template

    This class is a utility class used to provide a bound method to the
    C{re.sub()} function.  Gotten from OPAGCGI.
    c         C   s   | |  _ | |  _ d S(   s  
        It's only duty is to populate itself with the replacement dictionary
        passed.

        @param encoding: the encoding to use
        @type  encoding: string

        @param var_dict: The dict for variable substitution
        @type var_dict: dict
        N(   s   encodings   selfs	   _encodings   var_dict(   s   selfs   encodings   var_dict(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   __init__C   s    
 	c         C   sI  | i d ƒ } | i d ƒ d j o | i d ƒ o: | | i d ƒ d | i d ƒ !} | | i d ƒ  } n t } |  i i	 | ƒ o¹ |  i | } t | ƒ o, | o t d | d ƒ } qÎ | ƒ  } n t | ƒ t i j o t | ƒ t i j o t | ƒ } n t | ƒ t i j o t | |  i d ƒ } n | Sn d Sd S(	   sa  
        The replacement method. 
        
        This is passed a match object by re.sub(), which it uses to index the
        replacement dictionary and find the replacement string.

        @param matchobj: A C{re} object containing substitutions
        @type  matchobj: C{re} object

        @returns: Substitutions
        @rtype: string
        i   s   (iÿÿÿÿs   )s   r(s   replaceu    N(   s   matchobjs   groups   keys   finds   rfinds   argss   Nones   selfs   var_dicts   has_keys   rs   callables   evals   types   typess
   StringTypes   UnicodeTypes   strs   unicodes	   _encoding(   s   selfs   matchobjs   argss   rs   key(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   replaceQ   s$     &#,(   s   __name__s
   __module__s   __doc__s   __init__s   replace(    (    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   Replacer<   s    	c         C   sP   t  | ƒ t i j o t | |  d ƒ } n d t i t |  | ƒ i
 | ƒ Sd S(   s  
    This method parses the open file object passed, replacing any keys
    found using the replacement dictionary passed.  Uses the L{Replacer} 
    object.  From OPAGCGI library

    @param encoding: the encoding to use
    @type  encoding: string

    @param var_dict: The name value pair list containing variable replacements
    @type  var_dict: dict

    @param template: A template file with placeholders for variable 
        replacements
    @type  template: string

    @returns: Substituted template
    @rtype: string
    s   replaceu    N(   s   types   templates   typess   UnicodeTypes   unicodes   encodings
   VAR_REGEXPs   subs   Replacers   var_dicts   replace(   s   encodings   var_dicts   template(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   parse�   s     s   .i    s    c         C   s‰   | o: |  i ƒ  d } t i d d i | i ƒ  ƒ d ƒ } n y t i	 | ƒ } Wn t i j
 o g  Sn Xt | | | | ƒ Sd S(   s  
    This function walks a directory tree starting at a specified root folder,
    and returns a list of all of the files (and optionally folders) that match
    our pattern(s). Taken from the online Python Cookbook and modified to own
    needs.

    @param request: the Request object
    @type  request: Request

    @param root: Starting point to walk from
    @type root: string

    @param recurse: Depth of recursion,
        - 0: All the way
        - 1: Just this level
        - I{n}: I{n} depth of recursion
    @type recurse: integer

    @param pattern: A C{re.compile}'d object
    @type pattern: object

    @param return_folders: If true, just return list of folders
    @type return_folders: boolean

    @returns: A list of file paths
    @rtype: list
    s
   extensionss   .*\.(s   |s   )$N(   s   patterns   requests   getDatas   exts   res   compiles   joins   keyss   oss   listdirs   roots   namess   errors   _walk_internals   recurses   return_folders(   s   requests   roots   recurses   patterns   return_folderss   exts   names(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   Walk›   s     *	c         C   s#  g  } t i |  ƒ } x| D]û } t i i t i i |  | ƒ ƒ } | i | ƒ oJ t i i | ƒ o | p | o t i i | ƒ o | i | ƒ q� n | d j p
 | d j o` t i i | ƒ o t i i | ƒ o5 | t | | d j o | d p d | | ƒ } qq q W| Sd  S(   Ni    i   (   s   results   oss   listdirs   roots   namess   names   paths   normpaths   joins   fullnames   patterns   matchs   isfiles   return_folderss   isdirs   appends   recurses   islinks   _walk_internal(   s   roots   recurses   patterns   return_folderss   names   namess   fullnames   result(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   _walk_internalÄ   s     !5'	c         C   s®   |  i ƒ  } | i d h  ƒ } | i | ƒ o | | Sn h  d |  <d | <d t i | ƒ <} t
 d | d d „  d d	 „  ƒ} t i | d d
 ƒ } | | | <| Sd S(   s€  
    Returns the filestat on a given file.  We store the filestat
    in case we've already retrieved it this time.

    @param request: the Pyblosxom Request object
    @type  request: Request

    @param filename: the name of the file to stat
    @type  filename: string

    @returns: the mtime of the file (same as returned by time.localtime(...))
    @rtype: tuple of 9 ints
    s   filestat_caches   requests   filenames   mtimes   filestats   mappingfuncc         C   s   | S(   N(   s   y(   s   xs   y(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   <lambda>ö   s    s   defaultfuncc         C   s   |  S(   N(   s   x(   s   x(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   <lambda>÷   s    i   N(   s   requests   getDatas   datas
   setdefaults   filestat_caches   has_keys   filenames   oss   stats   argdicts   run_callbacks   times	   localtimes	   timetuple(   s   requests   filenames   datas   filestat_caches   argdicts	   timetuple(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   filestatÞ   s     *	
c         C   s<   x1 |  D]) } t i i | d | ƒ o | Sq q Wt Sd S(   sy  
    Takes in a filepath and a list of extensions and tries them all until
    it finds the first extension that works.

    @param extensions: the list of extensions to test
    @type  extensions: list of strings

    @param filepath: the complete file path (minus the extension) to test
    @type  filepath: string

    @return: the extension that was successful or None
    s   .N(   s
   extensionss   exts   oss   paths   isfiles   filepaths   None(   s
   extensionss   filepaths   ext(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   what_extý   s      c         C   s`   y" t  |  t ƒ  t ƒ  | g ƒ } Wn t j
 o t Sn Xy t | ƒ | SWn t Sn Xd S(   s{  
    Module importer
    
    For modules that can only be determined during runtime

    @param modulename: The base name of the module to import from
    @type modulename: string

    @param name: The name of the module to import from the modulename
    @type name: string

    @returns: If successful, returns an imported object reference, else C{None}
    @rtype: object
    N(	   s
   __import__s
   modulenames   globalss   localss   names   modules   ImportErrors   Nones   vars(   s
   modulenames   names   module(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys
   importName  s     "	i   i
   c         C   sc   d k  } t i t i } d } | i |  | ƒ } x' t
 | ƒ D] } | | i | ƒ 7} q> W| Sd S(   si  
    Generate a random string
    
    Tool to generate a random string between C{minlen} to C{maxlen} characters

    @param minlen: The minimum length the string should be
    @type minlen: integer

    @param maxlen: The maximum length the string could be
    @type maxlen: integer

    @returns: A string containing random characters
    @rtype: string
    Ns    (   s   randoms   strings   letterss   digitss   charss   randStrs   randints   minlens   maxlens   randStr_sizes   ranges   xs   choice(   s   minlens   maxlens   charss   randoms   randStr_sizes   randStrs   x(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   generateRandStr(  s     	 c         C   s   |  S(   N(   s   x(   s   xs   y(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   <lambda>@  s    c         C   s   d S(   Ni    (    (   s   x(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   <lambda>A  s    c         C   s�   t  i |  ƒ }  t } xA |  D]9 } | | ƒ } | | ƒ d j o Pn | | | ƒ } q Wt	 | ƒ o | | ƒ d j o | | ƒ Sn | Sd S(   s£  
    Executes a callback chain on a given piece of data.
    passed in is a dict of name/value pairs.  Consult the documentation
    for the specific callback chain you're executing.

    Callback chains should conform to their documented behavior.
    This function allows us to do transforms on data, handling data,
    and also callbacks.

    The difference in behavior is affected by the mappingfunc passed
    in which converts the output of a given function in the chain
    to the input for the next function.

    If this is confusing, read through the code for this function.

    @param chain: the callback chain to run
    @type  chain: string

    @param input: data is a dict filled with name/value pairs--refer
        to the callback chain documentation for what's in the data 
        dict.
    @type  input: dict

    @param mappingfunc: the function that maps output arguments
        to input arguments for the next iteration.  It must take
        two arguments: the original dict and the return from the
        previous function.  It defaults to returning the original
        dict.
    @type  mappingfunc: function

    @param donefunc: this function tests whether we're done doing
        what we're doing.  This function takes as input the output
        of the most recent iteration.  If this function returns 
        true (1) then we'll drop out of the loop.  For example,
        if you wanted a callback to stop running when one of the
        registered functions returned a 1, then you would pass in
        "donefunc=lambda x:x".
    @type  donefunc: function

    @param defaultfunc: if this is set and we finish going through all
        the functions in the chain and none of them have returned something
        that satisfies the donefunc, then we'll execute the defaultfunc
        with the latest version of the input dict.
    @type  defaultfunc: function

    @returns: the transformed dict
    @rtype: dict
    i   N(   s   plugin_utilss   get_callback_chains   chains   Nones   outputs   mems   inputs   donefuncs   mappingfuncs   callables   defaultfunc(   s   chains   inputs   mappingfuncs   donefuncs   defaultfuncs   mems   output(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   run_callback?  s    3   c         C   s�   |  i ƒ  } | i d d ƒ } | o_ |  i ƒ  } | i d d ƒ } | i d d ƒ } t	 d | ƒ } | i |  | ƒ } | | d <n | Sd S(   s  
    Retrieves the cache from the request or fetches a new CacheDriver
    instance.

    @param request: the Request object for this run
    @type  request: Request

    @returns: A BlosxomCache object reference
    @rtype: L{Pyblosxom.cache.base.BlosxomCacheBase} subclass
    s
   data_caches    s   cacheDrivers   bases   cacheConfigs   Pyblosxom.cacheN(   s   requests   getDatas   datas   gets   mycaches   getConfigurations   configs   cacheDriverConfigs   cacheConfigs
   importNames   cache_drivers   BlosxomCache(   s   requests   cacheConfigs   configs   cache_drivers   cacheDriverConfigs   datas   mycache(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys	   get_cache“  s    
 c            s–   y d k  } Wn t j
 o ‡  d †  a ne X| i d ƒ ‰ | i ˆ  ƒ } | i d ƒ } | i
 | ƒ ˆ i | ƒ ˆ i | i ƒ ‡ d †  a d S(   s   
    Create a logging function called log, which logs to the supplied filename
    usage is:

    >>> tools.make_logger('/tmp/pybloxom.log')
    >>> tools.log('log message')

    @param filename: the name of a file to log to
    @type filename: string
    Nc             s^   t  ˆ  d ƒ } x1 |  D]) } | i d t i ƒ  t | ƒ f ƒ q W| i d ƒ | i	 ƒ  d  S(   Ns   as
   %s INFO %ss   
(
   s   opens   filenames   fs   argss   is   writes   times   asctimes   reprs   close(   s   argss   fs   i(   s   filename(    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   log¾  s     's	   trackbacks%   %(asctime)s %(levelname)s %(message)sc            s   ˆ  i |  ƒ d  S(   N(   s   loggers   infos   str(   s   str(   s   logger(    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   logÌ  s    (   s   loggings   ImportErrors   logs	   getLoggers   loggers   FileHandlers   filenames   hdlrs	   Formatters	   formatters   setFormatters
   addHandlers   setLevels   INFO(   s   filenames   loggings   loggers	   formatters   hdlr(    (   s   filenames   loggers:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   make_logger¯  s    
  s   nts   posixs3   PortaLocker only defined for nt and posix platformsc         C   s2   t  i |  i ƒ  ƒ } t  i | | d d t ƒ d  S(   Ni    i  ÿÿ(   s	   win32files   _get_osfhandles   fs   filenos   hfiles
   LockFileExs   flagss   __overlapped(   s   fs   flagss   hfile(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   lock
  s    c         C   s/   t  i |  i ƒ  ƒ } t  i | d d t ƒ d  S(   Ni    i  ÿÿ(   s	   win32files   _get_osfhandles   fs   filenos   hfiles   UnlockFileExs   __overlapped(   s   fs   hfile(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   unlock  s    c         C   s   t  i |  i ƒ  | ƒ d  S(   N(   s   fcntls   flocks   fs   filenos   flags(   s   fs   flags(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   lock  s    c         C   s   t  i |  i ƒ  t  i ƒ d  S(   N(   s   fcntls   flocks   fs   filenos   LOCK_UN(   s   f(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   unlock  s    (/   s   __doc__s   plugin_utilss   sgmllibs   res   oss   strings   typess   times	   month2nums	   num2months   itemss   ks   vs   ints   keyss   MONTHSs   compiles
   VAR_REGEXPs
   SGMLParsers   Strippers   Replacers   parses   Walks   _walk_internals   filestats   what_exts
   importNames   generateRandStrs   Nones   run_callbacks	   get_caches   make_loggers   names   win32cons	   win32files
   pywintypess   LOCKFILE_EXCLUSIVE_LOCKs   LOCK_EXs   LOCK_SHs   LOCKFILE_FAIL_IMMEDIATELYs   LOCK_NBs
   OVERLAPPEDs   __overlappeds   fcntls   RuntimeErrors   locks   unlock(#   s   locks   generateRandStrs   filestats   parses	   win32files   LOCK_EXs
   VAR_REGEXPs   sgmllibs   __overlappeds   what_exts	   num2months   res   LOCK_NBs   win32cons   LOCK_SHs   fcntls   Replacers   strings	   get_caches   times   make_loggers	   month2nums   run_callbacks
   pywintypess   typess
   importNames   plugin_utilss   ks   MONTHSs   unlocks   Walks   vs   oss   _walk_internals   Stripper(    (    s:   /mit/python/lib/python2.3/site-packages/Pyblosxom/tools.pys   ?   sT   	6{ 
E	)				T		I										