<?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>finally{} &#187; ironpython</title>
	<atom:link href="http://www.jjude.com/tag/ironpython/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jjude.com</link>
	<description>all will be well finally</description>
	<lastBuildDate>Wed, 28 Dec 2011 18:00:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>IronPython talks to Google AppEngine</title>
		<link>http://www.jjude.com/2008/09/ironpython-talks-to-google-appengine/</link>
		<comments>http://www.jjude.com/2008/09/ironpython-talks-to-google-appengine/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 17:10:10 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ironpython]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/2008/09/29/ironpython-talks-to-google-appengine/</guid>
		<description><![CDATA[<p>Integrating IronPython application with that of Google App Engine - a desktop &#038; web integration with authentication</p><p><a href="http://www.jjude.com/2008/09/ironpython-talks-to-google-appengine/">IronPython talks to Google AppEngine</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m continuing from my earlier posts on <a href="http://www.jjude.com/index.php/archives/2008/09/01/a-time-tracking-tool/" target="_blank">Time Tracking Tool</a> and <a href="http://www.jjude.com/index.php/archives/2008/09/18/authenticating-in-gae/" target="_blank">Authenticating in GAE</a>. When I started with Time Tracking Tool, I had the idea of having a server which will act as a centralized data repository &#8211; laptop/desktop tool, mobile tool should send data to the server and data will be analyzed in the server.</p>
<p>To that end, I got the windows desktop client tool talking to a server application. The server is a Google AppEngine Application. Currently there is not much in the server side. Just plain data that is transferred from the client tool. I&#8217;ll continue to work on the components and improve on the features &#8211; especially dashboard, analytics and similar other features.</p>
<p>To start with <a href="http://code.google.com/p/mysecs/downloads/list" target="_blank">download</a> the windows client tool (mySecs_x.x.zip &#8211; as the general practice x.x denotes the version) and unzip the content to a directory. You can use the client tool as a standalone tool (without synchronizing data to the server). This is the default configuration. However if you are okay to synchronize then modify the config.xml accordingly.</p>
<div class="codecolorer-container xml blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serverupdate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/serverupdate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;host<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mysecs.appspot.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/host<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;email<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mysecs@gmail.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/email<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;password<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>yourpassword<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/password<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>As I said before, client tool works as a stand alone tool by default. If you&#8217;re okay to synchronize the data, then change this to 1. I use Google Authentication, hence you need to have a gmail account and provide these in the respective xml nodes.</p>
<p>(A note about data privacy: I don&#8217;t pass your email id  to the server. So I wouldn&#8217;t know about your email id. If you are particular about your email id, which you should be, then create another gmail id for this purpose.</p>
<p>Also, since code for the server is shared, you can download the GAE code and host it on your own).</p>
<p>This is a working version. I&#8217;m using it to capture details and synchronize with the GAE server. As I continue to find bugs, I&#8217;ll fix them. However if you find bugs, please report them in the <a href="http://code.google.com/p/mysecs/issues/list" target="_blank">Issue Log</a>. (A user reported that it doesn&#8217;t work with x64. I don&#8217;t know how to fix it. I will search around to fix it).</p>
<p>Next steps? Incorporate with Google Charts to provide some neat analytics reports, so that it really becomes an useful tool.</p>
<p>I need a help though. I am really bad at web design. So if you can take some time of you to design a cool home page and a list page, it will be great. I will surely acknowledge you for your contribution. So if you want to help, please <a href="http://www.jjude.com/contact" target="_blank">contact</a> me.</p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/09/authenticating-in-gae/" title="Authenticating in GAE">Authenticating in GAE</a></li><li><a href="http://www.jjude.com/2008/09/ironpython-learnings/" title="IronPython Learnings">IronPython Learnings</a></li><li><a href="http://www.jjude.com/2008/09/a-time-tracking-tool/" title="A time tracking tool">A time tracking tool</a></li></ul><p><a href="http://www.jjude.com/2008/09/ironpython-talks-to-google-appengine/">IronPython talks to Google AppEngine</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/09/ironpython-talks-to-google-appengine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Authenticating in GAE</title>
		<link>http://www.jjude.com/2008/09/authenticating-in-gae/</link>
		<comments>http://www.jjude.com/2008/09/authenticating-in-gae/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 07:37:54 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ironpython]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/2008/09/18/authenticating-in-gae/</guid>
		<description><![CDATA[<p>How to implement Basic Authentication in Google App Engine so as to access GAE apps from desktop.</p><p><a href="http://www.jjude.com/2008/09/authenticating-in-gae/">Authenticating in GAE</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>Having successfully created a <a href="http://code.google.com/p/mysecs/" target="_blank">desktop application</a> in <a href="http://en.wikipedia.org/wiki/IronPython" target="_blank">IronPython</a>, I wanted to go a step further &#8211; integrate desktop and web environment. Data can be captured in desktop and passed on to web; and analysis can be done on the web.</p>
<p>To start with it, I need to authenticate the incoming request. Hmm&#8230;when I started reading about authentication I read so many jargons that scared me &#8211; openid, openauth, authsub, basicauth. It took me a while to understand the basics of each (still I don&#8217;t claim that I&#8217;ve understood them; probably whatever I&#8217;ve understood is wrong too)</p>
<p>To some extent, I understood &#8216;Basic Authentication&#8217; and this is how I went about implementing it.</p>
<p><a href="http://www.jjude.com/wp-content/uploads/image21.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 10px; border-right-width: 0px" height="117" alt="image" src="http://www.jjude.com/wp-content/uploads/image-thumb19.png" width="414" border="0" /></a> </p>
<p>First of all, I am going with Google Account Authentication, assuming all the users will have a Google account; getting one is not a big deal. </p>
<p>IronPython Desktop Application will pass userid, password to AppEngine Application, which in turn will validate with Google Accounts Authentication service. If authenticated, AppEngine application will proceed; else it will pass the error back to the desktop application.</p>
<p>Having discussed the concepts, here are the code snippets. I&#8217;m sharing with a hope that it will be useful to someone; or if this is wrong, someone will raise an alarm; or if there is a better way to do it, someone will comment.</p>
<h5>AppEngine</h5>
<p>Here the expectation is that the incoming request will have a header (&#8216;HTTP_AUTHORIZATION&#8217;) with userid and password in Base64 format.</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">api</span> <span style="color: #ff7700;font-weight:bold;">import</span> users<br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">base64</span><br />
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">api</span> <span style="color: #ff7700;font-weight:bold;">import</span> urlfetch<br />
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">http</span> <span style="color: #ff7700;font-weight:bold;">import</span> HttpResponse<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> authenticate<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:<br />
&nbsp; response_vals<span style="color: #66cc66;">=</span><span style="color: black;">&#123;</span><span style="color: black;">&#125;</span><br />
&nbsp; resp <span style="color: #66cc66;">=</span> HttpResponse<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">try</span>:<br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>method<span style="color: #66cc66;">,</span> encoded<span style="color: black;">&#41;</span> <span style="color: #66cc66;">=</span> request.<span style="color: black;">META</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'HTTP_AUTHORIZATION'</span><span style="color: black;">&#93;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; response_vals<span style="color: black;">&#91;</span><span style="color: #483d8b;">'method'</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">=</span> method<br />
&nbsp; &nbsp; response_vals<span style="color: black;">&#91;</span><span style="color: #483d8b;">'encoded'</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">=</span> encoded<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> method.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #483d8b;">'basic'</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span>username<span style="color: #66cc66;">,</span> password<span style="color: black;">&#41;</span> <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">base64</span>.<span style="color: black;">b64decode</span><span style="color: black;">&#40;</span>encoded<span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">':'</span><span style="color: black;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; request_body <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlencode</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'Email'</span>: username<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'Passwd'</span>: password<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'accountType'</span>: <span style="color: #483d8b;">'HOSTED_OR_GOOGLE'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'service'</span>: <span style="color: #483d8b;">'ah'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'source'</span>: <span style="color: #483d8b;">'test'</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; auth_response <span style="color: #66cc66;">=</span> urlfetch.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'https://www.google.com/accounts/ClientLogin'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;method<span style="color: #66cc66;">=</span>urlfetch.<span style="color: black;">POST</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;headers<span style="color: #66cc66;">=</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'Content-type'</span>:<span style="color: #483d8b;">'application/x-www-form-urlencoded'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'Content-Length'</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>request_body<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;payload<span style="color: #66cc66;">=</span>request_body<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resp.<span style="color: black;">status_code</span> <span style="color: #66cc66;">=</span> auth_response.<span style="color: black;">status_code</span><br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">except</span>:<br />
&nbsp; &nbsp; resp.<span style="color: black;">status_code</span> <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">401</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> resp<br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> resp</div></div>
<h5>Desktop &#8211; Python</h5>
<p>Encode the user id, password and call the particular URL (/auth?). And handle the response.</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">base64</span><br />
<br />
url <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'http://localhost:8000/api/auth/'</span><br />
username <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'mysecs@gmail.com'</span><br />
password <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'mysecspwd'</span><br />
USER_AGENT <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'mySecsWndClient'</span><br />
<br />
request <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">Request</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span><br />
base64string <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">base64</span>.<span style="color: black;">encodestring</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%s:%s'</span> % <span style="color: black;">&#40;</span>username<span style="color: #66cc66;">,</span>password<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
authheader <span style="color: #66cc66;">=</span> &nbsp;&amp;quot<span style="color: #66cc66;">;</span>Basic %s&amp;quot<span style="color: #66cc66;">;</span> % base64string<br />
request.<span style="color: black;">add_header</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'USER_AGENT'</span><span style="color: #66cc66;">,</span> USER_AGENT<span style="color: black;">&#41;</span><br />
request.<span style="color: black;">add_header</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'AUTHORIZATION'</span><span style="color: #66cc66;">,</span> authheader<span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">try</span>:<br />
&nbsp; response <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> response<br />
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">HTTPError</span><span style="color: #66cc66;">,</span> e:<br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> e.<span style="color: #dc143c;">code</span><br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> e.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">URLError</span><span style="color: #66cc66;">,</span> e:<br />
&nbsp; &nbsp;<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">hasattr</span><span style="color: black;">&#40;</span>e<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'reason'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> e.<span style="color: black;">reason</span><br />
&nbsp; &nbsp;<span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #008000;">hasattr</span><span style="color: black;">&#40;</span>e<span style="color: #66cc66;">,</span><span style="color: #483d8b;">'code'</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> e.<span style="color: #dc143c;">code</span></div></div>
<h5>Desktop &#8211; IronPython</h5>
<p>Since I&#8217;ve written mySecs in IronPython, I&#8217;ve to translate the above into IronPython. As ipy is a relatively new entrant, there is not much of documentation on how to do it. Here is what I&#8217;ve done.</p>
<div class="codecolorer-container csharp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">import <span style="color: #000000;">System</span><br />
<span style="color: #0600FF; font-weight: bold;">from</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span> import StreamReader<br />
<span style="color: #0600FF; font-weight: bold;">from</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span> import HttpWebRequest, NetworkCredential, WebException<br />
<br />
url <span style="color: #008000;">=</span> <span style="color: #666666;">'http://localhost:8000/api/auth/'</span><br />
username <span style="color: #008000;">=</span> <span style="color: #666666;">'mysecs@gmail.com'</span><br />
password <span style="color: #008000;">=</span> <span style="color: #666666;">'mysecspwd'</span><br />
USER_AGENT <span style="color: #008000;">=</span> <span style="color: #666666;">'mySecsWndClient'</span><br />
<br />
<br />
req <span style="color: #008000;">=</span> HttpWebRequest<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>url<span style="color: #008000;">&#41;</span><br />
req<span style="color: #008000;">.</span><span style="color: #0000FF;">UserAgent</span> <span style="color: #008000;">=</span> USER_AGENT<br />
auth_string <span style="color: #008000;">=</span> <span style="color: #666666;">'%s:%s'</span> <span style="color: #008000;">%</span> <span style="color: #008000;">&#40;</span>username,password<span style="color: #008000;">&#41;</span><br />
authheader <span style="color: #008000;">=</span> &nbsp;<span style="color: #008000;">&amp;</span>quot<span style="color: #008000;">;</span>Basic <span style="color: #008000;">%</span>s<span style="color: #008000;">&amp;</span>quot<span style="color: #008000;">;</span> <span style="color: #008000;">%</span> <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Convert</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToBase64String</span><span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Encoding</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ASCII</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>auth_string<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
req<span style="color: #008000;">.</span><span style="color: #0000FF;">Headers</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">'AUTHORIZATION'</span>, authheader<span style="color: #008000;">&#41;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">try</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; rsp <span style="color: #008000;">=</span> req<span style="color: #008000;">.</span><span style="color: #0000FF;">GetResponse</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; response <span style="color: #008000;">=</span> StreamReader<span style="color: #008000;">&#40;</span>rsp<span style="color: #008000;">.</span><span style="color: #0000FF;">GetResponseStream</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ReadToEnd</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; print response<br />
&nbsp; &nbsp; rsp<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
except <span style="color: #008000;">&#40;</span>Exception, WebException<span style="color: #008000;">&#41;</span>, e<span style="color: #008000;">:</span><br />
&nbsp; &nbsp; print <span style="color: #666666;">'Error: %s'</span> <span style="color: #008000;">%</span> e</div></div>
<p>Applies to: GAE 1.1.1; Django 0.96 with helper; IronPython 1.1</p>
<p>Reference:<br />
  <br /><a href="http://code.google.com/apis/accounts/docs/AuthSub.html" target="_blank">AuthSub Authentication for Web Applications</a></p>
<p><a href="http://www.voidspace.org.uk/python/articles/authentication.shtml" target="_blank">Basic Authentication &#8211; Authentication with Python</a></p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/09/ironpython-talks-to-google-appengine/" title="IronPython talks to Google AppEngine">IronPython talks to Google AppEngine</a></li><li><a href="http://www.jjude.com/2008/09/ironpython-learnings/" title="IronPython Learnings">IronPython Learnings</a></li><li><a href="http://www.jjude.com/2008/09/a-time-tracking-tool/" title="A time tracking tool">A time tracking tool</a></li></ul><p><a href="http://www.jjude.com/2008/09/authenticating-in-gae/">Authenticating in GAE</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/09/authenticating-in-gae/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>IronPython Learnings</title>
		<link>http://www.jjude.com/2008/09/ironpython-learnings/</link>
		<comments>http://www.jjude.com/2008/09/ironpython-learnings/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 07:37:17 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ironpython]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/2008/09/07/ironpython-learnings/</guid>
		<description><![CDATA[<p>Sharing my learnings in developing a windows desktop application in IronPython.</p><p><a href="http://www.jjude.com/2008/09/ironpython-learnings/">IronPython Learnings</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>Recently I started developing Windows Desktop Applications in IronPython &#8211; a Python language port for Windows.NET. I blogged about the application already <a href="http://www.jjude.com/index.php/archives/2008/09/01/a-time-tracking-tool/" target="_blank">here</a>.</p>
<p>In the post, I&#8217;m sharing what I learnt in the process with a hope that it will be helpful to someone else.</p>
<h5>Visual Studio as ipy development environment</h5>
<p>You can download IronPython and start to develop using your favorite text editor. However having a Visual Studio environment helps. Fundamentally it involves:</p>
<ul>
<li>Download and install ironpython</li>
<li>Download and install Visual Studio SDK</li>
<li>Run IronPython Integration Sample from &#8216;C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Samples\IronPythonIntegration&#8217;</li>
</ul>
<h5>Designing Windows Forms</h5>
<p>With Visual Studio Integration, designing of Windows Forms is a simple drag and drop operation. Of course code generated by VS may not be as elegant as some Python purists like; but it works well.</p>
<h5>Calling unmanaged code from IronPython</h5>
<p>If you are into IronPython, you&#8217;ll definitely come across <a href="http://www.voidspace.org.uk/ironpython/index.shtml" target="_blank">VoidSpace</a>, who has a huge collection of IronPython articles.</p>
<p>I needed to query the active window for my application. VoidSpace discusses a <a href="http://www.voidspace.org.uk/ironpython/winforms/part10.shtml" target="_blank">solution</a> in his pages. Better to name the namespace as a &#8216;UnmanagedCode&#8217; as VoidSpace discusses in the solution. I named it as the name of the application and that created a lot of trouble and was difficult to troubleshoot.</p>
<h5>Logging in IronPython</h5>
<p>IPY doesn&#8217;t include standard python libraries (at least as of 1.1). So I used a <a href="http://sourceforge.net/projects/nspring" target="_blank">NSpring</a> .NET logging library.</p>
<p>(<em>I found out that any .NET library can be used with IronPython. I did same with <a href="http://sqlite.phxsoftware.com/" target="_blank">SQLite Library</a></em> and <a href="http://sourceforge.net/projects/sourcegrid" target="_blank">SourceGrid</a>, a grid library for .NET)</p>
<h5>Finding time difference</h5>
<p>One can find the time difference between two time variable (=System.DateTime.Now) using</p>
<pre>timeSpent = currentEndTime.Subtract(currentStartTime)</pre>
<p>If you want to know the differences in seconds then use</p>
<pre>timeSpentinSec = timeSpent.TotalSeconds.ToString()</pre>
<p>timeSpent.Seconds() will provide only the seconds part of the timespan. TotalSeconds() provide the time difference in seconds.</p>
<h5>Don&#8217;t forget to stop timer</h5>
<p>I used Timer() to poll activewindow on a regular interval. However, I forgot to stop that assuming that once the form is closed all instances will be cleared. Apparently not and so the application stayed in memory even after exit. Lesson learnt: stop all threads before exiting the application.</p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/09/ironpython-talks-to-google-appengine/" title="IronPython talks to Google AppEngine">IronPython talks to Google AppEngine</a></li><li><a href="http://www.jjude.com/2008/09/authenticating-in-gae/" title="Authenticating in GAE">Authenticating in GAE</a></li><li><a href="http://www.jjude.com/2008/09/a-time-tracking-tool/" title="A time tracking tool">A time tracking tool</a></li></ul><p><a href="http://www.jjude.com/2008/09/ironpython-learnings/">IronPython Learnings</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/09/ironpython-learnings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A time tracking tool</title>
		<link>http://www.jjude.com/2008/09/a-time-tracking-tool/</link>
		<comments>http://www.jjude.com/2008/09/a-time-tracking-tool/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 17:25:16 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ironpython]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/2008/09/01/a-time-tracking-tool/</guid>
		<description><![CDATA[<p>A simple time tracking tool developed in IronPython.</p><p><a href="http://www.jjude.com/2008/09/a-time-tracking-tool/">A time tracking tool</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>While I was waiting for Django 1.0 to be released, I wanted to quickly learn to develop desktop applications. I preferred it to be on Python so that I can continue to learn the language. I did an evaluation of different options and settled on <a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython" target="_blank">IronPython</a>.</p>
<p>As a consultant, there is always a need to submit timesheets. By the end of the day/week, it is difficult to remember the tasks done during that time-span (day/week). If somehow a tool can capture applications that were worked on, then it will help.</p>
<p>So I developed an application for the same.</p>
<p>This application polls the active window at an interval of 5 seconds and captures the application details (application name and the application title) and the time spent on each of these tasks.</p>
<p><a href="http://www.jjude.com/wp-content/uploads/image19.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 10px; border-right-width: 0px" height="168" alt="image" src="http://www.jjude.com/wp-content/uploads/image-thumb17.png" width="492" border="0" /></a>&#160;<a href="http://www.jjude.com/wp-content/uploads/image20.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 10px; border-right-width: 0px" height="51" alt="image" src="http://www.jjude.com/wp-content/uploads/image-thumb18.png" width="213" align="left" border="0" /></a> </p>
<p>It can be minimized into systray so that it can continue to capture details without any disturbance (first icon).</p>
<p>One can download the details on the grid as a csv file too.</p>
<p>Currently thats all in there. As I continue to use (and probably get some feedback) I will continue to enhance it.</p>
<p>The project is hosted in <a href="http://code.google.com/p/mysecs/" target="_blank">Google</a>. One can download the <a href="http://code.google.com/p/mysecs/downloads/list" target="_blank">executable</a> and the <a href="http://code.google.com/p/mysecs/downloads/list" target="_blank">source</a>. </p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/09/ironpython-talks-to-google-appengine/" title="IronPython talks to Google AppEngine">IronPython talks to Google AppEngine</a></li><li><a href="http://www.jjude.com/2008/09/authenticating-in-gae/" title="Authenticating in GAE">Authenticating in GAE</a></li><li><a href="http://www.jjude.com/2008/09/ironpython-learnings/" title="IronPython Learnings">IronPython Learnings</a></li></ul><p><a href="http://www.jjude.com/2008/09/a-time-tracking-tool/">A time tracking tool</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/09/a-time-tracking-tool/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

