Write a GATT Command without callback - not utf-8.
962658
def make_request(self, handle, value, timeout=DEFAULT_TIMEOUT, with_response=True):
        """"""
        try:
            with self:
                _LOGGER.debug("Writing %s to %s with with_response=%s", codecs.encode(value, 'hex'), handle, with_response)
                self._conn.writeCharacteristic(handle, value, withResponse=with_response)
                if timeout:
                    _LOGGER.debug("Waiting for notifications for %s", timeout)
                    self._conn.waitForNotifications(timeout)
        except btle.BTLEException as ex:
            _LOGGER.debug("Got exception from bluepy while making a request: %s", ex)
            raise
65368
def utf(text):
    """"""
    try:
        output = unicode(text, encoding='utf-8')
    except UnicodeDecodeError:
        output = text
    except TypeError:
        output = text
    return output
548566
def to_utf8(path, output_path=None):
    
    if output_path is None:
        basename, ext = os.path.splitext(path)
        output_path = basename + "-UTF8Encode" + ext
    
    text = smartread(path)
    write(text, output_path)
511022
def _init_prtfmt(self, key="fmta"):
        """"""
        prtfmt = self.gosubdag.prt_attr[key]
        return prtfmt.replace("{NS}", "{NS} {hdr1usr01:2} {num_usrgos:>4} uGOs")
809787
def cli(input, verbose, quiet, output_format, precision, indent):
    """"""

    verbosity = verbose - quiet
    configure_logging(verbosity)
    logger = logging.getLogger('geomet')

    # Handle the case of file, stream, or string input.
    try:
        src = click.open_file(input).readlines()
    except IOError:
        src = [input]

    stdout = click.get_text_stream('stdout')

    # Read-write loop.
    try:
        for line in src:
            text = line.strip()
            logger.debug("Input: %r", text)
            output = translate(
                text,
                output_format=output_format,
                indent=indent,
                precision=precision
            )
            logger.debug("Output: %r", output)
            stdout.write(output)
            stdout.write('\n')
        sys.exit(0)
    except Exception:
        logger.exception("Failed. Exception caught")
        sys.exit(1)
57599
def write(self, text):
        """"""
        text = str(text)    # eliminate any unicode or other snigglets
        text = text.replace(IAC, IAC+IAC)
        text = text.replace(chr(10), chr(13)+chr(10))
        self.writecooked(text)
667572
def commandstr(command):
    """"""
    if command == CMD_MESSAGE_ERROR:
        msg = "CMD_MESSAGE_ERROR"
    elif command == CMD_MESSAGE_LIST:
        msg = "CMD_MESSAGE_LIST"
    elif command == CMD_MESSAGE_PASSWORD:
        msg = "CMD_MESSAGE_PASSWORD"
    elif command == CMD_MESSAGE_MP3:
        msg = "CMD_MESSAGE_MP3"
    elif command == CMD_MESSAGE_DELETE:
        msg = "CMD_MESSAGE_DELETE"
    elif command == CMD_MESSAGE_VERSION:
        msg = "CMD_MESSAGE_VERSION"
    elif command == CMD_MESSAGE_CDR_AVAILABLE:
        msg = "CMD_MESSAGE_CDR_AVAILABLE"
    elif command == CMD_MESSAGE_CDR:
        msg = "CMD_MESSAGE_CDR"
    else:
        msg = "CMD_MESSAGE_UNKNOWN"
    return msg
838705
def _put_text(irods_path, text):
    """"""
    with tempfile.NamedTemporaryFile() as fh:
        fpath = fh.name

        try:
            # Make Python2 compatible.
            text = unicode(text, "utf-8")
        except (NameError, TypeError):
            # NameError: We are running Python3 => text already unicode.
            # TypeError: text is already of type unicode.
            pass

        fh.write(text.encode("utf-8"))
        fh.flush()
        cmd = CommandWrapper([
            "iput",
            "-f",
            fpath,
            irods_path
        ])
        cmd()
    assert not os.path.isfile(fpath)
