Returns the stdout as a byte stream in a Py2/PY3 compatible manner

    Returns
    -------
    io.BytesIO
        Byte stream of Stdout
975033
def stdout():
    

    # We write all of the data to stdout with bytes, typically io.BytesIO. stdout in Python2
    # accepts bytes but Python3 does not. This is due to a type change on the attribute. To keep
    # this consistent, we leave Python2 the same and get the .buffer attribute on stdout in Python3
    byte_stdout = sys.stdout

    if sys.version_info.major > 2:
        byte_stdout = sys.stdout.buffer  # pylint: disable=no-member

    return byte_stdout
491604
def _handle_io(self, args, file, result, passphrase=False, binary=False):
        """"""
        p = self._open_subprocess(args, passphrase)
        if not binary:
            stdin = codecs.getwriter(self._encoding)(p.stdin)
        else:
            stdin = p.stdin
        if passphrase:
            _util._write_passphrase(stdin, passphrase, self._encoding)
        writer = _util._threaded_copy_data(file, stdin)
        self._collect_output(p, result, writer, stdin)
        return result
384585
def _using_stdout(self):
        
        if WINDOWS and colorama:
            # Then self.stream is an AnsiToWin32 object.
            return self.stream.wrapped is sys.stdout

        return self.stream is sys.stdout
715830
def ToStream(value):
        
        ms = StreamManager.GetStream()
        writer = BinaryWriter(ms)

        value.Serialize(writer)

        retVal = ms.getvalue()
        StreamManager.ReleaseStream(ms)

        return retVal
1190044
def printo(msg, encoding=None, errors='replace', std_type='stdout'):
    
    std = getattr(sys, std_type, sys.stdout)
    if encoding is None:
        try:
            encoding = std.encoding
        except AttributeError:
            encoding = None
    # Fallback to ascii if no encoding is found
    if encoding is None:
        encoding = 'ascii'
    # https://docs.python.org/3/library/sys.html#sys.stdout
    # write in the binary buffer directly in python3
    if hasattr(std, 'buffer'):
        std = std.buffer
    std.write(msg.encode(encoding, errors=errors))
    std.write(b'\n')
    std.flush()
1026298
def decompile(
        bytecode_version, co, out=None, showasm=None, showast=False,
        timestamp=None, showgrammar=False, code_objects={},
        source_size=None, is_pypy=None, magic_int=None,
        mapstream=None, do_fragments=False):
    
    if bytecode_version is None:
        bytecode_version = sysinfo2float()

    # store final output stream for case of error
    real_out = out or sys.stdout

    def write(s):
        s += '\n'
        real_out.write(s)

    assert iscode(co)

    co_pypy_str = 'PyPy ' if is_pypy else ''
    run_pypy_str = 'PyPy ' if IS_PYPY else ''
    sys_version_lines = sys.version.split('\n')
    write('# uncompyle6 version %s\n'
          '# %sPython bytecode %s%s\n# Decompiled from: %sPython %s' %
          (VERSION, co_pypy_str, bytecode_version,
               " (%s)" % str(magic_int) if magic_int else "",
          run_pypy_str, '\n# '.join(sys_version_lines)))
    if co.co_filename:
        write('# Embedded file name: %s' % co.co_filename,)
    if timestamp:
        write('# Compiled at: %s' % datetime.datetime.fromtimestamp(timestamp))
    if source_size:
        write('# Size of source mod 2**32: %d bytes' % source_size)

    debug_opts = {
        'asm': showasm,
        'ast': showast,
        'grammar': showgrammar
    }

    try:
        if mapstream:
            if isinstance(mapstream, str):
                mapstream = _get_outstream(mapstream)

            deparsed = deparse_code_with_map(bytecode_version, co, out, showasm, showast,
                                             showgrammar,
                                             code_objects = code_objects,
                                             is_pypy = is_pypy,
                                             )
            header_count = 3+len(sys_version_lines)
            linemap = [(line_no, deparsed.source_linemap[line_no]+header_count)
                        for line_no in
                        sorted(deparsed.source_linemap.keys())]
            mapstream.write("\n\n# %s\n" % linemap)
        else:
            if do_fragments:
                deparse_fn = code_deparse_fragments
            else:
                deparse_fn = code_deparse
            deparsed = deparse_fn(co, out, bytecode_version,
                                  debug_opts = debug_opts,
                                  is_pypy=is_pypy)
            pass
        return deparsed
    except pysource.SourceWalkerError as e:
        # deparsing failed
        raise pysource.SourceWalkerError(str(e))
