C
:\Documents ard
Settings\AdminisbatorMy
Documents\aa
bthon...
woolcD
"dW,,P.i
I
,
4
5
o
I
9
10
11
!2
L1l
1q
ID
t7
18
19
20
2L
22
ZJ
4A
25
z4
2'7
2B
.zt
?n
5f
32
34
JO
5t
ae
39
llo
4I
42
i?
44
45
{b
418
.49
50
cl
5Z
CJ
54
58
59
OU
6t
o4
OJ
64
65
66
67
b5
CA
70
JL
'J
74
77
td
19
80
81
82
83
84
85
Ub
8?
88
dv
r ^ft
/r*'t
X
"vLt
dyi,ng
decorator
and
deco.rator
was
pointing
to.
assert
d.back
d.back.thing
=
d.thing
irnport
unitte-st
class TestcaseoL
(u]altte.st.fe.stcase)
:
def setup(se1f):
self .Proxything
=
f'3o*t,,
seIf.d1
=
Decoratorlo
def
checkNoDecoration(self
)
:
self .ProxYthing
=
P3o*U1,
res
=
self
.proxythinE.Do
(
)
#Tsrint
res
asgert
te.s
==
'hi'
def checkoneDecoration
(
self)
I
self .proxythi
rrg.AddDecorator
(
3elf'
dl)
res
=
self .prox!.thitg.Doo
&rir]t
res
u
usE-RM
=
1
(9-"^
if
USE_RM:
from
RM ilnpolt
RML
RM
=
RMlo
5,^,,.'hJr
il^^3
Il^
.ft
fl
RDl.RR("xy",'onetoone",
I'dixectionalrr)
clats
_CorE)onent
(obj
ect)
:
def
_setThing(sel'f,
thing) :
def
-getThing(self):
def
-getBack(sel^f):
ttring
=
property (_getThing,
baeL
=
property
(_getBack)
else:
class
_corqlonent{object):
\
de?
_init_(seir):
\
L
,h{e*""k
^w
sere.tf,jlng
=
Nonel
serr.back
=
NoneJ
o[f i.Adal
o4^l^'^1
crass component(tonulonent):
ll
tWO
/Oin\ry)'
def
Do(self):
#
virtual
F^'9?l-
|
raise
'Do
not
irtPlemented'
class Thj.ng
(Component
)
:
def
Do(seLf):
return
'hi'
clasg Decorator
(Conponent
)
:
pa93
class
Decoratorl
(Decorato.r)
:
def Do{5e1f}:
return
t**
I
* self.thing.Dc()
+'
""'
class
Proxy
(co[E]onent
)
:
def
-init-(self
)
:
cgtrE)snerrt .
_i"Iit_
(
s e 1f
)
self.thing
=
ThinSo
def Do{gel-f
}
:
assert
self.thing,
'oops,
have
lost
the real
thing
obiect'
return
self '
thing.Do
(
)
def AddDecorator(self'
d)
:
sel.f .hsertDecorator(d)
#
TODA
rnake
this append
to the
-ljst
of decorators.
def
InsertDecorator(self,
d) :
Inserts
the
decorator
first in
the list
of decorators.
rrirt
d.thing
=
sel-f.thing
#
make
decorater
paint
to
the thing
you
were
pointinEr
to
setf.thing
=
4 #
point'
to
the decotatox
Fj-nd
the thing_A
poj-ntj-ng
point
it
at the lhing
the
to the
dying
if
not
usE_RM:
d.thing.back
=
d.back #
update
back
pointer!
!
'
{zJ1
fa,cut
f
fr"-.
Ai""^7
hilhQdin
"
24f04f2604II:00
PM