@@ -47,6 +47,21 @@ def wrapped(*args, **kwargs):
47
47
return wrapped
48
48
49
49
50
+ def custom_tag (
51
+ name : str ,
52
+ ** arguments ,
53
+ ):
54
+ def actual_decorator (func ):
55
+ @functools .wraps (func )
56
+ def wrapped (* args , ** kwargs ):
57
+ attrs = get_attrs_str (arguments )
58
+ return f"<{ name } { attrs } >{ func (* args , ** kwargs )} </{ name } >"
59
+
60
+ return wrapped
61
+
62
+ return actual_decorator
63
+
64
+
50
65
def composed (* decs ):
51
66
def deco (f ):
52
67
for dec in reversed (decs ):
@@ -69,21 +84,6 @@ def multi(func):
69
84
)(func )
70
85
71
86
72
- def custom_tag (
73
- name : str ,
74
- ** arguments ,
75
- ):
76
- def actual_decorator (func ):
77
- @functools .wraps (func )
78
- def wrapped (* args , ** kwargs ):
79
- attrs = get_attrs_str (arguments )
80
- return f"<{ name } { attrs } >{ func (* args , ** kwargs )} </{ name } >"
81
-
82
- return wrapped
83
-
84
- return actual_decorator
85
-
86
-
87
87
@custom_tag (
88
88
name = "a" ,
89
89
href = "https://example.com" ,
@@ -101,8 +101,9 @@ def hello_2(text):
101
101
return text
102
102
103
103
104
- print (hello ("Hello World!" ))
105
- # <a href="https://example.com" title="Hint!"><b foo="1"><i bar="2">HELLO WORLD!</i></b></a>
104
+ if __name__ == '__main__' :
105
+ print (hello ("Hello World!" ))
106
+ # <a href="https://example.com" title="Hint!"><b foo="1"><i bar="2">HELLO WORLD!</i></b></a>
106
107
107
- print (hello_2 ("Hello World!" ))
108
- # <a href="https://example.com" title="Hint!"><b foo="1"><i bar="2">HELLO WORLD!</i></b></a>
108
+ print (hello_2 ("Hello World!" ))
109
+ # <a href="https://example.com" title="Hint!"><b foo="1"><i bar="2">HELLO WORLD!</i></b></a>
0 commit comments