Пример #1
0
class Loader(object):
    def __init__(self, tags=None, tags_dir=None, max_size=None, check_modified_time=False):
        self.tags = tags or {}
        self.tags_dir = tags_dir
        if not isinstance(tags_dir, (tuple, list)):
            self.tags_dir = [tags_dir]
        self.cache = LRUTmplatesCacheDict(max_size=max_size, check_modified_time=check_modified_time)

    def find(self, tag):
        if tag in self.tags:
            return self.tags[tag]
        if self.tags_dir:
            for path in self.tags_dir:
                tag_file = os.path.join(path, '{}.html'.format(tag.replace('.', '/')))
                if self.cache.has(tag_file):
                    return self.cache[tag_file]
                else:
                    if os.path.exists(tag_file):
                        with open(tag_file) as f:
                            text = f.read()
                            self.cache.set(tag_file, text)
                        return text
            raise ValueError("Tag {} template file {} can't be found".format(tag, tag_file))

        else:
            raise ValueError("Tag {} can't be found".format(tag))

    def available(self):
        return bool(self.tags or self.tags_dir)
Пример #2
0
 def __init__(self,
              tags=None,
              tags_dir=None,
              max_size=None,
              check_modified_time=False):
     self.tags = tags or {}
     self.tags_dir = tags_dir
     if not isinstance(tags_dir, (tuple, list)):
         self.tags_dir = [tags_dir]
     self.cache = LRUTmplatesCacheDict(
         max_size=max_size, check_modified_time=check_modified_time)
Пример #3
0
class Loader(object):
    def __init__(self,
                 tags=None,
                 tags_dir=None,
                 max_size=None,
                 check_modified_time=False):
        self.tags = tags or {}
        self.tags_dir = tags_dir
        if not isinstance(tags_dir, (tuple, list)):
            self.tags_dir = [tags_dir]
        self.cache = LRUTmplatesCacheDict(
            max_size=max_size, check_modified_time=check_modified_time)

    def find(self, tag):
        if tag in self.tags:
            return self.tags[tag]
        if self.tags_dir:
            for path in self.tags_dir:
                tag_file = os.path.join(
                    path, '{}.html'.format(tag.replace('.', '/')))
                if self.cache.has(tag_file):
                    return self.cache[tag_file]
                else:
                    if os.path.exists(tag_file):
                        with open(tag_file) as f:
                            text = f.read()
                            self.cache.set(tag_file, text)
                        return text
            raise ValueError("Tag {} template file {} can't be found".format(
                tag, tag_file))

        else:
            raise ValueError("Tag {} can't be found".format(tag))

    def available(self):
        return bool(self.tags or self.tags_dir)
Пример #4
0
 def __init__(self, tags=None, tags_dir=None, max_size=None, check_modified_time=False):
     self.tags = tags or {}
     self.tags_dir = tags_dir
     if not isinstance(tags_dir, (tuple, list)):
         self.tags_dir = [tags_dir]
     self.cache = LRUTmplatesCacheDict(max_size=max_size, check_modified_time=check_modified_time)