Exemplo n.º 1
0
def clean(hookloadtime, hookthirds):
    """清理系统"""
    if hookloadtime:
        s = get_storage()
        del s['hookloadtime']
    if hookthirds:
        s = get_storage()
        del s['hookthirds']
Exemplo n.º 2
0
def set_site_config(mapping):
    """设置站点信息"""
    if mapping and isinstance(mapping, dict):
        ALLOWED_TAGS = ['a', 'abbr', 'b', 'i', 'code', 'p', 'br', 'h3', 'h4']
        ALLOWED_ATTRIBUTES = {
            'a': ['href', 'title', 'target'],
            'abbr': ['title'],
            '*': ['style'],
        }
        ALLOWED_STYLES = ['color']
        upload_beforehtml = mapping.get("upload_beforehtml") or ""
        bulletin = mapping.get("bulletin") or ""
        if upload_beforehtml:
            mapping["upload_beforehtml"] = bleach_html(upload_beforehtml,
                                                       ALLOWED_TAGS,
                                                       ALLOWED_ATTRIBUTES,
                                                       ALLOWED_STYLES)
        if bulletin:
            ALLOWED_TAGS.append("img")
            ALLOWED_ATTRIBUTES["img"] = [
                'title', 'alt', 'src', 'width', 'height'
            ]
            mapping["bulletin"] = bleach_html(bulletin, ALLOWED_TAGS,
                                              ALLOWED_ATTRIBUTES,
                                              ALLOWED_STYLES)
        s = get_storage()
        cfg = s.get("siteconfig") or {}
        cfg.update(mapping)
        s.set("siteconfig", cfg)
Exemplo n.º 3
0
def set_site_config(mapping):
    """设置站点信息"""
    if mapping and isinstance(mapping, dict):
        ALLOWED_TAGS = ["a", "abbr", "b", "i", "code", "p", "br", "h3", "h4"]
        ALLOWED_ATTRIBUTES = {
            "a": ["href", "title", "target"],
            "abbr": ["title"],
            "*": ["style"],
        }
        ALLOWED_STYLES = ["color"]
        upload_beforehtml = mapping.get("upload_beforehtml") or ""
        bulletin = mapping.get("bulletin") or ""
        about = mapping.get("about") or ""
        if upload_beforehtml:
            mapping["upload_beforehtml"] = bleach_html(upload_beforehtml,
                                                       ALLOWED_TAGS,
                                                       ALLOWED_ATTRIBUTES,
                                                       ALLOWED_STYLES)
        if bulletin:
            ALLOWED_TAGS.append("img")
            ALLOWED_ATTRIBUTES["img"] = [
                "title", "alt", "src", "width", "height"
            ]
            mapping["bulletin"] = bleach_html(bulletin, ALLOWED_TAGS,
                                              ALLOWED_ATTRIBUTES,
                                              ALLOWED_STYLES)
        if about:
            mapping["about"] = bleach_html(about, ALLOWED_TAGS,
                                           ALLOWED_ATTRIBUTES, ALLOWED_STYLES)
        s = get_storage()
        cfg = s.get("siteconfig") or {}
        cfg.update(mapping)
        s.set("siteconfig", cfg)
Exemplo n.º 4
0
    def test_basestorage(self):
        class MyStorage(BaseStorage):
            pass

        ms = MyStorage()
        with self.assertRaises(AttributeError):
            ms.get('test')
        self.assertIsInstance(get_storage(), BaseStorage)
Exemplo n.º 5
0
def get_site_config():
    """获取站点配置"""
    s = get_storage()
    cfg = s.get("siteconfig") or {}
    #: Maybe to fix None
    if "upload_includes" not in cfg:
        cfg["upload_includes"] = ""
    return cfg
Exemplo n.º 6
0
Arquivo: cli.py Projeto: copyit/picbed
def clean(hookloadtime, hookthirds, invalidkey):
    """清理系统"""
    if hookloadtime:
        s = get_storage()
        del s["hookloadtime"]
    if hookthirds:
        s = get_storage()
        del s["hookthirds"]
    if invalidkey:
        rc = create_redis_engine()
        ius = rc.keys(rsp("index", "user", "*"))
        pipe = rc.pipeline()
        for uk in ius:
            us = rc.smembers(uk)
            for sha in us:
                if not rc.exists(rsp("image", sha)):
                    pipe.srem(uk, sha)
        try:
            pipe.execute()
        except RedisError:
            pass
Exemplo n.º 7
0
def get_site_config():
    """获取站点配置"""
    s = get_storage()
    cfg = s.get("siteconfig") or {}
    return cfg
Exemplo n.º 8
0
def set_site_config(mapping):
    if mapping and isinstance(mapping, dict):
        s = get_storage()
        cfg = s.get("siteconfig") or {}
        cfg.update(mapping)
        s.set("siteconfig", cfg)
Exemplo n.º 9
0
def get_site_config():
    s = get_storage()
    cfg = s.get("siteconfig") or {}
    return cfg
Exemplo n.º 10
0
def delete_hookloadtime():
    from libs.storage import get_storage
    s = get_storage()
    del s['hookloadtime']