Is there a tg_format=pickle option ?

3 views
Skip to first unread message

Joshua J. Kugler

unread,
Jan 20, 2007, 7:40:19 PM1/20/07
to turbogea...@googlegroups.com
[OK...let's try this again and see if I get through. I tried posting through
the web interface and through google's SMTP servers (while subscribed via my
Gmail account) and neither post has shown up. I subscribed via my work
address and we'll see if that works.]

I've tried digging through the code (trunk) but finally got lost and couldn't
track down a definitive place where the output is generated. Went back
through controllers.py, util.py, and some others. So, I'm posting. :)

Is there any option to return the data as a python pickle? With a good
Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really nice front end
to a nice back-end data service. I realize I could use XML-RPC or JSON, but
I thought, "Why not keep it in Python's native format, and avoid the overhead
of conversion?" I'm sure it wouldn't be that hard to add. I'll do it
myself, if someone wants to point me to the right place in the code. :)

Comments?

j

--
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/ ID 0xDB26D7CE
PO Box 80086 -- Fairbanks, AK 99708 -- Ph: 907-456-5581 Fax: 907-456-3111

Jorge Vargas

unread,
Jan 21, 2007, 12:45:17 AM1/21/07
to turbogea...@googlegroups.com
On 1/20/07, Joshua J. Kugler <jos...@eeinternet.com> wrote:
>
> [OK...let's try this again and see if I get through. I tried posting through
> the web interface and through google's SMTP servers (while subscribed via my
> Gmail account) and neither post has shown up. I subscribed via my work
> address and we'll see if that works.]
>
well this time it did :)

> I've tried digging through the code (trunk) but finally got lost and couldn't
> track down a definitive place where the output is generated. Went back
> through controllers.py, util.py, and some others. So, I'm posting. :)
>

yea the code is a little dark since the actual method is a "generic
function" based on the ruleDispatch package, alberto knows about it :)

> Is there any option to return the data as a python pickle? With a good
> Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really nice front end
> to a nice back-end data service. I realize I could use XML-RPC or JSON, but
> I thought, "Why not keep it in Python's native format, and avoid the overhead
> of conversion?"

sounds interesting although pickle in itself is not "native" and has
several problems you haven't consider like the fact that pickles may
not be compatible between version of python itself. and I think
transmitting a json string over the network is faster then a pickle
object (smaller data).

that said seems interesting

> I'm sure it wouldn't be that hard to add. I'll do it
> myself, if someone wants to point me to the right place in the code. :)
>

the first thing is that you need to understand generic functions after
that probably you'll need to patch the code in
http://trac.turbogears.org/browser/trunk/turbogears/controllers.py#L168
and below to add the new rule type (yes the code is a little dense)

after that it's just creating the rules and the API will take care of
deciding what to call.

Elvelind Grandin

unread,
Jan 21, 2007, 2:56:21 AM1/21/07
to turbogea...@googlegroups.com
What you could try to do is creating a pickle template engine, thats
the way json support works. take a look at
http://docs.turbogears.org/1.0/TemplatePlugins
and perhaps http://trac.turbogears.org/browser/projects/TurboJson for
exemples on how to do it.


--
cheers
elvelind grandin

Jorge Godoy

unread,
Jan 21, 2007, 7:25:32 AM1/21/07
to turbogea...@googlegroups.com
"Elvelind Grandin" <elve...@gmail.com> writes:

> What you could try to do is creating a pickle template engine, thats
> the way json support works. take a look at
> http://docs.turbogears.org/1.0/TemplatePlugins
> and perhaps http://trac.turbogears.org/browser/projects/TurboJson for
> exemples on how to do it.

It would be cool having a native Python "engine". And using the same code for
the WUI, GUI and TUI would be really good! A true MVC decoupling.

--
Jorge Godoy <jgo...@gmail.com>

Joshua J. Kugler

unread,
Jan 21, 2007, 11:33:58 AM1/21/07
to turbogea...@googlegroups.com
On Saturday 20 January 2007 20:45, Jorge Vargas wrote:
> > Is there any option to return the data as a python pickle? With a good
> > Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really nice front
> > end to a nice back-end data service. I realize I could use XML-RPC or
> > JSON, but I thought, "Why not keep it in Python's native format, and
> > avoid the overhead of conversion?"
>
> sounds interesting although pickle in itself is not "native"

Well, yes, it is a module, not necessarily built in. I guess what I meant was
that "The data format used by pickle is Python-specific." - Python Library
Reference, 3.14.2

> and has
> several problems you haven't consider like the fact that pickles may
> not be compatible between version of python itself.

