Function to visualize byte streams. Split into bytes, print to console.
    :param bs: BYTE STRING
482682
def print_bytes(data):
    
    bs = bytearray(data)
    symbols_in_one_line = 8
    n = len(bs) // symbols_in_one_line
    i = 0
    for i in range(n):
        print(str(i*symbols_in_one_line)+" | "+" ".join(["%02X" % b for b in bs[i*symbols_in_one_line:(i+1)*symbols_in_one_line]])) # for every 8 symbols line
    if not len(bs) % symbols_in_one_line == 0:
        print(str((i+1)*symbols_in_one_line)+" | "+" ".join(["%02X" % b for b in bs[(i+1)*symbols_in_one_line:]])+"\n")
775604
def _show_stat_wrapper_multi_Progress(count, last_count, start_time, max_count, speed_calc_cycles, 
                                      width, q, last_speed, prepend, show_stat_function, len_, 
                                      add_args, lock, info_line, no_move_up=False):
    
#         print(ESC_BOLD, end='')
#         sys.stdout.flush()
    for i in range(len_):
        _show_stat_wrapper_Progress(count[i], last_count[i], start_time[i], max_count[i], speed_calc_cycles, 
                                    width, q[i], last_speed[i], prepend[i], show_stat_function,
                                    add_args, i, lock[i])
    n = len_
    if info_line is not None:
        s = info_line.value.decode('utf-8')
        s = s.split('\n')
        n += len(s)
        for si in s:
            if width == 'auto':
                width = get_terminal_width()
            if len(si) > width:
                si = si[:width]
            print("{0:<{1}}".format(si, width))
    
    if no_move_up:
        n = 0
                                # this is only a hack to find the end
                                # of the message in a stream
                                # so ESC_HIDDEN+ESC_NO_CHAR_ATTR is a magic ending
    print(terminal.ESC_MOVE_LINE_UP(n) + terminal.ESC_MY_MAGIC_ENDING, end='')
    sys.stdout.flush()
15114
def bed(args):
    
    from jcvi.formats.blast import BlastLine
    p = OptionParser(bed.__doc__)

    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    btabfile, = args
    btab = Btab(btabfile)
    for b in btab:
        Bline = BlastLine(b.blastline)
        print(Bline.bedline)
1058840
def print_debug(self, msg):
        """"""
        assert isinstance(msg, bytes)
        state = STATE_NAMES[self.state].encode()
        console_output(b'[dbg] ' + self.display_name.encode() + b'[' + state +
                       b']: ' + msg + b'\n')
1304890
def main():
    
    t, kf, t0, major, minor, prod, beta = sympy.symbols(
        't k_f t0 Y Z X beta', negative=False)
    for f in funcs:
        args = [t, kf, prod, major, minor]
        if f in (pseudo_rev, binary_rev):
            args.insert(2, kf/beta)
        expr = f(*args, backend='sympy')
        with open(f.__name__ + '.png', 'wb') as ofh:
            sympy.printing.preview(expr, output='png', filename='out.png',
                                   viewer='BytesIO', outputbuffer=ofh)
        with open(f.__name__ + '_diff.png', 'wb') as ofh:
            sympy.printing.preview(expr.diff(t).subs({t0: 0}).simplify(),
                                   output='png', filename='out.png',
                                   viewer='BytesIO', outputbuffer=ofh)
891750
def print_chain_summary(self, stream=sys.stdout, indent=""):
        
        stream.write("%sTotal files      : %i\n" %
                     (indent, len(self.file_dict)))
        stream.write("%s  Input files    : %i\n" %
                     (indent, len(self.chain_input_files)))
        stream.write("%s  Output files   : %i\n" %
                     (indent, len(self.chain_output_files)))
        stream.write("%s  Internal files : %i\n" %
                     (indent, len(self.internal_files)))
        stream.write("%s  Temp files     : %i\n" %
                     (indent, len(self.temp_files)))
184821
def print_summary(self, w=0, objs=(), **print3opts):
        '''
        '''
        self._printf('%*d bytes%s%s', w, self._total, _SI(self._total), self._incl, **print3opts)
        if self._mask:
            self._printf('%*d byte aligned', w, self._mask + 1, **print3opts)
        self._printf('%*d byte sizeof(void*)', w, _sizeof_Cvoidp, **print3opts)
        n = len(objs or ())
        if n > 0:
            d = self._duplicate or ''
            if d:
                d = ', %d duplicate' % self._duplicate
            self._printf('%*d object%s given%s', w, n, _plural(n), d, **print3opts)
        t = _sum([1 for t in _values(self._seen) if t != 0])  # [] for Python 2.2
        self._printf('%*d object%s sized', w, t, _plural(t), **print3opts)
        if self._excl_d:
            t = _sum(_values(self._excl_d))
            self._printf('%*d object%s excluded', w, t, _plural(t), **print3opts)
        t = _sum(_values(self._seen))
        self._printf('%*d object%s seen', w, t, _plural(t), **print3opts)
        if self._missed > 0:
            self._printf('%*d object%s missed', w, self._missed, _plural(self._missed), **print3opts)
        if self._depth > 0:
            self._printf('%*d recursion depth', w, self._depth, **print3opts)
