# Path: Peach/publisher.py
# class Publisher(object):
#     """
#     The Publisher object(s) implement a way to send and/or receive data by
#     some means. There are two "types" of publishers, stream based and call
#     based. This base class supports both types.
#     To support stream based publishing implement everything but "call". To
#     support call based publishing implement start, stop, and call. A
#     publisher can support both stream and call based publishing.
#     """
# 
#     def __init__(self):
#         #: Indicates which method should be called.
#         self.withNode = False
#         self.publisherBuffer = None
# 
#     def initialize(self):
#         """
#         Called at start of test run. Called once per <Test> section.
#         """
#         pass
# 
#     def finalize(self):
#         """
#         Called at end of test run. Called once per <Test> section.
#         """
#         pass
# 
#     def start(self):
#         """
#         Change state such that send/receive will work. For TCP this could be
#         connecting to a remote host.
#         """
#         pass
# 
#     def stop(self):
#         """
#         Change state such that send/receive will not work. For TCP this could
#         be closing a connection, for a file it might be closing the file
#         handle.
#         """
#         pass
# 
#     def send(self, data):
#         """
#         Publish some data.
# 
#         :param data: data to publish
#         :type data: str
#         """
#         raise PeachException("Action 'send' not supported by publisher.")
# 
#     def sendWithNode(self, data, dataNode):
#         """
#         Publish some data.
# 
#         :param data: data to publish
#         :type data: str
#         :param dataNode: root of data model that produced data
#         :type dataNode: DataElement
#         """
#         raise PeachException("Action 'sendWithNode' not supported by "
#                              "publisher.")
# 
#     def receive(self, size=None):
#         """
#         Receive some data.
# 
#         :param size: number of bytes to return
#         :type size: int
#         :returns: data received
#         :rtype: str
#         """
#         raise PeachException("Action 'receive' not supported by publisher.")
# 
#     def call(self, method, args):
#         """
#         Call a method using arguments.
# 
#         :param method: method to call
#         :type method: str
#         :param args: list of strings as arguments
#         :type args: list
#         :returns: data (if any)
#         :rtype: str
#         """
#         raise PeachException("Action 'call' not supported by publisher.")
# 
#     def callWithNode(self, method, args, argNodes):
#         """
#         Call a method using arguments.
# 
#         :param method: method to call
#         :type method: str
#         :param args: list of strings as arguments
#         :type args: list
#         :param argNodes: list of DataElements
#         :type argNodes: list
#         :returns: data (if any)
#         :rtype: str
#         """
#         raise PeachException("Action 'callWithNode' not supported by publisher.")
# 
#     def property(self, property, value=None):
#         """
#         Get or set property.
# 
#         :param property: name of method to invoke
#         :type property: str
#         :param value: value to set. If None, return property instead
#         :type value: object
#         """
#         raise PeachException("Action 'property' not supported by publisher.")
# 
#     def propertyWithNode(self, property, value, valueNode):
#         """
#         Get or set property.
# 
#         :param property: name of method to invoke
#         :type property: str
#         :param value: value to set. If None, return property instead
#         :type value: object
#         :param valueNode: data model root node that produced value
#         :type valueNode: DataElement
#         """
#         raise PeachException("Action 'propertyWithNode' not supported by publisher.")
# 
#     def connect(self):
#         """
#         Called to connect or open a connection / file.
#         """
#         raise PeachException("Action 'connect' not supported by publisher.")
# 
#     def accept(self):
#         """
#         Accept incoming connection. Blocks until incoming connection occurs.
#         """
#         raise PeachException("Action 'accept' not supported by publisher.")
# 
#     def close(self):
#         """
#         Close current stream/connection.
#         """
#         raise PeachException("Action 'close' not supported by publisher.")
# 
#     def debug(self, fmt):
#         print("{}: {}".format(self.__class__.__name__, fmt))
# 
# Path: Peach/Engine/common.py
# class PeachException(HardException):
#     """
#     Peach exceptions are specialized hard exceptions.
#     The message contained in a PeachException is presentable to the user w/o any stack trace, etc.
#     Examples would be:
#         "Error: The DataModel element requires a name attribute."
#     """
#     def __init__(self, msg, module="Unknown"):
#         Exception.__init__(self, msg)
#         self.module = module
#         self.msg = msg


import sys
import time
import socket
        import lightblue
        import bluetooth
from Peach.publisher import Publisher
from Peach.Engine.common import PeachException
from Peach.Utilities.common import *

    return services


def lightblue_server_test():
    # L2CAP server sockets not currently supported :(
    s = lightblue.socket(lightblue.L2CAP)
    s.bind(("", 0x1001))
    s.listen(1)
    lightblue.advertise("Peach", s, lightblue.L2CAP)
    conn, addr = s.accept()
    print("Connected by", addr)
    data = conn.recv(1024)
    print("Received: %s" % data)
    conn.close()
    s.close()


def pybluez_server_test():
    s = bluetooth.BluetoothSocket(bluetooth.L2CAP)
    s.bind(("", 0x1001))
    s.listen(1)
    conn, addr = s.accept()
    print("Connected by %s" % addr)
    data = s.recv(1024)
    print("Received: %s" % data)
    conn.close()
    s.close()



