Build Huffman code table from symbol sequence

        :param data: sequence of symbols (e.g. byte string, unicode string, list, iterator)
        :return: HuffmanCoder
421144
def from_data(cls, data):
        
        frequencies = collections.Counter(data)
        return cls.from_frequencies(frequencies, concat=_guess_concat(data))
558496
def _decode(data):
    
    if not isinstance(data, bytes_types):
        data = six.b(str(data))
    return base64.b64decode(data.decode("utf-8"))
81467
def get_unicode(data):
    
    # if this is a common string, return its unicode representation
    if isinstance(data, str):
        return safe_unicode(data)

    # if this is a list of values, return list of unicode values
    if isinstance(data, list):
        return [get_unicode(item) for item in data]

    # if this is a dictionary, return dictionary of unicode keys and values
    if isinstance(data, dict):
        return {
            get_unicode(key): get_unicode(value)
            for key, value in data.iteritems()
        }
    # if it's anything else, return it in its original form
    return data
1354099
function HuffmanTable(table) {
  function createTree(codes, position) {
    if (codes.length === 1) {
      return [table.indexOf(codes[0])];
    }

    else {
      position = position || 0;
      var zero = [];
      var one = [];
      for (var i = 0; i < codes.length; i++) {
        var string = codes[i];
        if (string[position] === '0') {
          zero.push(string);
        } else {
          one.push(string);
        }
      }
      return [createTree(zero, position + 1), createTree(one, position + 1)];
    }
  }

  this.tree = createTree(table);

  this.codes = table.map(function(bits) {
    return parseInt(bits, 2);
  });
  this.lengths = table.map(function(bits) {
    return bits.length;
  });
}
276321
def _encode(data):
    
    if not isinstance(data, bytes_types):
        data = six.b(str(data))
    return base64.b64encode(data).decode("utf-8")
189388
def _build_data_block(self, lexer):
        
        data_block = OrderedDict()
        header = ''

        while True:
            token = next(lexer)
            key = token.__class__.__name__

            if key == 'DataHeader':
                header = token.header[1:-1]
                data_block.setdefault(header, [])

            elif key == 'DataItem':
                data_block[header].append(token.data_item)

            elif key == 'DataBlockEnd':
                break

            else:
                raise KeyError('SDfile data block does not supposed to have any other information: "{}".'.format(key))

        return data_block
1168476
def _loadData(self, data):
        
        self._data = data
        self.codec = data.attrib.get('codec')
        self.codecID = data.attrib.get('codecID')
        self.id = cast(int, data.attrib.get('id'))
        self.index = cast(int, data.attrib.get('index', '-1'))
        self.language = data.attrib.get('language')
        self.languageCode = data.attrib.get('languageCode')
        self.selected = cast(bool, data.attrib.get('selected', '0'))
        self.streamType = cast(int, data.attrib.get('streamType'))
        self.type = cast(int, data.attrib.get('streamType'))
125204
def to_str(data):
    
    if isinstance(data, bytes):
        return codecs.decode(data, TEXT_ENCODING)
    return data
1938
def _symbols():
    
    global _SYMBOLS
    if _SYMBOLS is None:
        tmp = [(s, 'symbol') for s in _data()['symbol'].keys()]
        tmp += [(s, 'alpha3') for s in _data()['alpha3'].keys()]
        tmp += [(s.name, 'name') for s in _data()['alpha3'].values()]
        _SYMBOLS = sorted(
            tmp,
            key=lambda s: (len(s[0]), ord(s[0][0])),
            reverse=True)

    return _SYMBOLS
191587
def _auto_decode(data):
    
    assert isinstance(data, six.binary_type)

    for e in ENCODINGS:
        try:
            return data.decode(e), e
        except UnicodeDecodeError:
            pass

    return data.decode('utf-8', 'ignore')
367410
def build_data_list(lst):
    
    txt = '<H3>' + List + '<H3><UL>'
    for i in lst:
        txt += '<LI>' + i + '</LI>'
        
    txt += '<UL>'
    return txt
850660
public static byte[] decodeBZRaw(byte[] data) {
    try {
      ByteArrayInputStream output = new ByteArrayInputStream(data);
      BZip2CompressorInputStream compresser = new BZip2CompressorInputStream(output);
      return IOUtils.toByteArray(compresser);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
418478
def from_byte_array(cls, bytes_):
        
        runs = cls._length_run_coding.parse(bytes_)
        pixels = (run.pixels for run in runs.data)
        data = "".join(itertools.chain.from_iterable(pixels))
        return cls(data)
1272832
private static String encodeHex(final byte[] data) {
        String rval = "";
        for (final byte b : data) {
            rval += String.format("%02x", b);
        }
        return rval;
    }
765831
private static byte[] base64Decode(String data) {
        int len = data.length();

        byte[] b64 = new byte[len * 3 / 4];
        byte[] buf = new byte[4];
        boolean done = false;

        for (int i = 0, j, k = 0; i < len && !done;) {
            buf[0] = buf[1] = buf[2] = buf[3] = 0;
            for (j = 0; j < 4 && i < len; ++j) {
                char c = data.charAt(i);
                if (c >= 'A' && c <= 'Z') {
                    c -= 'A';
                } else if (c >= 'a' && c <= 'z') {
                    c = (char) (c - 'a' + 26);
                } else if (c >= '0' && c <= '9') {
                    c = (char) (c - '0' + 52);
                } else if (c == '+') {
                    c = 62;
                } else if (c == '/') {
                    c = 63;
                } else if (c == '=' || c == '-') {
                    done = true;
                    break;
                } else {
                    ++i;
                    --j;
                    continue;
                }
                buf[j] = (byte) c;
                ++i;
            }

            if (k < b64.length && j >= 1) {
                b64[k++] = (byte) ((buf[0] << 2) | ((buf[1] & 0x30) >> 4));
            }
            if (k < b64.length && j >= 3) {
                b64[k++] = (byte) (((buf[1] & 0x0f) << 4) | ((buf[2] & 0x3c) >> 2));
            }
            if (k < b64.length && j >= 4) {
                b64[k++] = (byte) (((buf[2] & 0x03) << 6) | (buf[3] & 0x3f));
            }
        }
        return b64;
    }
190547
def encode_data(data):
    '''
    
    '''
    if isinstance(data, (six.string_types, bytes)):
        return encode_string(data)
    elif isinstance(data, (six.integer_types, bool, float)):
        return data
    elif data is None:
        return data
    elif isinstance(data, list):
        return [encode_data(x) for x in data]
    elif isinstance(data, dict):
        return {k: encode_data(v) for k, v in data.items()}
    else:
        raise ValueError('Cannot encode data of type %s' % type(data))
782438
def data_from_bytes(self, byte_representation):
        
        text = byte_representation.decode(self.encoding)
        return self.data_from_string(text)