コード例 #1
0
 def __get_meta(self, f_obj):
     name = getattr(
         f_obj,
         "__hookname__",
         f_obj.__name__.split('.')[-1],
     )
     state = self.__get_state_storage(name)
     if state is None:
         state = getattr(f_obj, "__state__", "enabled")
     return Attribution({
         "author":
         f_obj.__author__,
         "version":
         f_obj.__version__,
         "description":
         getattr(f_obj, "__description__", None),
         "state":
         state,
         "name":
         name,
         "proxy":
         f_obj,
         "time":
         time(),
         "catalog":
         getattr(f_obj, "__catalog__", None),
         "tplpath":
         join(self.__get_fileorparent(f_obj, True), "templates"),
     })
コード例 #2
0
ファイル: token.py プロジェクト: copyit/picbed
def verify_rule(Ld):
    """根据er、ir规则判断是否放行请求"""
    allow = Attribution(
        dict(
            ip=Attribution(
                dict(access=get_ip(), secure=parse_valid_comma(Ld["allow_ip"]) or [])
            ),
            origin=Attribution(
                dict(
                    access=get_origin(),
                    secure=parse_valid_comma(Ld["allow_origin"]) or [],
                )
            ),
            ep=Attribution(
                dict(
                    access=request.endpoint,
                    secure=parse_valid_comma(Ld["allow_ep"]) + ["api.index"],
                )
            ),
            method=Attribution(
                dict(
                    access=request.method,
                    secure=[
                        m.upper()
                        for m in parse_valid_comma(Ld["allow_method"]) or []
                        if m
                    ],
                )
            ),
        )
    )
    #: 参数 逻辑运算符 参数 逻辑运算符 参数...
    #: 参数: origin and ip and ep and method
    #: 逻辑运算符: and or not in not in
    #: er控制的是参与逻辑运算的参数及之间的逻辑运算符
    #: ir控制的是参数如何返回True
    er = Ld["exterior_relation"]
    ir = Ld["interior_relation"]
    if not er:
        er = "origin and ip and ep and method"
    #: ir定义的最终规则
    ir_cmd = _allow_ir(ir, allow)
    #: 综合er、ir构建最终执行的命令字符串
    for opt in ALLOWED_RULES:
        er = er.replace(opt, ir_cmd[opt])
    logger.debug("last er: %s" % er)
    return eval(er)
コード例 #3
0
ファイル: hook.py プロジェクト: copyit/picbed
 def __get_meta(self, f_obj):
     #: 钩子友好的可见名,非模块名
     name = getattr(
         f_obj,
         "__hookname__",
         f_obj.__name__.split(".")[-1],
     )
     state = self.__get_state_storage(name)
     if state is None:
         state = getattr(f_obj, "__state__", "enabled")
     (author, mail) = parse_author_mail(f_obj.__author__)
     return Attribution({
         "author":
         author,
         "email":
         mail,
         "version":
         f_obj.__version__,
         "appversion":
         getattr(f_obj, "__appversion__", None),
         "description":
         getattr(f_obj, "__description__", None),
         "state":
         state,
         "name":
         name,
         "proxy":
         f_obj,
         "time":
         time(),
         "catalog":
         getattr(f_obj, "__catalog__", None),
         "tplpath":
         join(self.__get_fileorparent(f_obj, True), "templates"),
         "atspath":
         join(self.__get_fileorparent(f_obj, True), "static"),
     })
コード例 #4
0
ファイル: test_utils.py プロジェクト: copyit/picbed
 def test_attrclass(self):
     d = Attribution(dict(a=1, b=2, c=3))
     with self.assertRaises(AttributeError):
         d.d
     self.assertEqual(d.a, 1)
     self.assertIsInstance(d, dict)