Skip to content

Commit

Permalink
remove _compat module
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Feb 5, 2020
1 parent b0015c7 commit 148a191
Show file tree
Hide file tree
Showing 29 changed files with 266 additions and 768 deletions.
132 changes: 0 additions & 132 deletions src/jinja2/_compat.py

This file was deleted.

24 changes: 10 additions & 14 deletions src/jinja2/bccache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@
"""
import errno
import fnmatch
import marshal
import os
import pickle
import stat
import sys
import tempfile
from hashlib import sha1
from os import listdir
from os import path

from ._compat import BytesIO
from ._compat import marshal_dump
from ._compat import marshal_load
from ._compat import pickle
from ._compat import text_type
from io import BytesIO

from .utils import open_if_exists

bc_version = 4
Expand Down Expand Up @@ -67,7 +63,7 @@ def load_bytecode(self, f):
return
# if marshal_load fails then we need to reload
try:
self.code = marshal_load(f)
self.code = marshal.load(f)
except (EOFError, ValueError, TypeError):
self.reset()
return
Expand All @@ -78,7 +74,7 @@ def write_bytecode(self, f):
raise TypeError("can't write empty bucket")
f.write(bc_magic)
pickle.dump(self.checksum, f, 2)
marshal_dump(self.code, f)
marshal.dump(self.code, f)

def bytecode_from_string(self, string):
"""Load bytecode from a string."""
Expand Down Expand Up @@ -145,7 +141,7 @@ def get_cache_key(self, name, filename=None):
hash = sha1(name.encode("utf-8"))
if filename is not None:
filename = "|" + filename
if isinstance(filename, text_type):
if isinstance(filename, str):
filename = filename.encode("utf-8")
hash.update(filename)
return hash.hexdigest()
Expand Down Expand Up @@ -241,7 +237,7 @@ def _unsafe_dir():
return actual_dir

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

def load_bytecode(self, bucket):
f = open_if_exists(self._get_cache_filename(bucket), "rb")
Expand All @@ -264,10 +260,10 @@ def clear(self):
# normally.
from os import remove

files = fnmatch.filter(listdir(self.directory), self.pattern % "*")
files = fnmatch.filter(os.listdir(self.directory), self.pattern % "*")
for filename in files:
try:
remove(path.join(self.directory, filename))
remove(os.path.join(self.directory, filename))
except OSError:
pass

Expand Down
Loading

0 comments on commit 148a191

Please sign in to comment.