1 """Test program for MimeWriter module.
3 The test program was too big to comfortably fit in the MimeWriter
4 class, so it's here in its own file.
6 This should generate Barry's example, modulo some quotes and newlines.
11 from MimeWriter
import MimeWriter
17 DOCUMENTATION "A simple Seller interface to test ILU"
25 def __setup__(self, maxprice):
26 self._maxprice = maxprice
28 def __main__(self, kos):
29 """Entry point upon arrival at a new KOS."""
31 # B4 == Barry's Big Bass Business :-)
32 seller = broker.lookup('Seller_1.Seller', 'B4')
34 price = seller.price()
35 print 'Seller wants $', price, '... '
36 if price > self._maxprice:
41 print 'no seller found here'
42 ''' # Don't ask why this comment is here
45 # instantiate a buyer instance and put it in a magic place for the KOS
52 ("Interpreter", "python"),
53 ("Interpreter-Version", "1.3"),
54 ("Owner-Name", "Barry Warsaw"),
55 ("Owner-Rendezvous", "bwarsaw@cnri.reston.va.us"),
56 ("Home-KSS", "kss.cnri.reston.va.us"),
57 ("Identifier", "hdl://cnri.kss/my_first_knowbot"),
58 ("Launch-Date", "Mon Feb 12 16:39:03 EST 1996"),
62 ("Metadata-Type", "complex"),
63 ("Metadata-Key", "connection"),
64 ("Access", "read-only"),
65 ("Connection-Description", "Barry's Big Bass Business"),
66 ("Connection-Id", "B4"),
67 ("Connection-Direction", "client"),
71 ("Metadata-Type", "complex"),
72 ("Metadata-Key", "generic-interface"),
73 ("Access", "read-only"),
74 ("Connection-Description", "Generic Interface for All Knowbots"),
75 ("Connection-Id", "generic-kp"),
76 ("Connection-Direction", "client"),
85 toplevel
= MimeWriter(sys
.stdout
)
86 toplevel
.addheader("From", "bwarsaw@cnri.reston.va.us")
87 toplevel
.addheader("Date", "Mon Feb 12 17:21:48 EST 1996")
88 toplevel
.addheader("To", "kss-submit@cnri.reston.va.us")
89 toplevel
.addheader("MIME-Version", "1.0")
93 f
= toplevel
.startmultipartbody("knowbot", "801spam999",
94 [("version", "0.1")], prefix
=0)
95 f
.write("This is a multi-part message in MIME format.\n")
97 # First toplevel body part: metadata
99 md
= toplevel
.nextpart()
100 md
.startmultipartbody("knowbot-metadata", "802spam999")
105 md1
.addheader("KP-Metadata-Type", "simple")
106 md1
.addheader("KP-Access", "read-only")
107 m
= MimeWriter(md1
.startbody("message/rfc822"))
108 for key
, value
in SIMPLE_METADATA
:
109 m
.addheader("KPMD-" + key
, value
)
116 for key
, value
in COMPLEX_METADATA
:
117 md2
.addheader("KP-" + key
, value
)
118 f
= md2
.startbody("text/isl")
125 f
= md3
.startbody("message/external-body",
126 [("access-type", "URL"),
127 ("URL", "hdl://cnri.kss/generic-knowbot")])
129 for key
, value
in EXTERNAL_METADATA
:
130 md3
.addheader("KP-" + key
, value
)
131 md3
.startbody("text/isl")
132 # Phantom body doesn't need to be written
136 # Second toplevel body part: code
138 code
= toplevel
.nextpart()
139 code
.startmultipartbody("knowbot-code", "803spam999")
141 # Code: buyer program source
143 buyer
= code
.nextpart()
144 buyer
.addheader("KP-Module-Name", "BuyerKP")
145 f
= buyer
.startbody("text/plain")
150 # Third toplevel body part: state
152 state
= toplevel
.nextpart()
153 state
.addheader("KP-Main-Module", "main")
154 state
.startmultipartbody("knowbot-state", "804spam999")
156 # State: a bunch of assignments
158 st
= state
.nextpart()
159 st
.addheader("KP-Module-Name", "main")
160 f
= st
.startbody("text/plain")
165 # End toplevel body parts