[Reality] c.getComponent(I) vs I(c)
Jp Calderone
reality@twistedmatrix.com
Tue, 8 Jul 2003 15:06:12 -0400
--pvezYHf7grwyp3Bc
Content-Type: multipart/mixed; boundary="UugvWAfsgieZRqgk"
Content-Disposition: inline
--UugvWAfsgieZRqgk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
The current Reality code seems to make a lot of assumptions about the
(non-None) return value of c.getComponent(). I think the thing to do is
change most of these uses to the new callable-Interface API, so that
CannotAdapt is raised by them (which can hopefully be handled properly),
rather than an AttributeError (which cannot).
Patch attached. Thoughts?
Jp
--=20
Where a calculator on the ENIAC is equipped with 18,000 vacuum tubes and
weighs 30 tons, computers in the future may have only 1,000 vacuum tubes and
weigh only 1.5 tons. -- Popular Mechanics, March 1949
--UugvWAfsgieZRqgk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff
Content-Transfer-Encoding: quoted-printable
? _trial_temp
? diff
? reality-shutdown.tap
Index: reality/actions.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/NewReality/reality/actions.py,v
retrieving revision 1.15
diff -u -r1.15 actions.py
--- reality/actions.py 25 May 2003 03:24:08 -0000 1.15
+++ reality/actions.py 8 Jul 2003 19:02:57 -0000
@@ -230,7 +230,7 @@
if comp is not None:
comp.eventReceived(self.actor, evt)
else:
- self.actor.getComponent(things.IThing).emitEvent(evt)
+ things.IThing(self.actor).emitEvent(evt)
=20
def toEvent(self):
return self
Index: reality/ambulation.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/NewReality/reality/ambulation.py,v
retrieving revision 1.14
diff -u -r1.14 ambulation.py
--- reality/ambulation.py 8 Apr 2003 00:43:27 -0000 1.14
+++ reality/ambulation.py 8 Jul 2003 19:02:57 -0000
@@ -99,7 +99,7 @@
=20
class Door(Exit):
def collectImplementors(self, asker, iface, collection, seen, event=3D=
None, name=3DNone, intensity=3D2):
- op =3D self.getComponent(IOpened).isOpen()
+ op =3D IOpened(self).isOpen()
if op or asker is self:
Exit.collectImplementors(self, asker, iface, collection, seen,=
event=3DNone, name=3Dname, intensity=3Dintensity)
else:
Index: reality/emporium.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/NewReality/reality/emporium.py,v
retrieving revision 1.9
diff -u -r1.9 emporium.py
--- reality/emporium.py 25 May 2003 03:24:08 -0000 1.9
+++ reality/emporium.py 8 Jul 2003 19:02:57 -0000
@@ -51,9 +51,9 @@
__implements__ =3D IVendor,
=20
def shoutPrice(self, merch, cust):
- n =3D self.getComponent(english.INoun)
- title =3D ('creature', 'sir','lady')[cust.getComponent(things.IThi=
ng).gender]
- self.original.emitEvent('%s says "For you, good %s, only %d zorkmi=
ds for this %s."' % (n.nounPhrase(cust), title, merch.price, merch.original=
.getComponent(english.INoun).name))
+ n =3D english.INoun(self)
+ title =3D ('creature', 'sir','lady')[things.IThing(cust).gender]
+ self.original.emitEvent('%s says "For you, good %s, only %d zorkmi=
ds for this %s."' % (n.nounPhrase(cust), title, merch.price, english.INoun(=
merch).name))
=20
def buy(self, merchandise, amount):
self.deposit(amount)
@@ -82,7 +82,7 @@
self.owner.shoutPrice(self, self.original.location)
if self.original.getOutermostRoom() !=3D self.home:
self.original.emitEvent("The %s vanishes with a *foop*."
- % self.getComponent(english.INoun).nam=
e)
+ % english.INoun(self).name)
self.original.moveTo(self.home)
=20
class ShopDoor(ambulation.Door):
Index: reality/test_reality.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/NewReality/reality/test_reality.py,v
retrieving revision 1.34
diff -u -r1.34 test_reality.py
--- reality/test_reality.py 25 May 2003 03:24:08 -0000 1.34
+++ reality/test_reality.py 8 Jul 2003 19:02:57 -0000
@@ -118,10 +118,10 @@
bob.moveTo(r)
pars =3D english.Parsing(bob).parse
pars("wear fedora")
- assert foo.getComponent(raiment.IWearTarget).wearer.original is bob
- assert bob.getComponent(raiment.IWearActor).clothing['crown'][-1].=
original is foo
+ assert raiment.IWearTarget(foo).wearer.original is bob
+ assert raiment.IWearActor(bob).clothing['crown'][-1].original is f=
oo
pars("remove fedora")
- assert foo.getComponent(raiment.IWearTarget).wearer is None
+ assert raiment.IWearTarget(foo).wearer is None
=20
def testBasicMovement(self):
a =3D things.Movable('a')
@@ -199,13 +199,13 @@
=20
class SwingDance(actions.TargetAction):
def doAction(self):
- self.actor.getComponent(things.IThing).swung =3D True
+ things.IThing(self.actor).swung =3D True
"You dance wildly!"
=20
# This should _really_ be a ToolAction with a possibly implicit target...
class Attack(actions.TargetAction):=20
def doAction(self):
- self.actor.getComponent(things.IThing).attacked =3D True
+ things.IThing(self.actor).attacked =3D True
"You swing wildly!"
=20
components.registerAdapter(NullAdapter, things.Actor, ISwingDanceActor)
@@ -252,7 +252,7 @@
for x in bob, red:#, blue:
x.moveTo(room)
=20
- p =3D bob.getComponent(common.IThinker)
+ p =3D common.IThinker(bob)
p.parse("swing sword")
self.assertEquals(len(p.potentialActions), 2)
p.parse("1")
@@ -273,7 +273,7 @@
bob =3D things.Actor('bob')
obj =3D things.Movable('hey')
c =3D obj.addAdapter(conveyance.Portable, 1)
- desc =3D obj.getComponent(common.IDescribeable)
+ desc =3D common.IDescribeable(obj)
desc.describe(c, "hello", 1)
self.assertEquals(desc.explainTo(bob), "hello")
=20
Index: reality/things.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/NewReality/reality/things.py,v
retrieving revision 1.24
diff -u -r1.24 things.py
--- reality/things.py 8 Jul 2003 07:52:53 -0000 1.24
+++ reality/things.py 8 Jul 2003 19:02:57 -0000
@@ -77,14 +77,14 @@
=20
def __init__(self, name=3D'@', gender=3DNone):
components.Componentized.__init__(self)
- self.getComponent(common.INoun).changeName(name) # get default lan=
guage implementor
+ common.INoun(self).changeName(name) # get default language impleme=
ntor
self._links =3D []
self._implementorFilters =3D []
if gender is not None:
self.gender =3D gender
=20
def knownAs(self, name, observer):
- return self.getComponent(common.INoun).knownAs(name, observer)
+ return common.INoun(self).knownAs(name, observer)
=20
def __repr__(self):
noun =3D self.getComponent(common.INoun)
@@ -154,7 +154,7 @@
"""
return [x for x in IInterfaceForwarder(self).lookFor(name, interfa=
ce)
if not isinstance(x, Refusal)
- if x.getComponent(IThing).location =3D=3D self]
+ if IThing(x).location =3D=3D self]
=20
def getOutermostRoom(self):
"desperate times, etc"
Index: reality/tools.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/NewReality/reality/tools.py,v
retrieving revision 1.1
diff -u -r1.1 tools.py
--- reality/tools.py 14 May 2003 07:32:46 -0000 1.1
+++ reality/tools.py 8 Jul 2003 19:02:57 -0000
@@ -25,9 +25,9 @@
c.todo.append(' '.join((time.asctime(),todoItem)))
=20
def describe(thing, desc):
- thing.getComponent(common.IDescribeable).describe('__main__',desc)
+ common.IDescribeable(thing).describe('__main__',desc)
#Do I really need to say anything about why this is wrong and bad?
- thing.getComponent(common.IDescribeable).describe('html',desc)
+ common.IDescribeable(thing).describe('html',desc)
=20
def simpleTRServer(*players,**kwargs):
application =3D app.Application("reality")
Index: reality/text/english.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/NewReality/reality/text/english.py,v
retrieving revision 1.18
diff -u -r1.18 english.py
--- reality/text/english.py 19 May 2003 08:14:10 -0000 1.18
+++ reality/text/english.py 8 Jul 2003 19:02:58 -0000
@@ -370,10 +370,10 @@
=20
=20
def askForAction(self):
- return self.getComponent(things.IThing).emitEvent(ActionMenu(self.=
potentialActions), intensity=3D1)
+ return things.IThing(self.original).emitEvent(ActionMenu(self.pote=
ntialActions), intensity=3D1)
=20
def askForThing(self):
- return self.getComponent(things.IThing).emitEvent(ThingMenu(self.a=
mbigs[0]), intensity=3D1)
+ return things.IThing(self.original).emitEvent(ThingMenu(self.ambig=
s[0]), intensity=3D1)
=20
=20
def doneResolvingThing(self, thing):
Index: sandbox/example1.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/NewReality/sandbox/example1.py,v
retrieving revision 1.2
diff -u -r1.2 example1.py
--- sandbox/example1.py 6 Mar 2003 15:29:01 -0000 1.2
+++ sandbox/example1.py 8 Jul 2003 19:02:58 -0000
@@ -27,4 +27,4 @@
import sys
from twisted.python import log
log.startLogging(sys.stdout, 0)
- application.run()
+ application.run(save=3D0)
Index: sandbox/example2.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/NewReality/sandbox/example2.py,v
retrieving revision 1.3
diff -u -r1.3 example2.py
--- sandbox/example2.py 6 Mar 2003 15:29:01 -0000 1.3
+++ sandbox/example2.py 8 Jul 2003 19:02:58 -0000
@@ -35,7 +35,7 @@
application =3D app.Application("reality")
application.listenTCP(8888, bobServer)
if __name__ =3D=3D '__main__':
- application.run()
+ application.run(save=3D0)
=20
'''
"go north"
Index: sandbox/example3.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/NewReality/sandbox/example3.py,v
retrieving revision 1.2
diff -u -r1.2 example3.py
--- sandbox/example3.py 6 Mar 2003 15:29:01 -0000 1.2
+++ sandbox/example3.py 8 Jul 2003 19:02:58 -0000
@@ -25,7 +25,7 @@
application.listenTCP(8888, bobServer)
application.listenTCP(8889, rodneyServer)
if __name__ =3D=3D '__main__':
- application.run()
+ application.run(save=3D3)
=20
'''
bob: "hit rodney with sword"
--UugvWAfsgieZRqgk--
--pvezYHf7grwyp3Bc
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)
iD8DBQE/CxYkedcO2BJA+4YRAueEAKCaMv5EUfDctyO70mLUg2ywAJM7zQCfSFbv
6RfB9rOXLJyhr6x8ibQCEqs=
=Z9Ox
-----END PGP SIGNATURE-----
--pvezYHf7grwyp3Bc--