2012年8月28日星期二

python 收取的邮件 内容解码

记录
[email.message对象].get_pay_load(decode=True)
可以处理base64之类编码的情况

邮件的标题中如果含有非ascii编码,标题会被重新编码:
编码后的形式为:
=?UTF-8?Q?=E7=AD=94=E5=A4=8D:xiaoyf=E5=AF=B9=E4=BB=BB=E5=8A=A1?=
 =?UTF-8?Q?=E2=80=9C=E6=B5=8B=E8=AF=95=E2=80=9D=E8=BF=9B=E8=A1=8C?=
 =?UTF-8?Q?=E4=BA=86=E7=BC=96=E8=BE=91tid?=
 =?UTF-8?Q?:50373904a2062824e400001b?=

可以通过
email.utils.decode_header解码。

2012年8月23日星期四

2012年8月16日星期四

fedora 自动挂载非 fedora 分区

fedora自带的磁盘工具里面可以可视化的设置。

2012年8月15日星期三

virtualbox secureCRT 配置(fedora)

这里有一篇,使用的方式是  NAT+Bridged  方式
http://www.cnblogs.com/songxk/archive/2012/02/08/2342611.html

本文用的方式是NAT+HostOnly 方式,与上一种相比,不用太多的配置。
1,VirtualBox中的网络,第一个选择NAT,默认选项。第二个选择HostOnly,高级配置中,混杂模式设为全部允许(此步重要,要不无法连接到虚拟机)。
2,虚拟机通过ifconfig  查看HostOnly网卡的ip,一般是192.168.56.X,然后就可以通过secureCRT 连接了。












备注:
1,确认你的虚拟机上的sshd已经安装并且打开。

2,宿主机可以通过  telnet 192.168.56.X(2步中的ip) 22  判断下是否可以连通



2012年5月28日星期一

pycurl简介

    一,简介与特性

    PycURLpython的库,通过python封装了libcurl的调用,pycurl本身的文档不多,主要的说明可以参考libcurl的文档。

    pycurl是一个成熟、非常快速并且支持多种特性。

    Overview

    • libcurl is a free and easy-to-use client-side URL transfer library, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, FILE, IMAP, SMTP, POP3 and RTSP. libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos4), file transfer resume, http proxy tunneling and more!
    • libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS and more...
    • libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported, fast, thoroughly documented and is already used by many known, big and successful companies and numerous applications.

     

    源文档 <http://pycurl.sourceforge.net/>

     

     

    二,与其他库对比

     

    Urllib2

    Urlgrabber

    Pycurl

    简介

    python程序,设计完善、灵活。

    比较基础

    python程序,基于urllib2yum实现的一部分

    libcurl的封装,libcurl本身是c库,非常快,支持多种协议

    优势

    1python自带,不依赖于外来库

    2)纯python,简单易用,可自己在其基础上定制

    1)比urllib2更友好的用户界面,封装了很多常用的基本功能

    2)易于修改。

    1)快

    2)支持多种协议,类似SSL-ed FTP

    劣势

    1)比pycurl

    2)对低层协议的封装比较简陋,如果需要更多的功能,需要有较多的开发时间

    1)比pycurl慢,某种程度上比urllib2略慢。不过封装的程序基本如此。

    1),使用方式比较复杂。有比较陡的学习曲线。

    调用方式C-style

    适用范围

    只需要基础的功能,比如url访问等,或者需要再其基础上作定制封装。

    需要较多的功能,灵活。

    很快的速度要求,需要自己做调整,必要的协议支持。

    http://urlgrabber.baseurl.org/comparison.html

    三,使用方式

    pycurl的文档的说明主要参考libcurl的文档说明,一些基本的用法,可以参考pycurltestexample目录

    http://pycurl.cvs.sourceforge.net/pycurl/pycurl/tests/

    http://pycurl.cvs.sourceforge.net/pycurl/pycurl/examples/

     

    基本的使用方式:

    1

    #! /usr/bin/env python

    2

    # -*- coding: iso-8859-1 -*-

    3

    # vi:ts=4:et

    4

    # $Id: test_cb.py,v 1.14 2003/04/21 18:46:10 mfx Exp $

    5

     

    6

    import sys

    7

    import pycurl

    8

     

    9

    ## Callback function invoked when body data is ready

    10

    def body(buf):

    11

    # Print body data to stdout

    12

    sys.stdout.write(buf)

    13

     

    14

    ## Callback function invoked when header data is ready

    15

    def header(buf):

    16

    # Print header data to stderr

    17

    sys.stderr.write(buf)

    18

     

    19

    c = pycurl.Curl()

    20

    c.setopt(pycurl.URL, 'http://www.python.org/')

    21

    c.setopt(pycurl.WRITEFUNCTION, body)

    22

    c.setopt(pycurl.HEADERFUNCTION, header)

    23

    c.setopt(pycurl.FOLLOWLOCATION, 1)

    24

    c.setopt(pycurl.MAXREDIRS, 5)

    25

    c.perform()

    26

    c.setopt(pycurl.URL, 'http://curl.haxx.se/')

    27

    c.perform()

    28

    c.close()

     

    源文档 <http://pycurl.cvs.sourceforge.net/viewvc/pycurl/pycurl/tests/test_cb.py?view=markup>

     

    重要的是setopt方法,setopt方法对应的参数的说明见

    http://curl.haxx.se/libcurl/c/curl_easy_setopt.html

    基本的对应为

    Pycurl

    Libcurl

     

    FOLLOWLOCATION

    CURLOPT_FOLLOWLOCATION

     

    诸如此类……

     

     

     

    参考:

    http://pycurl.sourceforge.net/

    http://curl.haxx.se/libcurl/

     

