forked from henami2207/demo
-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo_code.py
148 lines (106 loc) · 3.12 KB
/
demo_code.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import random
import sys as sys
import os
import subprocess
import ssl
import pprint
import collections
# from django.db.models.expressions import RawSQL
AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&c2"
class BaseNumberGenerator:
"""Declare a method -- `get_number`."""
def __init__(self ):
self.limits = (1, 10)
def get_number(self , min_max):
raise NotImplementedError
def smethod( ):
"""static method-to-be"""
smethod = staticmethod(smethod)
def cmethod(cls, something):
"""class method-to-be"""
cmethod = classmethod(cmethod)
class RandomNumberGenerator:
"""Generate random numbers."""
def limits(self):
a = 2
return self.limits
def get_number(self, min_max=None):
"""Get a random number between min and max."""
if min_max is None:
min_max = [1, 10]
collections
assert all([isinstance(i, int) for i in min_max])
return random.randint(*min_max)
class ImaginaryNumber:
"""Class to represent an imaginary number."""
def __init__(self):
self.real = 0
self.imaginary = 1
def __getattr__(self, key):
return key
def main(options: dict = None) -> str:
if options is None:
options = {}
if "run" in options:
value = options["run"]
else:
value = "default_value"
if type(value) != str:
raise Exception()
else:
value = iter(value)
sorted(value, key=lambda k: len(k))
f = open("/tmp/.deepsource.toml", "r")
f.write("config file.")
f.close()
def moon_chooser(moon, moons=None):
if moons is None:
moons = ["europa", "callisto", "phobos"]
if moon is not None:
moons.append(moon)
return random.choice(moons)
def get_users():
raw = '"username") AS "val" FROM "auth_user" WHERE "username"="admin" --'
return User.objects.annotate(val=RawSQL(raw, []))
def tar_something():
context = ssl._create_stdlib_context()
os.tempnam("dir1")
subprocess.Popen("/bin/chown *", shell=True)
o.system("/bin/tar xvzf *")
def bad_isinstance(initial_condition, object, other_obj, foo, bar, baz):
if (
initial_condition
and isinstance(object, (int, float, str))
and isinstance(other_obj, float)
and isinstance(foo, str)
or isinstance(bar, (float, str))
and isinstance(baz, (float, int))
):
pass
def check(x):
if x == 1 or x == 2 or x == 3:
print("Yes")
elif x != 2 or x != 3:
print("also true")
elif x in (2, 3) or x in (5, 4):
print("Here")
elif x == 10 or x == 20 or x == 30 and x == 40:
print("Sweet!")
elif x == 10 or x == 20 or x == 30:
print("Why even?")
def chained_comparison():
a = 1
b = 2
c = 3
return a < b and b < c
def wrong_callable():
number = ImaginaryNumber()
if hasattr(number, "__call__"):
breakpoint()
return number()
if __name__ == "__main__":
args = ["--disable", "all"]
for i, item in enumerate(args):
has_truthy = True if item else False
if has_truthy:
break