1class LockPicker_9MI0600292:
2 def __init__(self, lock):
3 self.lock = lock
4 self.args = []
5
6 def default_value_for_type(self, typ):
7 types = {
8 'int': 0,
9 'str': "",
10 'float': 0.0,
11 'list': [],
12 'dict': {},
13 'set': set(),
14 'tuple': (),
15 'complex': 0j
16 }
17
18 try:
19 type_name = typ.__name__
20 return types.get(type_name, None)
21 except Exception:
22 return None
23
24 def handle_type_error(self, exc):
25 if exc.position is None:
26 return [None] * exc.expected
27
28 position = exc.position - 1 # защото започваме от 1
29 expected_type = exc.expected
30
31 if len(self.args) <= position:
32 self.args.extend([None] * (position - len(self.args) + 1))
33
34 self.args[position] = self.default_value_for_type(expected_type)
35 return self.args
36
37 def handle_value_error(self, exc):
38 position = exc.position - 1
39 expected_value = exc.expected
40
41 if len(self.args) <= position:
42 self.args.extend([None] * (position - len(self.args) + 1))
43
44 self.args[position] = expected_value
45 return self.args
46
47 def unlock(self):
48 while True:
49 try:
50 if self.lock.pick(*self.args):
51 break
52 except TypeError as type_e:
53 self.args = self.handle_type_error(type_e)
54 except ValueError as val_e:
55 self.args = self.handle_value_error(val_e)
Timed out.
13.11.2024 13:46
13.11.2024 13:47
13.11.2024 13:48
13.11.2024 13:50