@SnoopJeDi/

MuffledUnfortunateWearables

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.29630920215866463","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IiIiCiAgQSBtb2NrLXVwIGZvciBmcmVlbm9kZSAjcHl0aG9uIG9mIGEgZGVjb3JhdG9yIGZhY3RvcnkgdGhhdCB0ZXN0cyBwcmVkaWNhdGVzIGJlZm9yZSBjYWxsaW5nIHRoZSB3cmFwcGVkCiAgZnVuY3Rpb24gQU5EIHBhc3NlcyB0aGUgdmFsdWUgYWxvbmcgdG8gdGhlIGZ1bmN0aW9uIHRvIGJlIHJlLXVzZWQuCiIiIgoKZGVmIGRlY2ZhY3QocHJlZGRpY3QpOgogIGRlZiBkZWMod3JhcHBlZCwgKmFyZ3MsICoqa3dhcmdzKToKICAgIGRlZiBnKCphcmdzLCAqKmt3YXJncyk6CiAgICAgIHByZWR2YWxzID0ge3ByZWRrZXk6cHJlZGZ1bmMoKmFyZ3MsICoqa3dhcmdzKSBmb3IgcHJlZGtleSxwcmVkZnVuYyBpbiBwcmVkZGljdC5pdGVtcygpfQogICAgICBpZiBhbGwocHJlZHZhbHMudmFsdWVzKCkpOgogICAgICAgIHJldHVybiB3cmFwcGVkKCphcmdzLCAqKnByZWR2YWxzLCAqKmt3YXJncykKICAgICAgZWxzZToKICAgICAgICByYWlzZSBWYWx1ZUVycm9yKGYnUHJlZGljYXRlIGZhaWxlZCBmb3Ige3dyYXBwZWQuX19uYW1lX199KCknKQogICAgZy5wcmVkID0gcHJlZGRpY3QKICAgIHJldHVybiBnCiAgcmV0dXJuIGRlYwoKZGVmIHRydWVwcmVkKCphcmdzKToKICByZXR1cm4gVHJ1ZQoKZGVmIGZhbHNlcHJlZCgqYXJncyk6CiAgcmV0dXJuIEZhbHNlCgpAZGVjZmFjdCh7J3ByZWQnOiB0cnVlcHJlZH0pCmRlZiBmb28oeCwgeSwgcHJlZCk6CiAgcHJpbnQocHJlZCkKICByZXR1cm4geCArIHkKCkBkZWNmYWN0KHsncHJlZCc6IGZhbHNlcHJlZH0pCmRlZiBiYXIoeCwgeSwgcHJlZCk6CiAgcHJpbnQocHJlZCkKICByZXR1cm4geCArIHkKCnByaW50KGZvby5wcmVkKQpwcmludChiYXIucHJlZCkKCmZvbygxLCAyKQpiYXIoMSwgMik="},"asBuffer":null},"loaded":true}}
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
"""
  A mock-up for freenode #python of a decorator factory that tests predicates before calling the wrapped
  function AND passes the value along to the function to be re-used.
"""

def decfact(preddict):
  def dec(wrapped, *args, **kwargs):
    def g(*args, **kwargs):
      predvals = {predkey:predfunc(*args, **kwargs) for predkey,predfunc in preddict.items()}
      if all(predvals.values()):
        return wrapped(*args, **predvals, **kwargs)
      else:
        raise ValueError(f'Predicate failed for {wrapped.__name__}()')
    g.pred = preddict
    return g
  return dec

def truepred(*args):
  return True

def falsepred(*args):
  return False

@decfact({'pred': truepred})
def foo(x, y, pred):
  print(pred)
  return x + y

@decfact({'pred': falsepred})
def bar(x, y, pred):
  print(pred)
  return x + y

print(foo.pred)
print(bar.pred)

foo(1, 2)
bar(1, 2)