Re: serializable object references
En Mon, 23 Apr 2007 03:35:42 -0300, Martin Drautzburg <[EMAIL PROTECTED]> escribió: > Gabriel Genellina wrote: > >> En Sun, 22 Apr 2007 12:47:10 -0300, Martin Drautzburg >> <[EMAIL PROTECTED]> escribió: >> >>> I was thinking that it would be nice if a web application could talk >>> to real objects. The client side does not need to know the internals >>> of an object, it acts as a "view" for server-side models. All it has >>> to be able to do is invoke methods on "its" model. So a view could >>> just store "its" object-reference in an instance variable and pass it >>> to the server, where my problem of looking it up comes in. >> >> This is more or less what several web frameworks do. You publish >> objects; URLs are mapped to method objects; URL parameters become >> method parameters. See http://wiki.python.org/moin/WebFrameworks > > Okay will look. I have checked out cherrypy, but it does not seem to > support direct object references, i.e. the server-side objects are > really stateless and all calls to an object method will see the same > state unless you do something about it youself. The description I wrote above aplies exactly to ZOPE: URLs map exactly to object methods and those objects can (and should) maintain state. (Zope uses an OO database, ZODB, to hold those objects). But Zope is a big framework and not easy to grasp, so I would not recomend it for a small site or web application. Using CherryPy you can keep state across requests, if you use some sort of session machinery; at least you could build a mapping SessionID-State (the state being as complex as you want). I think TurboGears has something built in for managing sessions, but I'm not sure. > I have also looked at the wonderful qooxdoo javascript framework and in > the examples they have, the data I receive on a published object method > on my cherrypy server is: Never used qooxdoo... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: serializable object references
Gabriel Genellina wrote: > En Sun, 22 Apr 2007 12:47:10 -0300, Martin Drautzburg > <[EMAIL PROTECTED]> escribió: > >> I was thinking that it would be nice if a web application could talk >> to real objects. The client side does not need to know the internals >> of an object, it acts as a "view" for server-side models. All it has >> to be able to do is invoke methods on "its" model. So a view could >> just store "its" object-reference in an instance variable and pass it >> to the server, where my problem of looking it up comes in. > > This is more or less what several web frameworks do. You publish > objects; URLs are mapped to method objects; URL parameters become > method parameters. See http://wiki.python.org/moin/WebFrameworks > Okay will look. I have checked out cherrypy, but it does not seem to support direct object references, i.e. the server-side objects are really stateless and all calls to an object method will see the same state unless you do something about it youself. I have also looked at the wonderful qooxdoo javascript framework and in the examples they have, the data I receive on a published object method on my cherrypy server is: dict: { '_ScriptTransport_id': '11', '_ScriptTransport_data': '{ "service":"qooxdoo.test", "method":"sleep", "id":13, "params":["10"], "server_data":null }', 'nocache': '1177256001914' } I am not sure what all of them mean, but my impression is that none of them denote an object in the sense of an INSTANCE, at least "service" and "method" definitely do not. The "id" is simply incremented with every call, so it is again not an instance. Now I could of course add an object reference do the "params" field and have qooxdoo.text dispatch the call to an INSTANCE of an object and invoke sleep() there. But first it is a shame, that I have to provide this magic myself, and second it raises again my original question: how to I pass an object reference and look up the object in qooxdoo.test. I know I can do this with a dictionary, I just thought that the __repr__() of an object could be used, as it seems the most obvious way to do it. -- http://mail.python.org/mailman/listinfo/python-list
Re: serializable object references
En Sun, 22 Apr 2007 12:47:10 -0300, Martin Drautzburg <[EMAIL PROTECTED]> escribió: > I was thinking that it would be nice if a web application could talk to > real objects. The client side does not need to know the internals of an > object, it acts as a "view" for server-side models. All it has to be > able to do is invoke methods on "its" model. So a view could just > store "its" object-reference in an instance variable and pass it to the > server, where my problem of looking it up comes in. This is more or less what several web frameworks do. You publish objects; URLs are mapped to method objects; URL parameters become method parameters. See http://wiki.python.org/moin/WebFrameworks > I am currently learning about web services but my feeling is > that "state" is not an integral part of this concept, rather an add-on, > but I may be mistaken here. > > But for any reasonable web application you have to introduce state one > way or the other. My impression is, that this is achieved with "session > objects", which hold all the state of a session (again I may be > mistaken). But this would be a strange concept in an OO world. You > might as well put "ALL" state into a global "state" state object, where > all the class methods deposit their state and classes would hold > behavior only and no state. This is of course nothing an OO programmer > would want to do. You can have a "persistent" state (stored in a backend database) and "transitory" state (kept in session objects). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: serializable object references
Gabriel Genellina wrote: > En Sun, 22 Apr 2007 08:07:27 -0300, Martin Drautzburg > <[EMAIL PROTECTED]> escribió: > >> Is it possible to convert an object into a string that identifies the >> object in a way, so it can later be looked up by this string. >> Technically this should be possible, because things like >> >> <__main__.Foo instance at 0xb7cfb6ac> >> >> say everything about an object. But how can I look up the real >> object, when I only have this string? >> >> I know such a thing can be achieved with a dictionary that holds >> reference-object pairs. Is there another way? > > Without further information, this would be the way. > What do you want to achieve? Maybe you are looking for the pickle > module. > I was thinking that it would be nice if a web application could talk to real objects. The client side does not need to know the internals of an object, it acts as a "view" for server-side models. All it has to be able to do is invoke methods on "its" model. So a view could just store "its" object-reference in an instance variable and pass it to the server, where my problem of looking it up comes in. I am currently learning about web services but my feeling is that "state" is not an integral part of this concept, rather an add-on, but I may be mistaken here. But for any reasonable web application you have to introduce state one way or the other. My impression is, that this is achieved with "session objects", which hold all the state of a session (again I may be mistaken). But this would be a strange concept in an OO world. You might as well put "ALL" state into a global "state" state object, where all the class methods deposit their state and classes would hold behavior only and no state. This is of course nothing an OO programmer would want to do. -- http://mail.python.org/mailman/listinfo/python-list
Re: serializable object references
On Apr 22, 5:07 am, Martin Drautzburg <[EMAIL PROTECTED]> wrote: > > <__main__.Foo instance at 0xb7cfb6ac> > > But how can I look up the real object, > when I only have this string? > You can't because that identifies the instance with an address, and pointers are not part of the python language. -- http://mail.python.org/mailman/listinfo/python-list
Re: serializable object references
> Is it possible to convert an object into a string that identifies the > object in a way, so it can later be looked up by this string. > Technically this should be possible, because things like > > <__main__.Foo instance at 0xb7cfb6ac> > > say everything about an object. But how can I look up the real object, > when I only have this string? > > I know such a thing can be achieved with a dictionary that holds > reference-object pairs. Is there another way? There is the pickle module for serializing objects into strings: http://docs.python.org/lib/module-pickle.html If you need to store objects and later look them up by some key I would recommend using a database. There are plenty: http://docs.python.org/lib/persistence.html HTH, Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: serializable object references
En Sun, 22 Apr 2007 08:07:27 -0300, Martin Drautzburg <[EMAIL PROTECTED]> escribió: > Is it possible to convert an object into a string that identifies the > object in a way, so it can later be looked up by this string. > Technically this should be possible, because things like > > <__main__.Foo instance at 0xb7cfb6ac> > > say everything about an object. But how can I look up the real object, > when I only have this string? > > I know such a thing can be achieved with a dictionary that holds > reference-object pairs. Is there another way? Without further information, this would be the way. What do you want to achieve? Maybe you are looking for the pickle module. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: serializable object references
Martin Drautzburg wrote: > Is it possible to convert an object into a string that identifies the > object in a way, so it can later be looked up by this string. > Technically this should be possible, because things like > > <__main__.Foo instance at 0xb7cfb6ac> > > say everything about an object. But how can I look up the real object, > when I only have this string? > > I know such a thing can be achieved with a dictionary that holds > reference-object pairs. Is there another way? How about: class Dog(object): def __init__(self, name): self.name = name d = Dog("Spot") print globals()["d"].name -- http://mail.python.org/mailman/listinfo/python-list
serializable object references
Is it possible to convert an object into a string that identifies the object in a way, so it can later be looked up by this string. Technically this should be possible, because things like <__main__.Foo instance at 0xb7cfb6ac> say everything about an object. But how can I look up the real object, when I only have this string? I know such a thing can be achieved with a dictionary that holds reference-object pairs. Is there another way? -- http://mail.python.org/mailman/listinfo/python-list