>>> bit_list = (
    ... [0,0,1,1,0,0,1,0], # L
    ... [1,0,0,1,0,0,1,0], # I
    ... )
    >>> print_block_bit_list(bit_list)
    ... # doctest: +NORMALIZE_WHITESPACE
       2 - 00110010 10010010
           0x4c 'L' 0x49 'I'
963881
def print_block_bit_list(block_bit_list, display_block_count=8, no_repr=False):
    
    def print_line(no, line, line_info):
        print "%4s - %s" % (no, line)
        if no_repr:
            return

        line = []
        for codepoint in line_info:
            r = repr(chr(codepoint))
            if "\\x" in r: # FIXME
                txt = "%s" % hex(codepoint)
            else:
                txt = "%s %s" % (hex(codepoint), r)
            txt = txt.center(8)
            line.append(txt)

        print "       %s" % " ".join(line)


    in_line_count = 0

    line = ""
    line_info = []
    for no, bits in enumerate(block_bit_list, 1):
        line += "%s " % "".join([str(c) for c in bits])

        codepoint = bits2codepoint(bits)
        line_info.append(codepoint)

        in_line_count += 1
        if in_line_count >= display_block_count:
            in_line_count = 0
            print_line(no, line, line_info)
            line_info = []
            line = ""
    if line:
        print_line(no, line, line_info)

    if in_line_count > 0:
        print
970184
def bits_in(length, keyspace):
    
    keyspace = len(keyspace)
    length_per_cycle = 64
    if length > length_per_cycle:
        bits = 0
        length_processed = 0
        cycles = ceil(length / length_per_cycle)
        for _ in range(int(cycles)):
            if length_processed + length_per_cycle > length:
                length_per_cycle = length - length_processed
            bits += calc_bits_in(length_per_cycle, keyspace)
            length_processed += length_per_cycle
    else:
        bits = calc_bits_in(length, keyspace)
    return float(abs(bits))
1124678
def _space_examples(self, list_examples, rows, section_value):
        
        examples_with_index = []

        for i, _ in list(enumerate(list_examples)):
            if len(list_examples[i]) > 1:
                examples_with_index.append("[" + str(i + 1) + "] " + list_examples[i][0] +
                                           list_examples[i][1])

        example = "".join(exam for exam in examples_with_index)
        num_newline = example.count('\n')

        page_number = ''
        if num_newline > rows * PART_SCREEN_EXAMPLE and rows > PART_SCREEN_EXAMPLE * 10:
            len_of_excerpt = math.floor(float(rows) * PART_SCREEN_EXAMPLE)

            group = example.split('\n')
            end = int(section_value * len_of_excerpt)
            begin = int((section_value - 1) * len_of_excerpt)

            if end < num_newline:
                example = '\n'.join(group[begin:end]) + "\n"
            else:
                # default chops top off
                example = '\n'.join(group[begin:]) + "\n"
                while ((section_value - 1) * len_of_excerpt) > num_newline:
                    self.example_page -= 1
            page_number = '\n' + str(section_value) + "/" + str(int(math.ceil(num_newline / len_of_excerpt)))

        return example + page_number + ' CTRL+Y (^) CTRL+N (v)'
948564
function binl(x, len) {
        var T, j, i, l,
          h0 = 0x67452301,
          h1 = 0xefcdab89,
          h2 = 0x98badcfe,
          h3 = 0x10325476,
          h4 = 0xc3d2e1f0,
          A1, B1, C1, D1, E1,
          A2, B2, C2, D2, E2;

        /* append padding */
        x[len >> 5] |= 0x80 << (len % 32);
        x[(((len + 64) >>> 9) << 4) + 14] = len;
        l = x.length;

        for (i = 0; i < l; i += 16) {
          A1 = A2 = h0;
          B1 = B2 = h1;
          C1 = C2 = h2;
          D1 = D2 = h3;
          E1 = E2 = h4;
          for (j = 0; j <= 79; j += 1) {
            T = safe_add(A1, rmd160_f(j, B1, C1, D1));
            T = safe_add(T, x[i + rmd160_r1[j]]);
            T = safe_add(T, rmd160_K1(j));
            T = safe_add(bit_rol(T, rmd160_s1[j]), E1);
            A1 = E1;
            E1 = D1;
            D1 = bit_rol(C1, 10);
            C1 = B1;
            B1 = T;
            T = safe_add(A2, rmd160_f(79 - j, B2, C2, D2));
            T = safe_add(T, x[i + rmd160_r2[j]]);
            T = safe_add(T, rmd160_K2(j));
            T = safe_add(bit_rol(T, rmd160_s2[j]), E2);
            A2 = E2;
            E2 = D2;
            D2 = bit_rol(C2, 10);
            C2 = B2;
            B2 = T;
          }

          T = safe_add(h1, safe_add(C1, D2));
          h1 = safe_add(h2, safe_add(D1, E2));
          h2 = safe_add(h3, safe_add(E1, A2));
          h3 = safe_add(h4, safe_add(A1, B2));
          h4 = safe_add(h0, safe_add(B1, C2));
          h0 = T;
        }
        return [h0, h1, h2, h3, h4];
      }
