-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecorator.py
More file actions
47 lines (34 loc) · 911 Bytes
/
decorator.py
File metadata and controls
47 lines (34 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#Two examples of Decorators.
# One (Converts array of strings to camelCase strings!)
def deco_camelcase(func):
def inner(list_of_values):
return [func(string) for string in list_of_values]
return inner
@deco_camelcase
def camelcase(string):
string = ''.join(one.capitalize() for one in string.split('_'))
return string
names = [
"hello_world",
"with_name",
"snoop_dogg"
]
# Two (Converts a unsecure function to secure!)
def secure_function(func):
def inner(key, pwd=None):
if pwd == "hello":
return func(key)
else:
return "Not allowed to access!!!"
return inner
@secure_function
def unsecure_function(key):
dict_val = {
"rohan" : 8799118910,
"mohan" : 1234987543,
"Sodhan" : 9876543210
}
if key in dict_val:
return dict_val[key]
else:
return "Not found"