# Path: picraft/exc.py
# class CommandError(ConnectionError):
#     "Exception raised when a network command fails"
# 
# class NoResponse(ConnectionError):
#     "Exception raised when a network command expects a response but gets none"
# 
# class BatchStarted(ConnectionError):
#     "Exception raised when a batch is started before a prior one is complete"
# 
# class BatchNotStarted(ConnectionError):
#     "Exception raised when a batch is terminated when none has been started"
# 
# class ConnectionClosed(ConnectionError):
#     "Exception raised when an operation is attempted against a closed connection"


import socket
import logging
import select
import threading
from .exc import (
        CommandError,
        NoResponse,
        BatchStarted,
        BatchNotStarted,
        ConnectionClosed,
        )

        .. note::

            This method can be used as a context manager (:keyword:`with`)
            which will cause a batch to be started, and implicitly terminated
            with :meth:`batch_send` or :meth:`batch_forget` depending on
            whether an exception is raised within the enclosed block.
        """
        try:
            self._local.batch
        except AttributeError:
            self._local.batch = []
            return self
        else:
            raise BatchStarted('batch already started')

    def batch_send(self):
        """
        Sends the batch transmission.

        This method is called after :meth:`batch_start` and :meth:`send` have
        been used to build up a list of batch commands. All the commands will
        be combined and sent to the server as a single transmission.

        If no batch is currently in progress, a
        :exc:`~picraft.exc.BatchNotStarted` exception will be raised.
        """
        try:
            self._local.batch
        except AttributeError:

# Path: picraft/exc.py
# class CommandError(ConnectionError):
#     "Exception raised when a network command fails"
# 
# class NoResponse(ConnectionError):
#     "Exception raised when a network command expects a response but gets none"
# 
# class BatchStarted(ConnectionError):
#     "Exception raised when a batch is started before a prior one is complete"
# 
# class BatchNotStarted(ConnectionError):
#     "Exception raised when a batch is terminated when none has been started"
# 
# class ConnectionClosed(ConnectionError):
#     "Exception raised when an operation is attempted against a closed connection"


# Path: picraft/connection.py
import socket
import logging
import select
import threading
from .exc import (
        CommandError,
        NoResponse,
        BatchStarted,
        BatchNotStarted,
        ConnectionClosed,
        )


        .. note::

            This method can be used as a context manager (:keyword:`with`)
            which will cause a batch to be started, and implicitly terminated
            with :meth:`batch_send` or :meth:`batch_forget` depending on
            whether an exception is raised within the enclosed block.
        """
        try:
            self._local.batch
        except AttributeError:
            self._local.batch = []
            return self
        else:
            raise BatchStarted('batch already started')

    def batch_send(self):
        """
        Sends the batch transmission.

        This method is called after :meth:`batch_start` and :meth:`send` have
        been used to build up a list of batch commands. All the commands will
        be combined and sent to the server as a single transmission.

        If no batch is currently in progress, a
        :exc:`~picraft.exc.BatchNotStarted` exception will be raised.
        """
        try:
            self._local.batch
        except AttributeError:

            raise BatchNotStarted('no batch in progress')