Don't rewrite URLs

Remove the code that was appending ../static in front of some URLs, and add a
way to do cross-content linking.
This commit is contained in:
Bruno Binet 2012-11-30 10:46:32 +01:00
commit c74abe579b
12 changed files with 228 additions and 125 deletions

View file

@ -4,7 +4,9 @@ import re
import pytz
import shutil
import logging
from collections import defaultdict
import errno
from collections import defaultdict, Hashable
from functools import partial
from codecs import open
from datetime import datetime
@ -19,6 +21,32 @@ class NoFilesError(Exception):
pass
class memoized(object):
'''Decorator. Caches a function's return value each time it is called.
If called later with the same arguments, the cached value is returned
(not reevaluated).
'''
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
if not isinstance(args, Hashable):
# uncacheable. a list, for instance.
# better to not cache than blow up.
return self.func(*args)
if args in self.cache:
return self.cache[args]
else:
value = self.func(*args)
self.cache[args] = value
return value
def __repr__(self):
'''Return the function's docstring.'''
return self.func.__doc__
def __get__(self, obj, objtype):
'''Support instance methods.'''
return partial(self.__call__, obj)
def get_date(string):
"""Return a datetime object from a string.
@ -300,3 +328,11 @@ def set_date_tzinfo(d, tz_name=None):
return tz.localize(d)
else:
return d
def mkdir_p(path):
try:
os.makedirs(path)
except OSError, e:
if e.errno != errno.EEXIST:
raise