stringified cPickle

2005-11-17 Thread David Bear
I'm rather new to pickling but I have some dictionaries and lists I want to
package and send to another process (on another machine).

I was hoping I could just send a stringified pickle. However, the examples
in the doc have:

>>> import pickle
>>> pickle.dump(obj,open('save.p','w'))

I don't really want to write to a file. I know I could write to sys.stdout.
But I'd rather collect the string and do some garbage collect, etc before I
exit the script.

Is there a way to have cPickle just hand me a string?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


email module documentation

2005-11-22 Thread David Bear
I'm confused about how to use the email module in python 2.4.x

I'm using python packaged with suse 9.3. 

>From the module documetation at http://docs.python.org/lib/node597.html I
found the following example (items cut):

import email

...
msg = email.message_from_file(fp)
..

Yet, when I try this I get the message 

Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'module' object has no attribute 'message_from_file'

so I dir(email) reveals:

['__builtins__', '__doc__', '__file__', '__name__', 'cStringIO', 'email',
'getMessage', 'sys']

This is nothing like the documentation on python.org.

Any idea what I am missing?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: email module documentation

2005-11-22 Thread David Bear
Robert Kern wrote:

> David Bear wrote:
>> I'm confused about how to use the email module in python 2.4.x
>> 
>> I'm using python packaged with suse 9.3.
>> 
>>>From the module documetation at http://docs.python.org/lib/node597.html I
>> found the following example (items cut):
>> 
>> import email
>> 
>> ...
>> msg = email.message_from_file(fp)
>> ..
>> 
>> Yet, when I try this I get the message
>> 
>> Traceback (most recent call last):
>>   File "", line 1, in ?
>> AttributeError: 'module' object has no attribute 'message_from_file'
>> 
>> so I dir(email) reveals:
>> 
>> ['__builtins__', '__doc__', '__file__', '__name__', 'cStringIO', 'email',
>> 'getMessage', 'sys']
>> 
>> This is nothing like the documentation on python.org.
>> 
>> Any idea what I am missing?
> 
> That's not what I have on OS X with Python 2.4.1.
> 
> In [1]: import email
> 
> In [2]: dir(email)
> Out[2]:
> ['__all__',
>  '__builtins__',
>  '__doc__',
>  '__file__',
>  '__name__',
>  '__path__',
>  '__version__',
>  'message_from_file',
>  'message_from_string']
> 
> Are you sure that you're getting the right file? Check email.__file__ .
> 

never mind. I just discovered my error. 
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


insert a dictionary into sql data base

2005-12-05 Thread David Bear
I have a dictionary that contains a row of data intended for a data base.

The dictionary keys are the field names. The values are the values to be
inserted.

I am looking for a good pythonic way of expressing this, but I have a
problem with the way lists are represented when converted to strings.

Lets say my dictionary is

data = {"fname": "todd", "lname": "Bush"}
fields = data.keys()
vals = []
for v in fields:
   vals.append(data[v])

sql = """INSERT INTO table (%s) VALUES (%s);""" % (fields, vals)

but fields and vals are represented as lists. So, then I need to strip the
[] from them, but then ... there must be an easier way.

Any advise?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: insert a dictionary into sql data base

2005-12-05 Thread David Bear
Fredrik Lundh wrote:

> cursor.execute(
> "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields)),
> *values
> )

Thanks for the hint. However, I don't understand the syntax.

I will be inserting in to postgresql 8.x. I assumed the entire string would
be evaluated prior to being sent to the cursor. However, when I attempt to
manual construct the sql insert statment above I get an error:

>>> print "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields),
*values)
  File "", line 1
print "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields),
*values)
      ^
SyntaxError: invalid syntax


-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: insert a dictionary into sql data base

2005-12-05 Thread David Bear
Fredrik Lundh wrote:

> David Bear wrote
> 
>> Fredrik Lundh wrote:
>>
>> > cursor.execute(
>> > "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields)),
>> > *values
>> > )
>>
>> Thanks for the hint. However, I don't understand the syntax.
>>
>> I will be inserting in to postgresql 8.x. I assumed the entire string
>> would be evaluated prior to being sent to the cursor.
> 
> Looks like you missed advice 1-3.  I'll take it again: DON'T USE STRING
> FORMATTING TO INSERT VALUES IN A DATABASE.  Sorry for shouting,
> but this is important.  Parameter passing gives you simpler code, and
> fewer security holes.
>

please, shout until I 'get it'... I don't mind. I just don't understand
using the star in front of the values variable; it generates a syntax
exception for me.
 
>> However, when I attempt to manual construct the sql insert statment
>> above I get an error:
>>
>> >>> print "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields),
>> *values)
>>   File "", line 1
>> print "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields),
>> *values)
>>   ^
>> SyntaxError: invalid syntax
> 
> DON'T MANUALLY CONSTRUCT THE SQL INSERT STATEMENT.  Use string
> formatting to insert the field names, but let the database layer deal with
> the values.

since I am so new to this, I didn't know the database layer would handle
this for me. Is the evaluation of the fieldname done by the dbapi layer or
by postgresql? 
> 
> If you want to do things in two steps, do the fields formatting first
> 
> query = "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields))
> 
> and pass the query and the values sequence to the database layer:
> 
> cursor.execute(query, values)

I found this info on the pgdb interface:

http://www.pygresql.org/pg.html

section 4.7 describes the insert method. It is passed the tablename and a
dictionary. But it doesn't describe how it resolves fieldnames and their
values. I assume the dictionary key MUST correspond to a named field.