2012年4月7日星期六

jquery html() ie8下问题

ie8下   jquery html()
$("#id").html(content)如果content内容不规范;
content内容不会被添加进id内
显示会有问题。

2012年3月15日星期四

批处理文件,执行多个命令

start /d "路径" 可执行程序  参数

2012年3月8日星期四

pylons学习(续)

学习Pylons的示例,最好用英文目录下测试,中文目录下很多编码问题,
目前还没找到好的办法解决中文目录造成的模板显示问题。

1,response ,request用法
2,Pylons提供了多种调试问题的方式,
网页调试
3,mako  Template技术
各种技术都大体类似
Mako语法的注释
<%doc></%doc>
##
输出文本语法
<%text></%text>
%  后面可以跟可执行的python命名
<%    %>中间是代码段
<%!     %>   module级的代码块,里面的内容只被执行一次


Mako模板调试
wingware提供了一种方式,蛮好用的,分享一下
To avoid this, do not specify the --reload flag for Paste. Place the following in a file that you add to your project and set as the main debug file:

from paste.script.serve import ServeCommand
ServeCommand("serve").run(["development.ini"])

This may vary somewhat, as necessary for your application.

http://wingware.com/doc/howtos/paste-pylons

pylons安装

pylons安装
1,安装python2.7
2,配置path环境,可以直接在命令行上使用python.exe
3,安装easy_install
python  ***ez_setup.py(从pypi网站下载)
并添加easy_install.exe所在目录到path环境
4,安装Pylons
easy_install Pylons
更新
easy_install -U Pylons
5,创建示例
paster create -t pylons HelloWorld

6,启动
paster server --reload development.ini

--reload,当文件改变时,自动重启服务

7,paster controller 建立controller
paster controller Hello
controller中可以使用的request,response变量

8,route文件配置,
config/route.py






2012年3月7日星期三

python学习笔记



Python与c#区别
仅作笔记,做不得学习的资料
1,浮点数可以取余
2,获取用户输入
input,rawinput
3,模块引入
import ,C#已命名空间方式引入using
4,python,math.floor方法的结果是浮点数
5,序列 数组操作

数组append,pop;pop可以接收参数,对应C#,push,pop

6,字符串
字符串格式化,元组的使用,
Template使用
字符串精度,对齐,填充

字符串查找


7,字典

8.函数,
以缩进表示作用域

9类,
self
__init__方法

10,文件读写


11,模块使用
 核心模块
os,
os.path.
sys
re
动态导入

12,异常处理

13,特殊的方法
__getitem__索引操作符

14,赋值
可以同时赋多值
and,or返回实际的值


15,内存管理