<?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>mFabrik - web and mobile development &#187; aptana studio</title>
	<atom:link href="http://blog.mfabrik.com/category/aptana-studio/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mfabrik.com</link>
	<description>Freedom delivered.</description>
	<lastBuildDate>Thu, 09 Sep 2010 07:16:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PyDev, Python and system default Unicode encoding problem</title>
		<link>http://blog.mfabrik.com/2010/01/24/aptana-studio-eclipse-pydev-default-unicode-encoding/</link>
		<comments>http://blog.mfabrik.com/2010/01/24/aptana-studio-eclipse-pydev-default-unicode-encoding/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 17:02:33 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[aptana studio]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[plone]]></category>
		<category><![CDATA[pydev]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://blog.twinapex.fi/?p=415</guid>
		<description><![CDATA[Python 2 has a thing called &#8220;default encoding&#8221; to automagically encode Unicode strings when they are presented as byte strings. This is evil and has been discussed various times before. What could be even more evil? Something in your development environment messes this setting set for you, without telling you that. This way you never [...]]]></description>
			<content:encoded><![CDATA[<p>Python 2 has a thing called &#8220;default encoding&#8221; to automagically encode Unicode strings when they are presented as byte strings. <a href="http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-evil/">This is evil and has been discussed various times before</a>.</p>
<p>What could be even more evil? Something in your development environment messes this setting set for you, without telling you that. This way you never encounter Unicode problems on your development computer and when you roll out your seemingly working code to production, the world goes haywire.</p>
<p>Evil. Evil. Evil. Thousands of curses and overworking hours to fix the problems.</p>
<p>I encountered this problem. And this is the code I used to track the problem down in site.py:</p>
<pre># Trap the bastard messing with the default encoding
# using a monkey patch
old_set_default_encoding = sys.setdefaultencoding

def aargh(x):
    import pdb ; pdb.set_trace()

sys.setdefaultencoding = aargh</pre>
<div>And the result was surprising:</div>
<pre>
<div id="_mcePaste">--Return--</div>
<div id="_mcePaste">&gt; /home/moo/py24/lib/python2.4/site.py(485)aargh()-&gt;None</div>
<div id="_mcePaste">-&gt; import pdb ; pdb.set_trace()</div>
<div id="_mcePaste">(Pdb) bt</div>
<div id="_mcePaste">/home/moo/py24/lib/python2.4/site.py(613)?()</div>
<div id="_mcePaste">-&gt; main()</div>
<div id="_mcePaste">/home/moo/py24/lib/python2.4/site.py(604)main()</div>
<div id="_mcePaste">-&gt; execsitecustomize()</div>
<div id="_mcePaste">/home/moo/py24/lib/python2.4/site.py(514)execsitecustomize()</div>
<div id="_mcePaste">-&gt; import sitecustomize</div>
<div id="_mcePaste">/home/moo/Desktop/Aptana Studio 2.0/plugins/org.python.pydev_1.5.3.1260479439/PySrc/pydev_sitecustomize/sitecustomize.py(99)?()</div>
<div id="_mcePaste">-&gt; sys.setdefaultencoding(encoding) #@UndefinedVariable (it's deleted after the site.py is executed -- so, it's undefined for code-analysis)</div>
<div id="_mcePaste">&gt; /home/moo/py24/lib/python2.4/site.py(485)aargh()-&gt;None</div>
<div id="_mcePaste">-&gt; import pdb ; pdb.set_trace()</div>

--Return--&gt; /home/moo/py24/lib/python2.4/site.py(485)aargh()-&gt;None-&gt; import pdb ; pdb.set_trace()(Pdb) bt  /home/moo/py24/lib/python2.4/site.py(613)?()-&gt; main()  /home/moo/py24/lib/python2.4/site.py(604)main()-&gt; execsitecustomize()  /home/moo/py24/lib/python2.4/site.py(514)execsitecustomize()-&gt; import sitecustomize  /home/moo/Desktop/Aptana Studio 2.0/plugins/org.python.pydev_1.5.3.1260479439/PySrc/pydev_sitecustomize/sitecustomize.py(99)?()-&gt; sys.setdefaultencoding(encoding) #@UndefinedVariable (it's deleted after the site.py is executed -- so, it's undefined for code-analysis)&gt; /home/moo/py24/lib/python2.4/site.py(485)aargh()-&gt;None-&gt; import pdb ; pdb.set_trace()</pre>
<p>Looks like the culprint was PyDev (Eclipse Python plug-in).  The interfering source code is <a href="http://github.com/aptana/Pydev/blob/master/plugins/org.python.pydev/PySrc/pydev_sitecustomize/sitecustomize.py">here</a>. Looks like the reason was to co-operate with Eclipse console. However it has been done incorrectly. Instead of setting the console encoding, the encoding is set to whole Python run-time environment, messing up the target run-time where the development is being done.</p>
<p>There is a possible fix for this problem. In Eclipse Run&#8230; dialog settings you can choose <em>Console Encoding</em> on <em>Common</em> tab. There is a possible value <em>US-ASCII</em>. I am not sure what Python 2 thinks &#8220;US-ASCII&#8221; encoding name, since the default is &#8220;ascii&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2010/01/24/aptana-studio-eclipse-pydev-default-unicode-encoding/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