Right, I did know that, having read through the standard library docs a few
weeks ago. But, in this case, I would most likely have control over both the
back end Python version, as well as the front end Python version. I know,
for instance, that "Protocol version 2 was introduced in Python 2.3. It
provides much more efficient pickling of new-style classes." - Ibid, 3.14.3
But I can pretty much guarantee that both my front end and back ends will be
running Python >= 2.3.

> and I think transmitting a json string over the network is faster then a
> pickle object (smaller data).

That I didn't know. How well does JSON handle binary data? And with pickle
you can do truly "scary" things like sending entire class instances over the
wire, which opens up a whole bunch of really off-the-wall possibilities when
talking about interaction of the client with the server.

> that said seems interesting

I thought so. :)

> > I'm sure it wouldn't be that hard to add. I'll do it
> > myself, if someone wants to point me to the right place in the code. :)
>
> the first thing is that you need to understand generic functions after
> that probably you'll need to patch the code in
> http://trac.turbogears.org/browser/trunk/turbogears/controllers.py#L168
> and below to add the new rule type (yes the code is a little dense)

I'll take a look at that. A template plugin was also suggested too. I'll see
if I can grok that first, as it would be more extensible.

Joshua J. Kugler

unread,
Jan 21, 2007, 1:41:18 PM1/21/07
to turbogea...@googlegroups.com
Something I just found to add to previous responses...

When TurboGears becomes more WSGI-ified, we can simply add in this nice little
piece of middleware, and we have all the serialization methods we want. :)

http://cheeseshop.python.org/pypi/wsgiserialize/

Cliff Wells

unread,
Jan 22, 2007, 12:02:53 PM1/22/07
to turbogea...@googlegroups.com
On Sat, 2007-01-20 at 15:40 -0900, Joshua J. Kugler wrote:
> [OK...let's try this again and see if I get through. I tried posting through
> the web interface and through google's SMTP servers (while subscribed via my
> Gmail account) and neither post has shown up. I subscribed via my work
> address and we'll see if that works.]
>
> I've tried digging through the code (trunk) but finally got lost and couldn't
> track down a definitive place where the output is generated. Went back
> through controllers.py, util.py, and some others. So, I'm posting. :)
>
> Is there any option to return the data as a python pickle? With a good
> Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really nice front end
> to a nice back-end data service.

I've done something similar using wxPython and TurbGears, but I
approached completely differently: I used the XRC GUI description
language provided by wxPython and served that from my TurboGears app
rather than HTML. Required no changes to TurboGears, simply some
templates. It was also nice in that I very rarely had to push a
new .exe to the Windows users since 90% of the changes happened on the
Linux server (i.e. just like a webapp ought to be).

That being said, I think if I were to redo it all today I'd use this:

http://techgame.net/projects/Framework/wiki/

which looks to be far superior to XRC.

Regards,
Cliff


Paul Johnston

unread,
Jan 22, 2007, 2:43:59 PM1/22/07
to turbogea...@googlegroups.com
Hi,

Just reading this thread again, I've realised, it's not tg_format=pickle
that you want, but tg_format=soap!

Paul

Joshua J. Kugler

unread,
Jan 22, 2007, 3:29:15 PM1/22/07
to turbogea...@googlegroups.com
On Monday 22 January 2007 08:02, Cliff Wells wrote:
> > Is there any option to return the data as a python pickle? With a good
> > Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really nice front
> > end to a nice back-end data service.
>
> I've done something similar using wxPython and TurbGears, but I
> approached completely differently: I used the XRC GUI description
> language provided by wxPython and served that from my TurboGears app
> rather than HTML. Required no changes to TurboGears, simply some
> templates. It was also nice in that I very rarely had to push a
> new .exe to the Windows users since 90% of the changes happened on the
> Linux server (i.e. just like a webapp ought to be).
>
> That being said, I think if I were to redo it all today I'd use this:
> http://techgame.net/projects/Framework/wiki/
> which looks to be far superior to XRC.

Wow...that just gave me all sorts of fun (possibly wrong) ideas. :) That
framework looks cool. Another idea you gave me was sending Qt .ui files over
the wire and loading them at run time, along with the Python code to set up
the signals and slots. There is also this: http://pyjamas.pyworks.org/
Write Python code, compile to Javascript...that looks pretty cool too. All
sorts of fun ideas.

Joshua J. Kugler

unread,
Jan 22, 2007, 3:37:18 PM1/22/07
to turbogea...@googlegroups.com
On Monday 22 January 2007 10:43, Paul Johnston wrote:
> >>Is there any option to return the data as a python pickle? With a good
> >>Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really nice front
> >> end to a nice back-end data service.
>
> Just reading this thread again, I've realised, it's not tg_format=pickle
> that you want, but tg_format=soap!

