# Path: _stbt/config.py
# class ConfigurationError(Exception):
#     """An error with your stbt configuration file."""
#     pass
# 
# Path: _stbt/logging.py
# def debug(msg):
#     """Print the given string to stderr if stbt run `--verbose` was given."""
#     if get_debug_level() > 0:
#         sys.stderr.write("%s\n" % (msg,))
# 
# Path: _stbt/utils.py
# @contextmanager
# def named_temporary_directory(
#         suffix='', prefix='tmp', dir=None):  # pylint:disable=redefined-builtin
#     dirname = tempfile.mkdtemp(suffix, prefix, dir)
#     try:
#         yield dirname
#     finally:
#         rmtree(dirname)
# 
# def to_bytes(text):
#     if isinstance(text, str):
#         return text.encode("utf-8", errors="backslashreplace")
#     elif isinstance(text, bytes):
#         return text
#     else:
#         raise TypeError("Unexpected type %s" % type(text))
# 
# def to_unicode(text):
#     if isinstance(text, bytes):
#         return text.decode("utf-8", errors="replace")
#     else:
#         return str(text)


import os
import re
import socket
import struct
import subprocess
import sys
import time
import requests
    import pytest
    import responses
    import pytest
    import responses
from distutils.spawn import find_executable
from . import irnetbox
from .config import ConfigurationError
from .logging import debug
from .utils import named_temporary_directory, to_bytes, to_unicode
    from .control_gpl import controls as gpl_controls
    from _stbt.android import AdbDevice
        from base64 import b64encode
    from unittest import SkipTest
    from .x11 import x_server

    def _release(self, key):
        key_code = self._get_key_code(key)
        self.socket.send(struct.pack('!BBxxI', 4, 0, key_code))
        debug("RemoteFrameBuffer: release (0x%04x)" % key_code)

    def _close(self):
        self.socket.shutdown(socket.SHUT_RDWR)
        self.socket.close()
        debug("RemoteFrameBuffer: socket connection closed")

    def _get_key_code(self, key):
        key_code = self._KEYNAMES.get(key, key)
        return key_code


class IRNetBoxControl(RemoteControl):
    """Send a key-press via the network-controlled RedRat IRNetBox IR emitter.

    See http://www.redrat.co.uk/products/irnetbox.html

    """

    def __init__(self, hostname, port, output, config):
        self.hostname = hostname
        self.port = int(port or 10001)
        self.output = int(output)
        self.config = irnetbox.RemoteControlConfig(config)
        # Connect once so that the test fails immediately if irNetBox not found
        # (instead of failing at the first `press` in the script).

# Path: _stbt/config.py
# class ConfigurationError(Exception):
#     """An error with your stbt configuration file."""
#     pass
# 
# Path: _stbt/logging.py
# def debug(msg):
#     """Print the given string to stderr if stbt run `--verbose` was given."""
#     if get_debug_level() > 0:
#         sys.stderr.write("%s\n" % (msg,))
# 
# Path: _stbt/utils.py
# @contextmanager
# def named_temporary_directory(
#         suffix='', prefix='tmp', dir=None):  # pylint:disable=redefined-builtin
#     dirname = tempfile.mkdtemp(suffix, prefix, dir)
#     try:
#         yield dirname
#     finally:
#         rmtree(dirname)
# 
# def to_bytes(text):
#     if isinstance(text, str):
#         return text.encode("utf-8", errors="backslashreplace")
#     elif isinstance(text, bytes):
#         return text
#     else:
#         raise TypeError("Unexpected type %s" % type(text))
# 
# def to_unicode(text):
#     if isinstance(text, bytes):
#         return text.decode("utf-8", errors="replace")
#     else:
#         return str(text)


# Path: _stbt/control.py
import os
import re
import socket
import struct
import subprocess
import sys
import time
import requests
    import pytest
    import responses
    import pytest
    import responses
from distutils.spawn import find_executable
from . import irnetbox
from .config import ConfigurationError
from .logging import debug
from .utils import named_temporary_directory, to_bytes, to_unicode
    from .control_gpl import controls as gpl_controls
    from _stbt.android import AdbDevice
        from base64 import b64encode
    from unittest import SkipTest
    from .x11 import x_server


    def _release(self, key):
        key_code = self._get_key_code(key)
        self.socket.send(struct.pack('!BBxxI', 4, 0, key_code))
        debug("RemoteFrameBuffer: release (0x%04x)" % key_code)

    def _close(self):
        self.socket.shutdown(socket.SHUT_RDWR)
        self.socket.close()
        debug("RemoteFrameBuffer: socket connection closed")

    def _get_key_code(self, key):
        key_code = self._KEYNAMES.get(key, key)
        return key_code


class IRNetBoxControl(RemoteControl):
    """Send a key-press via the network-controlled RedRat IRNetBox IR emitter.

    See http://www.redrat.co.uk/products/irnetbox.html

    """

    def __init__(self, hostname, port, output, config):
        self.hostname = hostname
        self.port = int(port or 10001)
        self.output = int(output)
        self.config = irnetbox.RemoteControlConfig(config)
        # Connect once so that the test fails immediately if irNetBox not found
        # (instead of failing at the first `press` in the script).

        debug("IRNetBoxControl: Connecting to %s" % hostname)