pack nibbles to binary

    :param nibbles: a nibbles sequence. may have a terminator
352055
def pack_nibbles(nibbles):
    

    if nibbles[-1] == NIBBLE_TERMINATOR:
        flags = 2
        nibbles = nibbles[:-1]
    else:
        flags = 0

    oddlen = len(nibbles) % 2
    flags |= oddlen   # set lowest bit if odd number of nibbles
    if oddlen:
        nibbles = [flags] + nibbles
    else:
        nibbles = [flags, 0] + nibbles
    o = b''
    for i in range(0, len(nibbles), 2):
        o += ascii_chr(16 * nibbles[i] + nibbles[i + 1])
    return o
87275
def flatten(sequence):
    
    for item in sequence:
        if hasattr(item, "__iter__") and not isinstance(item, str) and not isinstance(item, bytes):
            for i in item:
                yield i
        else:
            yield item
234183
def pack_blanks_doper(operator, token)   #:nodoc:
    if token == 'blanks'
      type     = 0x0C
      operator = 2
    else
      type     = 0x0E
      operator = 5
    end

    [type,       # Data type
      operator,
      0x0000, 0x0000     # Reserved
    ].pack('CCVV')
  end
165342
function() {
        gobbleSpaces();
        var to_check = expr.substr(index, max_binop_len),
          tc_len = to_check.length;
        while (tc_len > 0) {
          if (binary_ops.hasOwnProperty(to_check)) {
            index += tc_len;
            return to_check;
          }
          to_check = to_check.substr(0, --tc_len);
        }
        return false;
      }
497010
def pack(self):
        "  "
        pack_name = self.args.prefix + op.basename(self.path)
        pack_path = op.join(self.args.output or self.basedir, pack_name)

        self.out("Packing: %s" % self.path)
        self.out("Output: %s" % pack_path)

        if self.args.format:
            ext = self.get_ext(self.path)
            self.parsers[ext] = self.args.format

        out = "".join(self.merge(self.parse(self.path)))
        try:
            open(pack_path, 'w').write(out)
            self.out("Linked file saved as: '%s'." % pack_path)
        except IOError, ex:
            raise ZetaError(ex)
1075094
def b58check_unpack(b58_s):
    
    num_leading_zeros = len(re.match(r'^1*', b58_s).group(0))
    # convert from b58 to b16
    hex_s = change_charset(b58_s, B58_KEYSPACE, HEX_KEYSPACE)
    # if an odd number of hex characters are present, add a zero to the front
    if len(hex_s) % 2 == 1:
        hex_s = "0" + hex_s
    # convert from b16 to b2
    bin_s = unhexlify(hex_s)
    # add in the leading zeros
    bin_s = '\x00' * num_leading_zeros + bin_s
    # make sure the newly calculated checksum equals the embedded checksum
    newly_calculated_checksum = bin_checksum(bin_s[:-4])
    embedded_checksum = bin_s[-4:]
    if not (newly_calculated_checksum == embedded_checksum):
        raise ValueError('b58check value has an invalid checksum')
    # return values
    version_byte = bin_s[:1]
    encoded_value = bin_s[1:-4]
    checksum = bin_s[-4:]
    return version_byte, encoded_value, checksum
179486
def pack(self, value=None):
        
        if isinstance(value, type(self)):
            return value.pack()

        if value is None:
            value = self
        else:
            container = type(self)(items=None)
            container.extend(value)
            value = container

        bin_message = b''
        try:
            for item in value:
                bin_message += item.pack()
            return bin_message
        except exceptions.PackException as err:
            msg = "{} pack error: {}".format(type(self).__name__, err)
            raise exceptions.PackException(msg)
505442
def pack_iterable(messages):
    ''''''
    # [ 4-byte body size ]
    # [ 4-byte num messages ]
    # [ 4-byte message #1 size ][ N-byte binary data ]
    #      ... (repeated <num_messages> times)
    return pack_string(
        struct.pack('>l', len(messages)) +
        ''.join(map(pack_string, messages)))
190586
def numpy_bins_with_mask(self) -> Tuple[np.ndarray, np.ndarray]:
        
        bwm = to_numpy_bins_with_mask(self.bins)
        if not self.includes_right_edge:
            bwm[0].append(np.inf)
        return bwm
268180
public function isMarkerHigh($byte, $nibble)
    {
        $marker_raw = ord($byte);
        $marker = $marker_raw & 0xF0;

        return $marker === $nibble;
    }
176976
def flatten_binary_scores(scores, labels, ignore=None):
    
    scores = scores.view(-1)
    labels = labels.view(-1)
    if ignore is None:
        return scores, labels
    valid = (labels != ignore)
    vscores = scores[valid]
    vlabels = labels[valid]
    return vscores, vlabels
1040005
def _is_packed_binary(self, data):
        '''
        
        '''
        packed = False
        if isinstance(data, bytes) and len(data) == 16 and b':' not in data:
            try:
                packed = bool(int(binascii.hexlify(data), 16))
            except (ValueError, TypeError):
                pass

        return packed
412382
def b58check_encode(bin_s, version_byte=0):
    
    # append the version byte to the beginning
    bin_s = chr(int(version_byte)) + bin_s
    # calculate the number of leading zeros
    num_leading_zeros = len(re.match(r'^\x00*', bin_s).group(0))
    # add in the checksum add the end
    bin_s = bin_s + bin_checksum(bin_s)
    # convert from b2 to b16
    hex_s = hexlify(bin_s)
    # convert from b16 to b58
    b58_s = change_charset(hex_s, HEX_KEYSPACE, B58_KEYSPACE)

    return B58_KEYSPACE[0] * num_leading_zeros + b58_s
985230
def pack(self):
        """"""
        sn, sa = self.number, self.attribute
        return pack("<H", (sn & 0x3ff) << 6 | (sa & 0x3f))
918830
def _pack(self, msg):
        
        n = len(msg) 
        a = array.array('c')
        a.append(chr((n >> 24) & 0xFF))
        a.append(chr((n >> 16) & 0xFF))
        a.append(chr((n >>  8) & 0xFF))
        a.append(chr(n & 0xFF))
        return a.tostring() + msg
350706
def nlmsg_seq(self, value):
        """"""
        self.bytearray[self._get_slicers(3)] = bytearray(c_uint32(value or 0))
864284
def to_binary(self):
    
    c = containerize(exclude_fields(self))
    self.payload = MsgEphemerisGPSDepF._parser.build(c)
    return self.pack()