-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_proxy.py
More file actions
41 lines (29 loc) · 925 Bytes
/
1_proxy.py
File metadata and controls
41 lines (29 loc) · 925 Bytes
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
from abc import ABC, abstractmethod
class Image(ABC):
@abstractmethod
def display(self):
pass
class RealImnage(Image):
def __init__(self, filename: str):
self.filename = filename
print(f"Real image: laoding {filename}")
def display(self):
print(f"Real image: displaying {self.filename}", end="\n\n")
class ProxyImage(Image):
def __init__(self, filename: str):
self.filename = filename
self.real_image = None
def display(self):
print(f"Proxy image: displaying {self.filename}")
if not self.real_image:
print("From disk")
self.real_image = RealImnage(self.filename)
else:
print("From cache")
self.real_image.display()
if __name__ == "__main__":
image = ProxyImage("test.jpg")
# load image from disk
image.display()
# load image from cache
image.display()