1108264
def render_debug_img(
    file_name,
    page_num,
    elems,
    nodes=[],
    scaler=1,
    print_segments=False,
    print_curves=True,
    print_table_bbox=True,
    print_text_as_rect=True,
):
    
    # For debugging show the boolean pixels in black white grayscale
    height = scaler * int(elems.layout.height)
    width = scaler * int(elems.layout.width)
    debug_img, draw = create_img((0, 0, width, height))
    font = lazy_load_font()
    large_font = lazy_load_font(24)

    if print_curves:
        for i, c in enumerate(elems.curves):
            if len(c.pts) > 1:
                draw.polygon(c.pts, outline=blue)
            draw.rectangle(c.bbox, fill=blue)
            # for fig in elems.figures:
            #     draw.rectangle(fig.bbox, fill = blue)

    for i, m in enumerate(elems.mentions):
        if isinstance(m, LTAnno):
            continue
        if print_text_as_rect:
            fill = "pink" if hasattr(m, "feats") and m.feats["is_cell"] else green
            #             fill = green
            draw.rectangle(m.bbox, fill=fill)
            # draw.text(center(m.bbox), str(i), black, font = font) # Draw id
            draw.text(
                m.bbox[:2], m.get_text(), black, font=font
            )  # Draw mention content
        else:
            draw.text(m.bbox[:2], m.get_text(), "black", font=font)

    if print_segments:
        # draw skeleton for all segments
        for i, s in enumerate(elems.segments):
            draw.line(s.bbox, fill="black")

    if print_table_bbox:
        for node in nodes:
            is_table = node.is_table()
            color = "red" if is_table else "green"
            draw.rectangle(node.bbox, outline=color)
            if is_table:
                # text = 'Borderless' if node.is_borderless() else 'Bordered'
                text = "Table"
                draw.rectangle(node.bbox, outline=color)
                draw.text(node.bbox[:2], text, red, font=large_font)

    # Water mark with file name so we can identify among multiple images
    if file_name and page_num is not None:
        water_mark = (
            file_name + ":page " + str(page_num + 1) + "@%dx%d" % (width, height)
        )
        draw.text((10, 10), water_mark, black, font=font)
    debug_img.show()
    return debug_img
1133040
def print_summary(self):
        
        # Emit class summaries for each snapshot
        classlist = self.tracked_classes

        fobj = self.stream

        fobj.write('---- SUMMARY '+'-'*66+'\n')
        for snapshot in self.snapshots:
            self.annotate_snapshot(snapshot)
            fobj.write('%-35s %11s %12s %12s %5s\n' % (
                trunc(snapshot.desc, 35),
                'active',
                pp(snapshot.asizeof_total),
                'average',
                'pct'
            ))
            for classname in classlist:
                info = snapshot.classes.get(classname)
                fobj.write('  %-33s %11d %12s %12s %4d%%\n' % (
                    trunc(classname, 33),
                    info['active'],
                    pp(info['sum']),
                    pp(info['avg']),
                    info['pct']
                ))
        fobj.write('-'*79+'\n')
957987
def readinto(self, b):
        
        if not self._readable:
            raise UnsupportedOperation('read')

        # Get and update stream positions
        size = len(b)
        with self._seek_lock:
            start = self._seek
            end = start + size
            self._seek = end

        # Read data range
        with handle_os_exceptions():
            read_data = self._read_range(start, end)

        # Copy to bytes-like object
        read_size = len(read_data)
        if read_size:
            memoryview(b)[:read_size] = read_data

        # Update stream position if end of file
        if read_size != size:
            with self._seek_lock:
                self._seek = start + read_size

        # Return read size
        return read_size
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()
1235079
def _read_bin(self, stream, byte_order):
        '''
        

        '''
        try:
            return _read_array(stream, self.dtype(byte_order), 1)[0]
        except IndexError:
            raise StopIteration
604498
function(bs, data) {
        const type = data.type;
        if (bs.options.get('json')) {
            return console.log(JSON.stringify({
                "service:running": {
                    "options": bs.options.toJS()
                }
            }));
        }
        if (type === "server") {
            var baseDir = bs.options.getIn(["server", "baseDir"]);

            logUrls(bs.options.get("urls").toJS());

            if (baseDir) {
                if (utils.isList(baseDir)) {
                    baseDir.forEach(serveFiles);
                } else {
                    serveFiles(baseDir);
                }
            }
        }

        if (type === "proxy") {
            logger.info(
                "Proxying: {cyan:%s}",
                bs.options.getIn(["proxy", "target"])
            );
            logUrls(bs.options.get("urls").toJS());
        }

        if (type === "snippet") {
            if (bs.options.get("logSnippet")) {
                logger.info(
                    "{bold:Copy the following snippet into your website, " +
                        "just before the closing {cyan:</body>} tag"
                );

                logger.unprefixed("info", messages.scriptTags(bs.options));
            }

            logUrls(
                bs.options
                    .get("urls")
                    .filter(function(value, key) {
                        return key.slice(0, 2) === "ui";
                    })
                    .toJS()
            );
        }

        function serveFiles(base) {
            logger.info("Serving files from: {magenta:%s}", base);
        }
    }
37380
def display(result, stream):
    
    if result is None:
        return
    elif isinstance(result, basestring):
        pass
    elif isinstance(result, collections.Mapping):
        result = u'\n'.join(u'%s=%s' % (k, v) for
                            k, v in result.iteritems() if v is not None)
    elif isinstance(result, collections.Iterable):
        result = u'\n'.join(unicode(x) for x in result if x is not None)
    else:
        result = unicode(result)
    stream.write(result.encode('utf8'))
    stream.write('\n')
515344
def as_bin(self, *args, **kwargs):
        
        f = io.BytesIO()
        self.stream(f, *args, **kwargs)
        return f.getvalue()
176842
def find_stream(cls, fileobj, max_bytes):
        

        r = BitReader(fileobj)
        stream = cls(r)
        if stream.sync(max_bytes):
            stream.offset = (r.get_position() - 12) // 8
            return stream
1321251
def dump(self, blob, stream):
        

        json.dump(
            blob, stream, indent=self.indent, sort_keys=True,
            separators=self.separators,
        )