# 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,
        )
    .. attribute:: encoding

        The encoding that will be used for messages transmitted to, and
        received from the server. Defaults to ``'ascii'``.

    .. autoattribute:: server_version
    """

    def __init__(
            self, host, port, timeout=1.0, ignore_errors=True,
            encoding='ascii'):
        self._lock = threading.Lock()
        self._local = threading.local()
        self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # This is effectively an interactive protocol, so disable Nagle's
        # algorithm for better performance
        self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        self._socket.connect((host, port))
        self._rfile = self._socket.makefile('rb', -1)
        self._wfile = self._socket.makefile('wb', 0) # no buffering for writes
        self._directions = {} # temp space for calculated direction
        self.timeout = timeout
        self.encoding = encoding
        # Determine what version of Minecraft we're talking to. Sadly, nobody
        # seems to have thought about implementating an explicit means of
        # doing this (a connection message, a getVersion() call, etc.) so
        # we're relying on observed differences in implementation here...
        self.ignore_errors = False
        try:
            test_result = self.transact('foo()')

# 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,
        )

    .. attribute:: encoding

        The encoding that will be used for messages transmitted to, and
        received from the server. Defaults to ``'ascii'``.

    .. autoattribute:: server_version
    """

    def __init__(
            self, host, port, timeout=1.0, ignore_errors=True,
            encoding='ascii'):
        self._lock = threading.Lock()
        self._local = threading.local()
        self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # This is effectively an interactive protocol, so disable Nagle's
        # algorithm for better performance
        self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        self._socket.connect((host, port))
        self._rfile = self._socket.makefile('rb', -1)
        self._wfile = self._socket.makefile('wb', 0) # no buffering for writes
        self._directions = {} # temp space for calculated direction
        self.timeout = timeout
        self.encoding = encoding
        # Determine what version of Minecraft we're talking to. Sadly, nobody
        # seems to have thought about implementating an explicit means of
        # doing this (a connection message, a getVersion() call, etc.) so
        # we're relying on observed differences in implementation here...
        self.ignore_errors = False
        try:
            test_result = self.transact('foo()')

        except CommandError: