<commit_before># -*- coding: utf-8 -*-

"""Python module to control the RedRat irNetBox-III infrared emitter.

Author: <NAME> <<EMAIL>>
Copyright 2012 YouView TV Ltd.
License: LGPL v2.1 or (at your option) any later version (see
https://github.com/drothlis/stb-tester/blob/master/LICENSE for details).

The irNetBox-III is a network-controlled infrared emitter:
http://www.redrat.co.uk/products/irnetbox.html

This module only supports version III of the irNetBox hardware.

"§" section numbers in the function docstrings are from "The irNetBox
Network Control Protocol":
http://www.redrat.co.uk/products/IRNetBox_Comms-V3.0.pdf

Thanks to <NAME> at RedRat for friendly and prompt answers to all my
questions.

Classes:

IRNetBox -- An instance of IRNetBox holds a TCP connection to the device.
Note that the device only accepts one TCP connection at a time, so keep this
as short-lived as possible. For example:

    with irnetbox.IRNetBox("192.168.0.10") as ir:
        ir.power_on()
        ir.irsend_raw(port=1, power=100, data=binascii.unhexlify("000174F..."))

RemoteControlConfig -- Holds infrared signal data from a config file produced
by RedRat's "IR Signal Database Utility". Example usage (where "POWER" is a
signal defined in the config file):

    rcu = irnetbox.RemoteControlConfig("my-rcu.irnetbox.config")
    ir.irsend_raw(port=1, power=100, data=rcu["POWER"])

"""

import binascii
import random
import re
import socket
import struct
import sys
import time


class IRNetBox:
    def __init__(self, hostname):
        port = 10001  # §5
        for i in range(6):
            try:
                self._socket = socket.socket()
                self._socket.connect((hostname, port))
                break
            except socket.error as e:
                if e.errno == 61 and i < 5:  # Connection refused<commit_msg>irnetbox.py: Fix connection retry on Linux<commit_after># -*- coding: utf-8 -*-

"""Python module to control the RedRat irNetBox-III infrared emitter.

Author: <NAME> <<EMAIL>>
Copyright 2012 YouView TV Ltd.
License: LGPL v2.1 or (at your option) any later version (see
https://github.com/drothlis/stb-tester/blob/master/LICENSE for details).

The irNetBox-III is a network-controlled infrared emitter:
http://www.redrat.co.uk/products/irnetbox.html

This module only supports version III of the irNetBox hardware.

"§" section numbers in the function docstrings are from "The irNetBox
Network Control Protocol":
http://www.redrat.co.uk/products/IRNetBox_Comms-V3.0.pdf

Thanks to <NAME> at RedRat for friendly and prompt answers to all my
questions.

Classes:

IRNetBox -- An instance of IRNetBox holds a TCP connection to the device.
Note that the device only accepts one TCP connection at a time, so keep this
as short-lived as possible. For example:

    with irnetbox.IRNetBox("192.168.0.10") as ir:
        ir.power_on()
        ir.irsend_raw(port=1, power=100, data=binascii.unhexlify("000174F..."))

RemoteControlConfig -- Holds infrared signal data from a config file produced
by RedRat's "IR Signal Database Utility". Example usage (where "POWER" is a
signal defined in the config file):

    rcu = irnetbox.RemoteControlConfig("my-rcu.irnetbox.config")
    ir.irsend_raw(port=1, power=100, data=rcu["POWER"])

"""

import binascii
import random
import re
import socket
import struct
import sys
import time


class IRNetBox:
    def __init__(self, hostname):
        port = 10001  # §5
        for i in range(6):
            try:
                self._socket = socket.socket()
                self._socket.connect((hostname, port))
                break
            except socket.error as e:
                if e.errno == errno.ECONNREFUSED and i < 5:
{'fraction_non_alphanumeric': 0.09678291430116248, 'fraction_numerical': 0.02216815355501487, 'mean_word_length': 3.243119266055046, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6144777', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1106, 'n_words': 402}