ó
­«Y]c           @   só   d  Z  d d l Z d d l Z d d l m Z m Z e d d e ƒd d l m Z d Z d Z	 d	 Z
 d, d- d. d/ d0 d1 d2 g Z d3 d4 d5 d6 d7 d8 g Z d9 d: d; d< d= d> g Z d' Z d( e j f d) „  ƒ  YZ d* „  Z e d+ k rï e ƒ  n  d S(?   sÕ   Test program for MimeWriter module.

The test program was too big to comfortably fit in the MimeWriter
class, so it's here in its own file.

This should generate Barry's example, modulo some quotes and newlines.

iÿÿÿÿN(   t   run_unittestt   import_modulet
   MimeWritert
   deprecated(   R   s–   INTERFACE Seller-1;

TYPE Seller = OBJECT
    DOCUMENTATION "A simple Seller interface to test ILU"
    METHODS
            price():INTEGER,
    END;
sI  class Buyer:
    def __setup__(self, maxprice):
        self._maxprice = maxprice

    def __main__(self, kos):
        """Entry point upon arrival at a new KOS."""
        broker = kos.broker()
        # B4 == Barry's Big Bass Business :-)
        seller = broker.lookup('Seller_1.Seller', 'B4')
        if seller:
            price = seller.price()
            print 'Seller wants $', price, '... '
            if price > self._maxprice:
                print 'too much!'
            else:
                print "I'll take it!"
        else:
            print 'no seller found here'
sy   # instantiate a buyer instance and put it in a magic place for the KOS
# to find.
__kp__ = Buyer()
__kp__.__setup__(500)
t   Interpretert   pythons   Interpreter-Versions   1.3s
   Owner-Names   Barry Warsaws   Owner-Rendezvouss   bwarsaw@cnri.reston.va.uss   Home-KSSs   kss.cnri.reston.va.ust
   Identifiers   hdl://cnri.kss/my_first_knowbots   Launch-Dates   Mon Feb 12 16:39:03 EST 1996s   Metadata-Typet   complexs   Metadata-Keyt
   connectiont   Accesss	   read-onlys   Connection-Descriptions   Barry's Big Bass Businesss   Connection-Idt   B4s   Connection-Directiont   clients   generic-interfaces"   Generic Interface for All Knowbotss
   generic-kps§	  From: bwarsaw@cnri.reston.va.us
Date: Mon Feb 12 17:21:48 EST 1996
To: kss-submit@cnri.reston.va.us
MIME-Version: 1.0
Content-Type: multipart/knowbot;
    boundary="801spam999";
    version="0.1"

This is a multi-part message in MIME format.

--801spam999
Content-Type: multipart/knowbot-metadata;
    boundary="802spam999"


--802spam999
Content-Type: message/rfc822
KP-Metadata-Type: simple
KP-Access: read-only

KPMD-Interpreter: python
KPMD-Interpreter-Version: 1.3
KPMD-Owner-Name: Barry Warsaw
KPMD-Owner-Rendezvous: bwarsaw@cnri.reston.va.us
KPMD-Home-KSS: kss.cnri.reston.va.us
KPMD-Identifier: hdl://cnri.kss/my_first_knowbot
KPMD-Launch-Date: Mon Feb 12 16:39:03 EST 1996

--802spam999
Content-Type: text/isl
KP-Metadata-Type: complex
KP-Metadata-Key: connection
KP-Access: read-only
KP-Connection-Description: Barry's Big Bass Business
KP-Connection-Id: B4
KP-Connection-Direction: client

INTERFACE Seller-1;

TYPE Seller = OBJECT
    DOCUMENTATION "A simple Seller interface to test ILU"
    METHODS
            price():INTEGER,
    END;

--802spam999
Content-Type: message/external-body;
    access-type="URL";
    URL="hdl://cnri.kss/generic-knowbot"

Content-Type: text/isl
KP-Metadata-Type: complex
KP-Metadata-Key: generic-interface
KP-Access: read-only
KP-Connection-Description: Generic Interface for All Knowbots
KP-Connection-Id: generic-kp
KP-Connection-Direction: client


--802spam999--

--801spam999
Content-Type: multipart/knowbot-code;
    boundary="803spam999"


--803spam999
Content-Type: text/plain
KP-Module-Name: BuyerKP

class Buyer:
    def __setup__(self, maxprice):
        self._maxprice = maxprice

    def __main__(self, kos):
        """Entry point upon arrival at a new KOS."""
        broker = kos.broker()
        # B4 == Barry's Big Bass Business :-)
        seller = broker.lookup('Seller_1.Seller', 'B4')
        if seller:
            price = seller.price()
            print 'Seller wants $', price, '... '
            if price > self._maxprice:
                print 'too much!'
            else:
                print "I'll take it!"
        else:
            print 'no seller found here'

--803spam999--

--801spam999
Content-Type: multipart/knowbot-state;
    boundary="804spam999"
KP-Main-Module: main


--804spam999
Content-Type: text/plain
KP-Module-Name: main

# instantiate a buyer instance and put it in a magic place for the KOS
# to find.
__kp__ = Buyer()
__kp__.__setup__(500)

--804spam999--

--801spam999--
t   MimewriterTestc           B   s   e  Z d  „  Z RS(   c         C   sÐ  t  j  ƒ  } t | ƒ } | j d d ƒ | j d d ƒ | j d d ƒ | j d d ƒ | j d	 d
 d' g d d ƒ} | j d ƒ | j ƒ  } | j d d ƒ | j ƒ  } | j d d ƒ | j d d ƒ t | j d ƒ ƒ } x( t D]  \ } } | j d | | ƒ qç W| j ƒ  ~ | j ƒ  }	 x( t	 D]  \ } } |	 j d | | ƒ q+W|	 j d ƒ } | j t
 ƒ ~	 | j ƒ  }
 |
 j d d( d) g ƒ } t | ƒ } x( t D]  \ } } |
 j d | | ƒ q¥W|
 j d ƒ | j ƒ  | j ƒ  } | j d d ƒ | j ƒ  } | j d  d! ƒ | j d" ƒ } | j t ƒ | j ƒ  | j ƒ  } | j d# d$ ƒ | j d% d& ƒ | j ƒ  } | j d  d$ ƒ | j d" ƒ } | j t ƒ | j ƒ  | j ƒ  |  j | j ƒ  t ƒ d  S(*   Nt   Froms   bwarsaw@cnri.reston.va.ust   Dates   Mon Feb 12 17:21:48 EST 1996t   Tos   kss-submit@cnri.reston.va.uss   MIME-Versions   1.0t   knowbott
   801spam999t   versions   0.1t   prefixi    s-   This is a multi-part message in MIME format.
s   knowbot-metadatat
   802spam999s   KP-Metadata-Typet   simples	   KP-Accesss	   read-onlys   message/rfc822s   KPMD-s   KP-s   text/isls   message/external-bodys   access-typet   URLs   hdl://cnri.kss/generic-knowbots   knowbot-codet
   803spam999s   KP-Module-Namet   BuyerKPs
   text/plains   KP-Main-Modulet   mains   knowbot-statet
   804spam999(   R   s   0.1(   s   access-typeR   (   R   s   hdl://cnri.kss/generic-knowbot(   t   StringIOR   t	   addheadert   startmultipartbodyt   writet   nextpartt	   startbodyt   SIMPLE_METADATAt   flushheaderst   COMPLEX_METADATAt   SELLERt   EXTERNAL_METADATAt   lastpartt   BUYERt   STATEt   assertEqualt   getvaluet   OUTPUT(   t   selft   buft   toplevelt   ft   mdt   md1t   mt   keyt   valuet   md2t   md3t   codet   buyert   statet   st(    (    s%   lib/python2.7/test/test_MimeWriter.pyt   testÅ   sf    
	



(   t   __name__t
   __module__R;   (    (    (    s%   lib/python2.7/test/test_MimeWriter.pyR   Ã   s   c           C   s   t  t ƒ d  S(   N(   R    R   (    (    (    s%   lib/python2.7/test/test_MimeWriter.pyt	   test_main   s    t   __main__(   R   R   (   s   Interpreter-Versions   1.3(   s
   Owner-Names   Barry Warsaw(   s   Owner-Rendezvouss   bwarsaw@cnri.reston.va.us(   s   Home-KSSs   kss.cnri.reston.va.us(   R   s   hdl://cnri.kss/my_first_knowbot(   s   Launch-Dates   Mon Feb 12 16:39:03 EST 1996(   s   Metadata-TypeR   (   s   Metadata-KeyR   (   R	   s	   read-only(   s   Connection-Descriptions   Barry's Big Bass Business(   s   Connection-IdR
   (   s   Connection-DirectionR   (   s   Metadata-TypeR   (   s   Metadata-Keys   generic-interface(   R	   s	   read-only(   s   Connection-Descriptions"   Generic Interface for All Knowbots(   s   Connection-Ids
   generic-kp(   s   Connection-DirectionR   (   t   __doc__t   unittestR   t   test.test_supportR    R   t   TrueR   R$   R'   R(   R!   R#   R%   R+   t   TestCaseR   R>   R<   (    (    (    s%   lib/python2.7/test/test_MimeWriter.pyt   <module>   s>   
			r]	