<commit_before># encoding: UTF-8

"""
Utilities and extensions for the `cothread`_ catools library.

.. cothread: http://controls.diamond.ac.uk/downloads/python/cothread

.. moduleauthor:: <NAME> <<EMAIL>>
"""

from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

from collections import OrderedDict

from cothread import catools

# Export constants from catools module
FORMAT_RAW = catools.FORMAT_RAW
FORMAT_TIME = catools.FORMAT_TIME
FORMAT_CTRL = catools.FORMAT_CTRL


def _to_str(pvs):
    """Ensure argument is a string or list of strings."""
    if isinstance(pvs, (list, tuple)):
        return [str(pv) for pv in pvs]
    else:
        return str(pvs)


def caput(pvs, values, repeat_value=False, datatype=None,
          wait=True, timeout=5, callback=None, throw=True):
    """
    Convenience function that wraps the cothread.catools.caput()
    function with safe handling of unicode string in Python 2.X.

    .. note:: The default value of the 'wait' keyword argument
       has been changed from the original cothread function.
    """
    return catools.caput(_to_str(pvs), values,
                         repeat_value=repeat_value, wait=wait,
                         datatype=datatype, timeout=timeout,
                         callback=callback, throw=throw)
<commit_msg>Add work around for problem with cothreads caput.<commit_after># encoding: UTF-8

"""
Utilities and extensions for the `cothread`_ catools library.

.. cothread: http://controls.diamond.ac.uk/downloads/python/cothread

.. moduleauthor:: <NAME> <<EMAIL>>
"""

from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

from collections import OrderedDict

from cothread import catools

try:
    basestring # Python 2.X
except NameError:
    basestring = str # Python 3.X

# Export constants from catools module
FORMAT_RAW = catools.FORMAT_RAW
FORMAT_TIME = catools.FORMAT_TIME
FORMAT_CTRL = catools.FORMAT_CTRL


def _to_str(pvs):
    """Ensure argument is a string or list of strings."""
    # The logic follows that from the cothread library.
    # If is it NOT a string then assume it is an iterable.
    if isinstance(pvs, basestring):
        return str(pvs)
    else:
        return [str(pv) for pv in pvs]


def caput(pvs, values, repeat_value=False, datatype=None,
          wait=True, timeout=5, callback=None, throw=True):
    """
    Convenience function that wraps the cothread.catools.caput()
    function with safe handling of unicode string in Python 2.X.

    .. note:: The default value of the 'wait' keyword argument
       has been changed from the original cothread function.
    """
    # Work around for problem in cothread library.
    # Passing the repeat_value keyword parameter
    # with a single PV throws an exception.
    if isinstance(pvs, basestring):
        return catools.caput(_to_str(pvs), values,
                             datatype=datatype, wait=wait,
                             timeout=timeout, callback=callback, throw=throw)
    else:
        return catools.caput(_to_str(pvs), values,
                             repeat_value=repeat_value,
                             datatype=datatype, wait=wait,
                             timeout=timeout, callback=callback, throw=throw)

{'fraction_non_alphanumeric': 0.08137485311398356, 'fraction_numerical': 0.0023501762632197414, 'mean_word_length': 3.0487514863258025, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2177500', 'n_tokens_mistral': 997, 'n_tokens_neox': 967, 'n_words': 319}