162269
def dump(self, stream=None):
        
        if stream is None:
            stream = BytesIO()

        if isinstance(stream, bytes):
            stream = BytesIO(stream)

        stream = self.codec.compress(stream)
        self.fs.dump(stream)

        return self
1274745
def get_pipe_series_output(commands: Sequence[str],
                           stdinput: BinaryIO = None) -> bytes:
    
    # Python arrays indexes are zero-based, i.e. an array is indexed from
    # 0 to len(array)-1.
    # The range/xrange commands, by default, start at 0 and go to one less
    # than the maximum specified.

    # print commands
    processes = []  # type: List[subprocess.Popen]
    for i in range(len(commands)):
        if i == 0:  # first processes
            processes.append(
                subprocess.Popen(
                    shlex.split(commands[i]),
                    stdin=subprocess.PIPE,
                    stdout=subprocess.PIPE
                )
            )
        else:  # subsequent ones
            processes.append(
                subprocess.Popen(
                    shlex.split(commands[i]),
                    stdin=processes[i - 1].stdout,
                    stdout=subprocess.PIPE
                )
            )
    return processes[len(processes) - 1].communicate(stdinput)[0]
846037
def download_to_bytesio(url):
    
    logger.info("Downloading url: {0}".format(url))
    r = cleaned_request('get', url, stream=True)
    stream = io.BytesIO()
    total_length = int(r.headers.get('content-length'))
    for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1):
        if chunk:
            stream.write(chunk)
    stream.seek(0)
    return stream
1330202
def stdout_encode(u, default='utf-8'):
    
    # from http://stackoverflow.com/questions/3627793/best-output-type-and-
    #   encoding-practices-for-repr-functions
    encoding = sys.stdout.encoding or default
    return u.encode(encoding, "replace").decode(encoding, "replace")
289587
def to_byte(stype):
    
    output = []

    if stype in ('i8', 'u8'):
        return []

    if is_int_type(stype):
        output.append('ld a, l')
    elif stype == 'f16':
        output.append('ld a, e')
    elif stype == 'f':  # Converts C ED LH to byte
        output.append('call __FTOU32REG')
        output.append('ld a, l')
        REQUIRES.add('ftou32reg.asm')

    return output
242447
def get_buffer(self, format, output=None):
        
        return self.io.get_buffer(self._get_data(), self.get_header(),
                                  format, output=output)
458943
async def stdout_writer():
    
    if sys.stdout.seekable():
        # it’s a file
        return sys.stdout.buffer.raw

    if os.isatty(sys.stdin.fileno()):
        # it’s a tty, use fd 0
        fd_to_use = 0
    else:
        fd_to_use = 1

    twrite, pwrite = await loop.connect_write_pipe(
        asyncio.streams.FlowControlMixin,
        os.fdopen(fd_to_use, "wb"),
    )

    swrite = asyncio.StreamWriter(
        twrite,
        pwrite,
        None,
        loop,
    )

    return swrite
656423
def ToByteArray(self):
        
        ms = StreamManager.GetStream()
        writer = BinaryWriter(ms)
        self.Serialize(writer)

        retval = ms.ToArray()
        StreamManager.ReleaseStream(ms)

        return retval
218831
def _output_current_byte(self):
        
        if self.tape[self.pointer] is None:
            print "{}".format(chr(0)),
        else:
            print "{}".format(chr(int(self.tape[self.pointer]))),
476280
def get_bytes(self):
        

        pq_io = BytesIO()
        serialize_string(pq_io, self.pq)
        serialize_string(pq_io, self.p)
        serialize_string(pq_io, self.q)

        print("\nPQ")
        hexdump(self.pq)

        print("\nP")
        hexdump(self.p)

        print("\nQ")
        hexdump(self.q)

        print("\nPQ_io")
        hexdump(pq_io.getvalue())

        print("\nnonce")
        hexdump(self.nonce)

        print("\nserver_nonce")
        hexdump(self.server_nonce)

        print("\nnew_nonce")
        hexdump(self.new_nonce)

        ret = struct.pack("<I28s16s16s32s", p_q_inner_data.constructor, pq_io.getvalue(),
                           self.nonce, self.server_nonce, self.new_nonce)

        print("\np_q_inner_data")
        hexdump(ret)

        return ret
729891
def as_bin(self):
        """"""
        f = io.BytesIO()
        self.stream(f)
        return f.getvalue()