<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Oh Bug!</title>
	<atom:link href="http://ohbug.com/feed" rel="self" type="application/rss+xml" />
	<link>http://ohbug.com</link>
	<description>Fun with Programming.</description>
	<lastBuildDate>Tue, 15 Jun 2010 02:20:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Google App Engine 入门(1) 简介</title>
		<link>http://ohbug.com/archives/gae-intro.html</link>
		<comments>http://ohbug.com/archives/gae-intro.html#comments</comments>
		<pubDate>Tue, 15 Jun 2010 02:20:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[操作指南]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ohbug.com/?p=26</guid>
		<description><![CDATA[Google App Engine 是 Google 公司在2008年4月7日推出的一个开发、托管网络应用程序的云计算平台。它可以让你的网络应用程序在 Google 的基础架构上运行。 与 Google App Engine 类似的云计算平台还有 Amazon Web Service 和微软的 Azure 。Google App Engine 与他们不同的是 Google App Engine 给用户提供了一定的资源配额免费使用，当应用在免费配额无法负载的时候用户可以支付额外的费用以获得更多的CPU负载、带宽或是存储空间，用户只需要为使用超过免费配额的资源付费。 Google App Engine 最初只支持Python构建应用程序，2009年4月9日它开始支持 Java 构建应用程序。2010年5月20日 Google 发布 App Engine for Business，开始提供商用企业级云服务。 单个应用只能在Java 环境和 Python 环境之一中运行，App Engine 包括以下功能： 动态网络服务，提供对常用网络技术的完全支持 持久存储空间，支持查询、分类和事务 自动扩展和负载平衡 用于对用户进行身份验证和使用 Google 帐户发送电子邮件的 API 一种功能完整的本地开发环境（SDK），可以在您的计算机上模拟 Google App Engine [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://appengine.google.com/" target="_blank">Google App Engine</a> 是 Google 公司在2008年4月7日推出的一个开发、托管网络应用程序的云计算平台。它可以让你的网络应用程序在 Google 的基础架构上运行。</p>
<p>与 Google App Engine 类似的云计算平台还有 <a href="http://aws.amazon.com/" target="_blank">Amazon Web Service</a> 和微软的 <a href="http://www.microsoft.com/windowsazure/" target="_blank">Azure</a> 。Google App Engine 与他们不同的是 Google App Engine 给用户提供了一定的资源配额免费使用，当应用在免费配额无法负载的时候用户可以支付额外的费用以获得更多的CPU负载、带宽或是存储空间，用户只需要为使用超过免费配额的资源付费。</p>
<p>Google App Engine 最初只支持Python构建应用程序，2009年4月9日它开始支持 Java 构建应用程序。2010年5月20日 Google 发布 App Engine for Business，开始提供商用企业级云服务。</p>
<p>单个应用只能在Java 环境和 Python 环境之一中运行，App Engine 包括以下功能：</p>
<ul>
<li>动态网络服务，提供对常用网络技术的完全支持</li>
<li>持久存储空间，支持查询、分类和事务</li>
<li>自动扩展和负载平衡</li>
<li>用于对用户进行身份验证和使用 Google 帐户发送电子邮件的 API</li>
<li>一种功能完整的本地开发环境（SDK），可以在您的计算机上模拟 Google App Engine</li>
<li>用于在指定时间和定期触发事件的计划任务</li>
<li>高性能的内存键值缓存Memcache</li>
<li>网址抓取，图像操作和任务队列</li>
</ul>
<p><strong>开通 Google App Engine 帐户</strong><br />
使用你的 Google 帐户登录 Google App Engine ，会提示你需要使用短信验证。<br />
<a href="http://ohbug.com/wp-content/uploads/2010/06/gae-sms-verify.png"><img src="http://ohbug.com/wp-content/uploads/2010/06/gae-sms-verify-300x160.png" alt="" title="gae-sms-verify" width="300" height="160" class="alignnone size-medium wp-image-29" /></a></p>
<p>输入手机号码（带国家码如+8613612345678）,提交后会收到一条短消息（Google App Engine Code: 4444243）输入数字验证码提交便通过验证了。<br />
<a href="http://ohbug.com/wp-content/uploads/2010/06/gae-auth-code.png"><img src="http://ohbug.com/wp-content/uploads/2010/06/gae-auth-code-300x160.png" alt="" title="gae-auth-code" width="300" height="160" class="alignnone size-medium wp-image-27" /></a></p>
<p>现在可以开始创建你的第一个 Google App Engine 应用程序。(输入你的 Google Voice 号码也是可以收到短信息的，本文即是使用我的 Google Voice 号码接收短信来验证的帐号。)<br />
<a href="http://ohbug.com/wp-content/uploads/2010/06/gae-create-app.png"><img src="http://ohbug.com/wp-content/uploads/2010/06/gae-create-app-296x300.png" alt="" title="gae-create-app" width="296" height="300" class="alignnone size-medium wp-image-28" /></a></p>
<p>目前 Google App Engine(GAE)开发，Python 运行时环境是使用 Python 2.52版，Framework 使用 <a href="http://www.djangoproject.com/" target="_blank">Django</a> 0.96.1 版。</p>
<p><strong>GAE相关教程</strong><br />
<a href="http://code.google.com/appengine/docs/python/overview.html" target="_blank">Python 文档</a><br />
<a href="http://code.google.com/appengine/docs/java/overview.html" target="_blank">Java 文档</a><br />
<a href="http://code.google.com/appengine/docs/quotas.html" target="_blank">配额说明</a><br />
<a href="http://code.google.com/appengine/docs/billing.html" target="_blank">启用付费</a><br />
<a href="http://code.google.com/appengine/docs/domain.html" target="_blank">绑定域名</a></p>
<p><strong>GAE相关资料</strong><br />
<a href="http://code.google.com/appengine/downloads.html" target="_blank">下载 Google App Engine SDK</a><br />
<a href="http://code.google.com/status/appengine" target="_blank">App Engine 系统状态</a><br />
<a href="http://code.google.com/p/googleappengine/issues/list" target="_blank">App Engine SDK问题跟踪器</a><br />
<a href="http://code.google.com/appengine/business/" target="_blank">App Engine for Business</a></p>
<p>GAE 新闻<br />
<a href="http://www.reddit.com/r/appengine" target="_blank">Google App Engine news and articles</a><br />
<a href="http://googleappengine.blogspot.com/" target="_blank">Google App Engine Blog</a><br />
-EOF-</p>
]]></content:encoded>
			<wfw:commentRss>http://ohbug.com/archives/gae-intro.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GAE 查询1000条以外的记录</title>
		<link>http://ohbug.com/archives/gae-with_cursor.html</link>
		<comments>http://ohbug.com/archives/gae-with_cursor.html#comments</comments>
		<pubDate>Sun, 06 Jun 2010 02:35:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ohbug.com/?p=23</guid>
		<description><![CDATA[fetch()方法一次只能获取或者偏移1000条记录，这样对于两千条以外的记录就无能为力了。要么利用数据明确的标识来解决，如时间日期、ID等；好在GAE开发团队又提供了cursor()和with_cursor()来获取和设置游标，下面是例子。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 offset = 1234 last_cursor = None while offset &#62;1000: q = Blobs.all&#40;&#41; q.order&#40;'-created_at'&#41; q.filter&#40;'deleted =',False&#41; q.fetch&#40;1000&#41; last_cursor = q.cursor&#40;&#41; offset -= 1000 &#160; q = Blobs.all&#40;&#41; q.order&#40;'-created_at'&#41; q.filter&#40;'deleted =',False&#41; if last_cursor: q.with_cursor&#40;last_cursor&#41; results = q.fetch&#40;page_size, offset=offset&#41; -EOF-]]></description>
			<content:encoded><![CDATA[<p>fetch()方法一次只能获取或者偏移1000条记录，这样对于两千条以外的记录就无能为力了。要么利用数据明确的标识来解决，如时间日期、ID等；好在GAE开发团队又提供了cursor()和with_cursor()来获取和设置游标，下面是例子。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">offset = <span style="color: #ff4500;">1234</span>
last_cursor = <span style="color: #008000;">None</span>
<span style="color: #ff7700;font-weight:bold;">while</span> offset <span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">1000</span>:
  q = Blobs.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  q.<span style="color: black;">order</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-created_at'</span><span style="color: black;">&#41;</span>
  q.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'deleted ='</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
  q.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span>
  last_cursor = q.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  offset -= <span style="color: #ff4500;">1000</span>
&nbsp;
q = Blobs.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>    
q.<span style="color: black;">order</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-created_at'</span><span style="color: black;">&#41;</span>
q.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'deleted ='</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> last_cursor:
  q.<span style="color: black;">with_cursor</span><span style="color: black;">&#40;</span>last_cursor<span style="color: black;">&#41;</span>    
results = q.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span>page_size, offset=offset<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>-EOF-</p>
]]></content:encoded>
			<wfw:commentRss>http://ohbug.com/archives/gae-with_cursor.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A/B 向上取整</title>
		<link>http://ohbug.com/archives/ab-ceil.html</link>
		<comments>http://ohbug.com/archives/ab-ceil.html#comments</comments>
		<pubDate>Fri, 04 Jun 2010 15:42:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[程序设计]]></category>

		<guid isPermaLink="false">http://ohbug.com/?p=18</guid>
		<description><![CDATA[要写一个分页函数，需要获得两个数的商的向上取整，而Python里没有整除和浮点数除法的分别，虽然说乘个1.0就然后直接比较整除和浮点数除法的结果可以解决这个问题，或者我直接调用math.ceil(x)来解决这个问题，可我又不想导入一个module。于是找到了下面的这个公式，可以取得两个数的商的向上取整： UP(A/B) = int((A+B-1)/B) 原文说A和B都需要大于1，其实不需要的，用带值法可以证明其实等于1就可以了。对于分页来说，这个公式完全满足条件，爽歪歪～ -EOF-]]></description>
			<content:encoded><![CDATA[<p><a href="http://ohbug.com/wp-content/uploads/2010/06/01.jpg"><img src="http://ohbug.com/wp-content/uploads/2010/06/01-225x300.jpg" alt="" title="01" width="225" height="300" class="alignnone size-medium wp-image-19" /></a><br />
要写一个分页函数，需要获得两个数的商的向上取整，而Python里没有整除和浮点数除法的分别，虽然说乘个1.0就然后直接比较整除和浮点数除法的结果可以解决这个问题，或者我直接调用math.ceil(x)来解决这个问题，可我又不想导入一个module。于是<a href="http://www.vckbase.com/document/viewdoc/?id=743" target="_blank">找到了</a>下面的这个公式，可以取得两个数的商的向上取整：</p>
<blockquote><p>UP(A/B) = int((A+B-1)/B) </p></blockquote>
<p>原文说A和B都需要大于1，其实不需要的，用带值法可以证明其实等于1就可以了。对于分页来说，这个公式完全满足条件，爽歪歪～<br />
-EOF-</p>
]]></content:encoded>
			<wfw:commentRss>http://ohbug.com/archives/ab-ceil.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在Win32上为Python2.5安装SSL1.15</title>
		<link>http://ohbug.com/archives/compile-ssl-for-python.html</link>
		<comments>http://ohbug.com/archives/compile-ssl-for-python.html#comments</comments>
		<pubDate>Sun, 23 May 2010 15:27:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[操作指南]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://ohbug.com/?p=16</guid>
		<description><![CDATA[SSL for Python这个模块不像其它的模块直接下载下来执行setup.py install就安装好了，它需要编译再安装，过程遇到一些问题，这里记录一下如何安装成功的。 安装编译器MinGW 可以到MinGW网站下载GCC的win32版本 http://www.mingw.org/ 如果已经安装了VC6或者VS2003等编译器，可以略过此步骤。 获取依赖文件 OpenSSL libgw32c OpenSSL默认会安装在C:\Utils\GnuWin32,将libgw32c解压后也放在这个目录里。 获得ssl 1.15 Package代码 http://pypi.python.org/pypi/ssl/ 修改setup.py文件 如果OpenSSL安装路径不是默认的，就需要修改如下内容 if sys.platform == 'win32': &#160; # Assume the openssl libraries from GnuWin32 are installed in the # following location: gnuwin32_dir = os.environ.get&#40;&#34;GNUWIN32_DIR&#34;, r&#34;C:\Utils\GnuWin32&#34;&#41; 将C:\Utils\GnuWin32替换成实际的安装路径 修改cygwinccompiler.py文件 如果编译器版本不一致，还需要修改distutils\cygwinccompiler.py以跳过编译器版本检查，打开cygwinccompiler.py文件找到其中的如下内容(有两处)： result = re.search&#40;'(\d+\.\d+(\.\d+)*)',out_string&#41; 修改成 result = re.search&#40;'(\d+\.\d+(\.\d+)?)',out_string&#41; 开始编译吧 切换到ssl 1.15 Package解压目录下 [...]]]></description>
			<content:encoded><![CDATA[<p>SSL for Python这个模块不像其它的模块直接下载下来执行setup.py install就安装好了，它需要编译再安装，过程遇到一些问题，这里记录一下如何安装成功的。<br />
<strong>安装编译器MinGW</strong><br />
可以到MinGW网站下载GCC的win32版本 <a href="http://www.mingw.org/" target="_blank">http://www.mingw.org/</a><br />
如果已经安装了VC6或者VS2003等编译器，可以略过此步骤。<br />
<strong>获取依赖文件</strong></p>
<ul>
<li><a href="http://gnuwin32.sourceforge.net/packages/openssl.htm" target="_blank">OpenSSL</a> </li>
<li><a href="http://nchc.dl.sourceforge.net/project/gnuwin32/libgw32c/0.4/libgw32c-0.4-lib.zip" target="_blank">libgw32c</a></li>
</ul>
<p>OpenSSL默认会安装在C:\Utils\GnuWin32,将libgw32c解压后也放在这个目录里。 </p>
<p><strong>获得ssl 1.15 Package代码</strong><br />
<a href="http://pypi.python.org/pypi/ssl/" target="_blank">http://pypi.python.org/pypi/ssl/</a></p>
<p><strong>修改setup.py文件</strong><br />
如果OpenSSL安装路径不是默认的，就需要修改如下内容</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">sys</span>.<span style="color: #dc143c;">platform</span> == <span style="color: #483d8b;">'win32'</span>:
&nbsp;
    <span style="color: #808080; font-style: italic;"># Assume the openssl libraries from GnuWin32 are installed in the</span>
    <span style="color: #808080; font-style: italic;"># following location:</span>
    gnuwin32_dir = <span style="color: #dc143c;">os</span>.<span style="color: black;">environ</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;GNUWIN32_DIR&quot;</span>, r<span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\U</span>tils<span style="color: #000099; font-weight: bold;">\G</span>nuWin32&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>将C:\Utils\GnuWin32替换成实际的安装路径<br />
<strong>修改cygwinccompiler.py文件</strong><br />
如果编译器版本不一致，还需要修改distutils\cygwinccompiler.py以跳过编译器版本检查，打开cygwinccompiler.py文件找到其中的如下内容(有两处)：</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">result = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'(<span style="color: #000099; font-weight: bold;">\d</span>+<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\d</span>+(<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\d</span>+)*)'</span>,out_string<span style="color: black;">&#41;</span></pre></div></div>

<p>修改成</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">result = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'(<span style="color: #000099; font-weight: bold;">\d</span>+<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\d</span>+(<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\d</span>+)?)'</span>,out_string<span style="color: black;">&#41;</span></pre></div></div>

<p><strong>开始编译吧</strong><br />
切换到ssl 1.15 Package解压目录下<br />
编译并安装，运行命令</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">python setup.py build -c mingw32 install 
制作安装包，运行命令</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">python setup.py build -c mingw32 bdist_wininst</pre></div></div>

<p>最后附上我打包好的安装文件，下载后直接安装即可。<br />
下载 <a class="downloadlink" href="http://ohbug.com/download/1" title=" downloaded 98 times" >SSL1.15 for Python 2.52 (98)</a><br />
参考 <a href="http://beautifulisbetterthanugly.com/posts/2009/aug/19/compile-ssl-115-python-25-or-lower/" target="_blank">Compile ssl 1.15 for Python 2.5 or lower</a><br />
-EOF-</p>
]]></content:encoded>
			<wfw:commentRss>http://ohbug.com/archives/compile-ssl-for-python.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GAE图像API使用</title>
		<link>http://ohbug.com/archives/gae-image-api.html</link>
		<comments>http://ohbug.com/archives/gae-image-api.html#comments</comments>
		<pubDate>Thu, 13 May 2010 16:10:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ohbug.com/?p=10</guid>
		<description><![CDATA[GAE中提供了Image服务用于简单的处理图片，下面这个类调用相关的API将数据库中的图片文件转换到指定大小(正方形)，同时给图片加水印，处理完成后输出图片。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 class PhotoviewHandler&#40;webapp.RequestHandler&#41;: def get&#40;self,img_id&#41;: p = db.get&#40;img_id&#41; if p: MIN_SIZE = 500 image = images.Image&#40;p.blob&#41; width [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ohbug.com/wp-content/uploads/2010/05/gae_image_api_demo.png"><img src="http://ohbug.com/wp-content/uploads/2010/05/gae_image_api_demo-299x300.png" alt="" title="gae_image_api_demo" width="299" height="300" class="alignnone size-medium wp-image-12" /></a><br />
GAE中提供了Image服务用于简单的处理图片，下面这个类调用相关的API将数据库中的图片文件转换到指定大小(正方形)，同时给图片加水印，处理完成后输出图片。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> PhotoviewHandler<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">def</span> get<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,img_id<span style="color: black;">&#41;</span>:
    p = db.<span style="color: black;">get</span><span style="color: black;">&#40;</span>img_id<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> p: 
      MIN_SIZE = <span style="color: #ff4500;">500</span>
      image = images.<span style="color: black;">Image</span><span style="color: black;">&#40;</span>p.<span style="color: black;">blob</span><span style="color: black;">&#41;</span>
      width = image.<span style="color: black;">width</span>
      height = image.<span style="color: black;">height</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> width<span style="color: #66cc66;">&gt;</span>height:
        rate = width<span style="color: #66cc66;">*</span><span style="color: #ff4500;">1.0</span>/height
      <span style="color: #ff7700;font-weight:bold;">else</span>:
        rate = height<span style="color: #66cc66;">*</span><span style="color: #ff4500;">1.0</span>/width
      size = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>MIN_SIZE<span style="color: #66cc66;">*</span>rate+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
      new_image = images.<span style="color: black;">resize</span><span style="color: black;">&#40;</span>p.<span style="color: black;">blob</span>, width=size, height=size, output_encoding=images.<span style="color: black;">PNG</span><span style="color: black;">&#41;</span>        
      image = images.<span style="color: black;">Image</span><span style="color: black;">&#40;</span>new_image<span style="color: black;">&#41;</span>
      right_x = <span style="color: #008000;">round</span><span style="color: black;">&#40;</span>MIN_SIZE<span style="color: #66cc66;">*</span><span style="color: #ff4500;">1.0</span>/image.<span style="color: black;">width</span>,<span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> right_x<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">1</span>:
        right_x = <span style="color: #ff4500;">1.0</span>
      <span style="color: #ff7700;font-weight:bold;">else</span>:
        left_x = <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>- right_x<span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span>
        right_x = right_x + left_x
      bottom_y = <span style="color: #008000;">round</span><span style="color: black;">&#40;</span>MIN_SIZE<span style="color: #66cc66;">*</span><span style="color: #ff4500;">1.0</span>/image.<span style="color: black;">height</span>,<span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> bottom_y <span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">1</span>:
        bottom_y = <span style="color: #ff4500;">1.0</span>
      <span style="color: #ff7700;font-weight:bold;">else</span>:
        top_y = <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>-bottom_y<span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span>
        bottom_y = bottom_y + top_y
      new_image = images.<span style="color: black;">crop</span><span style="color: black;">&#40;</span>new_image, left_x, top_y, right_x, bottom_y, output_encoding=images.<span style="color: black;">PNG</span><span style="color: black;">&#41;</span>
      result = urlfetch.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://images.google.com.hk/intl/zh-CN_cn/images/logos/images_logo.gif'</span><span style="color: black;">&#41;</span>
      image = images.<span style="color: black;">Image</span><span style="color: black;">&#40;</span>new_image<span style="color: black;">&#41;</span>
      new_image = images.<span style="color: black;">composite</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>new_image, <span style="color: #ff4500;">0</span> ,<span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">1.0</span>, images.<span style="color: black;">TOP_LEFT</span><span style="color: black;">&#41;</span>,
                                    <span style="color: black;">&#40;</span>result.<span style="color: black;">content</span>, <span style="color: #ff4500;">0</span> ,<span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0.8</span>, images.<span style="color: black;">BOTTOM_LEFT</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>,
                                   image.<span style="color: black;">width</span>,image.<span style="color: black;">height</span>,<span style="color: #ff4500;">0</span>, images.<span style="color: black;">PNG</span><span style="color: black;">&#41;</span>
      <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'image/png'</span>
      <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>new_image<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>: 
      <span style="color: #008000;">self</span>.<span style="color: black;">error</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">404</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>-EOF-</p>
]]></content:encoded>
			<wfw:commentRss>http://ohbug.com/archives/gae-image-api.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python 风格指南</title>
		<link>http://ohbug.com/archives/python-style-guide.html</link>
		<comments>http://ohbug.com/archives/python-style-guide.html#comments</comments>
		<pubDate>Fri, 23 Apr 2010 15:33:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ohbug.com/?p=5</guid>
		<description><![CDATA[一个典型模块的内部结构： 起始行 模块文档(文档字符串) 模块导入 (全局)变量定义 类定义(若有) 函数定义(若有) 主程序 示例代码： 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #!/usr/bin/env python #coding:utf-8 &#160; &#34;this is a test module&#34; &#160; import sys import os &#160; debug = True &#160; class FooClass&#40;object&#41;: &#34;Foo class&#34; pass [...]]]></description>
			<content:encoded><![CDATA[<p>一个典型模块的内部结构：</p>
<ol>
<li>起始行</li>
<li>模块文档(文档字符串)</li>
<li>模块导入</li>
<li>(全局)变量定义</li>
<li>类定义(若有)</li>
<li>函数定义(若有)</li>
<li>主程序</li>
</ol>
<p>示例代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;">#coding:utf-8</span>
&nbsp;
<span style="color: #483d8b;">&quot;this is a test module&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
&nbsp;
debug = <span style="color: #008000;">True</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> FooClass<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;Foo class&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #dc143c;">test</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;test function&quot;</span>
    foo = FooClass<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> debug:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'ram test()'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    <span style="color: #dc143c;">test</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>-EOF-</p>
]]></content:encoded>
			<wfw:commentRss>http://ohbug.com/archives/python-style-guide.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>你好,世界!</title>
		<link>http://ohbug.com/archives/hello-world.html</link>
		<comments>http://ohbug.com/archives/hello-world.html#comments</comments>
		<pubDate>Sun, 18 Apr 2010 00:54:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[不会分类]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ohbug.com/?p=1</guid>
		<description><![CDATA[#!/usr/bin/env python #coding:utf-8 &#160; def helloworld&#40;&#41;: &#34;Hello World! \ \nWelcome to my blog.&#34; print 'Nice to meet you!' if __name__ == '__main__': helloworld&#40;&#41; -EOF-]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;">#coding:utf-8</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> helloworld<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;Hello World! <span style="color: #000099; font-weight: bold;">\</span>
    <span style="color: #000099; font-weight: bold;">\n</span>Welcome to my blog.&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Nice to meet you!'</span>
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    helloworld<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>-EOF-</p>
]]></content:encoded>
			<wfw:commentRss>http://ohbug.com/archives/hello-world.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
