# Path: jinja2/utils.py
# def open_if_exists(filename, mode='r'):
#     """Returns a file descriptor for the filename if that file exists,
#     otherwise `None`.
#     """
#     try:
#         return file(filename, mode)
#     except IOError, e:
#         if e.errno not in (errno.ENOENT, errno.EISDIR):
#             raise


from os import path, listdir
from cStringIO import StringIO
    from hashlib import sha1
    from sha import new as sha1
from jinja2.utils import open_if_exists
        from os import remove
import marshal
import tempfile
import cPickle as pickle
import fnmatch
        """Put the bucket into the cache."""
        self.dump_bytecode(bucket)


class FileSystemBytecodeCache(BytecodeCache):
    """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 the system temporary items folder is used.

    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.
    """

    def __init__(self, directory=None, pattern='__jinja2_%s.cache'):
        if directory is None:
            directory = tempfile.gettempdir()
        self.directory = directory
        self.pattern = pattern

    def _get_cache_filename(self, bucket):
        return path.join(self.directory, self.pattern % bucket.key)

    def load_bytecode(self, bucket):

# Path: jinja2/utils.py
# def open_if_exists(filename, mode='r'):
#     """Returns a file descriptor for the filename if that file exists,
#     otherwise `None`.
#     """
#     try:
#         return file(filename, mode)
#     except IOError, e:
#         if e.errno not in (errno.ENOENT, errno.EISDIR):
#             raise


# Path: jinja2/bccache.py
from os import path, listdir
from cStringIO import StringIO
    from hashlib import sha1
    from sha import new as sha1
from jinja2.utils import open_if_exists
        from os import remove
import marshal
import tempfile
import cPickle as pickle
import fnmatch

        """Put the bucket into the cache."""
        self.dump_bytecode(bucket)


class FileSystemBytecodeCache(BytecodeCache):
    """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 the system temporary items folder is used.

    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.
    """

    def __init__(self, directory=None, pattern='__jinja2_%s.cache'):
        if directory is None:
            directory = tempfile.gettempdir()
        self.directory = directory
        self.pattern = pattern

    def _get_cache_filename(self, bucket):
        return path.join(self.directory, self.pattern % bucket.key)

    def load_bytecode(self, bucket):

        f = open_if_exists(self._get_cache_filename(bucket), 'rb')