Spade
Mini Shell
�
��\c@s�dZddlmZmZddlZddlZddlZddlZddlZddlZddl Z ddl
mZddlm
Z
ddlmZmZmZmZes�ejZejZnd�Zd�Zd Zd
jd�ejed �ejejdd
>ejdB�Zdefd��YZdefd��YZdefd��YZdefd��YZ
dS(s�
jinja2.bccache
~~~~~~~~~~~~~~
This module implements the bytecode cache system Jinja is optionally
using. This is useful if you have very complex template situations and
the compiliation of all those templates slow down your application too
much.
Situations where this is useful are often forking web applications that
are initialized on the first request.
:copyright: (c) 2010 by the Jinja Team.
:license: BSD.
i����(tpathtlistdirN(tsha1(topen_if_exists(tBytesIOtpickletPY2t text_typecCs<t|t�r"tj||�n|jtj|��dS(N(t
isinstancetfiletmarshaltdumptwritetdumps(tcodetf((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pytmarshal_dump$scCs/t|t�rtj|�Stj|j��S(N(RR R
tloadtloadstread(R((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pytmarshal_load*s
itj2tasciiiiitBucketcBsDeZdZd�Zd�Zd�Zd�Zd�Zd�ZRS(suBuckets
are used to store the bytecode for one template. It's created
and initialized by the bytecode cache and passed to the loading
functions.
The buckets get an internal checksum from the cache assigned and use
this
to automatically reject outdated cache material. Individual bytecode
cache subclasses don't have to care about cache invalidation.
cCs)||_||_||_|j�dS(N(tenvironmenttkeytchecksumtreset(tselfRRR((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyt__init__Es cCs
d|_dS(s)Resets
the bucket (unloads the
bytecode).N(tNoneR(R((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyRKscCsn|jtt��}|tkr/|j�dStj|�}|j|kr[|j�dSt|�|_dS(s/Loads
bytecode from a file or file like
object.N( Rtlentbc_magicRRRRRR(RRtmagicR((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyt
load_bytecodeOs
cCsU|jdkrtd��n|jt�tj|j|d�t|j|�dS(s;Dump
the bytecode into the file or file like object passed.scan't write
empty bucketiN( RRt TypeErrorRR
RRRR(RR((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pytwrite_bytecode]s
cCs|jt|��dS(sLoad bytecode from a
string.N(R"R(Rtstring((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pytbytecode_from_stringescCs
t�}|j|�|j�S(sReturn the bytecode as
string.(RR$tgetvalue(Rtout((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pytbytecode_to_stringis
( t__name__t
__module__t__doc__RRR"R$R&R)(((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR<s t
BytecodeCachecBsPeZdZd�Zd�Zd�Zdd�Zd�Zd�Z d�Z
RS( s�To implement your own bytecode cache you have to subclass this
class
and override :meth:`load_bytecode` and :meth:`dump_bytecode`. Both of
these methods are passed a :class:`~jinja2.bccache.Bucket`.
A very basic bytecode cache that saves the bytecode on the file
system::
from os import path
class MyCache(BytecodeCache):
def __init__(self, directory):
self.directory = directory
def load_bytecode(self, bucket):
filename = path.join(self.directory, bucket.key)
if path.exists(filename):
with open(filename, 'rb') as f:
bucket.load_bytecode(f)
def dump_bytecode(self, bucket):
filename = path.join(self.directory, bucket.key)
with open(filename, 'wb') as f:
bucket.write_bytecode(f)
A more advanced version of a filesystem based bytecode cache is part of
Jinja2.
cCs
t��dS(s�Subclasses have to override this method to load
bytecode into a
bucket. If they are not able to find code in the cache for the
bucket, it must not do anything.
N(tNotImplementedError(Rtbucket((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR"�scCs
t��dS(s�Subclasses
have to override this method to write the bytecode
from a bucket back to the cache. If it unable to do so it must not
fail silently but raise an exception.
N(R.(RR/((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyt
dump_bytecode�scCsdS(s�Clears
the cache. This method is not used by Jinja2 but should be
implemented to allow applications to clear the bytecode cache used
by a particular environment.
N((R((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pytclear�scCsft|jd��}|dk r\d|}t|t�rL|jd�}n|j|�n|j�S(s3Returns
the unique hash key for this template
name.sutf-8t|N(RtencodeRRRtupdatet hexdigest(Rtnametfilenamethash((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyt
get_cache_key�s
cCst|jd��j�S(s"Returns a checksum for the
source.sutf-8(RR3R5(Rtsource((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pytget_source_checksum�scCsD|j||�}|j|�}t|||�}|j|�|S(swReturn
a cache bucket for the given template. All arguments are
mandatory but filename may be `None`.
(R9R;RR"(RRR6R7R:RRR/((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyt
get_bucket�s
cCs|j|�dS(sPut the bucket into the
cache.N(R0(RR/((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyt
set_bucket�sN(R*R+R,R"R0R1RR9R;R<R=(((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR-ps
tFileSystemBytecodeCachecBsJeZdZddd�Zd�Zd�Zd�Zd�Zd�Z RS( s�A
bytecode cache that stores bytecode on the filesystem. It accepts
two arguments: The directory where the cache items are stored and a
pattern string that is used to build the filename.
If no directory is specified a default cache directory is selected. On
Windows the user's temp directory is used, on UNIX systems a
directory
is created for the user in the system temp directory.
The pattern can be used to have multiple separate caches operate on the
same directory. The default pattern is
``'__jinja2_%s.cache'``. ``%s``
is replaced with the cache key.
>>> bcc =
FileSystemBytecodeCache('/tmp/jinja_cache', '%s.cache')
This bytecode cache supports clearing of the cache using the clear
method.
s__jinja2_%s.cachecCs1|dkr|j�}n||_||_dS(N(Rt_get_default_cache_dirt directorytpattern(RR@RA((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR�s cCstj�}tjdkr|Sttd�s=td��ndtj�}tjj||�}ytj |d�Wn+t
k
r�}|jtjkr��q�nXtj
|�jtj�kr�td��ntjtj
|�j�dkrtd��n|S(NtntgetuidsJCannot
determine safe temp directory. You need to explicitly provide
one.s_jinja2-cache-%di�sWSomeone else owns temp directory with your
uid. You need to explicitly provide another.sLBad permission flags on temp
directory, shoud be 0700. You need to fix this.(ttempfilet
gettempdirtosR6thasattrtRuntimeErrorRCRtjointmkdirtOSErrorterrnotEEXISTtlstattst_uidtstattS_IMODEtst_mode(Rttmpdirtdirnamet
actual_dirte((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR?�s"
!cCstj|j|j|j�S(N(RRIR@RAR(RR/((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyt_get_cache_filename�scCsJt|j|�d�}|dk rFz|j|�Wd|j�XndS(Ntrb(RRWRR"tclose(RR/R((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR"�s
cCs;t|j|�d�}z|j|�Wd|j�XdS(Ntwb(topenRWR$RY(RR/R((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR0�scCsxddlm}tjt|j�|jd�}x?|D]7}y|tj|j|��Wq9t k
roq9Xq9WdS(Ni����(tremovet*(
RFR\tfnmatchtfilterRR@RARRIRK(RR\tfilesR7((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR1s"
N(
R*R+R,RRR?RWR"R0R1(((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR>�s tMemcachedBytecodeCachecBs2eZdZdded�Zd�Zd�ZRS(suThis
class implements a bytecode cache that uses a memcache cache for
storing the information. It does not enforce a specific memcache
library
(tummy's memcache or cmemcache) but will accept any class that
provides
the minimal interface required.
Libraries compatible with this class:
- `werkzeug <http://werkzeug.pocoo.org/>`_.contrib.cache
- `python-memcached
<http://www.tummy.com/Community/software/python-memcached/>`_
- `cmemcache <http://gijsbert.org/cmemcache/>`_
(Unfortunately the django cache interface is not compatible because it
does not support storing binary data, only unicode. You can however
pass
the underlying cache client to the bytecode cache which is available
as `django.core.cache.cache._client`.)
The minimal interface for the client passed to the constructor is this:
.. class:: MinimalClientInterface
.. method:: set(key, value[, timeout])
Stores the bytecode in the cache. `value` is a string and
`timeout` the timeout of the key. If timeout is not provided
a default timeout or no timeout should be assumed, if it's
provided it's an integer with the number of seconds the
cache
item should exist.
.. method:: get(key)
Returns the value for the cache key. If the item does not
exist in the cache the return value must be `None`.
The other arguments to the constructor are the prefix for all keys that
is added before the actual cache key and the timeout for the bytecode
in
the cache system. We recommend a high (or no) timeout.
This bytecode cache does not support clearing of used items in the
cache.
The clear method is a no-operation function.
.. versionadded:: 2.7
Added support for ignoring memcache errors through the
`ignore_memcache_errors` parameter.
sjinja2/bytecode/cCs(||_||_||_||_dS(N(tclienttprefixttimeouttignore_memcache_errors(RRbRcRdRe((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyRAs cCsiy
|jj|j|j�}Wn&tk
rH|js?�nd}nX|dk re|j|�ndS(N(RbtgetRcRt ExceptionReRR&(RR/R((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR"Hs
cCsy|j|j|j�f}|jdk r>||jf7}ny|jj|�Wn tk
rt|jsu�qunXdS(N( RcRR)RdRRbtsetRgRe(RR/targs((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyR0Rs
N(R*R+R,RtTrueRR"R0(((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyRas
,
(!R,RFRRRPtsysRLR
RDR^thashlibRtjinja2.utilsRtjinja2._compatRRRRRRRRt
bc_versionR3R
tversion_infoR
tobjectRR-R>Ra(((s2/usr/lib/python2.7/site-packages/jinja2/bccache.pyt<module>s." &4NU