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