Noooooooooooooooo!!!!!!!! Not soap, anything but SOAP! :) I'll take XML-RPC
or or Pickle or whatever over soap. :) Well, at least Python's SOAP
implementation is sane (or so I've been told). I've heard some pretty bad
horror stories from other corners of the programming world.

Cliff Wells

unread,
Jan 22, 2007, 4:18:22 PM1/22/07
to turbogea...@googlegroups.com
On Mon, 2007-01-22 at 11:29 -0900, Joshua J. Kugler wrote:
> On Monday 22 January 2007 08:02, Cliff Wells wrote:
> > > Is there any option to return the data as a python pickle? With a good
> > > Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really nice front
> > > end to a nice back-end data service.
> >
> > I've done something similar using wxPython and TurbGears, but I
> > approached completely differently: I used the XRC GUI description
> > language provided by wxPython and served that from my TurboGears app
> > rather than HTML. Required no changes to TurboGears, simply some
> > templates. It was also nice in that I very rarely had to push a
> > new .exe to the Windows users since 90% of the changes happened on the
> > Linux server (i.e. just like a webapp ought to be).
> >
> > That being said, I think if I were to redo it all today I'd use this:
> > http://techgame.net/projects/Framework/wiki/
> > which looks to be far superior to XRC.
>
> Wow...that just gave me all sorts of fun (possibly wrong) ideas. :) That
> framework looks cool. Another idea you gave me was sending Qt .ui files over
> the wire and loading them at run time, along with the Python code to set up
> the signals and slots. There is also this: http://pyjamas.pyworks.org/
> Write Python code, compile to Javascript...that looks pretty cool too. All
> sorts of fun ideas.

The method I used was I had a basic "bootstrap" .exe file that could
parse a simple .ini file, fetch a zipfile of Python modules (since
Python can import from a zipfile now) and then finally begin fetching
the interface code in the form of XRC files. This way I only ever had
to push out .exe updates if I changed the bootstrap code (not very
often).

As an aside, this was not a public application, so I didn't need to
worry a lot about security issues that pushing Python modules out
implies. As another aside, if you think that's a horrible security
issue, then I'd recommend against using easy_install ;-) I *would*
however be certain to use SSL and have the client validate the
certificate before it downloads any code.

Have fun.

Cliff


Joshua J. Kugler

unread,
Jan 22, 2007, 5:07:31 PM1/22/07
to turbogea...@googlegroups.com
On Monday 22 January 2007 12:18, Cliff Wells wrote:
> The method I used was I had a basic "bootstrap" .exe file that could
> parse a simple .ini file, fetch a zipfile of Python modules (since
> Python can import from a zipfile now) and then finally begin fetching
> the interface code in the form of XRC files. This way I only ever had
> to push out .exe updates if I changed the bootstrap code (not very
> often).

Wow...you just totally destroyed my productivity for the day. Now I'm going
to be thinking about all these cool ways to distribute files at run time,
interact with the central server, and the like. Sigh. Thanks. :)

> As an aside, this was not a public application, so I didn't need to
> worry a lot about security issues that pushing Python modules out
> implies. As another aside, if you think that's a horrible security
> issue, then I'd recommend against using easy_install ;-) I *would*
> however be certain to use SSL and have the client validate the
> certificate before it downloads any code.

Right, I'd use SSL and probably GPG sign the zip file. Good reminders,
though.

> Have fun.

Oh, I will. Ever been at a point where you hear a new idea, and you get giddy
and silly thinking about all the new possibilities it opens up for you?
Yeah, well, I'm there. Sigh. :)

Joshua Kugler

unread,
Jan 20, 2007, 7:19:30 PM1/20/07
to TurboGears Trunk
[I've tried posting this twice: once through Google's smtp servers and
once via our smtp servers, (both times with my From address being my
Gmail address, which is the address I have registered for Google
Groups). I have yet to see it show up in my inbox or in the group's
list of messages. Anyone have any ideas? I'd really rather not have
to use the web interface to post all the time.]

I've tried digging through the code (trunk) but finally got lost and
couldn't track down a definitive place where the output is generated.
Went back through controllers.py, util.py, and some others. So, I'm
posting. :)

Is there any option to return the data as a python pickle? With a


good Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really

nice front end to a nice back-end data service. I realize I could use


XML-RPC or JSON, but I thought, "Why not keep it in Python's native

format, and avoid the overhead of conversion?" As well as a lot less
bandwidth needed, at least in the case of XML-RPC vs. Pickle. I'm


sure it wouldn't be that hard to add. I'll do it myself, if someone
wants to point me to the right place in the code. :)

Comments?

j

Jorge Godoy

unread,
Jan 30, 2007, 6:39:40 AM1/30/07
to turbogea...@googlegroups.com
"Joshua Kugler" <peda...@gmail.com> writes:

