
-X                 @   s   d  Z  d d l Z d d l Z d d l Z d d d g Z d d d  Z i  a d d   Z d d d	  Z d d
 d  Z	 d d d  Z
 d S)zCache lines from files.

This is intended to read lines from modules imported -- hence if a filename
is not found, it will look down the module search path for a file by
that name.
    Ngetline
clearcache
checkcachec             C   sE   t  |  |  } d | k o, t |  k n r= | | d Sd Sd  S)N    )getlineslen)filenamelinenomodule_globalslines r   9/home/kubikplay/www/django_dtb/lib/python3.4/linecache.pyr      s    "c               C   s
   i  a  d S)zClear the cache entirely.N)cacher   r   r   r   r      s    c             C   s)   |  t  k r t  |  d St |  |  Sd S)zsGet the lines for a file from the cache.
    Update the cache if it doesn't contain an entry for this file already.   N)r   updatecache)r	   r   r   r   r   r   "   s    r   c             C   s   |  d k r! t  t j    } n |  t k r9 |  g } n d Sx | D] }  t |  \ } } } } | d k rr qD n  y t j |  } Wn t k
 r t |  =wD Yn X| | j k s | | j k rD t |  =qD qD Wd S)zUDiscard cache entries that are out of date.
    (This is not checked upon each call!)N)listr   keysosstatOSErrorst_sizest_mtime)r	   Z	filenamessizemtimer   fullnamer   r   r   r   r   ,   s     c          "   C   s_  |  t  k r t  |  =n  |  s; |  j d  r? |  j d  r? g  S|  } y t j |  } Wnkt k
 r|  } | r3d | k r3| j d  } | d } t | d d  } | r3| r3y | |  } Wn t t f k
 r Yq0X| d k r g  St	 |  d d d   | j
   D | f t  |  <t  |  d	 Sq3n  t j j |   rIg  Sxu t j D]f }	 y t j j |	 |  } Wn t t f k
 rwSYn Xy t j |  } PWqSt k
 rYqSXqSWg  SYn Xy( t j |   }
 |
 j   } Wd QXWn t k
 rg  SYn X| r2| d j d  r2| d d 7<n  | j | j } } | | | | f t  |  <| S)zUpdate a cache entry and return its list of lines.
    If something's wrong, print a message, discard the cache entry,
    and return an empty list.<>
__loader____name__
get_sourceNc             S   s   g  |  ] } | d   q S)
r   ).0liner   r   r   
<listcomp>g   s   	 zupdatecache.<locals>.<listcomp>r   r   r!   r%   )r   
startswithendswithr   r   r   getgetattrImportErrorr   
splitlinespathisabssysjoin	TypeErrorAttributeErrortokenizeopen	readlinesr   r   )r	   r   r   r   basenamenameloaderr    datadirnamefpr   r   r   r   r   r   r   E   s\    
%
#			r   )__doc__r.   r   r2   __all__r   r   r   r   r   r   r   r   r   r   <module>   s   

