安装新版本python

wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xjf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure
make
make atlinstall

这时 python2.7.3 版本已经安装成功了。 但调用 python –version 依然会显示并使用旧版本

解决办法就是重新建立一个链接并覆盖掉旧的

ln -s /usr/local/bin/python2.7 /usr/bin/python -f

再调用 python –version 显示结果

[root@centos]# python --version
Python 2.7.3

至此,问题解决 :)

压缩

enData = zlib.compress(data)[2:-4]

对应:

compress2(dstbuf, &dstLen, strSrc, srcLen, 6);

解压

deData = zlib.decompress(enData, -zlib.MAX_WBITS)

对应:

bool gzipInflate( const std::string& compressedBytes, std::string& uncompressedBytes ) {
    if ( compressedBytes.size() == 0 ) {
        uncompressedBytes = compressedBytes ;
        return true ;
    }

    uncompressedBytes.clear() ;

    unsigned full_length = compressedBytes.size() ;
    unsigned half_length = compressedBytes.size() / 2;

    unsigned uncompLength = full_length ;
    char* uncomp = (char*) calloc( sizeof(char), uncompLength );

    z_stream strm;
    strm.next_in = (Bytef *) compressedBytes.c_str();
    strm.avail_in = compressedBytes.size() ;
    strm.total_out = 0;
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;

    bool done = false ;

    //if (inflateInit2(&strm, (16+MAX_WBITS)) != Z_OK)
    if (inflateInit2(&strm, -MAX_WBITS) != Z_OK)
    {
        free( uncomp );
        return false;
    }

    while (!done) {
        // If our output buffer is too small
        if (strm.total_out >= uncompLength ) {
            // Increase size of output buffer
            char* uncomp2 = (char*) calloc( sizeof(char), uncompLength + half_length );
            memcpy( uncomp2, uncomp, uncompLength );
            uncompLength += half_length ;
            free( uncomp );
            uncomp = uncomp2 ;
        }

        strm.next_out = (Bytef *) (uncomp + strm.total_out);
        strm.avail_out = uncompLength - strm.total_out;

        // Inflate another chunk.
        int err = inflate (&strm, Z_SYNC_FLUSH);
        if (err == Z_STREAM_END) done = true;
        else if (err != Z_OK)  {
            break;
        }
    }

    if (inflateEnd (&strm) != Z_OK) {
        free( uncomp );
        return false;
    }

    for ( size_t i=0; i<strm.total_out; ++i ) {
        uncompressedBytes += uncomp[ i ];
    }
    free( uncomp );
    return true ;
}

android

通过我写的一段Python代码可以让M8用户将联系人导入到Andriod系统中。

操作需要以下步骤:

  1. 先用M8PC工具将M8的联系人导出成XML格式。
  2. 将导出的文件重命名为mycontact.xml,并与m8toAndriod.py放到同一目录下
  3. 运行 python m8toAndriod.py 程序会生成一个名为 mycontact.vcf 的文件
  4. 将 mycontact.vcf 传到Andriod手机中导入

以下为 m8toAndriod.py 的代码:

#!/usr/bin/env python
# coding: utf-8
# 功能:将M8导出的联系人XML转化成Andriod可以导入的vcf文件
# 版本:python 2.6 以上
# 作者:leaker
# 网站:http://www.leelib.com
from xml.etree import ElementTree as ET

# 输出到的mycontact.vcf
out = file("mycontact.vcf", "wb")
root = ET.parse(file("mycontact.xml", "r")).getroot()
print root
for e in root.findall('Person'):
    out.write('BEGIN:VCARDrnVERSION:3.0rn')
    out.write('N:%s;%s;;;rn' % (e.findtext('LastName', '').encode('utf8'), e.findtext('FirstName', '').encode('utf8')))
    out.write('FN:%srn' % (e.findtext('FileAs', '').encode('utf8')))
    # print 'FN:%srn'% (e.findtext('FileAs', '').encode('gb2312'))
    for ee in root.findall('Phone'):
        if ee.findtext('PersonID','') == e.findtext('ID',''):
            primary = ee.get('IsPrimary') == 'true'
            out.write('TEL;TYPE=CELL%s:%srn' % ((';TYPE=PREF' if primary else ''), ee.findtext('Info','')))
    out.write('END:VCARDrn')
out.close()

点击这里下载:m8toAndriod.7z