# Path: Peach/publisher.py
# class PublisherBuffer(object):
#     """
#     An I/O buffer.
#     """
# 
#     def __init__(self, publisher, data=None, haveAllData=False):
#         self.publisher = publisher
#         if self.publisher is not None:
#             self.publisher.publisherBuffer = self
#         self.data = ""
#         self.haveAllData = haveAllData
#         if data is not None:
#             self.data = data
#             self.haveAllData = True
# 
#     def read(self, size=1):
#         """
#         Read additional data into I/O buffer.
#         """
#         if self.haveAllData:
#             return
#         ret = []
#         timeout = False
#         try:
#             if size is not None:
#                 need = size
#                 while need > 0 and not self.haveAllData:
#                     try:
#                         ret.append(self.publisher.receive(size))
#                         need -= len(ret[-1])
#                     except Timeout:
#                         # Retry once more after a timeout
#                         if timeout:
#                             raise
#                         timeout = True
#                         self.haveAllData = True
#             else:
#                 try:
#                     self.haveAllData = True
#                     ret.append(self.publisher.receive(size))
#                 except Timeout:
#                     pass
#         finally:
#             self.data = "".join([self.data] + ret)
# 
#     def readAll(self):
#         if self.haveAllData:
#             return
#         try:
#             self.read(None)
#         finally:
#             self.haveAllData = True


import re
import sys
import time
import types
import struct
import ctypes
import random
import traceback
import Peach
from lxml import etree
from Peach.Engine.dom import *
from Peach.Engine.parser import *
from Peach.Engine.path import *
from Peach.Engine.common import *
from Peach.Engine.incoming import *
from Peach.publisher import PublisherBuffer
        # EVENT: onStart
        if action.onStart is not None:
            environment = {
                'Peach': self.engine.peach,
                'Action': action,
                'State': action.parent,
                'StateModel': action.parent.parent,
                'Mutator': mutator,
                'peachPrint': self.f,
                'sleep': time.sleep
            }

            evalEvent(action.onStart, environment, self.engine.peach)

        if action.type == 'input':
            action.value = None

            if not pub.hasBeenStarted:
                pub.start()
                pub.hasBeenStarted = True
            if not pub.hasBeenConnected:
                pub.connect()
                pub.hasBeenConnected = True

            # Make a fresh copy of the template
            action.__delitem__(action.template.name)
            action.template = action.origionalTemplate.copy(action)
            action.append(action.template)

            # Create buffer

# Path: Peach/publisher.py
# class PublisherBuffer(object):
#     """
#     An I/O buffer.
#     """
# 
#     def __init__(self, publisher, data=None, haveAllData=False):
#         self.publisher = publisher
#         if self.publisher is not None:
#             self.publisher.publisherBuffer = self
#         self.data = ""
#         self.haveAllData = haveAllData
#         if data is not None:
#             self.data = data
#             self.haveAllData = True
# 
#     def read(self, size=1):
#         """
#         Read additional data into I/O buffer.
#         """
#         if self.haveAllData:
#             return
#         ret = []
#         timeout = False
#         try:
#             if size is not None:
#                 need = size
#                 while need > 0 and not self.haveAllData:
#                     try:
#                         ret.append(self.publisher.receive(size))
#                         need -= len(ret[-1])
#                     except Timeout:
#                         # Retry once more after a timeout
#                         if timeout:
#                             raise
#                         timeout = True
#                         self.haveAllData = True
#             else:
#                 try:
#                     self.haveAllData = True
#                     ret.append(self.publisher.receive(size))
#                 except Timeout:
#                     pass
#         finally:
#             self.data = "".join([self.data] + ret)
# 
#     def readAll(self):
#         if self.haveAllData:
#             return
#         try:
#             self.read(None)
#         finally:
#             self.haveAllData = True


# Path: Peach/Engine/state.py
import re
import sys
import time
import types
import struct
import ctypes
import random
import traceback
import Peach
from lxml import etree
from Peach.Engine.dom import *
from Peach.Engine.parser import *
from Peach.Engine.path import *
from Peach.Engine.common import *
from Peach.Engine.incoming import *
from Peach.publisher import PublisherBuffer

        # EVENT: onStart
        if action.onStart is not None:
            environment = {
                'Peach': self.engine.peach,
                'Action': action,
                'State': action.parent,
                'StateModel': action.parent.parent,
                'Mutator': mutator,
                'peachPrint': self.f,
                'sleep': time.sleep
            }

            evalEvent(action.onStart, environment, self.engine.peach)

        if action.type == 'input':
            action.value = None

            if not pub.hasBeenStarted:
                pub.start()
                pub.hasBeenStarted = True
            if not pub.hasBeenConnected:
                pub.connect()
                pub.hasBeenConnected = True

            # Make a fresh copy of the template
            action.__delitem__(action.template.name)
            action.template = action.origionalTemplate.copy(action)
            action.append(action.template)

            # Create buffer

            buff = PublisherBuffer(pub)