920983
def _compute_bits(self):
        
        bits = []
        totbits = 0
        bgbits  = 0
        bg      = self.background
        UNCERT  = lambda x: x*math.log(x)/math.log(2.0)
        for letter in ACGT:
            bgbits = bgbits + UNCERT(bg[letter])
        for i in range(self.width):
            tot = 0
            for letter in ACGT:
                Pij = pow(2.0, self.logP[i][letter])
                tot = tot + UNCERT(Pij)
                #bit = Pij * self.ll[i][letter]
                #if bit > 0:
                #    tot = tot + bit
            #print tot, bgbits, tot-bgbits
            bits.append(max(0,tot-bgbits))
            totbits = totbits + max(0,tot-bgbits)
        self.bits = bits
        self.totalbits = totbits
772292
def _print_bits(self,norm=2.3, height=8.0):
        
        bits   = []
        tots   = []
        str    = []
        for i in range(self.width):
            D = {}
            tot = 0
            for letter in ['A', 'C', 'T', 'G']:
                if self.logP:
                    Pij = pow(2.0, self.logP[i][letter])
                else:
                    Pij = pow(2.0, self.ll[i][letter]) * self.background[letter]
                if Pij > 0.01:
                    '''Old'''
                    D[letter] = Pij * self.ll[i][letter]
                    #'''new'''
                    #Q = self.background[letter]
                    #D[letter] = ( Pij * math.log(Pij) - Pij * math.log(Q) ) / math.log(2.0)
                    '''for both old and new'''
                    tot = tot + D[letter]
            bits.append(D)
            tots.append(tot)
        for i in range(self.width):
            s = []
            _l = bits[i].keys()
            _l.sort(lambda x,y,D=bits[i]: cmp(D[y],D[x]))
            for key in _l:
                for j in range(int(bits[i][key] / norm * height)):
                    s.append(key)
            str.append(''.join(s))
        fmt = '%%%ds'%height
        print '#  %s'%('-'*self.width)
        for h in range(int(height)):
            sys.stdout.write("#  ")
            for i in range(self.width):
                sys.stdout.write((fmt%str[i])[h])
            if h == 0:
                sys.stdout.write(' -- %4.2f bits\n'%norm)
            elif h == height-1:
                sys.stdout.write(' -- %4.2f bits\n'%(norm/height))
            else:
                sys.stdout.write('\n')
        print '#  %s'%('-'*self.width)
        print '#  %s'%self.oneletter
185990
def pt_shift(pt=(0.0, 0.0), shift=[0.0, 0.0]):
    '''
    '''
    assert isinstance(pt, tuple)
    l_pt = len(pt)
    assert l_pt > 1
    for i in pt:
        assert isinstance(i, float)
    assert isinstance(shift, list)
    l_sh = len(shift)
    assert l_sh == l_pt
    for i in shift:
        assert isinstance(i, float)

    return tuple([pt[i] + shift[i] for i in range(l_pt)])
1178614
def list_chunks(l, n):
    
    if n < 1:
        n = 1
    return [l[i:i + n] for i in range(0, len(l), n)]
