<?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>darkbrown.org</title>
	<atom:link href="http://www.darkbrown.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.darkbrown.org</link>
	<description>/home/emre</description>
	<lastBuildDate>Tue, 18 May 2010 11:22:36 +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>django 1.2 stable çıktı</title>
		<link>http://www.darkbrown.org/django-1-2-stable-cikti/</link>
		<comments>http://www.darkbrown.org/django-1-2-stable-cikti/#comments</comments>
		<pubDate>Tue, 18 May 2010 08:59:24 +0000</pubDate>
		<dc:creator>Emre Yılmaz</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.darkbrown.org/?p=114</guid>
		<description><![CDATA[dün gece django 1.2 stable sürümü duyuruldu. django 1.2 ile birlikte benim gözüme çarpan önemli yenilikler; multiple database desteği tek proje içinde birden fazla veritabanı kullanmak artık &#8220;hacky&#8221; bir yönteme başvurmadan mümkün. settings.py içinde ayarlıyorsunuz o kadar. model validation desteği artık ilgili objenin bağlı bulunduğu modele göre otomatik validation yapabiliyoruz. messages framework (bu özellik için [...]]]></description>
			<content:encoded><![CDATA[<p>dün gece django 1.2 stable sürümü duyuruldu. django 1.2 ile birlikte benim gözüme çarpan önemli yenilikler;</p>
<h4>multiple database desteği</h4>
<p> tek proje içinde birden fazla veritabanı kullanmak artık &#8220;hacky&#8221; bir yönteme başvurmadan mümkün. settings.py içinde ayarlıyorsunuz o kadar.</p>
<h4>model validation desteği </h4>
<p> artık ilgili objenin bağlı bulunduğu modele göre otomatik validation yapabiliyoruz.</p>
<h4>messages framework </h4>
<p> (bu özellik için svn versiyonunu kullanıyordum) messages framework, kullanıcılara tek seferlik görünen hata/bilgi/başarı mesajları göstermenizi sağlayan bir çatı. daha önce django-flashmessages gibi eklentiler vardı bu iş için, ama çekirdeğe böyle bir özellik gelmesi harika oldu. <strong>messages.error(request, &#8220;hata mesajı&#8221;)</strong> formatında kullanıcı oturumuna ait hata ekleyebiliyorsunuz mesela.</p>
<h4>template etiketlerinde akıllı kontroller</h4>
<p> ifequal gibi zorlama bir tag yerine, <em>-sonunda!-</em> artık, template dosyalarında statement&#8217;lar kullanabilir durumda. şöyle ki;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> ifequal request.<span style="color: #dc143c;">user</span>.<span style="color: black;">username</span> related_profile.<span style="color: black;">username</span> <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span></pre></div></div>

<p> yerine</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#123;</span><span style="color: #66cc66;">%</span> <span style="color: #ff7700;font-weight:bold;">if</span> request.<span style="color: #dc143c;">user</span>.<span style="color: black;">username</span> == related_profile.<span style="color: black;">username</span> <span style="color: #66cc66;">%</span><span style="color: black;">&#125;</span></pre></div></div>

<p> kullanabiliyoruz. yaşayanlar bilir, çok can sıkıcıydı bu durum.</p>
<p>bunların dışında &#8220;template caching&#8221;, &#8220;email backend desteği&#8221; gibi yeni özellikler mevcut,  tüm yeniliklerin listesi <a href="http://docs.djangoproject.com/en/dev/releases/1.2/">burada</a>. 1.2&#8242;ye geçmeden önce, önceki sürüme göre <a href="http://docs.djangoproject.com/en/dev/releases/1.2/#backwards-incompatible-changes-in-1-2">deprecated</a> olan değişikliklere göz atmayı unutmayın.</p>
<p>happy hacking! <img src='http://www.darkbrown.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.darkbrown.org/django-1-2-stable-cikti/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>kayıtlara geçmeliydi</title>
		<link>http://www.darkbrown.org/kayitlara-gecmeliydi/</link>
		<comments>http://www.darkbrown.org/kayitlara-gecmeliydi/#comments</comments>
		<pubDate>Tue, 18 May 2010 07:24:45 +0000</pubDate>
		<dc:creator>Emre Yılmaz</dc:creator>
				<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.darkbrown.org/?p=105</guid>
		<description><![CDATA[grafiklere tıklayınca açılıyorlar.]]></description>
			<content:encoded><![CDATA[<p>grafiklere tıklayınca açılıyorlar.</p>
<p><a href="http://www.aksam.com.tr/2009/12/20/haber/cumartesi/527/zekasina_guvenen_hacker_varsa_beni_hack_lesin_.html"><img class="size-medium wp-image-106 alignnone" title="huzeyfe" src="http://www.darkbrown.org/wp-content/uploads/2010/05/huzeyfe-300x300.png" alt="" width="300" height="300" /></a></p>
<p><a href="http://www.zone-h.org/mirror/id/10031544"><img class="alignleft size-medium wp-image-108" title="ge" src="http://www.darkbrown.org/wp-content/uploads/2010/05/ge-300x201.png" alt="" width="300" height="201" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.darkbrown.org/kayitlara-gecmeliydi/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>xkcd arşivi, python, threading</title>
		<link>http://www.darkbrown.org/xkcd-arsivi-python-threading/</link>
		<comments>http://www.darkbrown.org/xkcd-arsivi-python-threading/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 20:34:13 +0000</pubDate>
		<dc:creator>Emre Yılmaz</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[thread pool]]></category>

		<guid isPermaLink="false">http://www.darkbrown.org/?p=94</guid>
		<description><![CDATA[Yıllardır XKCD arşivine tam olarak göz atamadım, bugün aşağıdaki diyaloğu -tekrardan- görünce artık vaktinin geldiğini anladım. [buraya random gülüş gelecek] tüm arşivi indirmeye karar verince, yapmam gereken işlemin basit olduğunu gördüm, ama 700 küsür resmi tek thread/tek process çalışan bir python scriptiyle indirmek uzun sürecekti. bunun üstüne python&#8217;da thread pool mevzusunu hem öğrenmek hem de [...]]]></description>
			<content:encoded><![CDATA[<p>Yıllardır XKCD arşivine <strong>tam olarak</strong> göz atamadım, bugün aşağıdaki diyaloğu -tekrardan- görünce artık vaktinin geldiğini anladım. [buraya random gülüş gelecek]</p>
<p><a href="http://www.darkbrown.org/wp-content/uploads/2010/04/estimation.png"><img class="aligncenter size-medium wp-image-95" title="estimation" src="http://www.darkbrown.org/wp-content/uploads/2010/04/estimation-265x300.png" alt="" width="265" height="300" /></a></p>
<p>tüm arşivi indirmeye karar verince, yapmam gereken işlemin basit olduğunu gördüm, ama 700 küsür resmi tek thread/tek process çalışan bir python scriptiyle indirmek uzun sürecekti. bunun üstüne python&#8217;da<a href="http://en.wikipedia.org/wiki/Thread_pool_pattern"> thread pool</a> mevzusunu hem öğrenmek hem de etinden suyundan faydalanmak için araştırdım ve çok kısa bir sürede hallettim. (akabinde python&#8217;a yine aşık oldum, tekrardan. <em>literally</em>.)</p>
<p>aşağıdaki betik threading kütüphanesi yardımıyla -biraz daha hızlıca- XKCD arşivini download ediyor. çalışması için sadece ilgili makinede python kurulu olması yeterli.</p>

<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: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">Queue</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">threading</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>, <span style="color: #dc143c;">os</span>
&nbsp;
<span style="color: #483d8b;">&quot;&quot;&quot;
 XKCD dumper - http://www.xkcd.com
 emre yilmaz - www.darkbrown.org
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Fetcher<span style="color: black;">&#40;</span><span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, queue<span style="color: black;">&#41;</span>:
        <span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">queue</span> = queue
        <span style="color: #008000;">self</span>.__control_download_path<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
            comic_id = <span style="color: #008000;">self</span>.<span style="color: black;">queue</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">try</span>:
                url    = <span style="color: #483d8b;">&quot;http://www.xkcd.com/%s/&quot;</span> <span style="color: #66cc66;">%</span> comic_id
                source = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                image  = <span style="color: #008000;">self</span>.<span style="color: black;">retrieve_image_url</span><span style="color: black;">&#40;</span>source<span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">download_image</span><span style="color: black;">&#40;</span>image, comic_id<span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;downloading image: %s&quot;</span> <span style="color: #66cc66;">%</span> comic_id
            <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">Exception</span>, error:
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;image cannot be retrived for this id: %s&quot;</span> <span style="color: #66cc66;">%</span> comic_id
&nbsp;
            <span style="color: #808080; font-style: italic;"># birinci belli, ikinci kim?</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">queue</span>.<span style="color: black;">task_done</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> retrieve_image_url<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, source<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            reply = <span style="color: #dc143c;">re</span>.<span style="color: black;">findall</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;(http://imgs.xkcd.com/.*)&lt;/h3&gt;&quot;</span>, source<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span>:
            <span style="color: #ff7700;font-weight:bold;">print</span> error
            reply = <span style="color: #483d8b;">&quot;&quot;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">return</span> reply
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> __get_extension<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, image_url<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">findall</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>[a-z]{3,4}$&quot;</span>, image_url<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> __control_download_path<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">isdir</span><span style="color: black;">&#40;</span>XKCD.<span style="color: black;">DOWNLOAD_DIR</span><span style="color: black;">&#41;</span>:
            <span style="color: #dc143c;">os</span>.<span style="color: black;">mkdir</span><span style="color: black;">&#40;</span>XKCD.<span style="color: black;">DOWNLOAD_DIR</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> download_image<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, comic_url, comic_id<span style="color: black;">&#41;</span>:
        extension     = <span style="color: #008000;">self</span>.__get_extension<span style="color: black;">&#40;</span>comic_url<span style="color: black;">&#41;</span>
        image_content = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>comic_url<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        fp = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s/%s%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>XKCD.<span style="color: black;">DOWNLOAD_DIR</span>, comic_id, extension<span style="color: black;">&#41;</span>, <span style="color: #483d8b;">'wb'</span><span style="color: black;">&#41;</span>
        fp.<span style="color: black;">write</span><span style="color: black;">&#40;</span>image_content<span style="color: black;">&#41;</span>
        fp.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
queue = <span style="color: #dc143c;">Queue</span>.<span style="color: #dc143c;">Queue</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> XKCD<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
&nbsp;
    THREAD_COUNT = <span style="color: #ff4500;">10</span>
    COMIC_RANGE  = <span style="color: #ff4500;">732</span>
    DOWNLOAD_DIR = <span style="color: #483d8b;">'images'</span>   
&nbsp;
    @<span style="color: #008000;">staticmethod</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> fetch<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># thread'leri olustur, ve siraya diz</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>XKCD.<span style="color: black;">THREAD_COUNT</span><span style="color: black;">&#41;</span>:
            new_thread = Fetcher<span style="color: black;">&#40;</span>queue<span style="color: black;">&#41;</span>
            new_thread.<span style="color: black;">setDaemon</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
            new_thread.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># siradaki islere veriyi daya</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, XKCD.<span style="color: black;">COMIC_RANGE</span><span style="color: black;">&#41;</span>:
            queue.<span style="color: black;">put</span><span style="color: black;">&#40;</span>item<span style="color: black;">&#41;</span>
&nbsp;
        queue.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
XKCD.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.darkbrown.org/xkcd-arsivi-python-threading/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>new project is on the way!</title>
		<link>http://www.darkbrown.org/new-project-is-on-the-way/</link>
		<comments>http://www.darkbrown.org/new-project-is-on-the-way/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 08:39:13 +0000</pubDate>
		<dc:creator>Emre Yılmaz</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.darkbrown.org/?p=88</guid>
		<description><![CDATA[bir süredir işten arta kalan vakitlerde serdar ile birlikte geliştirdiğimiz proje iyice şekillenmeye başladı.]]></description>
			<content:encoded><![CDATA[<p>bir süredir işten arta kalan vakitlerde <a href="http://www.kokulusilgi.com/">serdar</a> ile birlikte geliştirdiğimiz proje iyice şekillenmeye başladı.</p>
<p><a href="http://www.darkbrown.org/wp-content/uploads/2010/04/Screenshot-2.png"><img src="http://www.darkbrown.org/wp-content/uploads/2010/04/Screenshot-2-300x168.png" alt="" title="gedit-django" width="300" height="168" class="aligncenter size-medium wp-image-89" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.darkbrown.org/new-project-is-on-the-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>minik bir django projesi: 500t.org</title>
		<link>http://www.darkbrown.org/500t-org/</link>
		<comments>http://www.darkbrown.org/500t-org/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 18:11:01 +0000</pubDate>
		<dc:creator>Emre Yılmaz</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[500t]]></category>
		<category><![CDATA[ciptis kurtis]]></category>

		<guid isPermaLink="false">http://www.darkbrown.org/?p=81</guid>
		<description><![CDATA[kaynak kodlarını indirmek için buraya, ne olduğuna dair bilgi almak için buraya tıklıyoruz.]]></description>
			<content:encoded><![CDATA[<p>kaynak kodlarını indirmek için <a href="http://500t.org/media/500t.tar.gz">buraya</a>,  ne olduğuna dair bilgi almak için <a href="http://www.500t.org/hakkinda/">buraya</a> tıklıyoruz.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.darkbrown.org/500t-org/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;güvenliksiz&#8221; güvenlik kodu</title>
		<link>http://www.darkbrown.org/guvenliksiz-guvenlik-kodu/</link>
		<comments>http://www.darkbrown.org/guvenliksiz-guvenlik-kodu/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 13:56:09 +0000</pubDate>
		<dc:creator>Emre Yılmaz</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[ajax fancy captcha]]></category>

		<guid isPermaLink="false">http://www.darkbrown.org/?p=73</guid>
		<description><![CDATA[jquery için ajax-fancy-captcha diye bir eklenti yazılmış. ilgili eklentiden şu siteden haberdar oldum. eklentinin kendi sitesinde ise 122 adet yorum mevcut. google kayıtları coşmuş, ama ilgili eklentinin güvenliğiyle alakalı bir şey bulamadım. halbuki, ilginç derecede basit ve &#8220;aşılabilir&#8221; bir mantığı var kodun. aşağıdaki kod da &#8220;aşılabilir&#8221; kısmını aşıyor &#60;?php &#160; /* * emre &#34;uic&#34; yilmaz [...]]]></description>
			<content:encoded><![CDATA[<p>jquery için ajax-fancy-captcha diye bir eklenti yazılmış. ilgili eklentiden <a href="http://www.serpito.com/php-ajax-fancy-captcha-uygulamasi/">şu siteden</a> haberdar oldum. eklentinin kendi sitesinde ise 122 adet yorum <a href="http://www.serpito.com/projects/ajax-fancy-captcha-php/">mevcut</a>. google kayıtları coşmuş, ama ilgili eklentinin güvenliğiyle alakalı bir şey bulamadım. halbuki, ilginç derecede <strong>basit</strong> ve &#8220;aşılabilir&#8221; bir mantığı var kodun. </p>
<p>aşağıdaki kod da &#8220;aşılabilir&#8221; kısmını aşıyor <img src='http://www.darkbrown.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-73"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* 
 * emre &quot;uic&quot; yilmaz - emre@darkbrown.org
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Request <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cookieFile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cookie_file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cookieFile</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> POST<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postData</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$postData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_set_usual_settings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> GET<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #339933;">,</span> CURLOPT_HTTPGET<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_set_usual_settings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _handle_cookie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #339933;">,</span> CURLOPT_COOKIEJAR<span style="color: #339933;">,</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cookie_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #339933;">,</span> CURLOPT_COOKIEFILE<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cookie_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _set_usual_settings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_handle_cookie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$reply</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$reply</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Request<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/home/emre/public_html/cookies.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$value</span>    <span style="color: #339933;">=</span>  <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GET</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://url/captcha/captcha.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">POST</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">&quot;http://url/captcha/captcha.php&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;captcha=<span style="color: #009933; font-weight: bold;">%s</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.darkbrown.org/guvenliksiz-guvenlik-kodu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>django versus mysql: karakter seti problemleri</title>
		<link>http://www.darkbrown.org/django-versus-mysql-karakter-seti-problemleri/</link>
		<comments>http://www.darkbrown.org/django-versus-mysql-karakter-seti-problemleri/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 09:55:21 +0000</pubDate>
		<dc:creator>Emre Yılmaz</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[it's not a design decision dude it is bullshit]]></category>
		<category><![CDATA[mysql default charset]]></category>

		<guid isPermaLink="false">http://www.darkbrown.org/?p=65</guid>
		<description><![CDATA[bildiğiniz üzere mysql varsayılan olarak &#8220;latin1_swedish_ci&#8221; karakter setiyle geliyor. django ise, her yerde &#8211; hemen hemen her yerde değil, her yerde- unicode kullanıyor. modellerinizi yazdıktan sonra &#8220;python manage.py syncdb&#8221; yapıp, tablolar yaratıldıktan sonra &#8220;süper kullanıcı&#8221; girmek isterseniz, standart bir mySQL kurulumunda (ubuntu gnu/linux) aşağıdaki hatayı alıyorsunuz: ... Warning: Incorrect string value: '\xC4\xB1nc\xC4\xB1...' for column 'name' [...]]]></description>
			<content:encoded><![CDATA[<p>bildiğiniz üzere mysql varsayılan olarak &#8220;latin1_swedish_ci&#8221; karakter setiyle geliyor. django ise, her yerde &#8211; hemen hemen her yerde değil, her yerde- unicode kullanıyor.</p>
<p>modellerinizi yazdıktan sonra &#8220;python manage.py syncdb&#8221; yapıp, tablolar yaratıldıktan sonra &#8220;süper kullanıcı&#8221; girmek isterseniz, standart bir mySQL kurulumunda (ubuntu gnu/linux) aşağıdaki hatayı alıyorsunuz:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">...
<span style="color: #008000;">Warning</span>: Incorrect <span style="color: #dc143c;">string</span> value: <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>C4<span style="color: #000099; font-weight: bold;">\x</span>B1nc<span style="color: #000099; font-weight: bold;">\x</span>C4<span style="color: #000099; font-weight: bold;">\x</span>B1...'</span> <span style="color: #ff7700;font-weight:bold;">for</span> column <span style="color: #483d8b;">'name'</span> at row <span style="color: #ff4500;">1</span></pre></div></div>

<p>django, her şeyi her yerde unicode kullanmasına rağmen, mysql&#8217;de tabloları yaratırken karakter seti olarak utf8_*_ci belirtmiyor. hatta belirtmek de istemiyor <a href="http://code.djangoproject.com/ticket/952#comment:61">buradaki</a> hata girdisinde görebileceğiniz üzere. O kısım, mysql sunucunun standart ayarlarıyla çalışıyor. (Django&#8217;nun <em>&#8220;it is not a bug, it is a feature!&#8221;</em> anlayışını sorgulamaya başladım son zamanlarda.)</p>
<p>her neyse, sorunun çözümü basit. mysql sunucusunu standart olarak utf8 ile çalışacak şekilde ayarlamanız gerekiyor. ubuntu için (ve bir çok linux dağıtımı için) root yetkileriyle aşağıdaki yolu takip edebilirsiniz:</p>
<p>/etc/mysql/conf.d/ dizini içine <strong>charset.cnf</strong> şeklinde bir dosya açın ve içine aşağıdakileri girin ve kaydedin.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#91;</span>mysqld<span style="color: black;">&#93;</span>
default-character-<span style="color: #008000;">set</span>=utf8
default-collation=utf8_general_ci
character-set-server=utf8
collation-server=utf8_general_ci
init_connect=’SET collation_connection = utf8_general_ci’
init_connect=’SET NAMES utf8′
skip-character-set-client-handshake</pre></div></div>

<p><strong>uyarı: </strong> uzattığınız dosyanın uzantısı kesinlikle .cnf olmaılıdır. mysql, sadece .cnf uzantılı dosyaları dikkate alıyor.</p>
<p>mysql sunucusunu yeniden başlatın:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">/etc/init.<span style="color: black;">d</span>/mysql restart</pre></div></div>

<p>sorun kalmayacaktır <img src='http://www.darkbrown.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.darkbrown.org/django-versus-mysql-karakter-seti-problemleri/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>django için &#8220;gerçek&#8221; @login_required dekoratörü</title>
		<link>http://www.darkbrown.org/django-icin-gercek-login_required-dekoratoru/</link>
		<comments>http://www.darkbrown.org/django-icin-gercek-login_required-dekoratoru/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 10:15:41 +0000</pubDate>
		<dc:creator>Emre Yılmaz</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[django auth]]></category>
		<category><![CDATA[it's not a design decision dude it is bullshit]]></category>

		<guid isPermaLink="false">http://www.darkbrown.org/?p=51</guid>
		<description><![CDATA[django-developers ve django-users mail listelerini takip ediyorum. Django ile uygulama geliştirmeye meraklı arkadaşlara da tavsiye ederim. geçenlerde gördüğüm şu thread ise dikkat çekici. django auth bünyesinde ufak bir decorator barındırıyor. view dosyalarınızın başına koyduğunuz @login_required ile o kısma sadece sisteme giriş yapmış kullanıcıların girebilmesini basitçe sağlıyorsunuz. Django&#8217;nun auth modülünün tasarımında kullanıcı pasif durumda olsa bile, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://groups.google.com/group/django-developers">django-developers</a> ve <a href="http://groups.google.com/group/django-users">django-users</a> mail listelerini takip ediyorum. Django ile uygulama geliştirmeye meraklı arkadaşlara da tavsiye ederim. geçenlerde gördüğüm şu <a href="http://groups.google.com/group/django-developers/browse_thread/thread/c0ec6dab1b0e293c/0de1362c802385c0?lnk=gst&#038;q=login_required#0de1362c802385c0">thread</a> ise dikkat çekici.</p>
<p>django auth bünyesinde ufak bir decorator barındırıyor. view dosyalarınızın başına koyduğunuz @login_required ile o kısma sadece sisteme giriş yapmış kullanıcıların girebilmesini basitçe sağlıyorsunuz. Django&#8217;nun auth modülünün tasarımında kullanıcı pasif durumda olsa bile, authenticated (yetkilendirilmiş) sayılıyor. ilgili dekoratörümüz login_required ise gerekli kontrolü yaparken is_authenticated() değerine bakıyor. </p>
<p>sorun şu ki, pasif bir kullanıcı giriş yapmaya çalıştığında <strong>hesap bilgilerini doğru girerse</strong> is_authenticated() <strong>True</strong> dönüyor. <strong>is_active</strong> kolonu False dönse de. bu da görmemelere gereken sayfaları görebiliyor, yapamamaları gereken işlemleri yapabiliyor olmaları demek.</p>
<p>işin kısası, pasif kullanıcılarınız pek de pasif değiller eğer login_required dekoratörüne güvendiyseniz. aşağıda kendi projem için yazmış olduğum decorator var, projeniz içinde herhangi bir yere gömüp view fonksiyonlarınızdan önce <strong>@activeMemberOnly</strong> şeklinde kullanabilirsiniz.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span> <span style="color: #ff7700;font-weight:bold;">import</span> REDIRECT_FIELD_NAME
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span>.<span style="color: black;">decorators</span> <span style="color: #ff7700;font-weight:bold;">import</span> user_passes_test
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> activeMemberOnly<span style="color: black;">&#40;</span>function=<span style="color: #008000;">None</span>, redirect_field_name=REDIRECT_FIELD_NAME<span style="color: black;">&#41;</span>:
    actual_decorator = user_passes_test<span style="color: black;">&#40;</span>
        <span style="color: #ff7700;font-weight:bold;">lambda</span> u: u.<span style="color: black;">is_authenticated</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">and</span> u.<span style="color: black;">is_active</span>,
        redirect_field_name=redirect_field_name
    <span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> function:
        <span style="color: #ff7700;font-weight:bold;">return</span> actual_decorator<span style="color: black;">&#40;</span>function<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> actual_decorator</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.darkbrown.org/django-icin-gercek-login_required-dekoratoru/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ubuntu 9.10 için sphinx kurulumu</title>
		<link>http://www.darkbrown.org/ubuntu-9-10-icin-sphinx-kurulumu/</link>
		<comments>http://www.darkbrown.org/ubuntu-9-10-icin-sphinx-kurulumu/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 11:50:45 +0000</pubDate>
		<dc:creator>Emre Yılmaz</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[installation for dummies]]></category>
		<category><![CDATA[sphinx]]></category>

		<guid isPermaLink="false">http://www.darkbrown.org/?p=40</guid>
		<description><![CDATA[yeni projemiz için sphinx full text arama motorunu kullanmayı planlıyorum. Solr ile geçirdiğimiz güzel günler söz konusu olsa da, arama işi için ayrı bir server ayakta tutmak ve bununla HTTP üzerinden iletişime geçmek, türkçe karakter problemleriyle uğraşmak yerine sphinx&#8217;i incelemeye aldım. (memnun kalmazsam sırada xapian var.) ilginçtir ki sphinx&#8217;in ubuntu ya da başka bir dağıtım [...]]]></description>
			<content:encoded><![CDATA[<p>yeni projemiz için <a href="http://www.sphinxsearch.com/">sphinx</a> full text arama motorunu kullanmayı planlıyorum. Solr ile geçirdiğimiz güzel günler söz konusu olsa da, arama işi için ayrı bir server ayakta tutmak ve bununla HTTP üzerinden iletişime geçmek, türkçe karakter problemleriyle uğraşmak yerine sphinx&#8217;i incelemeye aldım. (memnun kalmazsam sırada <a href="http://xapian.org/">xapian</a> var.)</p>
<p>ilginçtir ki sphinx&#8217;in ubuntu ya da başka bir dağıtım için paketi yok. kendiniz derlemeniz gerekiyor. güncel bir ubuntu&#8217;da aşağıdaki adımlarla sphinx&#8217;i başarılı bir şekilde kurabilirsiniz.</p>
<p>ilk önce mysql-devel paketlerini kurmak gerekiyor. (bunlar yüzünden biraz zaman kaybettim kurulumda..)</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">sudo apt-get install libmysqld-dev libmysqlclient-dev</pre></div></div>

<p>bu aşamadan sonra sphinx&#8217;i <a href="http://www.sphinxsearch.com/downloads.html">indirip</a>, arşivi açtıktan sonra sırasıyla aşağıdaki komutları verin:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">./configure --with-prefix=/usr/local/sphinx
make
sudo make install</pre></div></div>

<p>işlemler bittikten sonra konsolda search yazarsanız şöyle bir ekran sizi karşılayacaktır:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">root@yunusemre-desktop:/home/yunusemre/Desktop/sphinx-0.9.9<span style="color: #808080; font-style: italic;"># search</span>
Sphinx 0.9.9-release <span style="color: black;">&#40;</span>r2117<span style="color: black;">&#41;</span></pre></div></div>

<p>her şey sorunsuz bittiyse gönül rahatlığıyla sphinx <a href="http://www.sphinxsearch.com/docs/current.html">dökümantasyonuna</a> atlayabilirsiniz <img src='http://www.darkbrown.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.darkbrown.org/ubuntu-9-10-icin-sphinx-kurulumu/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>writing view decorators in django</title>
		<link>http://www.darkbrown.org/writing-view-decorators-in-django/</link>
		<comments>http://www.darkbrown.org/writing-view-decorators-in-django/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 21:59:25 +0000</pubDate>
		<dc:creator>Emre Yılmaz</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[decorators]]></category>
		<category><![CDATA[django decorators]]></category>

		<guid isPermaLink="false">http://www.darkbrown.org/?p=12</guid>
		<description><![CDATA[what the heck is decorators decorators are the funniest part of python. decorators allow you to execute your additional code at the entry and exit points of a function or a class with a clear syntax. it is very handy when you need to do locking, logging, tracking, caching etc. with your function. decorators on [...]]]></description>
			<content:encoded><![CDATA[<h4>what the heck is decorators</h4>
<p>decorators are the funniest part of python. decorators allow you to execute your additional code at the entry and exit points of a function or a class with a clear syntax. it is very handy when you need to do locking, logging, tracking, caching etc. with your function.</p>
<h4>decorators on air</h4>
<p>that is the simplest usage of decorators in python.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> sayWelcome<span style="color: black;">&#40;</span>originalFunction<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> decorated<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
         <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;welcome, my bloody sexy function&quot;</span><span style="color: black;">&#41;</span>
         originalFunction<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> decorated
&nbsp;
@sayWelcome
<span style="color: #ff7700;font-weight:bold;">def</span> myfunction<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hi, i am the one who will be decorated&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
myfunction<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>it&#8217;s output will be:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">emre@amy:~$ python <span style="color: #dc143c;">test</span>.<span style="color: black;">py</span>
welcome, my bloody sexy function
hi, i am the one who will be decorated
emre@amy:~$</pre></div></div>

<p> you can check out some details in <a href="http://pythonconquerstheuniverse.wordpress.com/2009/08/06/introduction-to-python-decorators-part-1/">here</a>.</p>
<h4>applying it to your django project</h4>
<p>if you ever used django auth, you must be aware of bundled decorators in django like <em>@authentication_required</em>, <em>@permission_required</em>.</p>
<p>let&#8217;s write a &#8220;@limited_access&#8221; decorator for django auth. If you don&#8217;t wanna deal with user groups/permissions this is for you. This allows you to point views for the users you selected.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><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> HttpResponseRedirect
<span style="color: #ff7700;font-weight:bold;">class</span> limited_access<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, user_list<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">user_list</span> = user_list
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__call__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, view_function<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">def</span> wrapped_function<span style="color: black;">&#40;</span>request, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> request.<span style="color: #dc143c;">user</span>.<span style="color: black;">username</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">user_list</span>:
                <span style="color: #808080; font-style: italic;"># user is not in access_list, so redirect him/her</span>
                <span style="color: #ff7700;font-weight:bold;">return</span> HttpResponseRedirect<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://noaccess.yoursite.com&quot;</span><span style="color: black;">&#41;</span> 
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span> view_function<span style="color: black;">&#40;</span>request, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> wrapped_function</pre></div></div>

<p>use this in views like this;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@limited_access<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;emre&quot;</span>, <span style="color: #483d8b;">&quot;mary&quot;</span>,<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> test_view<span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> HttpResponse<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;this view is just for emre and mary.&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>any suggestions and comments are wellcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.darkbrown.org/writing-view-decorators-in-django/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
