Re: Pickling/unpickling Cookie.SimpleCookie fails with protocol=2

2006-02-24 Thread Erwin S. Andreasen
"Erwin S. Andreasen" <[EMAIL PROTECTED]> writes:

> Pickling a Cookie.SimpleCookie (or SmartCookie) when using protocol=2
> seems to do something very strange. Protocol 0/1 work fine:

Oh well, it seems that it's a well-known bug that has been around for
more than 2 years:

http://sourceforge.net/tracker/index.php?func=detail&aid=826897&group_id=5470&atid=105470

http://sourceforge.net/tracker/index.php?func=detail&aid=964868&group_id=5470&atid=105470

-- 
===
<[EMAIL PROTECTED]>London, E14
http://www.andreasen.org/> <*>   
===

-- 
http://mail.python.org/mailman/listinfo/python-list


Pickling/unpickling Cookie.SimpleCookie fails with protocol=2

2006-02-23 Thread Erwin S. Andreasen

Pickling a Cookie.SimpleCookie (or SmartCookie) when using protocol=2
seems to do something very strange. Protocol 0/1 work fine:

$ python2.4
Python 2.4.2 (#2, Nov 20 2005, 17:04:48) 
[GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import cPickle, Cookie
>>> cPickle.loads(cPickle.dumps(Cookie.SimpleCookie('hi=there')))


Protocol 2 however:

>>> pickle.loads(pickle.dumps(Cookie.Cookie('hi=there'),2))
>

>>>pickle.loads(pickle.dumps(Cookie.Cookie('hi=there'),2))['hi'].__dict__

{'coded_value':
'"ccopy_reg\\012_reconstructor\\012p1\\012(cCookie\\012Morsel\\012p2\\012c__builtin__\\012dict\\012p3\\012(dp4\\012S\'comment\'\\012p5\\012S\'\'\\012sS\'domain\'\\012p6\\012S\'\'\\012sS\'version\'\\012p7\\012S\'\'\\012sS\'secure\'\\012p8\\012S\'\'\\012sS\'path\'\\012p9\\012S\'\'\\012sS\'expires\'\\012p10\\012S\'\'\\012sS\'max-age\'\\012p11\\012S\'\'\\012stRp12\\012(dp13\\012S\'coded_value\'\\012p14\\012S\'there\'\\012p15\\012sS\'value\'\\012p16\\012g15\\012sS\'key\'\\012p17\\012S\'hi\'\\012p18\\012sb."',
'value': , 'key': 'hi'}


I can't really say what goes wrong here, but it looks like a bug to me
-- comments? I guess I'll have to go to protocol 0 for this, or not
serialize the cookie but re-parse it on the other side (this pickle
gets passed down a UNIX socket together with the file descriptor of a
request, in a load balancing system).



-- 
===
<[EMAIL PROTECTED]>   London, E14
http://www.andreasen.org/> <*>   
===

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: except clause not catching IndexError

2006-02-22 Thread Erwin S. Andreasen
Derek Schuff <[EMAIL PROTECTED]> writes:

> I have some code like this:

[...]

> except IndexError: #happens if theres a partial line at the 
> end of file
> print "indexerror"
> break
>
> However, when I run it, it seems that I'm not catching the IndexError:
> Traceback (most recent call last):
>   File "/home/dschuff/bin/speeds.py", line 202, in ?
> if int(toks[2],16) == qaddrs[i]+0x1000 and toks[0] == "200": #producer
> write
> IndexError: list index out of range

Did you by any chance do something like:

except ValueError, IndexError:

at some point earlier in this function? That, when catching ValueError
assigns the resulting exception to IndexError (and so the following
except IndexError: wouldn't work as IndexError is no longer what you
think it is). The correct syntax for catching multiple exceptions is:

except (ValueError, IndexError), targetVariable:

You could verify this by doing a print repr(IndexError) before your
line 202, to see that it really is the IndexError builtin.



-- 
===
<[EMAIL PROTECTED]>London, E14
http://www.andreasen.org/> <*>   
===

-- 
http://mail.python.org/mailman/listinfo/python-list


Making dynamic data available via ODBC with Python

2005-02-07 Thread Erwin S. Andreasen

I have a Python application server that manages several different data
sets, permits various reports to be run on them and the data to be
downloaded as tab-delimetered files, all via a web interface.

I'd like to explore the possibilities of making the data directly
available in Windows applications (such as Excel, where it would very
nice to directly do pivot tables from the live data) via ODBC.

So I basically need for my Python server (deployed on UNIX) to act as
a remotely queriable database. This is live and changing data, so I'd
prefer not to have to dump it into a real database first, but I
suppose that's one solution (e.g. letting PostgreSQL get the query,
run some trigger that asks my server to update the table with data and
then return the data).

Knowing little about the various available ODBC modules, one solution
seems to be to take a client/server protocol of an existing database
(such as PostgreSQL) and implement a Python server for it: so my
Python program acts like a server you could run the psql client up
against and so also get data via ODBC using the PG ODBC drivers. It
seems a bit complex because all I want to allow is to select a table
with a certain name, allow a query of what columns are available and
what type they are and to fetch the data, perhaps with minimal support
for filtering queries.

I've seen at least one program that emulates the PG client/server API
-- I think it stored some configuration data, so it acted like a
ordinary PG server you could run queries against but wasn't really
one. Its name completely escapes me at the moment though.

Is there some better way of doing this -- some way to provide tabular
data remotely to Windows machines, usable in Office programs, which
happens to already have some Python code written for it? Looking
around, there is at least one XML-to-ODBC bridge but encoding the
entire data file as XML is likely to have prohibitive overhead.



-- 
===
<[EMAIL PROTECTED]>Herlev, Denmark 
http://www.andreasen.org/> <*>   
===

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Excel module for Python

2005-01-16 Thread Erwin S. Andreasen
Simon Brunning <[EMAIL PROTECTED]> writes:

> On Wed, 12 Jan 2005 23:19:44 +0800, sam <[EMAIL PROTECTED]> wrote:
>>
>> No, I don't use MS windows. I need to generate Excel file by printing
>> data to it, just like Perl module Spreadsheet::WriteExcel.

> If you need to write out formulae, formratting, that kind of thing,
> then I think you'll need to write a 'real' Excel file. I don't have a
> clue how to do that - sorry.

There's actually an ancient open spreadsheet format called SYLK which
is a step above CSV: it allows formatting of data, formulas etc.

Google for SYLK to get the rather sparse specification (and skip over
the first few links!)

If you want to generate "real" Office files from UNIX, another
alternative is to automate OpenOffice (which has a COM-like interface
too) or generate OO XML files and feed them to OO asking to conver
them with a bit of OO macro magic.



-- 
===
<[EMAIL PROTECTED]>Herlev, Denmark 
http://www.andreasen.org/> <*>   
===

-- 
http://mail.python.org/mailman/listinfo/python-list