goagent用到的模块简介
来源:互联网 发布:日本股票行情软件 编辑:程序博客网 时间:2024/05/29 04:51
1. base64
base64模块是用来作base64编码解码的。这种编码方式在电子邮件中是很常见的。
它可以把不能作为文本显示的二进制数据编码为可显示的文本信息。编码后的文本大小会增大1/3。
闲话不说了,base64模块真正用的上的方法只有8个,分别是encode, decode, encodestring, decodestring, b64encode,b64decode, urlsafe_b64decode,urlsafe_b64encode。他们8个可以两两分为4组,encode,decode一组,专门用来编码和 解码文件的,也可以对StringIO里的数据做编解码;encodestring,decodestring一组,专门用来编码和解码字符串; b64encode和b64decode一组,用来编码和解码字符串,并且有一个替换符号字符的功能。这个功能是这样的:因为base64编码后的字符除 了英文字母和数字外还有三个字符 + / =, 其中=只是为了补全编码后的字符数为4的整数,而+和/在一些情况下需要被替换的,b64encode和b64decode正是提供了这样的功能。至于什 么情况下+和/需要被替换,最常见的就是对url进行base64编码的时候。urlsafe_b64encode和urlsafe_b64decode 一组,这个就是用来专门对url进行base64编解码的,实际上也是调用的前一组函数。
def proxy_basic_auth_header(self): return 'Proxy-Authorization: Basic %s' + base64.b64encode('%s:%s'%(self.PROXY_USERNAME, self.PROXY_PASSWROD))
2. urllib2
在网上找了一下关于urllib2模块的介绍,都比较简单,下面是从python文档中找的,贴了一部分。
一句话概括的话:urllib2是一个可扩展的库,可根据不同的协议打开URLs。
>>> help (urllib2)Help on module urllib2:NAME urllib2 - An extensible library for opening URLs using a variety of protocolsFILE c:\python27\lib\urllib2.pyDESCRIPTION The simplest way to use this module is to call the urlopen function, which accepts a string containing a URL or a Request object (described below). It opens the URL and returns the results as file-like object; the returned object has some extra methods described below. The OpenerDirector manages a collection of Handler objects that do all the actual work. Each Handler implements a particular protocol or option. The OpenerDirector is a composite object that invokes the Handlers needed to open the requested URL. For example, the HTTPHandler performs HTTP GET and POST requests and deals with non-error returns. The HTTPRedirectHandler automatically deals with HTTP 301, 302, 303 and 307 redirect errors, and the HTTPDigestAuthHandler deals with digest authentication. urlopen(url, data=None) -- Basic usage is the same as original urllib. pass the url and optionally data to post to an HTTP URL, and get a file-like object back. One difference is that you can also pass a Request instance instead of URL. Raises a URLError (subclass of IOError); for HTTP errors, raises an HTTPError, which can also be treated as a valid response. build_opener -- Function that creates a new OpenerDirector instance. Will install the default handlers. Accepts one or more Handlers as arguments, either instances or Handler classes that it will instantiate. If one of the argument is a subclass of the default handler, the argument will be installed instead of the default. install_opener -- Installs a new opener as the default opener.
def install_opener(self): if self.PROXY_ENABLE: proxy = '%s:%s@%s:%d'%(self.PROXY_USERNAME, self.PROXY_PASSWROD, self.PROXY_HOST, self.PROXY_PORT) handlers = [urllib2.ProxyHandler({'http':proxy,'https':proxy})] if self.PROXY_NTLM: if ntlm is None: logging.critical('You need install python-ntlm to support windows domain proxy! "%s:%s"', self.PROXY_HOST, self.PROXY_PORT) sys.exit(-1) passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, '%s:%s' % (self.PROXY_HOST, self.PROXY_PORT), self.PROXY_USERNAME, self.PROXY_PASSWROD) auth_NTLM = ntlm.HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman) handlers.append(auth_NTLM) else: handlers = [urllib2.ProxyHandler({})] opener = urllib2.build_opener(*handlers) opener.addheaders = [] urllib2.install_opener(opener)
- goagent用到的模块简介
- 【python系列】经常用到的random模块
- 编程中常用到的输入模块
- MM模块中常用到的透明表
- 麻将后台登陆模块用到的字典
- goagent 的原理图
- GoAgent原理的理解
- Goagent
- goAgent
- goagent
- goagent
- GoAgent
- goagent
- goagent
- Ubuntu安装goagent的问题
- Ubuntu下goagent的安装
- GoAgent - linux下的使用
- GoAgent不能用的解决方法
- 地球,请你不要颤抖!----如何解决ArcGIS Globe视角模式切换产生抖动的问题
- linux vps定时工具crontab的安装及使用方法
- Spring的注入,Ioc,DI详解
- 如何在程序中获取系统语言及修改value-的语言
- ".section .text.lock,\"ax\"\n" \
- goagent用到的模块简介
- ate a window with a bit depth of 32
- MediaPlayer和AudioTrack播放Audio的区别与联系
- Android定制系统语言为简体中文
- 9个点画10条直线,要求每条直线上至少3个点
- QT实现不规则窗体
- 谈"舌尖上的中国"
- T_SQL数学函数
- tomcat does not exist /多个tomcat运行在一台机器上/一个tomcat运行多个实例