3 G\1 @ s d Z ddlmZmZ ddlZddlZddlZddlZddlZddlZddl Z ddl mZ ddlm Z ddlmZmZmZmZ esejZejZndd Zd d ZdZdjd ejed ejejd d> ejd B ZG dd deZG dd deZG dd deZG dd deZ dS )a 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) 2017 by the Jinja Team. :license: BSD. )pathlistdirN)sha1)open_if_exists)BytesIOpicklePY2 text_typec C s, t |trtj| | n|jtj| d S )N) isinstancefilemarshaldumpwritedumps)codef r /usr/lib/python3.6/bccache.pymarshal_dump$ s r c C s" t | trtj| S tj| j S )N)r r r loadloadsread)r r r r marshal_load* s r Zj2ascii c @ s@ e Zd ZdZdd Zdd Zdd Zdd Zd d Zdd Z dS )Bucketau Buckets 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. c C s || _ || _|| _| j d S )N)environmentkeychecksumreset)selfr r r! r r r __init__E s zBucket.__init__c C s d| _ dS )z)Resets the bucket (unloads the bytecode).N)r )r# r r r r" K s zBucket.resetc C sx |j tt}|tkr"| j dS tj|}| j|krB| j dS yt|| _W n" t t tfk rr | j dS X dS )z/Loads bytecode from a file or file like object.N)r lenbc_magicr" r r r! r r EOFError ValueError TypeError)r# r magicr! r r r load_bytecodeO s zBucket.load_bytecodec C s<