o ?Og:@sldZddlZddlZddlZddlZgdZiZddZdddZddd Z dd d Z dd d Z ddZ dS)zCache lines from Python source 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 checkcache lazycachecCs tdS)zClear the cache entirely.N)cacheclearrr0/opt/alt/python310/lib64/python3.10/linecache.pyrs rcCs8t||}d|krt|krndS||dSdS)z~Get a line for a Python source file from the cache. Update the cache if it doesn't contain an entry for this file already.)getlineslen)filenamelinenomodule_globalslinesrrr rs  rcCsR|tvrt|}t|dkrt|dSzt||WSty(tgYSw)zGet the lines for a Python source file from the cache. Update the cache if it doesn't contain an entry for this file already.r )rr updatecache MemoryErrorr)rrentryrrr r $s    r c Cs|dur tt}n |tvr|g}ndS|D]?}t|}t|dkr$q|\}}}}|dur/qzt|}WntyEt|dYqw||jksP||j krVt|dqdS)zUDiscard cache entries that are out of date. (This is not checked upon each call!)Nr ) listrkeysr osstatOSErrorpopst_sizest_mtime)r filenamesrsizemtimerfullnamerrrr r4s,     rc Cs|tvrtt|dkrt|d|r|dr |dr gS|}zt|}Wnty|}t||rmz t|d}Wn t tfyKYn"w|durTgYSt|ddd| D|ft|<t|dYStj |rwgYSt j D](}z tj ||}Wn ttfyYqzwzt|}Wn tyYqzwgYSYnwzt| }|}Wdn1swYWntttfygYSw|r|d d s|d d 7<|j|j} } | | ||ft|<|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.r N<>rcSsg|]}|dqS) r).0linerrr pszupdatecache..rr$)rr r startswithendswithrrrr ImportError splitlinespathisabssysjoin TypeErrorAttributeErrortokenizeopen readlinesUnicodeDecodeError SyntaxErrorrr) rrr!rbasenamedatadirnamefprrr rrr rPsl       )  rcCs|tvrtt|dkrdSdS|r|dr|drdS|r^d|vr^|d}|d}durG|d }rGz|j}Wn tyFYnwt|d d}|r^|r^t ||}|ft|<dSdS) aSeed the cache for filename with module_globals. The module loader will be asked for the source only when getlines is called, not immediately. If there is an entry in the cache already, it is not altered. :return: True if a lazy load is registered in the cache, otherwise False. To register such a load a module loader with a get_source method must be found, the filename must be a cacheable filename, and the filename must not be already cached. r TFr"r#__name__ __loader__N__spec__ get_source) rr r)r*getloaderr2getattr functoolspartial)rrnamerAspecr? get_linesrrr rs*       r)N) __doc__rCr/rr3__all__rrrr rrrrrrr s    C