Get the server IP of BaseHTTPServer.BaseHTTPRequestHandler
获取 BaseHTTPServer.BaseHTTPRequestHandler 请求服务器的 IP。
serveradress = re.findall('Host: (.*?)\r\n',str(self.headers))
Show PIL image object in browser
在浏览器显示 PIL 处理过的图片对象。
Using PIL module, you can resize or crop an image and return an image object. After that, I want to show the resized-image-object in browser. Here it is.
pic = thumbPicture()
f = StringIO()
pic.save(f,'JPEG')
f.seek(0)
shutil.copyfileobj(f,self.wfile)
self.sendHeader(contenttype = 'image/jpeg',contentlength = f.tell())
f.close()
Get parameters from BaseHTTPServer http GET request
BaseHTTPHandler from the BaseHTTPServer module doesn’t seem to provide any convenient way to access http request parameters. What is the best way to parse the GET parameters from the path, and the POST parameters from the request body?
Right now, I’m using this for GET:
parsed_path = urlparse.urlparse(self.path)
try:
params = dict([p.split('=') for p in parsed_path[4].split('&')])
except:
params = {}
还有很长的路要走
自己现在的技术掌握太糙了。
整体上,难以把握整体结构设计,各个模块功能设计,各模块间通信传输等等。
细节上,Python 如此简洁优美的语法让我写的是惨不忍睹,Python 自带的模块、函数还很不熟悉。
我才刚刚上路。
毕业一年了
准确说应该是昨天,6 月 26 日离开学校整一年。
结束三高的一年,我来到北京,继续我的努力。
我,还在路上。
cdto open iTerm
cdto:Fast mini application that opens a Terminal.app window cd’d to the front most finder window,快速在当前路径打开一个 Termainal。iTerm 是 Mac 下一个增强终端。默认状态下 cdto 是打开系统自带的 Terminal.app,其实 cdto 也是支持 iTerm 的。
右键 Show Package Contents 打开 cdto.app,将 Contents/Plugins Disabled 下的 iterm.bundle mv 替换 Contents/Plugins 下 terminal.bundle 即可。
Mac OS X: decoder jpeg not available
When you are using PIL to resize a JPEG image file, you will probably have a “decoder jpeg not available” error,this means that PIL doesn’t have JPEG support.
Here is the solution:
- Download and install MacPorts.
- sudo port install jpeg, this will install libjpeg.
- sudo port install py25-pil
That’s it.
Simple HTTP Server in Python
Python has an embedded HTTP server that can serve the current directory from a given port.
python -m SimpleHTTPServer 8000
You and me
你不坚强时候有我在,我不坚强时候有你在,这就够了。
2010 FIFA World Cup South Africa
世界杯来啦。看好西班牙。