<commit_before>"""Main stb-tester python module. Intended to be used with `stbt run`.

See `man stbt` and http://stb-tester.com for documentation.

Copyright 2012-2013 YouView TV Ltd and contributors.
License: LGPL v2.1 or (at your option) any later version (see
https://github.com/drothlis/stb-tester/blob/master/LICENSE for details).
"""

from collections import namedtuple, deque
import argparse
import ConfigParser
import Queue
import errno
import inspect
import os
import re
import socket
import sys
import time
import warnings

import irnetbox


warnings.filterwarnings(
    action="always", message='stbt-templatematch',
    category=DeprecationWarning, module='stbt')


class ArgvHider:  # pylint: disable=W0232
    """ For use with 'with' statement:  Unsets argv and resets it.

    This is used because otherwise gst-python will exit if '-h', '--help', '-v'
    or '--version' command line arguments are given.
    """

    def __enter__(self):
        self.argv = sys.argv[:]  # pylint: disable=W0201
        del sys.argv[1:]

    def __exit__(self, ex_type, exc_value, traceback):
        sys.argv = self.argv


class StdErrHider:  # pylint: disable=W0232
    """For use with 'with' statement: Hide stderr output.

    This is used because otherwise gst-python will print
    'pygobject_register_sinkfunc is deprecated'.
    """

    def __enter__(self):
        # pylint: disable=W0201
        fd = sys.__stderr__.fileno()
        self.saved_fd = os.dup(fd)
        sys.__stderr__.flush()
        self.null_stream = open(os.devnull, 'w', 0)
        os.dup2(self.null_stream.fileno(), fd)

    def __exit__(self, ex_type, ex_value, traceback):
        sys.__stderr__.flush()
        os.dup2(self.saved_fd, sys.__stderr__.fileno())
        self.null_stream.close()


import pygst  # gstreamer
pygst.require("0.10")
with ArgvHider(), StdErrHider():  # pylint: disable=C0321
    import gst
import gobject
import glib


# Functions available to stbt scripts
#===========================================================================
# -- warn about missing docstrings # pylint: enable=C0111

def press(key):
    """Send the specified key-press to the system under test.<commit_msg>stbt.py: Cleanup: Move `warnings` configuration after imports<commit_after>"""Main stb-tester python module. Intended to be used with `stbt run`.

See `man stbt` and http://stb-tester.com for documentation.

Copyright 2012-2013 YouView TV Ltd and contributors.
License: LGPL v2.1 or (at your option) any later version (see
https://github.com/drothlis/stb-tester/blob/master/LICENSE for details).
"""

from collections import namedtuple, deque
import argparse
import ConfigParser
import Queue
import errno
import inspect
import os
import re
import socket
import sys
import time
import warnings

import irnetbox


class ArgvHider:  # pylint: disable=W0232
    """ For use with 'with' statement:  Unsets argv and resets it.

    This is used because otherwise gst-python will exit if '-h', '--help', '-v'
    or '--version' command line arguments are given.
    """

    def __enter__(self):
        self.argv = sys.argv[:]  # pylint: disable=W0201
        del sys.argv[1:]

    def __exit__(self, ex_type, exc_value, traceback):
        sys.argv = self.argv


class StdErrHider:  # pylint: disable=W0232
    """For use with 'with' statement: Hide stderr output.

    This is used because otherwise gst-python will print
    'pygobject_register_sinkfunc is deprecated'.
    """

    def __enter__(self):
        # pylint: disable=W0201
        fd = sys.__stderr__.fileno()
        self.saved_fd = os.dup(fd)
        sys.__stderr__.flush()
        self.null_stream = open(os.devnull, 'w', 0)
        os.dup2(self.null_stream.fileno(), fd)

    def __exit__(self, ex_type, ex_value, traceback):
        sys.__stderr__.flush()
        os.dup2(self.saved_fd, sys.__stderr__.fileno())
        self.null_stream.close()


import pygst  # gstreamer
pygst.require("0.10")
with ArgvHider(), StdErrHider():  # pylint: disable=C0321
    import gst
import gobject
import glib


warnings.filterwarnings(
    action="always", message='stbt-templatematch',
    category=DeprecationWarning, module='stbt')


# Functions available to stbt scripts
#===========================================================================
# -- warn about missing docstrings # pylint: enable=C0111

def press(key):
    """Send the specified key-press to the system under test.
{'fraction_non_alphanumeric': 0.13702031602708803, 'fraction_numerical': 0.01851015801354402, 'mean_word_length': 3.615625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '5717603', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1350, 'n_words': 415}