Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.42827826164934124","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"ZnJvbSBhYmMgaW1wb3J0IEFCQ01ldGEsIGFic3RyYWN0bWV0aG9kCmltcG9ydCBqc29uCgoKY2xhc3MgVXNlcjoKICBkZWYgX19pbml0X18oc2VsZiwgbmFtZSk6CiAgICBzZWxmLm5hbWUgPSBuYW1lCgoKY2xhc3MgQWRtaW5Vc2VyKFVzZXIpOgogIGRlZiBiZV9yZXByZXNlbnRlZF9ieShzZWxmLCBzZXJpYWxpemVyKToKICAgIHJldHVybiBzZXJpYWxpemVyLnJlcHJlc2VudF9hZG1pbl91c2VyKHNlbGYpCgoKY2xhc3MgVHJpYWxVc2VyKFVzZXIpOgogIGRlZiBiZV9yZXByZXNlbnRlZF9ieShzZWxmLCBzZXJpYWxpemVyKToKICAgIHJldHVybiBzZXJpYWxpemVyLnJlcHJlc2VudF90cmlhbF91c2VyKHNlbGYpCgoKCmNsYXNzIFJlcHJlc2VudGVyKG1ldGFjbGFzcz1BQkNNZXRhKToKICBkZWYgcmVwcmVzZW50KHNlbGYsIHVzZXIpOgogICAgcmV0dXJuIHVzZXIuYmVfcmVwcmVzZW50ZWRfYnkoc2VsZikKCiAgQGFic3RyYWN0bWV0aG9kCiAgZGVmIHJlcHJlc2VudF9hZG1pbl91c2VyKHNlbGYsIHVzZXIpOgogICAgcGFzcwoKICBAYWJzdHJhY3RtZXRob2QKICBkZWYgcmVwcmVzZW50X3RyaWFsX3VzZXIoc2VsZiwgdXNlcik6CiAgICBwYXNzCgoKY2xhc3MgSnNvblJlcHJlc2VudGVyKFJlcHJlc2VudGVyKToKICBkZWYgcmVwcmVzZW50X2FkbWluX3VzZXIoc2VsZiwgdXNlcik6CiAgICByZXR1cm4ganNvbi5kdW1wcyh7CiAgICAgICJhZG1pbiI6IFRydWUsCiAgICAgICJuYW1lIjogdXNlci5uYW1lLAogICAgfSkKCiAgZGVmIHJlcHJlc2VudF90cmlhbF91c2VyKHNlbGYsIHVzZXIpOgogICAgcmV0dXJuIGpzb24uZHVtcHMoewogICAgICAidHJpYWwiOiBUcnVlLAogICAgICAibmFtZSI6IHVzZXIubmFtZSwKICAgIH0pCgoKY2xhc3MgU3RyaW5nUmVwcmVzZW50ZXIoUmVwcmVzZW50ZXIpOgogIGRlZiByZXByZXNlbnRfYWRtaW5fdXNlcihzZWxmLCB1c2VyKToKICAgIHJldHVybiAnPDx7fT4+Jy5mb3JtYXQodXNlci5uYW1lKQoKICBkZWYgcmVwcmVzZW50X3RyaWFsX3VzZXIoc2VsZiwgdXNlcik6CiAgICByZXR1cm4gJ1tUUklBTF0ge30nLmZvcm1hdCh1c2VyLm5hbWUpCgoKdXNlciA9IEFkbWluVXNlcignSG9tZXInKQpyZXByZXNlbnRlciA9IEpzb25SZXByZXNlbnRlcigpCgpmb3IgdXNlciBpbiBBZG1pblVzZXIoJ0hvbWVyJyksIFRyaWFsVXNlcignQmFydCcpOgogIGZvciByZXByZXNlbnRlciBpbiBKc29uUmVwcmVzZW50ZXIoKSwgU3RyaW5nUmVwcmVzZW50ZXIoKToKICAgIHByaW50KHJlcHJlc2VudGVyLnJlcHJlc2VudCh1c2VyKSk="},"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
from abc import ABCMeta, abstractmethod
import json


class User:
  def __init__(self, name):
    self.name = name


class AdminUser(User):
  def be_represented_by(self, serializer):
    return serializer.represent_admin_user(self)


class TrialUser(User):
  def be_represented_by(self, serializer):
    return serializer.represent_trial_user(self)



class Representer(metaclass=ABCMeta):
  def represent(self, user):
    return user.be_represented_by(self)

  @abstractmethod
  def represent_admin_user(self, user):
    pass

  @abstractmethod
  def represent_trial_user(self, user):
    pass


class JsonRepresenter(Representer):
  def represent_admin_user(self, user):
    return json.dumps({
      "admin": True,
      "name": user.name,
    })

  def represent_trial_user(self, user):
    return json.dumps({
      "trial": True,
      "name": user.name,
    })


class StringRepresenter(Representer):
  def represent_admin_user(self, user):
    return '<<{}>>'.format(user.name)

  def represent_trial_user(self, user):
    return '[TRIAL] {}'.format(user.name)


user = AdminUser('Homer')
representer = JsonRepresenter()

for user in AdminUser('Homer'), TrialUser('Bart'):
  for representer in JsonRepresenter(), StringRepresenter():
    print(representer.represent(user))