403666
def _send_command(self, cmd, expect=None):
        
        if not self.is_alive:
            raise NotPlayingError()
        logger.debug("Send command to mplayer: " + cmd)
        cmd = cmd + "\n"
        # In Py3k, TypeErrors will be raised because cmd is a string but stdin
        # expects bytes. In Python 2.x on the other hand, UnicodeEncodeErrors
        # will be raised if cmd is unicode. In both cases, encoding the string
        # will fix the problem.
        try:
            self.sub_proc.stdin.write(cmd)
        except (TypeError, UnicodeEncodeError):
            self.sub_proc.stdin.write(cmd.encode('utf-8', 'ignore'))
        time.sleep(0.1)     # wait for mplayer (better idea?)
        # Expect a response for 'get_property' only
        if not expect:
            return
        while True:
            try:
                output = self.sub_proc.stdout.readline().rstrip()
                output = output.decode('utf-8')
            except IOError:
                return None
            # print output
            split_output = output.split('=')
            # print(split_output)
            if len(split_output) == 2 and split_output[0].strip() == expect:
                # We found it
                value = split_output[1]
                return value.strip()
812264
def tts_cli(text, file, output, slow, lang, nocheck):
    

    # stdin for <text>
    if text == '-':
        text = click.get_text_stream('stdin').read()

    # stdout (when no <output>)
    if not output:
        output = click.get_binary_stream('stdout')

    # <file> input (stdin on '-' is handled by click.File)
    if file:
        try:
            text = file.read()
        except UnicodeDecodeError as e:  # pragma: no cover
            log.debug(str(e), exc_info=True)
            raise click.FileError(
                file.name,
                "<file> must be encoded using '%s'." %
                sys_encoding())

    # TTS
    try:
        tts = gTTS(
            text=text,
            lang=lang,
            slow=slow,
            lang_check=not nocheck)
        tts.write_to_fp(output)
    except (ValueError, AssertionError) as e:
        raise click.UsageError(str(e))
    except gTTSError as e:
        raise click.ClickException(str(e))
770252
def _utf8str(x):
  """"""
  if six.PY3:
    return str(x)
  if isinstance(x, six.binary_type):
    return x
  elif isinstance(x, six.text_type):
    return x.encode('utf-8')
  else:
    return six.binary_type(x)
840345
def write_output(output, text=True, output_path=None):
    """"""

    if output_path is None and text is False:
        print("ERROR: You must specify an output file using -o/--output for binary output formats")
        sys.exit(1)

    if output_path is not None:
        if text:
            outfile = open(output_path, "w", encoding="utf-8")
        else:
            outfile = open(output_path, "wb")
    else:
        outfile = sys.stdout

    try:
        if text and isinstance(output, bytes):
            output = output.decode('utf-8')

        outfile.write(output)
    finally:
        if outfile is not sys.stdout:
            outfile.close()
173607
def _send(self, command):
        
        command = command.encode('utf-8')
        log.debug('>> ' + command)
        self.conn.oqueue.put(command)
903221
def convert_nonascii(self, lst):
        """"""
        for item in lst:
            if item.startswith('"') and item.endswith('"'):
                item = item[1:-1]
                yield item.encode('utf-8').decode('unicode-escape')
            else:
                yield item.encode('utf-8').decode('unicode-escape')
192097
def handle_to_uuid(handle, services):
    """"""

    for service in services.values():
        for char_uuid, char_def in service['characteristics'].items():
            if char_def['handle'] == handle:
                return char_uuid

    raise ValueError("Handle not found in GATT table")
1263938
def force_ascii_values(data):
    """"""
    return {
        k: v.encode('utf8').decode('ascii', 'backslashreplace')
        for k, v in data.items()
    }
137155
def system(*args, **kwargs):
    """"""
    kwargs.setdefault('stdout', subprocess.PIPE)
    proc = subprocess.Popen(args, **kwargs)
    out, _ = proc.communicate()
    if proc.returncode:
        raise SystemExit(proc.returncode)
    return out.decode('utf-8')