> [I've tried posting this twice: once through Google's smtp servers and
> once via our smtp servers, (both times with my From address being my
> Gmail address, which is the address I have registered for Google
> Groups). I have yet to see it show up in my inbox or in the group's
> list of messages. Anyone have any ideas? I'd really rather not have
> to use the web interface to post all the time.]

I don't use the web interface... :-) It might be some MUA configuration
error.

> Is there any option to return the data as a python pickle? With a

Sure!


class MyClass(Controller):
def index(self):
pass

def __get_data_to_serve(self, *args, **kwargs):
# Get and return your data in a suitable way to your methods reuse it


@expose()
def exposed_method(self, *args, **kwargs):
data = self.__get_data_to_serve(*args, **kwargs)
# Return what you need to the web interface

def _this_returns_pickle(self, *args, **kwargs):
data = self.__get_data_to_serve(*args, **kwargs)
# build and return pickle


With the use of RuleDispatch you could even abstract the different names.

> good Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really
> nice front end to a nice back-end data service. I realize I could use
> XML-RPC or JSON, but I thought, "Why not keep it in Python's native
> format, and avoid the overhead of conversion?" As well as a lot less
> bandwidth needed, at least in the case of XML-RPC vs. Pickle. I'm
> sure it wouldn't be that hard to add. I'll do it myself, if someone
> wants to point me to the right place in the code. :)
>
> Comments?

From past discussions it was seen that such a thing doesn't belong to TG
because of how simple it is to implement it (see my code sample above)...
Nothing prevents you from adding something and providing it as, e.g., another
template option.

I believe that it belongs in TG the changes needed to provide enough entry
points so that you can write it and publish it outside of TG core...


--
Jorge Godoy <jgo...@gmail.com>

Kevin Dangoor

unread,
Jan 30, 2007, 7:16:49 AM1/30/07
to turbogea...@googlegroups.com
On Jan 20, 2007, at 7:19 PM, Joshua Kugler wrote:

>
> [I've tried posting this twice: once through Google's smtp servers and
> once via our smtp servers, (both times with my From address being my
> Gmail address, which is the address I have registered for Google
> Groups). I have yet to see it show up in my inbox or in the group's
> list of messages. Anyone have any ideas? I'd really rather not have
> to use the web interface to post all the time.]

New users are moderated (we really should spell that out somewhere).
This eliminates spam from the lists. When I approve messages, I also
turn off moderation for that user.

> Is there any option to return the data as a python pickle? With a
> good Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really
> nice front end to a nice back-end data service. I realize I could use
> XML-RPC or JSON, but I thought, "Why not keep it in Python's native
> format, and avoid the overhead of conversion?" As well as a lot less
> bandwidth needed, at least in the case of XML-RPC vs. Pickle. I'm
> sure it wouldn't be that hard to add. I'll do it myself, if someone
> wants to point me to the right place in the code. :)

You can pretty easily create a template engine to do this. Take a
look at how TurboJson works (http://svn.turbogears.org/projects/
TurboJson). It's really quite simple.

Note, however, that you don't want your server-side code to accept
pickles on the way in. Pickles are not secure.

Kevin

Jorge Vargas

unread,
Jan 30, 2007, 8:30:32 AM1/30/07
to turbogea...@googlegroups.com
On 1/30/07, Kevin Dangoor <dan...@gmail.com> wrote:

On Jan 20, 2007, at 7:19 PM, Joshua Kugler wrote:

>
> [I've tried posting this twice: once through Google's smtp servers and
> once via our smtp servers, (both times with my From address being my
> Gmail address, which is the address I have registered for Google
> Groups).  I have yet to see it show up in my inbox or in the group's
> list of messages.  Anyone have any ideas?  I'd really rather not have
> to use the web interface to post all the time.]

New users are moderated (we really should spell that out somewhere).
This eliminates spam from the lists. When I approve messages, I also
turn off moderation for that user.

you can customize the email that is being send on registration, although noone reads it :)

> Is there any option to return the data as a python pickle?  With a
> good Pythoon GUI toolkit (Qt, Gtk, Wx, etc) you could make a really
> nice front end to a nice back-end data service.  I realize I could use
> XML-RPC or JSON, but I thought, "Why not keep it in Python's native
> format, and avoid the overhead of conversion?"  As well as a lot less
> bandwidth needed, at least in the case of XML-RPC vs. Pickle.    I'm
> sure it wouldn't be that hard to add.  I'll do it myself, if someone
> wants to point me to the right place in the code. :)
You can pretty easily create a template engine to do this. Take a
look at how TurboJson works ( http://svn.turbogears.org/projects/
Reply all
Reply to author
Forward
0 new messages