-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappointments.py
executable file
·54 lines (43 loc) · 1.36 KB
/
appointments.py
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
#!/usr/bin/python2
from contextpy import (
layer, base, around, proceed, globalActivateLayer, globalDeactivateLayer,
activelayers, inactivelayer, inactivelayers)
from datetime import datetime
time_layer = layer("Time")
location_layer = layer("Location")
class Appointment:
def __init__(self, datetime=datetime.now(), location="Anywhere"):
self.datetime = datetime
self.location = location
@base
def __str__(self):
return self.datetime.strftime(format="%Y-%m-%d")
@around(time_layer)
def __str__(self):
return proceed() + self.datetime.strftime(format=", %H:%M")
@around(location_layer)
def __str__(self):
return proceed() + ", " + self.location
appointment = Appointment()
print "Global Layer Activation:"
print appointment
globalActivateLayer(time_layer)
print appointment
globalActivateLayer(location_layer)
print appointment
globalDeactivateLayer(time_layer)
print appointment
globalDeactivateLayer(location_layer)
print appointment
print "---"
print "Thread-Local Layer Activation:"
with activelayers(time_layer, location_layer):
print appointment
with inactivelayer(time_layer):
print appointment
with inactivelayer(location_layer):
print appointment
with inactivelayers(time_layer, location_layer):
print appointment
print appointment
print appointment