516305
def _pack_bits_into_byte(iterable):
    
    return (reduce(lambda x, y: (x << 1) + y, e)
            for e in zip_longest(*[iter(iterable)] * 8, fillvalue=0x0))
136324
def translate_bit_for_bit(data):
    
    headers = sorted(data.get("Headers", []))
    table = '\\FloatBarrier \n \\section{$NAME} \n'.replace('$NAME', data.get("Title", "table"))
    table += '\\begin{table}[!ht] \n \\begin{center}'
    # Set the number of columns
    n_cols = "c"*(len(headers)+1)
    table += '\n \\begin{tabular}{$NCOLS} \n'.replace("$NCOLS", n_cols)

    # Put in the headers
    table += " Variable &"
    for header in headers:
        table += ' $HEADER &'.replace('$HEADER', header).replace('%', '\%')
    table = table[:-1] + ' \\\\ \n \hline \n'

    # Put in the data
    for k, v in data.get("Data", []).items():
        table += "\n \\textbf{$VAR} & ".replace("$VAR", k)
        for header in headers:
            table += ' $VAL &'.replace("$VAL", str(v[header]))
        table = table[:-1] + ' \\\\'
    table += '\n \hline \n \end{tabular} \n \end{center} \n \end{table}\n'
    return table
290908
def bibitems(self):
        """"""
        bibitems = []
        lines = self.text.split('\n')
        for i, line in enumerate(lines):
            if line.lstrip().startswith(u'\\bibitem'):
                # accept this line
                # check if next line is also part of bibitem
                # FIXME ugh, re-write
                j = 1
                while True:
                    try:
                        if (lines[i + j].startswith(u'\\bibitem') is False) \
                                and (lines[i + j] != '\n'):
                            line += lines[i + j]
                        elif "\end{document}" in lines[i + j]:
                            break
                        else:
                            break
                    except IndexError:
                        break
                    else:
                        print line
                        j += 1
                print "finished", line
                bibitems.append(line)
        return bibitems
1293799
def numList2blocks(l, n):
    """"""
    # Note that ASCII printable characters range is 0x20 - 0x7E
    returnList = []
    toProcess = copy.copy(l)
    ''' copy message ascii list'''
    if len(toProcess) % n != 0:
        for i in range(0, n - len(toProcess) % n):
            ''' append rand str to list'''
            toProcess.append(random.randint(32, 126))
    toProcess[len(l)] = 0  # 0 after origin message list

    ''' generate int from ascii number list'''
    for i in range(0, len(toProcess), n):
        block = 0
        for j in range(0, n):
            block += toProcess[i + j] << (8 * (n - j - 1))
        returnList.append(block)
    return returnList
923139
def pl (listoflists):
    
    for row in listoflists:
        if row[-1] == '\n':
            print(row, end=' ')
        else:
            print(row)
    return None
845782
def strip_block_whitespace(string_list):
    """"""
    min_ws = min([(len(x) - len(x.lstrip())) for x in string_list if x != '\n'])
    return [x[min_ws:] if x != '\n' else x for x in string_list]
1325099
def standard_block(self, bytes_):
        
        self.out(self.LH(len(bytes_) + 1))  # + 1 for CHECKSUM byte

        checksum = 0
        for i in bytes_:
            checksum ^= (int(i) & 0xFF)
            self.out(i)

        self.out(checksum)
1058036
def list_strip(list_, to_strip, left=True, right=True):
    
    import utool as ut
    flags = [item != to_strip for item in list_]
    flag_lists = []
    if right:
        rstrip_flags = ut.cumsum(flags[::-1])[::-1]
        flag_lists.append(rstrip_flags)
    if left:
        lstrip_flags = ut.cumsum(flags)
        flag_lists.append(lstrip_flags)
    strip_flags = ut.and_lists(*flag_lists)
    stripped_list = ut.compress(list_, strip_flags)
    return stripped_list
1239926
def p_list0(p):
    ''''''
    parts = p[1]
    if len(parts) > 1 or p.slice[2].ttype != tokenizer.tokentype.NEWLINE:
        parts.append(ast.node(kind='operator', op=p[2], pos=p.lexspan(2)))
        p[0] = ast.node(kind='list', parts=parts, pos=_partsspan(parts))
    else:
        p[0] = parts[0]