> 
> The database will take care of the rest.

this is my trouble. I always think I need to do more -- but I can't seem to
find good examples on the http://www.pygresql.org/pgdb.html website.

Do know of any good examples?

> 
> 

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: insert a dictionary into sql data base

2005-12-05 Thread David Bear
Fredrik Lundh wrote:

> David Bear wrote
> 
>> Fredrik Lundh wrote:
>>
>> > cursor.execute(
>> > "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields)),
>> > *values
>> > )
>>
>> Thanks for the hint. However, I don't understand the syntax.
>>
>> I will be inserting in to postgresql 8.x. I assumed the entire string
>> would be evaluated prior to being sent to the cursor.
> 
> Looks like you missed advice 1-3.  I'll take it again: DON'T USE STRING
> FORMATTING TO INSERT VALUES IN A DATABASE.  Sorry for shouting,
> but this is important.  Parameter passing gives you simpler code, and
> fewer security holes.
> 
>> However, when I attempt to manual construct the sql insert statment
>> above I get an error:
>>
>> >>> print "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields),
>> *values)
>>   File "", line 1
>> print "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields),
>> *values)
>>   ^
>> SyntaxError: invalid syntax
> 
> DON'T MANUALLY CONSTRUCT THE SQL INSERT STATEMENT.  Use string
> formatting to insert the field names, but let the database layer deal with
> the values.
> 
> If you want to do things in two steps, do the fields formatting first
> 
> query = "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields))
> 
> and pass the query and the values sequence to the database layer:
> 
> cursor.execute(query, values)
> 
> The database will take care of the rest.
> 
> 

I think I'm missing some important documentation somewhere. Here's what I
tried (using both % and $ signs):

>>> sql
'INSERT INTO nic (addr_code,ip_address,property_control,mac_address) VALUES
(%s);'

>>> sql2
'INSERT INTO nic (addr_code,ip_address,property_control,mac_address) VALUES
($s);'
>>> values
['p', '129.219.120.134', '6154856', '00:40:50:60:03:02']

>>> cursor.execute(sql1, values)
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'sql1' is not defined
>>> cursor.execute(sql, values)
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib64/python2.4/site-packages/pgdb.py", line 163, in execute
self.executemany(operation, (params,))
  File "/usr/lib64/python2.4/site-packages/pgdb.py", line 187, in
executemany
raise OperationalError, "internal error in '%s': %s" % (sql,err)
pg.OperationalError: internal error in 'INIT': not all arguments converted
during string formatting

I get the same error if using $ sign.

When I look at the pygresql dbapi official site at
http://www.pygresql.org/pgdb.html

"this section needs to be written"...

I would really appreciate some more examples on using pgdb (pygresql)


-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: insert a dictionary into sql data base

2005-12-06 Thread David Bear
Carsten Haese wrote:

> The
> example he gave you constructs an insert query with only one parameter
> placeholder. You'll need as many placeholders as the number of values that
> are inserted.
> 
> The following example should work better:
> 
> def insertDict(curs, tablename, data):
>   fields = data.keys()
>   values = data.values()
>   placeholder = "%s"
>   fieldlist = ",".join(fields)
>   placeholderlist = ",".join([placeholder] * len(fields))
>   query = "insert into %s(%s) values (%s)" % (tablename, fieldlist,
>   placeholderlist)
>   curs.execute(query, values)
> 
> The main thing to note here is that we *are* using string formatting to
> build a query that's based on a variable table name and a variable column
> list, but we *are not* using string formatting to fill in the values.[*]
> 
> On a somewhat related note, it's unfortunate that many database modules
> use %s
>  as parameter placeholders, because it makes it too tempting to write bad
>  code
> such as
> 
> cur.execute("insert into tab1(spam,eggs) values (%s,%s)" % (a,b)) # Bad,
> uses vulnerable and error-prone string formatting
> 
> instead of
> 
> cur.execute("insert into tab1(spam,eggs) values (%s,%s)", (a,b)) # Good,
> uses parameters.
> 
> [*] This code blindly trusts that the table name and dictionary keys don't
> contain SQL injection attacks. If the source of these is not completely
> trustworthy, the code needs to be hardened against such attacks. I'll
> leave that as an exercise for the reader.
> 
> Hope this helps,
> 
> Carsten.

Thank you very much for the greater explanation. Yes, I was not
understanding that that %s in one instance was a python string format
operator, and in another instance it was a placeholder sent to the dbapi
objects (and I supposed on down into the data base cursor) for the
parameters following the function call. BIG DIFFERENCE.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


sql escaping module

2005-12-07 Thread David Bear
Being new to pgdb, I'm finding there are lot of things I don't understand
when I read the PEP and the sparse documentation on pgdb.

I was hoping there would be a module that would properly escape longer text
strings to prevent sql injection -- and other things just make sure the
python string object ends up being a properly type for postgresql. I've
bought 3 books on postgresql and none of th code samples demonstrate this.

web searchs for 'python sql escape  string' yeild way too many results.

Any pointers would be greatly appreciated.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sql escaping module

2005-12-08 Thread David Bear
Fredrik Lundh wrote:

