<br><br><div class="gmail_quote">On Tue, Mar 2, 2010 at 3:00 PM, Fred C <span dir="ltr">&lt;<a href="mailto:fred@bsdhost.net">fred@bsdhost.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="word-wrap: break-word;"><br><div><div><div></div><div class="h5"><div>On Mar 2, 2010, at 12:45 PM, Kevin Horn wrote:</div><br><blockquote type="cite"><div class="gmail_quote">On Tue, Mar 2, 2010 at 1:19 PM, Fred C <span dir="ltr">&lt;<a href="mailto:fred@bsdhost.net" target="_blank">fred@bsdhost.net</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hello,<br>
<br>
I am totally new with Twisted and this the first code I have ever written using that package. One of my main problem was to figure out how to fit things together and I am not even sure I understand everything I am doing here.<br>


<br>
Anyway, for a project I have to write a proxy that figure out where is located a resource by requesting a database. then figure out if the resource is accessible and them open a proxy connection to download that resource.<br>


<br>
I was wandering if there is someone in that mailing list who can review that code and tell me how I can improve things. I know I am not accessing the database the right way but I can&#39;t figure out how to work with the Callbacks.<br>


<br>
Any help or advice will be very much appreciated. The code is available here: <a href="http://pastebin.com/BGcqzh4Y" target="_blank">http://pastebin.com/BGcqzh4Y</a><br>
<br>
-fred-<br>
<font color="#888888"></font><br></blockquote></div><br>I don&#39;t really use Twisted for web work, so I don&#39;t have much of a comment on that, but for database access you probably want to use `twisted.enterprise.adbapi`.<br>
</blockquote><div><br></div><div><br></div></div></div><div>That was of the thing I know it&#39;s wrong with my code. I have to use adbapi and have a call back to get the result from the database. My main problem in that case is I don&#39;t know how to have the caller wait for the response from the database.</div>
<div><br></div><div>Thanks for taking time to look at that code and for your reply.</div><div><br></div><div>-fred-</div></div><div>
<span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: &#39;Trebuchet MS&#39;; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: &#39;Trebuchet MS&#39;; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div style="word-wrap: break-word;">
<span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Verdana; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div style="word-wrap: break-word;">
<span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Verdana; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div style="word-wrap: break-word;">
<span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Verdana; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div style="word-wrap: break-word;">
<div><font face="&#39;Trebuchet MS&#39;"><font size="3" face="Courier"><span style="font-size: 12px; line-height: 15px;"><span style="font-family: monospace; font-size: medium; line-height: normal;"><a href="http://kiq.me/oi" target="_blank">http://kiq.me/oi</a><br>
</span></span></font></font></div><div><font face="monospace"><br></font></div></div></span></div></span></div></span></div></span></span></div></div><br></blockquote></div><br>Have a look at: <a href="http://twistedsphinx.funsize.net/projects/core/howto/rdbms.html#how-do-i-use-adbapi">http://twistedsphinx.funsize.net/projects/core/howto/rdbms.html#how-do-i-use-adbapi</a><br>
<br>Basically, when you call runQuery, you get back a deferred object.  You&#39;ll want to add a callback to that using something like:<br><br>def get_stuff_from_db():<br>    d = dbpool.runQuery(&#39;Your SQL Here&#39;)<br>
    d.addCallback(your_callback_function)<br><br>def your_callback_function(results):<br>    # do some stuff with your results<br><br>so when the DB query completes, your_callback_function will get called automatically by the deferred object.<br>
<br>Obviously this is very rough, probably incorrect code, but hopefully it&#39;s enough to get you started.<br><br>Kevin Horn<br>