<br><br>Sent from my HTC on the Now Network from Sprint!<br><br>----- Reply message -----<br>From: twisted-python-request@twistedmatrix.com<br>Date: Fri, Sep 10, 2010 12:09 pm<br>Subject: Twisted-Python Digest, Vol 78, Issue 15<br>To: &lt;twisted-python@twistedmatrix.com&gt;<br><br>Send Twisted-Python mailing list submissions to<br>        twisted-python@twistedmatrix.com<br><br>To subscribe or unsubscribe via the World Wide Web, visit<br>        <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>or, via email, send a message with subject or body &#39;help&#39; to<br>        twisted-python-request@twistedmatrix.com<br><br>You can reach the person managing the list at<br>        twisted-python-owner@twistedmatrix.com<br><br>When replying, please edit your Subject line so it is more specific<br>than &quot;Re: Contents of Twisted-Python digest...&quot;<br><br><br>Today&#39;s Topics:<br><br> &nbsp; 1. Re: Strange error: SQL-Server tries to rollback (Paul Goins)<br> &nbsp; 2. reactor for both udp and tcp/ timer issue (belk Dj)<br> &nbsp; 3. Re: twisted cred: why does avatarId need to be a        str?<br> &nbsp; &nbsp; &nbsp;(Laurens Van Houtven)<br> &nbsp; 4. Re: reactor for both udp and tcp/ timer issue<br> &nbsp; &nbsp; &nbsp;(Pantelis Theodosiou)<br><br><br>----------------------------------------------------------------------<br><br>Message: 1<br>Date: Sat, 11 Sep 2010 01:39:13 +0900<br>From: Paul Goins &lt;general@vultaire.net&gt;<br>Subject: Re: [Twisted-Python] Strange error: SQL-Server tries to<br>        rollback<br>To: twisted-python@twistedmatrix.com<br>Message-ID: &lt;4C8A5F31.8020305@vultaire.net&gt;<br>Content-Type: text/plain; charset=UTF-8; format=flowed<br><br>Thanks for the code example.<br><br>I can&#39;t offer to take this work over, but maybe I can make a comment. <br>There&#39;s one part that stands out to me.<br><br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try:<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deferred = self.dbpool.runOperation(sql)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#print(&quot;DATA sent&quot;)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;except Exception as e:<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print(&quot;error in insertDATA&quot;)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print(e)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return deferred<br><br>It seems like maybe you have a misunderstanding about how Deferreds <br>generally work in Twisted. &nbsp;(Been there myself.) &nbsp;Basically, the above <br>try/except block won&#39;t work to catch errors from most Deferreds... well, <br>at least not without some extra magic.<br><br>You really should read the Deferred section of the Twisted documentation <br>to understand how errors are handled.<br><br>Docs are here: <br><a href="http://twistedmatrix.com/documents/current/core/howto/defer.html">http://twistedmatrix.com/documents/current/core/howto/defer.html</a><br><br>----<br><br>Basically, to &quot;fix&quot; the above code&#39;s error catching, you have two choices:<br><br>1. You can add an errback to the deferred. &nbsp;This is the &quot;standard&quot; <br>Twisted way, and would replace the try/except block entirely.<br><br>2. You can use the @inlineCallbacks decorator (from <br>twisted.internet.defer), and yield on the Deferred. &nbsp;This is easier, and <br>it allows try/except blocks, but there&#39;s some gotchas.<br><br>inlineCallbacks is what I used when I was learning Twisted, and you may <br>want to try that for now. &nbsp;But please understand that it hides details <br>about how Deferreds and callbacks really work. &nbsp;When you find time, read <br>the Deferred docs.<br><br>----<br><br>Best of luck,<br><br>- Paul Goins<br><br><br><br>------------------------------<br><br>Message: 2<br>Date: Fri, 10 Sep 2010 16:55:01 +0000 (GMT)<br>From: belk Dj &lt;d_belkhiter@yahoo.fr&gt;<br>Subject: [Twisted-Python] reactor for both udp and tcp/ timer issue<br>To: twisted-python@twistedmatrix.com<br>Message-ID: &lt;228404.72208.qm@web24406.mail.ird.yahoo.com&gt;<br>Content-Type: text/plain; charset=&quot;utf-8&quot;<br><br>I need to communicate with servers over tcp and also communicate with other servers over udp.<br>It seems not possible to launch two reactor objects one for tcp and one for udp.<br>The code after a reactor.run is not called.<br>How can this can be solved ?<br><br>One more thing that deals with timer.<br>When i send a message to a server if after some time i don&#39;t get an acknowledge i re send the message. <br>And that x times.<br>To do that i use Timer. When i send the message i start the timer if the acknowledge comes before the timeout i cancel the timer.<br>If i don&#39;t receive this acknwledge in time i cancel the timer i re send the previous message and i re start the timer.<br><br>In this two cases the program fails with the message the timer is still started.<br>What is the issue ? <br><br>Regards<br><br><br> &nbsp; &nbsp; &nbsp;<br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <a href="http://twistedmatrix.com/pipermail/twisted-python/attachments/20100910/2b939a7f/attachment-0001.htm">http://twistedmatrix.com/pipermail/twisted-python/attachments/20100910/2b939a7f/attachment-0001.htm</a> <br><br>------------------------------<br><br>Message: 3<br>Date: Fri, 10 Sep 2010 19:01:41 +0200<br>From: Laurens Van Houtven &lt;lvh@laurensvh.be&gt;<br>Subject: Re: [Twisted-Python] twisted cred: why does avatarId need to<br>        be a        str?<br>To: Twisted general discussion &lt;twisted-python@twistedmatrix.com&gt;<br>Message-ID:<br>        &lt;AANLkTimugXx6Fp588+MPyGc8Ws31S316W8Mbg=i9dQ-3@mail.gmail.com&gt;<br>Content-Type: text/plain; charset=&quot;utf-8&quot;<br><br>I&#39;ll give a very practical example of an example request + response, because<br>I&#39;m not entirely sure I communicated that properly. The code we&#39;re<br>discussing is part of a TokenEndpoint, which is an IResource. Something (a<br>client, in OAuth terminology) makes a request that looks like this:<br><br>---<br>POST /token HTTP/1.1<br>Host: server.example.com<br>Content-Type: application/x-www-form-urlencoded<br><br>grant_type=password&amp;client_id=s6BhdRkqt3&amp;client_secret=47HDu8s&amp;username=johndoe&amp;password=A3ddj3w<br>---<br><br>And hopefully the code we&#39;re discussing answers with a request that looks<br>like this:<br><br>---<br>HTTP/1.1 200 OK<br>Content-Type: application/json<br>Cache-Control: no-store<br><br>{<br>&quot;access_token&quot;:&quot;SlAV32hkKG&quot;,<br>&quot;expires_in&quot;:3600,<br> &quot;refresh_token&quot;:&quot;8xLOxBtZp8&quot;<br>&quot;scope&quot;: &quot;tummies cookies parrots&quot;<br>}<br>---<br><br>Where, as mentioned before, everything besides &quot;access_token&quot; is not always<br>required (but it must be possible to set them, because occasionally they are<br>required).<br><br>On Fri, Sep 10, 2010 at 2:34 AM, Glyph Lefkowitz &lt;glyph@twistedmatrix.com&gt;wrote:<br><br>&gt; for any given cred implementation, there are two key questions:<br>&gt;<br>&gt; &nbsp; &nbsp;1. What is the avatar interface?<br>&gt; &nbsp; &nbsp;2. What is the associated mind interface?<br>&gt;<br>&gt; If we&#39;re not talking about a system where the avatar interface (the one<br>&gt; passed to &#39;login&#39;, the one that the realm must return something that gets<br>&gt; implemented) is IResource, then that&#39;s the problem. &nbsp;What *is* that<br>&gt; interface that you&#39;re talking about? &nbsp;Be very specific: what methods does it<br>&gt; have and why?<br>&gt;<br><br>Okay, to be specific: I believe the appropriate interface is IResource. This<br>is in line with t.web&#39;s general way of interacting with cred: you give me<br>credentials, I give you a protected IResource.<br><br><br>&gt; It sounds like OAuth is very precisely implementing something that maps<br>&gt; almost exactly onto the *checker* part of cred, but you&#39;re doing it by<br>&gt; implementing a realm to allow applications to provide their own logic. &nbsp;This<br>&gt; might not be the wrong idea, but it needs to be spelled out very clearly.<br>&gt;<br><br>Doing everything in the checker probably might make more sense. The reason I<br>originally thought to do this in the IRealm is that I figured credentials<br>checkers should just check credentials, and creating a new credential (the<br>access token) wasn&#39;t part of ICredentialsChecker&#39;s job (more like IRealm&#39;s<br>job). Apparently I was mistaken.<br><br><br>&gt; As you describe it:<br>&gt;<br>&gt; token endpoints let you trade in some credentials that prove you&#39;re<br>&gt; supposed to have access for a token that actually *gives* you that access<br>&gt;<br>&gt; In cred-ese, that would be &quot;checkers let you trade in some credentials that<br>&gt; prove you&#39;re supposed to have access for an &lt;avatar ID, which you give to a<br>&gt; Realm&gt; that actually *gives* you that access&quot;. &nbsp;As far as the OAuth response<br>&gt; is concerned, it&#39;s like a checker. &nbsp;Looking at the individual parts,<br>&gt; assuming that the avatar interface for the purposes of this discussion is<br>&gt; IResource, it breaks down like this in my mind:<br>&gt;<br>&gt; &nbsp; &nbsp; - the access token (an ascii string, mandatory)<br>&gt;<br>&gt; Avatar ID. &nbsp;(See, it&#39;s a str!)<br>&gt;<br><br>Heh, okay; as long as there&#39;s a plausible way to get the other important<br>information (see rest of email) into the HTTP response, I&#39;ll believe you.<br><br>&gt; &nbsp; &nbsp; - the expiration time (optional)<br>&gt;<br>&gt; Implementation detail of the session. &nbsp;Avatars are actually sessions, which<br>&gt; expire: sometimes (as with POP) at the end of a connection, sometimes (as<br>&gt; with nevow.guard&#39;s HTTP support) with a session timeout.<br>&gt;<br><br>Right, but:<br>a) The avatar needs to know about this timeout, since the timeout<br>information needs to be able to make it into the HTTP response.<br>b) The expiration time is only known to the thing that creates the access<br>token (obviously). From the previous discussion, this is apparently<br>ICredentialsChecker.<br><br>c) (From (a, b)) The ICredentialsChecker needs to be able to communicate the<br>expiration to the avatar.<br>d) The ICredentialsChecker and IRealm can only communicate through the<br>avatarId.<br><br>Conclusion (from c,d): The expiration time needs to be in the avatarId?<br><br>&gt; &nbsp; &nbsp; - the refresh token (another ascii string, similar to the access token,<br>&gt; optional)<br>&gt;<br>&gt;<br>&gt; Implementation detail of the authentication protocol. &nbsp;The client library<br>&gt; and server library should be transparently refreshing this without telling<br>&gt; either the client application code or server application code, right?<br>&gt;<br><br>Sure, but we&#39;re still writing library code here.<br><br>If the avatar interface isn&#39;t actually IResource, but a new interface<br>IAccessToken, getting the refresh token later might be feasible. (It should<br>be a different interface, because in order to create a refresh token outside<br>of this entire cred cycle, I need to know about the thing it&#39;s refreshing --<br>so, the information in the response needs to be easily accessible and not<br>just an opaque IResource).<br><br>I agree entirely that clever client library code would abstract this mess<br>away from application code. However, right now this code still needs to<br>somehow be able to eventually produce HTTP responses that don&#39;t abstract<br>anything yet and just contain all the appropriate data, because that&#39;s just<br>what the OAuth spec says it needs to be able to do. There isn&#39;t any real<br>application code in the token endpoint; they&#39;re pretty similar for all OAuth<br>setups, and customization would typically happen through implementing the<br>appropriate ICredentialsChecker.<br><br> &nbsp; &nbsp;- scope (an ascii string consisting of a set of space-separated words,<br>&gt; optional)<br>&gt;<br>&gt;<br>&gt; This part doesn&#39;t quite fit, but could be expressed in one of two ways: a<br>&gt; modification to the avatar ID, or as some extra structure on the Mind that<br>&gt; modifies what functionality the Realm bundles in to your avatar<br>&gt; implementation (without changing the interface provided by that object, of<br>&gt; course).<br>&gt;<br><br>Unfortunately I don&#39;t believe this can be done through the mind. Again<br>working under the previous assumption that ICredentialsChecker and not the<br>IRealm is responsible for creating the access token, and scope is known to<br>the thing that makes the access token, the ICredentialsChecker knows about<br>the scope. Unfortunately the only way to pass stuff &nbsp;between the<br>ICredentialsChecker and the IRealm is the avatar ID, so you don&#39;t have a<br>choice.<br><br><br>thanks for your infinite patience,<br>Laurens<br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <a href="http://twistedmatrix.com/pipermail/twisted-python/attachments/20100910/76080471/attachment-0001.htm">http://twistedmatrix.com/pipermail/twisted-python/attachments/20100910/76080471/attachment-0001.htm</a> <br><br>------------------------------<br><br>Message: 4<br>Date: Fri, 10 Sep 2010 22:09:17 +0300<br>From: Pantelis Theodosiou &lt;ypercube@gmail.com&gt;<br>Subject: Re: [Twisted-Python] reactor for both udp and tcp/ timer<br>        issue<br>To: Twisted general discussion &lt;twisted-python@twistedmatrix.com&gt;<br>Message-ID:<br>        &lt;AANLkTikcuEW-pGSVPy+fs9A2crKmF5HBBrXOymif7N+Z@mail.gmail.com&gt;<br>Content-Type: text/plain; charset=&quot;utf-8&quot;<br><br>On Fri, Sep 10, 2010 at 7:55 PM, belk Dj &lt;d_belkhiter@yahoo.fr&gt; wrote:<br><br>&gt; I need to communicate with servers over tcp and also communicate with other<br>&gt; servers over udp.<br>&gt; It seems not possible to launch two reactor objects one for tcp and one for<br>&gt; udp.<br>&gt; The code after a reactor.run is not called.<br>&gt; How can this can be solved ?<br>&gt;<br>&gt;<br>I&#39;m not an expert in any way, but I&#39;ve made something similar using 2<br>factories.<br><br>I think that it is also possible with one factory that uses 2 protocols.<br><br>The code after reactor.run() will be invoked only after the reactor stops.<br>So, you can have 2 factories, each with a different protocol (1 tcp, 1 udp)<br>and then start the reactor.<br><br>Pandelis<br><br><br>&gt; One more thing that deals with timer.<br>&gt; When i send a message to a server if after some time i don&#39;t get an<br>&gt; acknowledge i re send the message.<br>&gt; And that x times.<br>&gt; To do that i use Timer. When i send the message i start the timer if the<br>&gt; acknowledge comes before the timeout i cancel the timer.<br>&gt; If i don&#39;t receive this acknwledge in time i cancel the timer i re send the<br>&gt; previous message and i re start the timer.<br>&gt;<br>&gt; In this two cases the program fails with the message the timer is still<br>&gt; started.<br>&gt; What is the issue ?<br>&gt;<br>&gt; Regards<br>&gt;<br>&gt; _______________________________________________<br>&gt; Twisted-Python mailing list<br>&gt; Twisted-Python@twistedmatrix.com<br>&gt; <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>&gt;<br>&gt;<br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <a href="http://twistedmatrix.com/pipermail/twisted-python/attachments/20100910/7848c316/attachment.htm">http://twistedmatrix.com/pipermail/twisted-python/attachments/20100910/7848c316/attachment.htm</a> <br><br>------------------------------<br><br>_______________________________________________<br>Twisted-Python mailing list<br>Twisted-Python@twistedmatrix.com<br><a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br><br><br>End of Twisted-Python Digest, Vol 78, Issue 15<br>**********************************************<br><br><br>