# Path: Peach/publisher.py
# class Publisher(object):
#     """
#     The Publisher object(s) implement a way to send and/or receive data by
#     some means. There are two "types" of publishers, stream based and call
#     based. This base class supports both types.
#     To support stream based publishing implement everything but "call". To
#     support call based publishing implement start, stop, and call. A
#     publisher can support both stream and call based publishing.
#     """
# 
#     def __init__(self):
#         #: Indicates which method should be called.
#         self.withNode = False
#         self.publisherBuffer = None
# 
#     def initialize(self):
#         """
#         Called at start of test run. Called once per <Test> section.
#         """
#         pass
# 
#     def finalize(self):
#         """
#         Called at end of test run. Called once per <Test> section.
#         """
#         pass
# 
#     def start(self):
#         """
#         Change state such that send/receive will work. For TCP this could be
#         connecting to a remote host.
#         """
#         pass
# 
#     def stop(self):
#         """
#         Change state such that send/receive will not work. For TCP this could
#         be closing a connection, for a file it might be closing the file
#         handle.
#         """
#         pass
# 
#     def send(self, data):
#         """
#         Publish some data.
# 
#         :param data: data to publish
#         :type data: str
#         """
#         raise PeachException("Action 'send' not supported by publisher.")
# 
#     def sendWithNode(self, data, dataNode):
#         """
#         Publish some data.
# 
#         :param data: data to publish
#         :type data: str
#         :param dataNode: root of data model that produced data
#         :type dataNode: DataElement
#         """
#         raise PeachException("Action 'sendWithNode' not supported by "
#                              "publisher.")
# 
#     def receive(self, size=None):
#         """
#         Receive some data.
# 
#         :param size: number of bytes to return
#         :type size: int
#         :returns: data received
#         :rtype: str
#         """
#         raise PeachException("Action 'receive' not supported by publisher.")
# 
#     def call(self, method, args):
#         """
#         Call a method using arguments.
# 
#         :param method: method to call
#         :type method: str
#         :param args: list of strings as arguments
#         :type args: list
#         :returns: data (if any)
#         :rtype: str
#         """
#         raise PeachException("Action 'call' not supported by publisher.")
# 
#     def callWithNode(self, method, args, argNodes):
#         """
#         Call a method using arguments.
# 
#         :param method: method to call
#         :type method: str
#         :param args: list of strings as arguments
#         :type args: list
#         :param argNodes: list of DataElements
#         :type argNodes: list
#         :returns: data (if any)
#         :rtype: str
#         """
#         raise PeachException("Action 'callWithNode' not supported by publisher.")
# 
#     def property(self, property, value=None):
#         """
#         Get or set property.
# 
#         :param property: name of method to invoke
#         :type property: str
#         :param value: value to set. If None, return property instead
#         :type value: object
#         """
#         raise PeachException("Action 'property' not supported by publisher.")
# 
#     def propertyWithNode(self, property, value, valueNode):
#         """
#         Get or set property.
# 
#         :param property: name of method to invoke
#         :type property: str
#         :param value: value to set. If None, return property instead
#         :type value: object
#         :param valueNode: data model root node that produced value
#         :type valueNode: DataElement
#         """
#         raise PeachException("Action 'propertyWithNode' not supported by publisher.")
# 
#     def connect(self):
#         """
#         Called to connect or open a connection / file.
#         """
#         raise PeachException("Action 'connect' not supported by publisher.")
# 
#     def accept(self):
#         """
#         Accept incoming connection. Blocks until incoming connection occurs.
#         """
#         raise PeachException("Action 'accept' not supported by publisher.")
# 
#     def close(self):
#         """
#         Close current stream/connection.
#         """
#         raise PeachException("Action 'close' not supported by publisher.")
# 
#     def debug(self, fmt):
#         print("{}: {}".format(self.__class__.__name__, fmt))
# 
# Path: Peach/Engine/common.py
# class PeachException(HardException):
#     """
#     Peach exceptions are specialized hard exceptions.
#     The message contained in a PeachException is presentable to the user w/o any stack trace, etc.
#     Examples would be:
#         "Error: The DataModel element requires a name attribute."
#     """
#     def __init__(self, msg, module="Unknown"):
#         Exception.__init__(self, msg)
#         self.module = module
#         self.msg = msg


# Path: Peach/Publishers/bluetooth.py
import sys
import time
import socket
        import lightblue
        import bluetooth
from Peach.publisher import Publisher
from Peach.Engine.common import PeachException
from Peach.Utilities.common import *


    return services


def lightblue_server_test():
    # L2CAP server sockets not currently supported :(
    s = lightblue.socket(lightblue.L2CAP)
    s.bind(("", 0x1001))
    s.listen(1)
    lightblue.advertise("Peach", s, lightblue.L2CAP)
    conn, addr = s.accept()
    print("Connected by", addr)
    data = conn.recv(1024)
    print("Received: %s" % data)
    conn.close()
    s.close()


def pybluez_server_test():
    s = bluetooth.BluetoothSocket(bluetooth.L2CAP)
    s.bind(("", 0x1001))
    s.listen(1)
    conn, addr = s.accept()
    print("Connected by %s" % addr)
    data = s.recv(1024)
    print("Received: %s" % data)
    conn.close()
    s.close()



class L2CAP_Client(Publisher):