Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.882475735657928","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IGpzb24KZnJvbSBmdW5jdG9vbHMgaW1wb3J0IHdyYXBzCmZyb20gY29sbGVjdGlvbnMuYWJjIGltcG9ydCBDYWxsYWJsZQoKY2xhc3MgQ2FsbGFibGVXaXRoT3JpZyhDYWxsYWJsZSk6CiAgICBkZWYgX19pbml0X18oc2VsZiwgdG9fY2FsbCwgb3JpZyk6CiAgICAgICAgc2VsZi5fdG9fY2FsbCA9IHRvX2NhbGwKICAgICAgICBzZWxmLl9vcmlnID0gb3JpZwogICAgCiAgICBkZWYgX19jYWxsX18oc2VsZiwgKmFyZ3MsICoqa3dhcmdzKToKICAgICAgICByZXR1cm4gc2VsZi5fdG9fY2FsbCgqYXJncywgKiprd2FyZ3MpCgogICAgQHByb3BlcnR5CiAgICBkZWYgb3JpZyhzZWxmKToKICAgICAgICBpZiBpc2luc3RhbmNlKHNlbGYuX29yaWcsIHR5cGUoc2VsZikpOgogICAgICAgICAgICByZXR1cm4gc2VsZi5fb3JpZy5vcmlnCiAgICAgICAgZWxzZToKICAgICAgICAgICAgcmV0dXJuIHNlbGYuX29yaWcKCmNsYXNzIFNhdmluZ09yaWcoQ2FsbGFibGUpOgogICAgZGVmIF9faW5pdF9fKHNlbGYsIGFub3RoZXJfZGVjb3JhdG9yKToKICAgICAgICBzZWxmLl9hbm90aGVyID0gYW5vdGhlcl9kZWNvcmF0b3IKICAKICAgIGRlZiBfX2NhbGxfXyhzZWxmLCBmKToKICAgICAgICByZXR1cm4gQ2FsbGFibGVXaXRoT3JpZyhzZWxmLl9hbm90aGVyKGYpLCBmKQoKc2F2aW5nX29yaWcgPSBTYXZpbmdPcmlnCgpkZWYgZW5zdXJlX2xpc3QoZik6CiAgICBAd3JhcHMoZikKICAgIGRlZiBkZWNvcmF0ZWQoKmFyZ3MsICoqa3dhcmdzKToKICAgICAgICByZXN1bHQgPSBmKCphcmdzLCAqKmt3YXJncykKCiAgICAgICAgaWYgaXNpbnN0YW5jZShyZXN1bHQsIGxpc3QpOgogICAgICAgICAgICByZXR1cm4gcmVzdWx0CiAgICAgICAgZWxzZToKICAgICAgICAgICAgcmV0dXJuIFtyZXN1bHRdCgogICAgcmV0dXJuIGRlY29yYXRlZAoKZGVmIGVuc3VyZV9pbnRzKCosIGRlZmF1bHQ9Tm9uZSk6CiAgICBkZWYgZGVjb3JhdG9yKGYpOgogICAgICAgIEB3cmFwcyhmKQogICAgICAgIGRlZiBkZWNvcmF0ZWQoKmFyZ3MsICoqa3dhcmdzKToKICAgICAgICAgICAgcmVzdWx0ID0gZigqYXJncywgKiprd2FyZ3MpCiAgICAgICAgICAgIGludHMgPSBbXQogICAgICAgICAgICBmb3IgeCBpbiByZXN1bHQ6CiAgICAgICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICAgICAgeF9pbnQgPSBpbnQoeCkKICAgICAgICAgICAgICAgIGV4Y2VwdCBWYWx1ZUVycm9yOgogICAgICAgICAgICAgICAgICAgIGlmIGRlZmF1bHQgaXMgTm9uZToKICAgICAgICAgICAgICAgICAgICAgICAgcmFpc2UKICAgICAgICAgICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgICAgICAgICB4X2ludCA9IGRlZmF1bHQKICAgICAgICAgICAgICAgIGludHMuYXBwZW5kKHhfaW50KQogICAgICAgICAgICByZXR1cm4gaW50cwogICAgICAgIHJldHVybiBkZWNvcmF0ZWQKICAgIHJldHVybiBkZWNvcmF0b3IKCkBzYXZpbmdfb3JpZyhlbnN1cmVfaW50cyhkZWZhdWx0PTQyKSkKQHNhdmluZ19vcmlnKGVuc3VyZV9saXN0KQpkZWYgbG9hZF9kYXRhKHN0cmluZyk6CiAgICByZXR1cm4ganNvbi5sb2FkcyhzdHJpbmcpCgpmb3IgZiBpbiAoCiAgICBsb2FkX2RhdGEsCiAgICBsb2FkX2RhdGEub3JpZywKKToKICAgIHByaW50KHJlcHIoZignIlgiJykpKQoK"},"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
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
import json
from functools import wraps
from collections.abc import Callable

class CallableWithOrig(Callable):
    def __init__(self, to_call, orig):
        self._to_call = to_call
        self._orig = orig
    
    def __call__(self, *args, **kwargs):
        return self._to_call(*args, **kwargs)

    @property
    def orig(self):
        if isinstance(self._orig, type(self)):
            return self._orig.orig
        else:
            return self._orig

class SavingOrig(Callable):
    def __init__(self, another_decorator):
        self._another = another_decorator
  
    def __call__(self, f):
        return CallableWithOrig(self._another(f), f)

saving_orig = SavingOrig

def ensure_list(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        result = f(*args, **kwargs)

        if isinstance(result, list):
            return result
        else:
            return [result]

    return decorated

def ensure_ints(*, default=None):
    def decorator(f):
        @wraps(f)
        def decorated(*args, **kwargs):
            result = f(*args, **kwargs)
            ints = []
            for x in result:
                try:
                    x_int = int(x)
                except ValueError:
                    if default is None:
                        raise
                    else:
                        x_int = default
                ints.append(x_int)
            return ints
        return decorated
    return decorator

@saving_orig(ensure_ints(default=42))
@saving_orig(ensure_list)
def load_data(string):
    return json.loads(string)

for f in (
    load_data,
    load_data.orig,
):
    print(repr(f('"X"')))