> David Bear wrote:
> 
>> Being new to pgdb, I'm finding there are lot of things I don't understand
>> when I read the PEP and the sparse documentation on pgdb.
>>
>> I was hoping there would be a module that would properly escape longer
>> text strings to prevent sql injection -- and other things just make sure
>> the python string object ends up being a properly type for postgresql.
>> I've bought 3 books on postgresql and none of th code samples demonstrate
>> this.
>>
>> web searchs for 'python sql escape  string' yeild way too many results.
>>
>> Any pointers would be greatly appreciated.
> 
> for x in range(100):
> print "USE PARAMETERS TO PASS VALUES TO THE DATABASE"
> 
> 
Yes. Fredrik and others. Thank you for the advice.

I know have the following code:

..
parmChar = '%s'
sqlInsert = """INSERT INTO %s (%s) VALUES (%s); """ % (tn, ",
".join(fieldnames), ", ".join([parmChar] * len(fieldnames)))
try:
cursor.execute(sqlInsert, datum)
except pgdb.DatabaseError:
logerror("Error on record insert \n %s \n %s" % (sqlInsert, 
   traceback.print_exc()))

I was not aware that the python db interface would just handle proper
escaping of python data types to proper postgresql data types.

Any other hints on database programming much appreciated.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sql escaping module - Frank Millman Followup

2005-12-08 Thread David Bear

>Steve Holden wrote:

> Fredrik Lundh wrote:
>> Frank Millman wrote:
>> 
>> 
>>>Each of the API's includes the capability of passing commands in the
>>>form of 'string + parameters' directly into the database. This means
>>>that the data values are never embedded into the SQL command at all,
>>>and therefore there is no possibility of injection attacks.
>> 
>> 

My news server didn't get Franks initial post to the group, so I'm glad that
Steve included it in his followup.

The statement above can cause relief or pain. Letting the DBAPI handle
proper string escapes, formating, etc., is a big relief. However, I am
still wondering what happens under the covers. If I have a string '1\n'
that I've read from some source and I really intend on inserting it into
the data base as a number 1, if the tape column it goes into is of type int
or num or float, will the DBAPI really know what to do with the newline?



-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


query python env

2005-01-13 Thread David Bear
How does one query the python environment, ie pythonhome, pythonpath,
etc.

also, are there any HOWTO's on keeping multiple versions of python
happy? 
-- 
http://mail.python.org/mailman/listinfo/python-list


reading a list from a file

2005-06-20 Thread David Bear
I have a file that contains lists -- python lists. sadly, these are not
pickled. These are lists that were made using a simple print list
statement.

Is there an easy way to read this file into a list again?  I'm thinking I
would have to 

read until char = '['
   read until char = " ' "

Well, reading character by char until I have the list and then parse it all
myself.

I was hoping there was a pythonic way of doing this..

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


getting an object name

2005-06-21 Thread David Bear
Let's say I have a list called, alist. If I pass alist to a function,
how can I get the name of it?

alist = range(10)

def afunction(list):
listName = list.__name__ (fails for a list object)

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


a dictionary from a list

2005-06-24 Thread David Bear
I know there must be a better way to phrase this so google understands, but
I don't know how.. So I'll ask people.

Assume I have a list object called 'alist'.

Is there an easy way to create a dictionary object with the members of
'alist' being the keys in the dictionary, and the value of the keys set to
null?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


rsync protocol in python

2005-06-27 Thread David Bear
I was wondering if anyone has implemented the rsync protocol in python.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


return the last item in a list

2005-03-30 Thread David Bear

I've googled for the above and get way too many hits.. 

I'm looking for an 'easy' way to have the last item in a list returned.

I've thought about

list[len(list)-1]

but thought there would be a more gracefull way.

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


mod_python and zope

2005-03-31 Thread David Bear
I will be running zope, and I would also like to run mod_python. The problem
arised when zope wants a threaded version of python and mod_python wants
no_threads.

I've been searching the mod_python site for pointers on how to install two
instances of python, then configuring mod_python to use the non-thread
instance. Haven't found anything yet.

I'd appreciate any pointers the group may have as to how to install two
pythons on the system -- and freely switch between a threaded and non-threaded
version.  I know I can do this with pythonpath or/and python home but I'm not
really good at experimenting without destroying things. 

--
David Bear
phone:  480-965-8257
fax:480-965-9189
College of Public Programs/ASU
Wilson Hall 232
Tempe, AZ 85287-0803
 "Beware the IP portfolio, everyone will be suspect of trespassing"
-- 
http://mail.python.org/mailman/listinfo/python-list


ipv4 class

2005-04-12 Thread David Bear
I was hoping to write some network utils and found an ipv4 class written 
by Keith Dart circa 1999. It doesn't work any longer under python 2.3. I 
think I found it on starship python and links to his web site point to a 
 non-functional server.

anyone know of a simple ipv4 class I might steal... Im mean use?
--
http://mail.python.org/mailman/listinfo/python-list


config errors on Freebsd and python 2.3

2006-01-05 Thread David Bear
I need python 2.3. I have freebsd 4.10-releng. when configuring python I
received the following:

./configure --prefix=/home/webenv > config-results
configure: WARNING: curses.h: present but cannot be compiled
configure: WARNING: curses.h: check for missing prerequisite headers?
configure: WARNING: curses.h: see the Autoconf documentation
configure: WARNING: curses.h: section "Present But Cannot Be Compiled"
configure: WARNING: curses.h: proceeding with the preprocessor's result
configure: WARNING: curses.h: in the future, the compiler will take
precedence
configure: WARNING: ## - ##
configure: WARNING: ## Report this to the python lists.  ##
configure: WARNING: ## - ##
configure: WARNING: ncurses.h: present but cannot be compiled
configure: WARNING: ncurses.h: check for missing prerequisite headers?
configure: WARNING: ncurses.h: see the Autoconf documentation
configure: WARNING: ncurses.h: section "Present But Cannot Be Compiled"
configure: WARNING: ncurses.h: proceeding with the preprocessor's result
configure: WARNING: ncurses.h: in the future, the compiler will take
precedence
configure: WARNING: ## - ##
configure: WARNING: ## Report this to the python lists.  ##
configure: WARNING: ## - ##

I don't plan on using curses -- so I'd like to ignore this. But, I'm just
wondering if there is an 'easy' fix...


-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


understanding stat module names

2006-01-18 Thread David Bear
I'm trying to use os.chmod and am refered to the stat module.

Is there are explanation of:
* S_ISUID
* S_ISGID
* S_ENFMT
* S_ISVTX
* S_IREAD
* S_IWRITE
* S_IEXEC
* S_IRWXU
* S_IRUSR
* S_IWUSR
* S_IXUSR
* S_IRWXG
* S_IRGRP
* S_IWGRP
* S_IXGRP
* S_IRWXO
* S_IROTH
* S_IWOTH
* S_IXOTH

this isn't much help:

 dir(stat)
['ST_ATIME', 'ST_CTIME', 'ST_DEV', 'ST_GID', 'ST_INO', 'ST_MODE',
'ST_MTIME', 'ST_NLINK', 'ST_SIZE', 'ST_UID', 'S_ENFMT', 'S_IEXEC',
'S_IFBLK', 'S_IFCHR', 'S_IFDIR', 'S_IFIFO', 'S_IFLNK', 'S_IFMT', 'S_IFREG',
'S_IFSOCK', 'S_IMODE', 'S_IREAD', 'S_IRGRP', 'S_IROTH', 'S_IRUSR',
'S_IRWXG', 'S_IRWXO', 'S_IRWXU', 'S_ISBLK', 'S_ISCHR', 'S_ISDIR',
'S_ISFIFO', 'S_ISGID', 'S_ISLNK', 'S_ISREG', 'S_ISSOCK', 'S_ISUID',
'S_ISVTX', 'S_IWGRP', 'S_IWOTH', 'S_IWRITE', 'S_IWUSR', 'S_IXGRP',
'S_IXOTH', 'S_IXUSR', '__builtins__', '__doc__', '__file__', '__name__']
>>> print stat.__doc__
Constants/functions for interpreting results of os.stat() and os.lstat().

Suggested usage: from stat import *




-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: understanding stat module names

2006-01-18 Thread David Bear
Claudio Grondi wrote:

> David Bear wrote:
>> I'm trying to use os.chmod and am refered to the stat module.
>> 
>> Is there are explanation of:
>> * S_ISUID
>> * S_ISGID
>> * S_ENFMT
>> * S_ISVTX
>> * S_IREAD
>> * S_IWRITE
>> * S_IEXEC
>> * S_IRWXU
>> * S_IRUSR
>> * S_IWUSR
>> * S_IXUSR
>> * S_IRWXG
>> * S_IRGRP
>> * S_IWGRP
>> * S_IXGRP
>> * S_IRWXO
>> * S_IROTH
>> * S_IWOTH
>> * S_IXOTH
>> 
>> this isn't much help:
>> 
>>  dir(stat)
>> ['ST_ATIME', 'ST_CTIME', 'ST_DEV', 'ST_GID', 'ST_INO', 'ST_MODE',
>> 'ST_MTIME', 'ST_NLINK', 'ST_SIZE', 'ST_UID', 'S_ENFMT', 'S_IEXEC',
>> 'S_IFBLK', 'S_IFCHR', 'S_IFDIR', 'S_IFIFO', 'S_IFLNK', 'S_IFMT',
>> 'S_IFREG', 'S_IFSOCK', 'S_IMODE', 'S_IREAD', 'S_IRGRP', 'S_IROTH',
>> 'S_IRUSR', 'S_IRWXG', 'S_IRWXO', 'S_IRWXU', 'S_ISBLK', 'S_ISCHR',
>> 'S_ISDIR', 'S_ISFIFO', 'S_ISGID', 'S_ISLNK', 'S_ISREG', 'S_ISSOCK',
>> 'S_ISUID', 'S_ISVTX', 'S_IWGRP', 'S_IWOTH', 'S_IWRITE', 'S_IWUSR',
>> 'S_IXGRP', 'S_IXOTH', 'S_IXUSR', '__builtins__', '__doc__', '__file__',
>> '__name__']
>> 
>>>>>print stat.__doc__
>> 
>> Constants/functions for interpreting results of os.stat() and os.lstat().
>> 
>> Suggested usage: from stat import *
>> 
>> 
>> 
>> 
> from stat.h of Microsoft Visual C++ .NET 2003:
> 
> #define _S_IFMT 017 /* file type mask */
> #define _S_IFDIR004 /* directory */
> #define _S_IFCHR002 /* character special */
> #define _S_IFIFO001 /* pipe */
> #define _S_IFREG010 /* regular */
> #define _S_IREAD400 /* read permission, owner */
> #define _S_IWRITE   200 /* write permission, owner */
> #define _S_IEXEC100 /* execute/search permission,
> owner */
> #define S_IFMT   _S_IFMT
> #define S_IFDIR  _S_IFDIR
> #define S_IFCHR  _S_IFCHR
> #define S_IFREG  _S_IFREG
> #define S_IREAD  _S_IREAD
> #define S_IWRITE _S_IWRITE
> #define S_IEXEC  _S_IEXEC
> 
> struct stat {
>  _dev_t st_dev;
>  _ino_t st_ino;
>  unsigned short st_mode;
>  short st_nlink;
>  short st_uid;
>  short st_gid;
>  _dev_t st_rdev;
>  _off_t st_size;
>  time_t st_atime;
>  time_t st_mtime;
>  time_t st_ctime;
>  };
> 
>  From MSDN Help:
> 
> The _fstat function obtains information about the open file associated
> with fd and stores it in the structure pointed to by buffer. The _stat
> structure, defined in SYS\STAT.H, contains the following fields:
> 
> st_atime
> Time of last file access.
> st_ctime
> Time of creation of file.
> st_dev
> If a device, fd; otherwise 0.
> st_mode
> Bit mask for file-mode information. The _S_IFCHR bit is set if fd refers
> to a device. The _S_IFREG bit is set if fd refers to an ordinary file.
> The read/write bits are set according to the file's permission mode.
> _S_IFCHR and other constants are defined in SYS\STAT.H.
> st_mtime
> Time of last modification of file.
> st_nlink
> Always 1 on non-NTFS file systems.
> st_rdev
> If a device, fd; otherwise 0.
> st_size
> Size of the file in bytes.
> 
> Probably googling for the constants will show up some more useful
> information , too.
> 
> Hope this helps.
> 
> Claudio

Thnks for the info. I didn't even think I would have to look in a unix/c ref
manual.  This was usefull.

 http://www.opengroup.org/onlinepubs/007908799/xsh/sysstat.h.html

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


verify a user

2006-01-18 Thread David Bear
If I have a unix user name, is there a way to verify that the user really
exists and query default group memberships?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


using logger module

2006-07-17 Thread David Bear
I attempted to use the logger module per the instructions in
http://docs.python.org/lib/minimal-example.html

I tried a couple of differnet levels. Nothing appeared in any logs. Has this
module been tested with syslog-ng? That is what is packaged with suse and I
am wondering if it is a version problem with the syslog server.

I am using python 2.4 -- on a 2.6.11.4-xx kernel. (suse 9.3)
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


under naming

2006-07-31 Thread David Bear
I must have missed reading something important about naming conventions.

I have found that if I have a python module where I have an identifier named
with a beginning underscore that I cannot use from module import * to make
that name available in another module.

for example,
module A

_myvar = 'a local var'

module B
from A import *

_myvar -- is not available.

Is this in a pep somewhere ?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


PIL issues

2006-07-31 Thread David Bear
I am trying to use PIL and when building it, PIL fails to find my jpeg
library. I am using a python 2.4.3 that I build myself on Suse linux 9.3. I
do have the following jpeg libraries:

rpm -qa | grep jpeg
jpeg-6b-738
libjpeg-32bit-9.3-7
libjpeg-6.2.0-738


yet, when building PIL I get:

python setup.py build_ext -i
running build_ext

PIL 1.1.5 BUILD SUMMARY

version   1.1.5
platform  linux2 2.4.2 (#4, Jul 27 2006, 14:34:30)
  [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)]

*** TKINTER support not available
*** JPEG support not available
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not available

To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

I don't know what ROOT variable the message is referring too. Any advice
would be appreciated.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


realine not found error

2006-07-31 Thread David Bear
I built python 2.4.2 for suse linux 9.3. I configured it to be a separate
instance of python from the version packaged with suse.

Now when I start it I get an error:
python
Python 2.4.2 (#4, Jul 27 2006, 14:34:30)
[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "/etc/pythonstart", line 7, in ?
import readline
ImportError: No module named readline

however, I do have readline installed:

rpm -qa | grep readline
readline-5.0-7.2
readline-32bit-9.3-7.1

it id truly does exist:

locate readline 
...
/lib/libreadline.so.5
/lib/libreadline.so.5.0
/lib64/libreadline.so.5
/lib64/libreadline.so.5.0
...

I googled about for this and there were numerous hits on this problem from
others, but I never found a 'solution'.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: readline not found error

2006-07-31 Thread David Bear
Robert Kern wrote:

> David Bear wrote:
>> I built python 2.4.2 for suse linux 9.3. I configured it to be a separate
>> instance of python from the version packaged with suse.
>> 
>> Now when I start it I get an error:
>> python
>> Python 2.4.2 (#4, Jul 27 2006, 14:34:30)
>> [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> Traceback (most recent call last):
>>   File "/etc/pythonstart", line 7, in ?
>> import readline
>> ImportError: No module named readline
>> 
>> however, I do have readline installed:
>> 
>> rpm -qa | grep readline
>> readline-5.0-7.2
>> readline-32bit-9.3-7.1
>> 
>> it id truly does exist:
>> 
>> locate readline
>> ...
>> /lib/libreadline.so.5
>> /lib/libreadline.so.5.0
>> /lib64/libreadline.so.5
>> /lib64/libreadline.so.5.0
> 
> However, these are not the Python readline module. The Suse package for it
> is probably called python-readline or something like that.
> 
okay. Since I grabbed the python tar file from python.org, do I then assume
that readline is not included in the python source distribution? if so,
where would I find it. If not, what different build instructions do I need
to follow to make it build with readline?
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


current recursion level

2006-08-03 Thread David Bear
Is there an easy way to get the current level of recursion? I don't mean
sys.getrecursionlimit.  I want to know during a live run of a script how
many times the functions has recursed -- curses, I don't know how to say it
better.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


popen2 question

2006-06-21 Thread David Bear
I'm using popen2 and getting an extra 1 at the end of my output. I didn't
see where this was explained in the docs so I clearly don't understand the
behavior. My code is simple.

(input, output) = os.popen2('whackyperlprogram')
results = output.read()
rc = output.close()
print results

The documentation said that the return code would returned with the stdout
handled was closed.

This does not explain why I am getting a '1' appended to the end of the
results.

And yes, there is some functionality bundled in a perl program that I need
-- and I don't have time to reimplement what was written in perl. When I
run the perl code directly, I get the output I want. When I run it through
the os.popen2 module, I get an additional 1 appended. (It's all string
output)

Is this normal behavior for this module? What am I missing?
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


inet_aton and struct issue

2006-08-30 Thread David Bear
I found this simple recipe for converting a dotted quad ip address to a
string of a long int.

struct.unpack('L',socket.inet_aton(ip))[0]

trouble is when I use this, I get

struct.error: unpack str size does not match format

I thought ip addresses were unsigned 32 bit integers.

Is there a better way to take a dotted quad and convert it to a string
representation of an long int?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: inet_aton and struct issue

2006-08-30 Thread David Bear
Diez B. Roggisch wrote:

> David Bear schrieb:
>> I found this simple recipe for converting a dotted quad ip address to a
>> string of a long int.
>> 
>> struct.unpack('L',socket.inet_aton(ip))[0]
>> 
>> trouble is when I use this, I get
>> 
>> struct.error: unpack str size does not match format
>> 
>> I thought ip addresses were unsigned 32 bit integers.
>> 
>> Is there a better way to take a dotted quad and convert it to a string
>> representation of an long int?
> 
> Works for me:
> 
>  >>> import socket
>  >>> import struct
>  >>> ip = "127.0.0.1"
>  >>> struct.unpack('L',socket.inet_aton(ip))[0]
> 2130706433L
> 

I really wish it worked for me:

>>> struct.unpack('L', socket.inet_aton('129.219.120.129'))
Traceback (most recent call last):
  File "", line 1, in ?
struct.error: unpack str size does not match format

This is python packaged with Suse 9.3.
>>> dir(struct)
['__doc__', '__file__', '__name__', 'calcsize', 'error', 'pack', 'unpack']
>>> print struct.__file__
/usr/lib64/python2.4/lib-dynload/struct.so

could I have a broken python?

> 
> Diez

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: inet_aton and struct issue

2006-08-30 Thread David Bear
David Bear wrote:

> Diez B. Roggisch wrote:
> 
>> David Bear schrieb:
>>> I found this simple recipe for converting a dotted quad ip address to a
>>> string of a long int.
>>> 
>>> struct.unpack('L',socket.inet_aton(ip))[0]
>>> 
>>> trouble is when I use this, I get
>>> 
>>> struct.error: unpack str size does not match format
>>> 
>>> I thought ip addresses were unsigned 32 bit integers.
>>> 
>>> Is there a better way to take a dotted quad and convert it to a string
>>> representation of an long int?
>> 
>> Works for me:
>> 
>>  >>> import socket
>>  >>> import struct
>>  >>> ip = "127.0.0.1"
>>  >>> struct.unpack('L',socket.inet_aton(ip))[0]
>> 2130706433L
>> 
> 
> I really wish it worked for me:
> 
>>>> struct.unpack('L', socket.inet_aton('129.219.120.129'))
> Traceback (most recent call last):
>   File "", line 1, in ?
> struct.error: unpack str size does not match format
> 
> This is python packaged with Suse 9.3.
>>>> dir(struct)
> ['__doc__', '__file__', '__name__', 'calcsize', 'error', 'pack', 'unpack']
>>>> print struct.__file__
> /usr/lib64/python2.4/lib-dynload/struct.so
> 
> could I have a broken python?
> 
>> 
>> Diez
> 
I played around with format size and here are some results. (they don't make
sense)

>>> ip1 = '123.254.254.252'
>>> import socket
>>> import struct
>>> ip1s = socket.inet_aton(ip1)
>>> struct.unpack('L',ip1s)
Traceback (most recent call last):
  File "", line 1, in ?
struct.error: unpack str size does not match format
>>> struct.unpack('f',ip1s)
(-1.0592039033369304e+37,)
>>> struct.unpack('I',ip1s)
(4244569723L,)
>>> struct.unpack('Q',ip1s)
Traceback (most recent call last):
  File "", line 1, in ?
struct.error: unpack str size does not match format
>>> struct.unpack('L',ip1s)
Traceback (most recent call last):
  File "", line 1, in ?
struct.error: unpack str size does not match format
>>> struct.unpack('i',ip1s)
(-50397573,)
>>> struct.unpack('I',ip1s)
(4244569723L,)
>>>

So, ip1s really should be a long unsigned int.. but it doesn't decode as
that. Is this the way to interpret this?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


help tranlating perl expressions

2006-09-28 Thread David Bear
I am trying to translate some perl code to python and I need some advice on
making fixed sized strings. The perl code creates a sha1 signatured using a
key and a 'pad'. It creates fixed sized strings as follows:

 my $klen = length($key);
 my $blen = 64;
 my $ipad = chr(0x36)x$blen;
 my $opad = chr(0x5c)x$blen;

I don't know if I ever seen any way in python of created a fixed size
string. Can anyone show me how to implement the same statements in python?

Next, it zero-fills a string to a certain size.

 if($klen <= $blen) {
  $key .= "\0"x($blen-length($key)); #zero-fill to blocksize
 } else {
  $key = sha1($key); #if longer, pre-hash key
 }

Finally it concatenates and xors these strings together like this:

 return sha1($key^$opad . sha1($key^$ipad . $data));

I when python XOR's strings, is it the same as when perl xor's them?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help tranlating perl expressions

2006-09-28 Thread David Bear
Fredrik Lundh wrote:

> David Bear wrote:
> 
>  > I am trying to translate some perl code to python and I need some
>  > advice on making fixed sized strings.
> 
> looks like you're reimplementing HMAC; there's no need to do that in
> Python, really, since it's part of the standard library:
> 
>  http://docs.python.org/lib/module-hmac.html
> 
> pass in hashlib.sha1 instead of the default, and you're done.
> 
> if you insist on doing it yourself, read on:
> 
>>  my $ipad = chr(0x36)x$blen;
>>  my $opad = chr(0x5c)x$blen;
>> 
>> I don't know if I ever seen any way in python of created a fixed size
>> string. Can anyone show me how to implement the same statements in
>> python?
> 
> just remove all the junk, and use multiply instead of "x":
> 
>  ipad = chr(0x36) * blen
>  opad = chr(0x5c) * blen
> 
> however, Python strings are not mutable, so to implement the rest of
> that algorithm, you probably want to use a list or array object instead.
>   the md5-example-4.py script on this page shows one way to do that:
> 
>  http://effbot.org/librarybook/md5.htm
> 
> to get a SHA-1 hmac, you have to replace "md5" with "sha".
> 
> 

Yes, this is what I am doing. Because I am using code sold to me by a vendor
-- I was worried that they are doing something with it that had some
dependencies on the way perl was making the digest. So I was trying to
better understand the perl by doing it in python.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


understanding htmllib

2006-10-03 Thread David Bear
I'm trying to understand how to use the HTMLParser in htmllib but I'm not
seeing enough examples.

I just want to grab the contents of everything enclosed in a '' tag,
i.e. items from where  begins to where  ends. I start by doing

class HTMLBody(HTMLParser):
   def __init__(self):
  self.contents = []

   def handle_starttag()..

Now I'm stuck. I cant see that there is a method on handle_starttag that
would return everthing to the end tag. And I haven't seen anything on how
to define my one handle_unknowntag..

Any pointers would be greatly appreciated. The documentation on this module
at python.org seems to assume a great deal about what the reader would
already know about which methods they should subclass.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


creating a hex value

2005-06-01 Thread David Bear
I have a file that I need to parse. Items in it are delimited by a hex 15
(0x015). I know it must be trivial to assign a hex value to a variable but
I'm not seeing it in my python essential ref. how can I do

delim = 0x15
while:
ln = file.read()
if ln[0] == delim:
do something

I've looked at the hex function but it doesn't sound like what I want.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


EOFError not getting raised

2005-06-09 Thread David Bear
I have been trying to do something like this:

f = open('someDocs.str', 'r')
try:
while True:
ln = f.readline()
except EOFError:
print 'reached eof'
f.close()
sys.exit(1)


However, EOFError is never raised. What am I missing? 
-- 
http://mail.python.org/mailman/listinfo/python-list


just learning eric ide

2005-06-13 Thread David Bear
Eric is the first IDE I have used since the borland c++ ide for dos many
many years ago. Aside from the docs that come in the help system, I'm
looking for a quick tutorial that gives me an overview of the test, debug
cycle that is considered -- for beginners.

any pointers or books. This seems like a terrific environment.
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


running a random function

2007-06-07 Thread David Bear
I would like to write some code that would randomly select a function from a
list of functions and call it. I was looking in the globals names space and
randomly selecting items that were of type function.. but I didn't see a
way of actually running the function.

Any pointers?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a process every N days

2007-06-07 Thread David Bear
[EMAIL PROTECTED] wrote:

> What's the best way to run either an entire python process or a python
> thread every N days. I'm running Python 2.4.3 on Fedora Core 5 Linux.
> My code consists of a test and measurement system that runs 24/7 in a
> factory setting. It collects alot of data and I'd like to remove all
> data older than 30 days. My ideal solution would be something that
> runs in the background but only wakes up to run every few days to
> check for old data.
> 
> Thanks,
> 
> Dan McLeran


And you can use cron to launch your python program?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


storing pickles in sql data base

2007-07-10 Thread David Bear
I need to store pickled objects in postgresql. I reading through the pickle
docs it says to always open a file in binary mode because you can't be sure
if the pickled data is binary or text. So I have 2 question. Can I set the
pickle to be text -- and then store it in a 'text' type field in my sql
table, or should what sql type should I save the pickle as?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


persistent fifo queue class

2007-03-05 Thread David Bear
I'm looking to see if there are any examples or prewritting fifo queue
classes. I know this is a broad topic. I'm looking to implement a simple
application where a web server enqueue and pickle using a local socket on
to a 'queue server' -- and then I will have another application dequeue the
pickles again using a local socket.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


using python to query active directory

2007-03-06 Thread David Bear
Is it possible to use python to make calls agains microsoft active
directory? I suppose this should be qualified by what is needed to do it
from windows (I assume the win32all package) and from linux (if possible).
Any code samples would be great. 
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using python to query active directory

2007-03-06 Thread David Bear
jay graves wrote:

> On Mar 6, 1:34 pm, David Bear <[EMAIL PROTECTED]> wrote:
>> Is it possible to use python to make calls agains microsoft active
>> directory? I suppose this should be qualified by what is needed to do it
>> from windows (I assume the win32all package) and from linux (if
>> possible). Any code samples would be great.
> 
> Tim Golden is your man.
> 
> http://tgolden.sc.sabren.com/python/active_directory.html
> 

Yes, thank you. This looks great.
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: persistent fifo queue class

2007-03-07 Thread David Bear
Diez B. Roggisch wrote:

> David Bear schrieb:
>> I'm looking to see if there are any examples or prewritting fifo queue
>> classes. I know this is a broad topic. I'm looking to implement a simple
>> application where a web server enqueue and pickle using a local socket on
>> to a 'queue server' -- and then I will have another application dequeue
>> the pickles again using a local socket.
> 
> Why don't you use a DB for that? If you want pickles, use a  blob
> column. But all the rest - a defined protocol, stable server,
> transactions - you get for free.
> 
> Diez

Thanks for the suggestion. I did think of this. Indeed the final destination
of the data is in a db. However, the postsgresql server is on a separate
box. It will be connected via a private lan. I was worried that possible
network disruptions would cause either the web application to hang -- or
data to just get lost. I was thinking along the lines is a message queue
architecture, where the web app would push data directly onto a queue --
and then a worker app would dequeue the data and handle it by sending it to
the db server or otherwise.


-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


string templates

2007-04-04 Thread David Bear
I was justing wondering how safe python string templates are to use with
unicode. I was just scanning pep 292 and it seems to say that they are --
or can by with inheritance... but I don't quite understand.


-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


python 2.3 module ref

2007-01-29 Thread David Bear
Since redhat packages python2.3 with their distro (RHEL 4..) I was looking
for a module reference for that version. Looking at python.org I only see
current documentation.

any pointers to a 2.3 module ref?
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


more examples on lamba

2007-02-02 Thread David Bear
I've been going through David Mertz's python book and he is heavy in to
lamba's and higher order functions. This is all very new to me. 

Can anyone point me to more web stuff that describes more deeply lamba's and
making high order functions -- functional programming styles. 

Coming from BASIC and Pascal, these are constructions that never entered
into youthfull learning;-)

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


calling perl modules from python

2006-05-11 Thread David Bear
I have a hash function written by another organization that I need to use.
It is implemented in perl. I've been attempting to decode what they are
doing in their hash  function and it is taking way too long. I've
identified two functions in a perl module that I would like to 'call' from
a python program. I found the following:
http://www.annocpan.org/~GAAS/pyperl-1.0/perlmodule.pod

and wondered if anyone had any comments. This thing implements a perl
interpreter inside python. That seems like overkill to me.

I wonder what wisdom this group can offer.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


apache config file parser

2006-03-17 Thread David Bear
I was wondering if anyone has written an apache config file parser in
python. There seem to be a number of perl mods to do this. But I don't seem
to be able to find anything in python.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python cgi permision error

2006-03-17 Thread David Bear
[EMAIL PROTECTED] wrote:

> Hi
> 
> I have python cgi script, but when I call it I got server internal
> error. The log in my apache is
> 
> [Sat Mar 18 04:17:14 2006] [error] [client 127.0.0.1] (13)Permission
> denied: exec of '/srv/www/cgi-bin/helo.cgi' failed
> [Sat Mar 18 04:17:14 2006] [error] [client 127.0.0.1] Premature end of
> script headers: helo.cgi
> [Sat Mar 18 04:20:09 2006] [notice] caught SIGTERM, shutting down
> 
> I have set the correct permision for the script(755) and the script is
> also own by apache uid.

assuming you are running this python script the standard cgi way and not
through modpython or fastcgi.

try debugging this way.

execute the python script from command line as the web user. 

make sure your python script prints the standard 

"""Content-type: text/html

"""

header.

> I think somehow apache cannot run python to process my python cgi
> script, but I don't know what I should do anymore.
> When I run it via shell, the cgi work fine
> I also can't make my mod_python .py write anything inside my /var/www
> dir although permision already true, even if I gave /var/www permision
> recursively to 777(I know this not good idea, just for testing), still
> have permision denied stuff.
> Btw I'm using SuSE 10, Apache/2.0.54, and python 2.4
> Sighhh, there's a lot of weird thing with my apache and I can't
> understand why :'(

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


using a perl mod

2006-03-27 Thread David Bear
almost 41 million hits from google about using perl mod's in python was a
bit discouraging...So, I thought about asking humans.

There are some perl modules written to manage files, acls, etc in afs.
Rather than wrapping the c-compiled versions of afs commands in sys.popen
and parsing the output, I was hoping to use the perl mods and the perl
objects returned by these mods in python -- since I can't stand reading
perl.

The question then becomes, are there any python modules that encapsulate and
map perl objects into python object?
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


unboundlocalerror with cgi module

2006-04-10 Thread David Bear
I'm attempting to use the cgi module with code like this:

import cgi
fo = cgi.FieldStorage()
# form field names are in the form if 'name:part'
keys = fo.keys()
for i in keys:
try:
item,value=i.split(':')
except NameError, UnboundLocalError:
print "exception..."
item,value=(None,None)
return(item,value)

However, the except block does not seem to catch the exception and an
unboundlocalerror is thrown anyway. What am I missing?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list