PChess 0.9

2007-05-07 Thread majeed rana
I want pchess 0.9-- 
http://mail.python.org/mailman/listinfo/python-list

Re: CGI python use under a curse

2007-05-07 Thread Adrian Smith
On May 7, 2:30 pm, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 On Sun, 06 May 2007 21:30:16 -0700, Adrian Smith wrote:

 It is NOT the same error. There are NO syntax errors in the script, there
 is a runtime error. The so-called administrator is wrong: you can't use
 Perl to test just any old CGI scripts. They have to be written in Perl.

Well, I thought that, but you know what happens to newbies who come
out with such opinions forcefully. Maybe they have special magic perl
which parses python.

 I see from the source code on your page that you have a line:

 TEXTAREA NAME=essay COLS=60 ROWS=20 WRAP=HARD/TEXTAREA

 You have two lines in your cgi script:

 form = cgi.FieldStorage()
 print form[essay].value

 Having never done cgi programming, I'm not sure what the problem is, but
 after reading help(cgi) I'll take a stab in the dark and say try this:

 print form.value

 It might also help for you to try this:

 print form.keys()

Both give me the same ISE, alas.

 Good luck with the admins at your hosting company.

Well, it *is* free, and there aren't that many free ones that offer
Python. My paid-for host has sent me a message to say they're
ruminating on my issues, though, so I live in hope.

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


Re: Help creating Tiger hash function in Python

2007-05-07 Thread Vyacheslav Maslov
 I am a Uni student and for a project in Information Systems Security due
 in just under two weeks, I have tried to make a Python version of the
 Biham / Anderson Tiger Hash function. I have put the original C source
 and my two files Tiger.py and doHash.py on my website:
 
 http://www.users.on.net/~mlivingstone/
 
 My problems are doubtless basic since I have been teaching myself
 Python. My best knowledge is Java :-(
 
 Firstly, in doHash.py, I cannot invoke tiger() without getting unbounded
 errors and / or complaints about no such method.

First of all you should create an instance of you Tiger class, you try 
to do this by line:
x = Tiger.Tiger

But this is wrong, because you should call constructor and pass all 
necessary parameters, in very simple case:
x = Tiger.Tiger() (if there is no constructor parameters)

-- 
Vyacheslav Maslov
SWsoft, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


PChess 0.9

2007-05-07 Thread majeed rana
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problem to Download ftp file

2007-05-07 Thread Stefan Sonnenberg-Carstens
Perhaps a problem with name resolution ?

On Mo, 7.05.2007, 07:27, Shakil Ahmed wrote:
 hi
 Actually i need to know that how can i download a ftp file from ncbi by
 using python module ftputil.
 please help me.

 Thanks
 regards,
 Shakil

 import ftputil

 host = ftputil.FTPHost('ftp.ncbi.nih.gov/repository/OMIM/morbidmap',
 'anonymous', 'password')





 The Error message is:

 raise FTPOSError(ftp_error)

 FTPOSError: (11001, 'getaddrinfo failed')

 Debugging info: ftputil 2.2.2, Python 2.4.3 (win32)





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

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


Re: default test method name in unittest framework

2007-05-07 Thread Gabriel Genellina
En Sun, 06 May 2007 22:17:44 -0300, Vyacheslav Maslov  
[EMAIL PROTECTED] escribió:

 i have question related to python's unit testing framework.

 Take a look at unittest.TestCase class. The main method which contains  
 all
 code related to test case execution have name run. But in the same time
 constructor of unittest.TestCase class have param methodName with default
 value runTest, not run! Why? This leads to AttributeError exception  
 if i
 do not explicitly set methodName to run during TestCase initialization.

No: method run is used by the framework, it internally calls the setUp,  
tearDown, etc. You don't have to override run (you must not override  
run!), instead, you provide the runTest method in your class.
Furthermore, instead of many similar TestCase classes, you can write a  
single class with many methods named testXXX, and they will be found and  
used by a TestLoader.

-- 
Gabriel Genellina

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


Re: problem with quoted strings while inserting into varchar field of database.

2007-05-07 Thread krishnakant Mane
On 6 May 2007 11:22:52 -0700, Daniele Varrazzo [EMAIL PROTECTED] 
 Every serious database driver has a complete and solid SQL escaping
 mechanism. This mechanism tipically involves putting placeholders in
 your SQL strings and passing python data in a separate tuple or
 dictionary. Kinda

 cur.execute(INSERT INTO datatable (data) VALUES (%s);,
 (pickled_data,))

I will try doing that once I get back to the lab.
mean while I forgot to mention in my previous email that I use MySQLdb
for python-mysql connection.
I did not find any such reference to storing pickled objects in the API.

any Idea what could be done with the mysql python module I am using?
regards,
Krishnakant.
-- 
http://mail.python.org/mailman/listinfo/python-list


N00b question on Py modules

2007-05-07 Thread lokesh . jagasia
Hi. Sorry to sound like a noob but that's what I am when it comes to
Python. I just wrote the below module and it behaves funny.

My python module:

_exitcode = 0

def setExitCode():
_exitcode = 1

if __name__ == '__main__':
print _exitcode
setExitCode()
print _exitcode

Actual O/P:
0
0

I expected to see an output of 0 followed by 1. But it turns out that
the _exitcode variable is not changed at all. It seems that
setExitCode() might be editing a local copy of the _exitcode variable.
But then, how do I tell it to change the value of the module variable
and not its local variable.

I've been through the modules section of Python docs and a few ebooks
as well, all suggest that it shouldn't be working this way.

Please help out ppl.

Thanks

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


Re: DiffLib Question

2007-05-07 Thread Gabriel Genellina
En Mon, 07 May 2007 00:52:18 -0300, whitewave [EMAIL PROTECTED] escribió:

 I am currently doing the third option. Doing file.read() to both file
 to be compared then feed the result to the compare function.

 Let me give you a brief sample of what I want to achieve.

 Using this code
 diffline=[]
 fileDiff = difflib.Differ().compare(f1, f2)
 diffline = list(fileDiff)
 finStr = ''.join(diffline)

So you are concerned with character differences, ignoring higher order  
structures. Use a linejunk filter function to the Differ constructor -as  
shown in my post last Wednesday- to ignore \n characters when matching.  
That is:

def ignore_eol(c): return c in \r\n
fileDiff = difflib.Differ(linejunk=ignore_eol).compare(f1, f2)
print ''.join(fileDiff)

you get:

-T  h  e s  o  l  v  a  b+ i  l- e+ i+ t+ y c  o  n  d  i  t   
i  o
n  s a  n  d t  h  e G  r  e  e  n  '  s f  u  n  c  t  i   
o  n
  s o  f l  i  n  e  a  r b  o  u  n  d  a  r  y v  a  l   
u  e-
+p  r  o  b  l  e  m  s f  o  r o  r  d  i  n  a  r  y-  +
   d  i  f  f  e  r  e  n  t  i  a  l e  q  u  a  t  i  o  n  s w   
i  t
h s  u  f  f  i  c  i  e  n  t  l  y s  m  o  o  t  h c  o  e   
f  f
  i  c  i  e  n  t  s h  a  v  e b  e  e  n-
+i  n  v  e  s  t  i  g  a  t  e  d i  n d  e  t  a  i  l  
b  y
  + m+ a+ n+ y+
- o- t- h- e- r-a  u  t  h  o  r  s \  c  i  t  e  {  C  R  1  ,   
C  R
2  ,  C  R  3  ,  C  R  4  ,  C  R  5  }  .

-- 
Gabriel Genellina

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


Re: N00b question on Py modules

2007-05-07 Thread Christoph Haas
On Mon, May 07, 2007 at 12:00:38AM -0700, [EMAIL PROTECTED] wrote:
 Hi. Sorry to sound like a noob but that's what I am when it comes to
 Python. I just wrote the below module and it behaves funny.
 
 My python module:
 
 _exitcode = 0
 
 def setExitCode():
 _exitcode = 1
 
 if __name__ == '__main__':
 print _exitcode
 setExitCode()
 print _exitcode
 
 Actual O/P:
 0
 0
 
 I expected to see an output of 0 followed by 1. But it turns out that
 the _exitcode variable is not changed at all. It seems that
 setExitCode() might be editing a local copy of the _exitcode variable.
 But then, how do I tell it to change the value of the module variable
 and not its local variable.

_exitcode is a global variable in your program. In functions (def) you
can read global variables. But if you change or reassign them the change
will be only local to the function. If you want to change the global
variable your def needs to be:

def setExitCode():
global _exitcode
_exitcode = 1

Kindly
 Christoph

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


Re: N00b question on Py modules

2007-05-07 Thread rishi pathak

Hi
this  variable is local to function
do this
def setExitCode():
  global _exitcode
  _exitcode = 1
On 7 May 2007 00:00:38 -0700, [EMAIL PROTECTED] 
[EMAIL PROTECTED] wrote:


Hi. Sorry to sound like a noob but that's what I am when it comes to
Python. I just wrote the below module and it behaves funny.

My python module:

_exitcode = 0

def setExitCode():
_exitcode = 1



this  variable is local to function

if __name__ == '__main__':

print _exitcode
setExitCode()
print _exitcode

Actual O/P:
0
0

I expected to see an output of 0 followed by 1. But it turns out that
the _exitcode variable is not changed at all. It seems that
setExitCode() might be editing a local copy of the _exitcode variable.
But then, how do I tell it to change the value of the module variable
and not its local variable.

I've been through the modules section of Python docs and a few ebooks
as well, all suggest that it shouldn't be working this way.

Please help out ppl.

Thanks

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





--
Regards--
Rishi Pathak
National PARAM Supercomputing Facility
Center for Development of Advanced Computing(C-DAC)
Pune University Campus,Ganesh Khind Road
Pune-Maharastra
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: N00b question on Py modules

2007-05-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], lokesh.jagasia
wrote:

 My python module:
 
 _exitcode = 0
 
 def setExitCode():
 _exitcode = 1
 
 if __name__ == '__main__':
 print _exitcode
 setExitCode()
 print _exitcode
 
 Actual O/P:
 0
 0
 
 I expected to see an output of 0 followed by 1. But it turns out that
 the _exitcode variable is not changed at all. It seems that
 setExitCode() might be editing a local copy of the _exitcode variable.
 But then, how do I tell it to change the value of the module variable
 and not its local variable.

Any name that gets bound to an object within a function is local to that
function unless you declare it as ``global``.  But using lots of global
variables is considered bad style so you may think about rewriting
functions with ``global`` names to return the value(s) instead:

_exitcode = 0

def set_exitcode():
return 1

if __name__ == '__main__':
print _exitcode
_exitcode = set_exitcode()
print _exitcode

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie prob: How to write a file with 3 threads?

2007-05-07 Thread est
On May 7, 5:12 am, MRAB [EMAIL PROTECTED] wrote:
 On May 6, 9:51 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: In 
 [EMAIL PROTECTED], est wrote:
   I need to write a file using 3 threads simutaniously, e.g. Thread 1
   write the first byte of test.bin with an a, second thread write the
   second byte b, third thread write the third byte c. Anyone could
   give a little example on how to do that?

  Simplest solution is: don't do that.  Write from one thread and send the
  date from the other threads via a `Queue.Queue` to the writing thread.
  Send the number of the thread with the data so the writer thread knows in
  which order the data has to be written.

 [snip]
 Or have a `Queue.Queue` for each source thread and make the writer
 thread read from each in turn.


I'll try Queue.Queue, thank you. I didn't expect that multithread
write a file is so troublesome

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


Re: N00b question on Py modules

2007-05-07 Thread Gary Herron
[EMAIL PROTECTED] wrote:
 Hi. Sorry to sound like a noob but that's what I am when it comes to
 Python. I just wrote the below module and it behaves funny.

 My python module:

 _exitcode = 0

 def setExitCode():
 _exitcode = 1

 if __name__ == '__main__':
 print _exitcode
 setExitCode()
 print _exitcode

 Actual O/P:
 0
 0

 I expected to see an output of 0 followed by 1. But it turns out that
 the _exitcode variable is not changed at all. It seems that
 setExitCode() might be editing a local copy of the _exitcode variable.
 But then, how do I tell it to change the value of the module variable
 and not its local variable.

 I've been through the modules section of Python docs and a few ebooks
 as well, all suggest that it shouldn't be working this way.

 Please help out ppl.
   

It's a scoping problem. The line

_exitcode = 0

creates a (module level) global object.

But in 

def setExitCode():
_exitcode = 1

you are running into Python's default presumption that variables assigned to in 
a function are *local* to that function.  And like all local variables, they 
can be set and used within the function, but are independent of objects outside 
the function.

If you want to assign to a global object from within a function, then you must 
explicitly say so:

def setExitCode():
global _exitcode
_exitcode = 1

See: http://docs.python.org/ref/global.html 

Gary Herron


 Thanks

   

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


Re: c macros in python.

2007-05-07 Thread A.T.Hofkamp
On 2007-05-06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hey,

 I'm writing a script to generate code. I'm a bit tired of typing
 outfile.write(). Does python have a way to c-like macros? Every
 instance of o(...) in the code will be replaced by outfile.write(...)?

Just in case you don't know, you can write an arbitrary number of lines in one
write. Below is how I format a usage() message of a program in one write call:

def usage(fp):
fp.write(Usage: convert options [infile] [outfile]\n
with\n
options\n
\t--prefix=name-prefix\t(obligatory)\n
\t--write-size\t\tWrite a line containing the size\n
\t--append-zero\t\tAppend a terminating 0 byte\n)

ie one multi-line write call. Pyhon concatenates two consequtive string
literals for us. Unfortunately, this gets less pretty when inserting variable
values.




In other code generation code, I normally use a list of lines. Rather than
writing everything directly to file, I make a list data structure containing
lines, then dump the list to file, as in:

lines = []
gencode_first(lines)
gencode_second(lines)
lines.append(the end)
write_lines(lines)

where write_lines() is

def write_lines(lines):
for line in lines:
outfile.write(line)
outfile.write('\n')

(i left out the opening and closing of outfile).


I normally do not include the \n in the list but instead add it while writing
it to file. This makes life much easier since there are no special last-value
problems in the code generator itself.
The nice thing here is that 'lines' is a normal data structure which you can
manipulate if you like.




For more demanding code generators (ie C or C++ code) I use the concept
'sections'. At a global level, the generated code has an 'include',
'declarations', 'definitions', and 'main' section, each section is a list of
lines.
I use a dictionary for this, like

output = { 'incl': [], 'decl': [], 'def': [], 'main': [] }

then pass around this in the code generator.
Each part of the generator can write in each section, for example when defining
a C function, you can write the declaration in the decl section and the
definition in the def section at the same time.
For example

def write_c_function(output):
output['decl'].append('int mycfunc(void);')
output['def'].extend(['int myfunc(void)', '{' 'return 131;', }' ])

Reducing such a dictionary to a list is then something like

def make_lines(sec_list, output):
lines = []
for sec in sec_list:
lines.extend(output[sec])
return lines

And outputting the code is then something like

write_lines(make_lines(['incl', 'decl', 'def', 'main'], output))

In this way you can abstract away from the order of code as required by the
target language and instead generate code in a nicer order.
Note that this section trick can be done recursively. for example, a function
can be thought of as a number of sections like

funcoutput = { 'header': [], 'opening-bracket' : [], 'localvars':[], 
'closing-bracket': [] }

so you can generate a function using sections as well, then at the end reduce
funcoutput to a list of lines, and insert that in a section of the global
'output'.




Last but not least, if you replace the lists by an object, you can do much
smarter things. For example, in general you don't want to have double #include
lines in the 'incl' section. Instead of worrying about generation of doubles,
just make an object that behaves like a list but silently drops doubles.
In the same way, you can create a list-like object that handles indenting for
you.

The possibilities here are endless!!


Good luck with your code generation problem, I hope I gave you some ideas of
alternative solutions that are available.

Albert

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


Re: Examples / Links needed

2007-05-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Andy wrote:

 Gurus, I'm looking for definite examples (pardon me if I'm not clear
 here) on Stack class...Somewhat like this :
 
 class Stack(object):
   def __init__(self__)
   self.__contents = []

I don't know what to tell you here without writing the thing for you.  Ask
yourself what operations a `Stack` needs and look at the documentation for
`list` operations.  It's pretty easy to map the stack operations to `list`
ones.

 and ad hoc implementation of a class based on number system like for
 example somewhat like this
 
 
 def __imult__(self, other):
self.__numerator   *= other.__numerator
self.__denominator *= other.__denominator
.
.
   return self

So what exactly is your problem?  Take a number like, look at the
methods it implements and do this for your number like class.

 I'm not satisfied with Python Docs.

Why?  What does `Emulating numeric types`_ in the reference manual lack in
your opinion?

.. _Emulating numeric types: http://docs.python.org/ref/numeric-types.html

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: N00b question on Py modules

2007-05-07 Thread Steven D'Aprano
On Mon, 07 May 2007 00:00:38 -0700, lokesh.jagasia wrote:

 I expected to see an output of 0 followed by 1. But it turns out that
 the _exitcode variable is not changed at all. It seems that
 setExitCode() might be editing a local copy of the _exitcode variable.

Yes, that's exactly what is happening.


 But then, how do I tell it to change the value of the module variable
 and not its local variable.

(1) Don't do that.

(2) If you think you really need to do it, you don't.

(3) If you REALLY need to do it, use the statement:

global variable name

in your function.

Over-use of global variables is one of the sins of programming. Some 
people might even say that using ANY global variables is a sin. I'm not 
that strict, but I encourage you to avoid global variables if you can.

See here for more details:

http://en.wikipedia.org/wiki/Global_variable




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


Re: Newbie prob: How to write a file with 3 threads?

2007-05-07 Thread Gary Herron
est wrote:
 On May 7, 5:12 am, MRAB [EMAIL PROTECTED] wrote:
   
 On May 6, 9:51 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: In 
 [EMAIL PROTECTED], est wrote:
 
 I need to write a file using 3 threads simutaniously, e.g. Thread 1
 write the first byte of test.bin with an a, second thread write the
 second byte b, third thread write the third byte c. Anyone could
 give a little example on how to do that?
 
 Simplest solution is: don't do that.  Write from one thread and send the
 date from the other threads via a `Queue.Queue` to the writing thread.
 Send the number of the thread with the data so the writer thread knows in
 which order the data has to be written.
   
 [snip]
 Or have a `Queue.Queue` for each source thread and make the writer
 thread read from each in turn.
 


 I'll try Queue.Queue, thank you. I didn't expect that multithread
 write a file is so troublesome
   

As a general rule, *ALL* multithread operations are at least that
troublesome, and most are far more so.

Pessimistically-yours,
Gary Herron


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


Re: invoke user's standard mail client

2007-05-07 Thread Gabriel Genellina
En Mon, 07 May 2007 01:52:18 -0300, [EMAIL PROTECTED]  
[EMAIL PROTECTED] escribió:

 On May 6, 9:50 am, Gabriel Genellina [EMAIL PROTECTED] wrote:

 On Windows you can use MAPI.
 But how? I could not find any starting point.
Get the pywin32 package (Python for Windows extensions) from sourceforge,  
install it, and look into the win32comext\mapi\demos directory.

 I found examples about sending mail directly, which gives me the
 impression that MAPI is just Microsoft's version of SMTP. This is not
 what I need. I need the user's client to start, so that the user may
 edit the message and decide herself whether she clicks on the Send
 button to really send it.

No, it should launch the email client (Outlook Express by example) and let  
the user confirm it. I think there were some flags to suppress the GUI or  
the confirmation, but they're not honored anymore, I presume. At least  
Eudora warns the user on such attempts.

-- 
Gabriel Genellina

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


long lists

2007-05-07 Thread Merrigan
Hi All,

Firstly - thank you Sean for the help and the guideline to get the
size comparison, I will definitely look into this.

At the moment I actually have 2 bigger issues that needs sorting...

1. I have the script popping all the files that need to be checked
into a list, and have it parsing the list for everything...Now the
problem is this : The sever needs to check (at the moment) 375 files
and eliminate those that don't need reuploading. This number will
obviously get bigger and bigger as more files gets uploaded. Now, the
problem that I'm having is that the script is taking forever to parse
the list and give the final result. How can I speed this up?

2. This issue is actually because of the first one. While the script
is parsing the lists and files, the connection to the ftp server times
out, and I honestly must say that is is quite annoying. I know I can
set the function to reconnect if it cannot find a connection, but
wouldn't it just be easier just to keep the connection alive? Any idea
how I can keep the connection alive?

Thanks for all the help folks, I really appreciate it!

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


Re: Problem to Download ftp file

2007-05-07 Thread Gabriel Genellina
En Mon, 07 May 2007 02:27:59 -0300, Shakil Ahmed  
[EMAIL PROTECTED] escribió:

 Actually i need to know that how can i download a ftp file from ncbi by
 using python module ftputil.

 import ftputil

 host = ftputil.FTPHost('ftp.ncbi.nih.gov/repository/OMIM/morbidmap',
 'anonymous', 'password')

The host is the first part, ftp.ncbi.nih.gov. The remaining parts are  
a directory and a filename. You should write:

host = ftputil.FTPHost('ftp.ncbi.nih.gov','anonymous', 'password')
host.chdir('repository/OMIM')
host.download('morbidmap','path/to/local/file/morbidmap','b')

See the ftputil documentation for more info.

-- 
Gabriel Genellina

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


Re: default test method name in unittest framework

2007-05-07 Thread Vyacheslav Maslov

Yes, i general you are right. I meant following case, please look at my
example

Suppose i have following simple test case:

import unittest

class SomeTest(unittest.TestCase):

   def testAdd(self):
   self.assertEqual(2+2,4)

if __name__==__main__:
   unittest.TextTestRunner().run(SomeTest())

this code produce following exception:
ValueError: no such test method in class '__main__.SomeTest': runTest

Because default test method name is run, but TestCase class have
constructor parameter testMethod with default value runTest not run!

As result i always should explicitly pass testMethod name when create object
of test case class:
   unittest.TextTestRunner().run(SomeTest(run))

Why i should do this?

2007/5/7, Gabriel Genellina [EMAIL PROTECTED]:


En Sun, 06 May 2007 22:17:44 -0300, Vyacheslav Maslov
[EMAIL PROTECTED] escribió:

 i have question related to python's unit testing framework.

 Take a look at unittest.TestCase class. The main method which contains
 all
 code related to test case execution have name run. But in the same
time
 constructor of unittest.TestCase class have param methodName with
default
 value runTest, not run! Why? This leads to AttributeError exception
 if i
 do not explicitly set methodName to run during TestCase
initialization.

No: method run is used by the framework, it internally calls the setUp,
tearDown, etc. You don't have to override run (you must not override
run!), instead, you provide the runTest method in your class.
Furthermore, instead of many similar TestCase classes, you can write a
single class with many methods named testXXX, and they will be found and
used by a TestLoader.

--
Gabriel Genellina

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

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

Re: PChess 0.9

2007-05-07 Thread Brian van den Broek
majeed rana said unto the world upon 05/07/2007 01:13 AM:
 I want pchess 0.9
 

I want a mansion and a yacht. Unlike you, google can't help me. 
http://www.google.ca/search?q=PCHess

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


Re: default test method name in unittest framework

2007-05-07 Thread Gabriel Genellina
En Mon, 07 May 2007 04:49:12 -0300, Vyacheslav Maslov  
[EMAIL PROTECTED] escribió:

 Yes, i general you are right. I meant following case, please look at my
 example

 Suppose i have following simple test case:

 import unittest

 class SomeTest(unittest.TestCase):

 def testAdd(self):
 self.assertEqual(2+2,4)

 if __name__==__main__:
 unittest.TextTestRunner().run(SomeTest())

 this code produce following exception:
 ValueError: no such test method in class '__main__.SomeTest': runTest

 Because default test method name is run, but TestCase class have
 constructor parameter testMethod with default value runTest not run!

NO! the default test method name is not run but runTest, as explained  
in my previous post. You can either rename the testAdd method to runTest,  
or change the last line to be, simply:

if __name__==__main__:
unittest.main()

main() will create a TestRunner, a TestLoader, a TestSuite containing all  
your TestCases, and run them.

 As result i always should explicitly pass testMethod name when create  
 object
 of test case class:
 unittest.TextTestRunner().run(SomeTest(run))

 Why i should do this?

You should *not* do that! Your tests will not even be run that way.

-- 
Gabriel Genellina

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


Re: msbin to ieee

2007-05-07 Thread revuesbio
On 7 mai, 03:52, John Machin [EMAIL PROTECTED] wrote:
 On May 7, 7:44 am, revuesbio [EMAIL PROTECTED] wrote:

  Hi
  Does anyone have the python version of the conversion from msbin to
  ieee?
  Thank u

 Yes, Google has it. Google is your friend. Ask Google. It will lead
 you to such as:

 http://mail.python.org/pipermail/python-list/2005-August/337817.html

 HTH,
 John

Thank you,

I've already read it but the problem is always present. this script is
for double precision MBF format ( 8 bytes).
I try to adapt this script for single precision MBF format ( 4 bytes)
but i don't find the right float value.

for example : 'P\xad\x02\x95' will return '0.00024924660101532936'



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


Re: long lists

2007-05-07 Thread Steven D'Aprano
On Mon, 07 May 2007 00:28:14 -0700, Merrigan wrote:

 1. I have the script popping all the files that need to be checked into
 a list, and have it parsing the list for everything...Now the problem is
 this : The sever needs to check (at the moment) 375 files and eliminate
 those that don't need reuploading. This number will obviously get bigger
 and bigger as more files gets uploaded. Now, the problem that I'm having
 is that the script is taking forever to parse the list and give the
 final result. How can I speed this up?

By writing faster code???

It's really hard to answer this without more information. In particular:

- what's the format of the list and how do you parse it?

- how does the script decide what files need uploading?



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


Re: problem with quoted strings while inserting into varchar field of database.

2007-05-07 Thread Daniele Varrazzo
On 7 Mag, 08:55, krishnakant Mane [EMAIL PROTECTED] wrote:
 On 6 May 2007 11:22:52 -0700, Daniele Varrazzo [EMAIL PROTECTED]  Every 
 serious database driver has a complete and solid SQL escaping
  mechanism. This mechanism tipically involves putting placeholders in
  your SQL strings and passing python data in a separate tuple or
  dictionary. Kinda

  cur.execute(INSERT INTO datatable (data) VALUES (%s);,
  (pickled_data,))

 I will try doing that once I get back to the lab.
 mean while I forgot to mention in my previous email that I use MySQLdb
 for python-mysql connection.

OK: MySQLdb implements the escaping mechanism i described. You can
find the documentation if you look for it harder.

 I did not find any such reference to storing pickled objects in the API.

Storing pickled object is not different from storing anything else
into BLOB. You would have faced the same problem if you had to write
O'Reilly in a VARCHAR field.

-- Daniele

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


Re: problem with quoted strings while inserting into varchar field of database.

2007-05-07 Thread Stefan Sonnenberg-Carstens
On Mo, 7.05.2007, 10:30, Daniele Varrazzo wrote:
 On 7 Mag, 08:55, krishnakant Mane [EMAIL PROTECTED] wrote:
 On 6 May 2007 11:22:52 -0700, Daniele Varrazzo
 [EMAIL PROTECTED]  Every serious database driver has a
 complete and solid SQL escaping
  mechanism. This mechanism tipically involves putting placeholders in
  your SQL strings and passing python data in a separate tuple or
  dictionary. Kinda

  cur.execute(INSERT INTO datatable (data) VALUES (%s);,
  (pickled_data,))

 I will try doing that once I get back to the lab.
 mean while I forgot to mention in my previous email that I use MySQLdb
 for python-mysql connection.

 OK: MySQLdb implements the escaping mechanism i described. You can
 find the documentation if you look for it harder.

 I did not find any such reference to storing pickled objects in the API.

 Storing pickled object is not different from storing anything else
 into BLOB. You would have faced the same problem if you had to write
 O'Reilly in a VARCHAR field.

 -- Daniele

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


Why not use qmark parameter passing (PEP 249) ?

cur.execute(INSERT INTO datatable (data) VALUES (?); , (pickled_data,))

Then the DB driver will take care for you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Properties on old-style classes actually work?

2007-05-07 Thread Paul Melis
Hello,

The python library docs read in section 2.1 
(http://docs.python.org/lib/built-in-funcs.html):


...

property(   [fget[, fset[, fdel[, doc)
 Return a property attribute for new-style classes (classes that 
derive from object).

...



But in 2.4 at least properties also seem to work for old-style classes:

class O:

 def __init__(self):
 self._x = 15

 def get_x(self):
 return self._x

 x = property(get_x)

o = O()
print o.x

outputs 15 as expected for the property.

Regards,
Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Properties on old-style classes actually work?

2007-05-07 Thread Steven D'Aprano
On Mon, 07 May 2007 10:44:35 +0200, Paul Melis wrote:

 Hello,
 
 The python library docs read in section 2.1
 (http://docs.python.org/lib/built-in-funcs.html):
 
 
 ...
 
 property( [fget[, fset[, fdel[, doc)
  Return a property attribute for new-style classes (classes that
 derive from object).
 
 ...
 
 
 
 But in 2.4 at least properties also seem to work for old-style classes:


Unfortunately, they don't -- they seem to work until you try assigning to 
them. Here's the same property implemented with a new-style and old-style 
class:


class New(object):
def __init__(self, s):
self._value = s
def upgetter(self):
return self._value.upper()
def upsetter(self, s):
self._value = s
value = property(upgetter, upsetter)

class Old:
def __init__(self, s):
self._value = s
def upgetter(self):
return self._value.upper()
def upsetter(self, s):
self._value = s
value = property(upgetter, upsetter)


Properties work with new-style classes:

 obj = New('norwegian blue')
 obj.value
'NORWEGIAN BLUE'
 obj.value = 'nobody expects the spanish inquisition!'
 obj.value
'NOBODY EXPECTS THE SPANISH INQUISITION!'


At first, they seem to work with old-style classes:

 obj = Old('norwegian blue')
 obj.value
'NORWEGIAN BLUE'

But problems occur once you try assigning to it:

 obj.value = 'nobody expects the spanish inquisition!'
 obj.value
'nobody expects the spanish inquisition!'

And now it is easy to see why:

 obj.__dict__['value']
'nobody expects the spanish inquisition!'
 obj.__dict__['_value']
'norwegian blue'

The call to assign obj.value over-rides the property with the raw value, 
and from that moment on, obj.value is no longer a property, but just an 
ordinary instance attribute.


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


Re: invoke user's standard mail client

2007-05-07 Thread Paul Boddie
On 4 Mai, 18:54, [EMAIL PROTECTED] (Cameron Laird) wrote:
 .
 Portland 
 URL:http://ct.enews.eweek.com/rd/cts?d=186-6281-53-799-798304-697089-0-0-0-1
 is the best standardization of this problem we have under Linux.

 I'll address Windows in a subsequent follow-up.

Portland [1] provides scripts (xdg-open, xdg-email...) which overlap
with the functionality provided by the desktop module:

http://www.python.org/pypi/desktop

The desktop module should even work with Windows as well, but it seems
that xdg-email has the edge in terms of providing the inquirer's
desired support for composing e-mail messages (on Free Software
desktops, anyway).

Paul

[1] http://portland.freedesktop.org/wiki/

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


Re: Properties on old-style classes actually work?

2007-05-07 Thread Nick Vatamaniuc
On May 7, 4:44 am, Paul Melis [EMAIL PROTECTED] wrote:
 Hello,

 The python library docs read in section 2.1
 (http://docs.python.org/lib/built-in-funcs.html):

 
 ...

 property(   [fget[, fset[, fdel[, doc)
  Return a property attribute for new-style classes (classes that
 derive from object).

 ...
 

 But in 2.4 at least properties also seem to work for old-style classes:

 class O:

  def __init__(self):
  self._x = 15

  def get_x(self):
  return self._x

  x = property(get_x)

 o = O()
 print o.x

 outputs 15 as expected for the property.

 Regards,
 Paul

Paul,

Sorry to dissapoint, but properties don't work in old style classes.
The 'get' property seems to work but as soon as you use the set
property it fails and even 'get' won't work after that. It surely is
deceiving, I wish it would just give an error or something.  See
below.

-Nick Vatamaniuc




 class O:
   : def __init__(self):
   : self._x=15
   : def get_x(self):
   : print in O.get_x()
   : return self._x
   : def set_x(self,newx):
   : print in O.set_x(newx)
   : self._x=newx
   : x=property(get_x, set_x)
   :

 o=O()

 o._x
15

 o.x
in O.get_x()
in O.get_x()
15

 o.x=42

 #DANGER WILL ROBINSON, set_x NOT CALLED!!!

 o.x
42

 #HMM... properties ARE BROKEN FROM NOW ON

 o._x
15

 #...BROKEN INDEED



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


Re: problem with quoted strings while inserting into varchar field of database.

2007-05-07 Thread Daniele Varrazzo
On 7 Mag, 10:46, Stefan Sonnenberg-Carstens
[EMAIL PROTECTED] wrote:
 On Mo, 7.05.2007, 10:30, Daniele Varrazzo wrote:

  On 7 Mag, 08:55, krishnakant Mane [EMAIL PROTECTED] wrote:
  On 6 May 2007 11:22:52 -0700, Daniele Varrazzo
  [EMAIL PROTECTED]  Every serious database driver has a
  complete and solid SQL escaping
   mechanism. This mechanism tipically involves putting placeholders in
   your SQL strings and passing python data in a separate tuple or
   dictionary. Kinda

   cur.execute(INSERT INTO datatable (data) VALUES (%s);,
   (pickled_data,))

  I will try doing that once I get back to the lab.
  mean while I forgot to mention in my previous email that I use MySQLdb
  for python-mysql connection.

 Why not use qmark parameter passing (PEP 249) ?

 cur.execute(INSERT INTO datatable (data) VALUES (?); , (pickled_data,))

 Then the DB driver will take care for you.

 import MySQLdb
 print MySQLdb.paramstyle
format

MySQLdb (as many other drivers) use format parameter passing. Not much
difference w.r.t. qmark, at least when passing positional parameters:
the placeholder is %s instead of ?. A difference is that format
also allows named parameters (actually it should have been pyformat,
but IIRC MySQLdb can also use named placeholders, even if they
advertise format).

Anyway it is only a matter of placeholder style: they both allow the
driver to take care of data escaping, the concept the OT didn't know
about.

-- Daniele

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


Re: High resolution sleep (Linux)

2007-05-07 Thread Hendrik van Rooyen
 Tim Roberts [EMAIL PROTECTED] wrote

 Consider what you're asking here.  The operating system can only age the
 timer list and re-evaluate process ready states when a process goes into
 kernel mode, either by releasing the CPU or hitting the end of its time
 slice.  In order to know that a process has reached the end of its time
 slice, it has to be interrupted by something, typically the timer
 interrupt.

Yes

 
 In order to provide 10us sleep resolution, the timer interrupt would have
 to fire every 10us.

Not necessarily. see below

  The overhead of handling the timer interrupt and
 rescheduling that often is quite significant.

Yes

It is also possible to keep the timer list sorted by expiry date,
and to reprogram the timer to interrupt at the next expiry time
to give arbitrary resolution, instead of implementing a regular 'tick'.
But this also adds overhead and its a PITA to do efficiently, 
using a linked list of next interrupt time.   So its not normally 
done unless you *really* need it.  Its easier to make a free 
running hardware counter and to read it and do the sums 
yourself, hogging the processor, if you need such fine resolution.

Ten microseconds is not much time - Speed of light is about 
one foot per nanosecond, so that gives ten thousand feet of
travel for a radio wave - less than two miles, or about three
kilometres.

A rifle bullet can travel at around 5000 feet per second.
In ten microseconds it moves six tenths of an inch.
A vehicle at 300 Km/h (about 187 MPH) will not move
as much as a millimetre in that time.

OTOH - if you are trying to make a software radar system to
pick up intruders in your back yard, then ten microseconds
is a hopelessly long time...

- Hendrik


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


matplotlib: howto redraw figure automatically, without stop in show()/draw()?

2007-05-07 Thread dmitrey
Hi all,
here is a question already mentioned below, and I'm also interested in
that one very much.
unfortunatly, I can't write anything to matplotlib mailing lists
because I constantly get server internal error (500)
Does anyone knows the answer?
(howto redraw figure automatically (for example update from time to
time in cycle), without stop in show()/draw()?)
Thx in advance, D.

 redcic [EMAIL PROTECTED] wrote:
 I've already got this package. I just wanted to try something new.

 However, since you talk about it, I've got a question regarding this
 package. The execution of the code stops after the line:
 pylab.show()
 which is off course the last line of my code. My problem is that I
 have to close the figure window in order to launch my program another
 time. I'd like to be able to launch my program many times with
 different parameters without having to close the figure windows before
 each launch.
 Just so you know, I'm using TkAgg backend.

 Any hint ?

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


Custom software development

2007-05-07 Thread VB
iTechArt Group - Custom Software Development and Offshore outsourcing
Company

http://www.itechart.com/

Offshore custom software development company iTechArt - Web site and
Content Management Solutions development, CMS consulting: Ektron,
Drupal and DotNetNuke

iTechArt Group provides high quality custom software development
services and offshore software development. On December 2006, iTechArt
Group became an authorized Microsoft Certified Partner. This means
that our company has been recognized by Microsoft for our vast
expertise and authorized to custom software development; provide IT
service consulting and custom business solutions.

Custom Software Development and Offshore outsourcing Company iTechArt
has worked together since 2003 to design build and deliver .NET Web
Content Management software solutions that help clients meet their
strategic objectives. We are agile oriented development partner able
to consistently deliver solid results.

iTechArt software development team assemblies specialists in the
development of custom software applications and offshore software
outsourcing services.

Working concepts of our company are based on proven approaches and
international standards used for custom software development such as
Capability Maturity Model Integration for Software Engineering (CMMI-
SW). In the same breath we have our own standpoint on software
development process management which is fully effective and
comprehensible for our clients.


iTechArt offers software development in the next main directions:

1. Custom Software Development (Offshore outsourcing for worldwide
based software development companies.)

2. Software Development for Digital Signage (Media content development
and remote displays / information kiosks Web-based software
application management.)

3. Web Site Development  (E-commerce solutions, CMS/DotNetNuke/Ektron/
Drupal,  Web 2.0/PHP/MySQL/AJAX, Flash/Action script/Flex and many
more.)

4. Offshore Development Center (Dedicated development team of software
developers. Our offshore development centers operate as an extension
to clients' existing software engineering business.)

Contact iTechArt (  http://www.itechart.com/  )about custom software
development, end-to-end software solutions, outsourcing software
development, custom DotNetNuke module development, DotNetNuke
consulting, dotnetnuke hosting, first class Java and .Net developers,
software application design, software testing, Quality Assurance,
functionality testing and defect analysis, performance and stress
testing, usability testing, Microsoft Media Services and Adobe Media
Flash Server solutions, digital signage solutions and custom
development, Ektron CMS400.NET developers, CMS, .NET Web Content
Management software solutions

Web:
http://www.itechart.com/
http://www.itechart.com/Pages/ProductsServices/HowWeWork.aspx
http://www.itechart.com/Pages/ProductsServices/BusinessModels.aspx
http://www.itechart.com/Pages/ProductsServices/CustomSoftwareDevelopment.aspx
http://www.itechart.com/Pages/ProductsServices/DotNetNukeModuleDevelopment.aspx

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


Bastion/rexec use cases?

2007-05-07 Thread Paul Miller
Bastion and rexec have been deprecated since Python 2.2, so it seems
we (the Python community) have gotten along well enough without them.
Have these modules not been reimplemented because:

a) There are no valid use cases for them.
b) Doing so would be difficult and prone to breakage as new features
are introduced into the language.
c) Nobody has any idea how to do it.
d) Nobody cares.
e) Guido thinks it's a bad idea.

or, some combination of these?

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


assisging multiple values to a element in dictionary

2007-05-07 Thread saif . shakeel
Hi,
   I have a dictionary which is something like this:
id_lookup={
16:'subfunction',
26:'dataId',
34:'parameterId',
39:'subfunction',
44:'dataPackageId',
45:'parameterId',
54:'subfunction',
59:'dataId',
165:'subfunction',
169:'subfunction',
170:'dataPackageId',
174:'controlParameterId'
}
 How do i assign multiple values to the key here.Like i want the
key 170 to take either the name 'dataPackageID' or the name
'LocalId'.I use this in my code,and hence if either comes it should
work .
Can someone help me.
  Thanks

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


Re: N00b question on Py modules

2007-05-07 Thread lokesh . jagasia
Thanks a lot for the responses ppl. Python's treatment of global
variables was an eye-opener. I have coded in Java  C/C++ in the past
and there the behaviour is diametrically opposite.

Cheers

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


Re: invoke user's standard mail client

2007-05-07 Thread Cameron Laird
In article [EMAIL PROTECTED], Cameron Laird [EMAIL PROTECTED] wrote:
In article [EMAIL PROTECTED],
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
Hello,

the simplest way to launch the user's standard mail client from a
Python program is by creating a mailto: URL and launching the
webbrowser:

def mailto_url(to=None,subject=None,body=None,cc=None):

encodes the content as a mailto link as described on
http://www.faqs.org/rfcs/rfc2368.html
Examples partly taken from
http://selfhtml.teamone.de/html/verweise/email.htm

url = mailto:; + urllib.quote(to.strip(),@,)
sep = ?
if cc:
url+= sep + cc= + urllib.quote(cc,@,)
sep = 
if subject:
url+= sep + subject= + urllib.quote(subject,)
sep = 
if body:
# Also note that line breaks in the body of a message MUST be
# encoded with %0D%0A. (RFC 2368)
body=\r\n.join(body.splitlines())
url+= sep + body= + urllib.quote(body,)
sep = 
return url

import webbrowser
url = mailto_url(...)
webbrowser.open(url,new=1)

(Excerpt from
http://svn.berlios.de/wsvn/lino/trunk/src/lino/tools/mail.py?op=filerev=0sc=0)

But this method is limited: you cannot specify a file to be attached
to the mail. And I guess that there would be problems if the body text
is too complex.

Does somebody know about a better method?
It should be possible at least on Windows, since Acrobat Reader is
able to do it.
   .
   .
   .
Portland URL:
http://ct.enews.eweek.com/rd/cts?d=186-6281-53-799-798304-697089-0-0-0-1 
is the best standardization of this problem we have under Linux.

I'll address Windows in a subsequent follow-up.

A.  Apologies!  I'm sorry about the URL above; it was
completely wrong.  I intended URL:
http://www-128.ibm.com/developerworks/linux/library/l-portland.html .
B.  The best approach I know under Windows is to invoke
start mailto:$ADDRESS
1.  That invocation does *not* communicate
subject, attachments, ...  To do so 
adequately involves application-specific
work, as other follow-ups have mentioned.
2.  start has its own complexities.  The
best invocation from console-based Python
is likely to be 
start /w  mailto:$ADDRESS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assisging multiple values to a element in dictionary

2007-05-07 Thread Nick Vatamaniuc
On May 7, 7:03 am, [EMAIL PROTECTED] wrote:
 Hi,
I have a dictionary which is something like this:
 id_lookup={
 16:'subfunction',
 26:'dataId',
 34:'parameterId',
 39:'subfunction',
 44:'dataPackageId',
 45:'parameterId',
 54:'subfunction',
 59:'dataId',
 165:'subfunction',
 169:'subfunction',
 170:'dataPackageId',
 174:'controlParameterId'}

  How do i assign multiple values to the key here.Like i want the
 key 170 to take either the name 'dataPackageID' or the name
 'LocalId'.I use this in my code,and hence if either comes it should
 work .
 Can someone help me.
   Thanks

id_lookup[170]=('dataPackageID', 'LocallId')

-Nick V.

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


Re: msbin to ieee

2007-05-07 Thread John Machin
On May 7, 6:18 pm, revuesbio [EMAIL PROTECTED] wrote:
 On 7 mai, 03:52, John Machin [EMAIL PROTECTED] wrote:

  On May 7, 7:44 am, revuesbio [EMAIL PROTECTED] wrote:

   Hi
   Does anyone have the python version of the conversion from msbin to
   ieee?
   Thank u

  Yes, Google has it. Google is your friend. Ask Google. It will lead
  you to such as:

 http://mail.python.org/pipermail/python-list/2005-August/337817.html

  HTH,
  John

 Thank you,

 I've already read it but the problem is always present. this script is
 for double precision MBF format ( 8 bytes).

It would have been somewhat more helpful had you said what you had
done so far,  even posted your code ...

 I try to adapt this script for single precision MBF format ( 4 bytes)
 but i don't find the right float value.

 for example : 'P\xad\x02\x95' will return '0.00024924660101532936'

If you know what the *correct* value is, you might like to consider
shifting left by log2(correct_value/erroneous_value) :-)

Do you have any known correct pairs of (mbf4 string, decimal_float
value)? My attempt is below -- this is based on a couple of
descriptive sources that my friend Google found, with no test data. I
believe the correct answer for the above input is 1070506.0 i.e. you
are out by a factor of 2 ** 32

def mbf4_as_float(s):
m0, m1, m2, m3 = [ord(c) for c in s]
exponent = m3
if not exponent:
return 0.0
sign = m2  0x80
m2 |= 0x80
mant = (((m2  8) | m1)  8) | m0
adj = 24 + 128
num = mant * 2.0 ** (exponent - adj)
if sign:
return -num
return num

HTH,
John

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


Re: Basic question about sockets and security

2007-05-07 Thread Steve Holden
Dave Dean wrote:
 Hi all,
   I'm just starting out in sockets/network programming, and I have a very 
 basic question...what are the 'security' implications of opening up a 
 socket?  For example, suppose I've written a simple chat server and chat 
 client.  The server opens a socket, listens on a port, and accepts incoming 
 connections.  The clients open a socket and connect to the server.  If the 
 server receives a message from a client, it sends that message out to every 
 client.  When a client receives a message, it places it in a text widget.
   So...are there inherent dangers in doing this?  I have no real security 
 concern in the actual application, but can an open socket somehow allow 
 someone access to the rest of the computer?  Is the 'security' of the socket 
 handled at the OS level (or within the socket module)?
   I realize this isn't necessarily a Python question, but I wrote my 
 application in Python and I'm not sure where to start.  I'll repost this 
 elsewhere if someone points me towards a more relevant group.

It's something that all Python network newbies would like to know about 
(and OUGHT to know about), so it's a valid question.

Essentially all opening a server socket does is to allow anyone who can 
connect to send data to your process. The difficulties usually begin 
when your process doesn't handle it in a secure way.

Typically in a language like C this will involve failing to check its 
length, thereby allowing a malicious user to send an over-length input 
and (since local variables in CC are held on the stack) overwriting 
crucial data like function return addresses.

Such exploits can be used to inject code into your process and have it 
run. Since server processes often run at a high level of privilege, so 
does the exploit code.

Another way you can introduce vulnerabilities into your code is to craft 
inputs that, when incorporated into system calls, maliciously change the 
intent of your code. So suppose you had a command to allow a user to 
ping another computer, you might do (something like)

   os.system(ping +address)

where the address is what the user types in. However, if the user types 
in something like

   192.168.12.13 ; rm /etc/passwd

then your call becomes

   os.system(ping 192.168.12.13; rm /etc/passwd)

and executes two shell statements, the second of which is rather 
destructive.

So, as long as you aren't passing any user data to the operating system 
in any way shape or form you are probably in reasonably good shape. But 
this is easier to do than you might imagine, and you always need to ask 
yourself what the downside potential of malicious inputs might be.

Python's libraries are well written by and large, and the language 
itself checks the bounds of all data structure accesses, making buffer 
overflow exploits of the type I described much less of a risk, but the 
OS vulnerabilities still remain for you to avoid by careful coding.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
-- Asciimercial -
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.comsquidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

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


Re: assisging multiple values to a element in dictionary

2007-05-07 Thread Vyacheslav Maslov
I have a dictionary which is something like this:
 id_lookup={
 16:'subfunction',
 26:'dataId',
 34:'parameterId',
 39:'subfunction',
 44:'dataPackageId',
 45:'parameterId',
 54:'subfunction',
 59:'dataId',
 165:'subfunction',
 169:'subfunction',
 170:'dataPackageId',
 174:'controlParameterId'
 }
  How do i assign multiple values to the key here.Like i want the
 key 170 to take either the name 'dataPackageID' or the name
 'LocalId'.
In general dictionary define strong relation between keys and values, 
key should have only one associated value, but in your case value can be 
  a tuple or list.

Anyway, i think that your question contradict to dictionary concept, 
because is impossilbe to assign for some key multiple values.


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


Re: Basic question about sockets and security

2007-05-07 Thread Steve Holden
Dave Dean wrote:
[socket security inquiry]

One further point: everything I wrote for server sockets applies to 
client sockets too if there's a possibility they are interacting with a 
server that's been maliciously coded, or compromised in some way by an 
attacker.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
-- Asciimercial -
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.comsquidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

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


Re: CGI python use under a curse

2007-05-07 Thread Steve Holden
Adrian Smith wrote:
 On May 7, 2:30 pm, Steven D'Aprano
 [EMAIL PROTECTED] wrote:
 On Sun, 06 May 2007 21:30:16 -0700, Adrian Smith wrote:
 
 It is NOT the same error. There are NO syntax errors in the script, there
 is a runtime error. The so-called administrator is wrong: you can't use
 Perl to test just any old CGI scripts. They have to be written in Perl.
 
 Well, I thought that, but you know what happens to newbies who come
 out with such opinions forcefully. Maybe they have special magic perl
 which parses python.
 
 I see from the source code on your page that you have a line:

 TEXTAREA NAME=essay COLS=60 ROWS=20 WRAP=HARD/TEXTAREA

 You have two lines in your cgi script:

 form = cgi.FieldStorage()
 print form[essay].value

 Having never done cgi programming, I'm not sure what the problem is, but
 after reading help(cgi) I'll take a stab in the dark and say try this:

 print form.value

 It might also help for you to try this:

 print form.keys()
 
 Both give me the same ISE, alas.
 
 Good luck with the admins at your hosting company.
 
 Well, it *is* free, and there aren't that many free ones that offer
 Python. My paid-for host has sent me a message to say they're
 ruminating on my issues, though, so I live in hope.
 
I'd go to Cornerhost. You can get a cheap account there and the support 
is friendly and knowledgable. I am no longer a customer and do not stand 
to gain by this recommendation, but they are a small business that were 
very helpful to me when I *was* a customer.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
-- Asciimercial -
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.comsquidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

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


Re: Bastion/rexec use cases?

2007-05-07 Thread Steve Holden
Paul Miller wrote:
 Bastion and rexec have been deprecated since Python 2.2, so it seems
 we (the Python community) have gotten along well enough without them.
 Have these modules not been reimplemented because:
 
 a) There are no valid use cases for them.
 b) Doing so would be difficult and prone to breakage as new features
 are introduced into the language.
 c) Nobody has any idea how to do it.
 d) Nobody cares.
 e) Guido thinks it's a bad idea.
 
 or, some combination of these?
 
All of the above except c) and d), I think.

You might like to Google for something like

   Brett Cannon secure Python

to get up to speed on some work that may eventually result in Python 
acquiring a more security-minded framework. Bastion and rexec were so 
full of holes you could drive a London double-decker bus through them, 
so their deprecation and eventual exclusion was felt to be safer than 
leaving them in to be mistaken for secure code.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
-- Asciimercial -
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.comsquidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

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


Re: msbin to ieee

2007-05-07 Thread revuesbio
On 7 mai, 13:21, John Machin [EMAIL PROTECTED] wrote:
 On May 7, 6:18 pm, revuesbio [EMAIL PROTECTED] wrote:



  On 7 mai, 03:52, John Machin [EMAIL PROTECTED] wrote:

   On May 7, 7:44 am, revuesbio [EMAIL PROTECTED] wrote:

Hi
Does anyone have the python version of the conversion from msbin to
ieee?
Thank u

   Yes, Google has it. Google is your friend. Ask Google. It will lead
   you to such as:

  http://mail.python.org/pipermail/python-list/2005-August/337817.html

   HTH,
   John

  Thank you,

  I've already read it but the problem is always present. this script is
  for double precision MBF format ( 8 bytes).

 It would have been somewhat more helpful had you said what you had
 done so far,  even posted your code ...

  I try to adapt this script for single precision MBF format ( 4 bytes)
  but i don't find the right float value.

  for example : 'P\xad\x02\x95' will return '0.00024924660101532936'

 If you know what the *correct* value is, you might like to consider
 shifting left by log2(correct_value/erroneous_value) :-)

 Do you have any known correct pairs of (mbf4 string, decimal_float
 value)? My attempt is below -- this is based on a couple of
 descriptive sources that my friend Google found, with no test data. I
 believe the correct answer for the above input is 1070506.0 i.e. you
 are out by a factor of 2 ** 32

 def mbf4_as_float(s):
 m0, m1, m2, m3 = [ord(c) for c in s]
 exponent = m3
 if not exponent:
 return 0.0
 sign = m2  0x80
 m2 |= 0x80
 mant = (((m2  8) | m1)  8) | m0
 adj = 24 + 128
 num = mant * 2.0 ** (exponent - adj)
 if sign:
 return -num
 return num

 HTH,
 John

well done ! it's exactly what i'm waiting for !!

my code was:
 from struct import *
 x = list(unpack('','P\xad\x02\x95'))
 x
[80, 173, 2, 149]
 def conversion1(bytes):
b=bytes[:]
sign = bytes[-2]  0x80
b[-2] |= 0x80
exp = bytes[-1] - 0x80 - 56
acc = 0L
for i,byte in enumerate(b[:-1]):
acc |= (long(byte)(i*8))
return (float(acc)*2.0**exp)*((1.,-1.)[sign!=0])

 conversion1(x)
0.00024924660101532936

this script come from google groups but i don't understand bit-string
manipulation (I'm a  newbie). informations about bit-string
manipulation with python is too poor on the net.

thank you very much for your script.
A.

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


Re: Bastion/rexec use cases?

2007-05-07 Thread Duncan Booth
Paul Miller [EMAIL PROTECTED] wrote:

 Bastion and rexec have been deprecated since Python 2.2, so it seems
 we (the Python community) have gotten along well enough without them.
 Have these modules not been reimplemented because:
 
 a) There are no valid use cases for them.
 b) Doing so would be difficult and prone to breakage as new features
 are introduced into the language.
 c) Nobody has any idea how to do it.
 d) Nobody cares.
 e) Guido thinks it's a bad idea.
 
 or, some combination of these?
 
 
I think it is mostly 'b' plus partly nobody cares sufficiently to put the 
time, money and effort behind it.

The recent release of Silverlight means that there is now a way to run 
Python in a secure sandbox. At present it is only available for Windows and 
Mac, but hopefully the Mono community will be able to overcome that 
deficiency (also of course you don't get all of the standard Python 
libraries): see http://www.mono-project.com/Moonlight for the current state 
of the Mono based Silverlight implementation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: long lists

2007-05-07 Thread Merrigan
On May 7, 10:18 am, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 On Mon, 07 May 2007 00:28:14 -0700, Merrigan wrote:
  1. I have the script popping all the files that need to be checked into
  a list, and have it parsing the list for everything...Now the problem is
  this : The sever needs to check (at the moment) 375 files and eliminate
  those that don't need reuploading. This number will obviously get bigger
  and bigger as more files gets uploaded. Now, the problem that I'm having
  is that the script is taking forever to parse the list and give the
  final result. How can I speed this up?

 By writing faster code???

 It's really hard to answer this without more information. In particular:

 - what's the format of the list and how do you parse it?

 - how does the script decide what files need uploading?

 --
 Steven.

Hi, Thanx for the reply,

The Script it available at this url : http://www.lewendewoord.co.za/theScript.py

P.S. I know it looks like crap, but I'm a n00b, and not yet through
the OOP part of the tutorial.

Thanx in advance!

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


Re: matplotlib: howto redraw figure automatically, without stop in show()/draw()?

2007-05-07 Thread WEINHANDL Herbert
dmitrey wrote:
 Hi all,
 here is a question already mentioned below, and I'm also interested in
 that one very much.
 unfortunatly, I can't write anything to matplotlib mailing lists
 because I constantly get server internal error (500)
 Does anyone knows the answer?

maybe this is what you want ?

 http://matplotlib.sourceforge.net/faq.html#DYNAMIC

happy pythoning

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


Re: Bastion/rexec use cases?

2007-05-07 Thread Paul Boddie
On 7 Mai, 14:01, Duncan Booth [EMAIL PROTECTED] wrote:
 Paul Miller [EMAIL PROTECTED] wrote:
  Bastion and rexec have been deprecated since Python 2.2, so it seems
  we (the Python community) have gotten along well enough without them.
  Have these modules not been reimplemented because:

  a) There are no valid use cases for them.
  b) Doing so would be difficult and prone to breakage as new features
  are introduced into the language.
  c) Nobody has any idea how to do it.
  d) Nobody cares.
  e) Guido thinks it's a bad idea.

  or, some combination of these?

 I think it is mostly 'b' plus partly nobody cares sufficiently to put the
 time, money and effort behind it.

I'd agree with this, adding that (c) is increasingly starting to apply
to CPython as new features make any potential sandboxing strategy less
coherent. Brett Cannon appears to be tackling this situation head-on,
however.

 The recent release of Silverlight means that there is now a way to run
 Python in a secure sandbox.

Also possible with Jython for a long time, I believe. Meanwhile,
others (including non-Python developers) have turned to other kinds of
solutions including virtualisation at different levels. See this page
for more discussion:

http://wiki.python.org/moin/SandboxedPython

I've experimented somewhat with a chroot-based solution, although I'm
reluctant to make it available because of an uncertainty as to whether
it really offers proper jailing of the executed code, along with
concerns that people may consider it secure without doing their own
homework on the matter. Ideally, I'd want to trim the Python
interpreter right down to the very basic virtual machine (without I/O)
and then build the different extensions back on in a security-oriented
framework, but I guess this is what Mr Cannon has in mind.

Paul

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


Re: Plot with scipy

2007-05-07 Thread [EMAIL PROTECTED]
On 4 Mai, 15:57, redcic [EMAIL PROTECTED] wrote:
 I've already got this package. I just wanted to try something new.

 However, since you talk about it, I've got a question regarding this
 package. The execution of the code stops after the line:
 pylab.show()
 which is off course the last line of my code. My problem is that I
 have to close the figure window in order to launch my program another
 time. I'd like to be able to launch my program many times with
 different parameters without having to close the figure windows before
 each launch.
 Just so you know, I'm using TkAgg backend.

 Any hint ?

There's an option in your matplotlibrc file (personal lives in
$HOME/.matplotlib, default in $PYTHONPATH/matplotlib/mpl-data):

 CONFIGURATION BEGINS HERE
# the default backend; one of GTK GTKAgg GTKCairo FltkAgg QtAgg TkAgg
# Agg Cairo GD GDK Paint PS PDF SVG Template
backend  : TkAgg
numerix  : numpy  # numpy, Numeric or numarray
interactive  : True  # see 
http://matplotlib.sourceforge.net/interactive.html
.

Take a look at the quoted webpage for details and troubleshooting.

Bernhard

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


Re: assisging multiple values to a element in dictionary

2007-05-07 Thread Carsten Haese
On Mon, 2007-05-07 at 04:03 -0700, [EMAIL PROTECTED] wrote:
 Hi,
I have a dictionary which is something like this:
 id_lookup={
 16:'subfunction',
 26:'dataId',
 34:'parameterId',
 39:'subfunction',
 44:'dataPackageId',
 45:'parameterId',
 54:'subfunction',
 59:'dataId',
 165:'subfunction',
 169:'subfunction',
 170:'dataPackageId',
 174:'controlParameterId'
 }
  How do i assign multiple values to the key here.Like i want the
 key 170 to take either the name 'dataPackageID' or the name
 'LocalId'.I use this in my code,and hence if either comes it should
 work .

That sounds to me like you're translating names to numbers. If that is
true, you're much better off turning your dictionary around, making the
name the key and the corresponding number the value. That way you'll
have two keys pointing to the same value, which is perfectly legal,
whereas having one key pointing to two values is not really possible.
You could have one key pointing to a list or tuple of two values, but
it's not obvious whether that would solve your problem.

Hope this helps,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: long lists

2007-05-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Merrigan wrote:

 The Script it available at this url : 
 http://www.lewendewoord.co.za/theScript.py
 
 P.S. I know it looks like crap, but I'm a n00b, and not yet through
 the OOP part of the tutorial.

One spot of really horrible runtime is the `comp_are()` function, it has
quadratic runtime. Why the funny spelling BTW?

Why are you binding the objects to new names all the time and calling
`str()` repeatedly on string objects?  The names `a`, `b` and `fn2up` are
unnecessary, you can use `file1`, `file2` and `filename` instead.  And
``str(str(b))`` on a string object is a no-operation.  It's the same as
simply writing ``b``.

Those two nested ``for``-loops can be replaced by converting both lists
into `set()` objects, calculating the difference and convert back to a
sorted list:

def compare(remote, local):
return sorted(set(local) - set(remote))

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: assisging multiple values to a element in dictionary

2007-05-07 Thread John Machin
On May 7, 10:59 pm, Carsten Haese [EMAIL PROTECTED] wrote:
 On Mon, 2007-05-07 at 04:03 -0700, [EMAIL PROTECTED] wrote:
  Hi,
 I have a dictionary which is something like this:
  id_lookup={
  16:'subfunction',
  26:'dataId',
  34:'parameterId',
  39:'subfunction',
  44:'dataPackageId',
  45:'parameterId',
  54:'subfunction',
  59:'dataId',
  165:'subfunction',
  169:'subfunction',
  170:'dataPackageId',
  174:'controlParameterId'
  }
   How do i assign multiple values to the key here.Like i want the
  key 170 to take either the name 'dataPackageID' or the name
  'LocalId'.I use this in my code,and hence if either comes it should
  work .

 That sounds to me like you're translating names to numbers. If that is
 true, you're much better off turning your dictionary around, making the
 name the key and the corresponding number the value. That way you'll
 have two keys pointing to the same value, which is perfectly legal,
 whereas having one key pointing to two values is not really possible.
 You could have one key pointing to a list or tuple of two values, but
 it's not obvious whether that would solve your problem.

 Hope this helps,

Unlikely. Turning it around produces one key ('subfunction') with
*FIVE* different values.



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


Re: assisging multiple values to a element in dictionary

2007-05-07 Thread Carsten Haese
On Mon, 2007-05-07 at 06:06 -0700, John Machin wrote:
 Unlikely. Turning it around produces one key ('subfunction') with
 *FIVE* different values.

Whoops! I assumed the OP's problem was reasonably well-formed and didn't
actually check if any of the values were duplicated. I guess the OP will
just have to live with the suggestion of storing tuples or lists, or
explain to us what he's actually trying to achieve.

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


how do you implement a reactor without a select?

2007-05-07 Thread Michele Simionato
I have always been curious about how people implement mainloops (or,
in Twisted terminology, reactors). So I sit down and I wrote the
following simple implementation:

import itertools

class SimpleReactor(object):

DELAY = 0.001 # seconds

def __init__(self):
self._event = {} # action id - (scheduled time, action, args)
self._counter = itertools.count(1) # action id generator
self.running = False

def callLater(self, deltat, action, *args):
Schedule an action with arguments args in deltat seconds.
Return the action id
now = time.time()
i = self._counter.next()
self._event[i] = now + deltat, action, args
return i

def cancelCallLater(self, action_id):
Cancel the action identified by action_id
del self._event[action_id]

def default_action(self): # to be overridden
Invoked at each lap in the mainloop
time.sleep(self.DELAY) # don't run too fast, rest a bit

def cleanup_action(self): # to be overridden
Invoked at the end of the mainloop

def manage_exc(self, e):
Invoked at each call
raise e

def dooneevent(self):
Perfom scheduled actions
now = time.time()
for i, (start_time, action, args) in self._event.items():
if now = start_time: # it's time to start the action
self.cancelCallLater(i) # don't run it again
try:
action(*args)
except Exception, e:
self.manage_exc(e)

def run(self):
Run the main loop
self.running = True
try:
while self.running:
self.default_action()
self.dooneevent()
except KeyboardInterrupt:
print 'Stopped via CTRL-C'
finally:
self.cleanup_action()

def stop(self):
self.running = False

Notice that I copied the Twisted terminology, but
I did not look at Twisted implementation because I did not want to
use a select (I assume that the GUI mainloops do not use it either).
The trick I use is to store the actions to perform (which are
callables identified by an integer) in an event dictionary and
to run them in the mainlooop if the current time is greater than
the scheduled time.
I had to add a time.sleep(.001) call in the default_action to avoid
consuming 100%
of the CPU in the loop.
I wonder if real mainloops are done in this way and how bad/good is
this implementation compared to a serious one. Any suggestion/hint/
advice
is well appreciated. Thanks,

 Michele Simionato

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


Can Python Parse an MS SQL Trace?

2007-05-07 Thread kyosohma
Hi All,

Can Python parse a trace file created with MS SQL's profiler? There
are a few thousand lines in the trace file and I need to find the
insert statements and the stored procedures. Unfortunately, I am not
an SQL guru and was hoping Python could help.

Any pointers are appreciated.

Thanks!

Mike

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


Re: adding methods at runtime and lambda

2007-05-07 Thread Mike
On May 4, 5:46 pm, Peter Otten [EMAIL PROTECTED] wrote:
 Mike wrote:
  I just realized in working with this more that the issues I was having
  with instancemethod and other things seems to be tied solely to

 What you describe below is a function that happens to be an attribute of an
 instance. There are also real instance methods that know about their
 instance:

  import new
  class A(object):

 ... def __init__(self, name):
 ... self.name = name
 ... def method(self): # a function...

 ... print self.name
 ... a = A(alpha)
  b = A(beta)
  a.method = new.instancemethod(method, a) # ...turned into a method...
  a.method()
 alpha
  b.method() # ... but only known to a specific instance of A

 Traceback (most recent call last):
   File stdin, line 1, in module
 AttributeError: 'A' object has no attribute 'method'

  builtins like dict or object. I remember at some point just doing
  something like:

  x.fn = myfnFunction

  and having it just work.

 With the caveat that x.fn is now an alias for myfnFunction, but doesn't get
 x passed as its first argument (conventionally named 'self') and therefore
 has no knowledge of the instance x.



  If I do that with an instance of generic
  object however, I get an AttributeError. So:

  x = object()
  x.fn = myFn

  blows up. However, if I do

  class nc(object):pass
  x = nc()
  x.fn = myFn

  Then all is well.

  checking for an ability on somebody is as simple as

  'fn' in dir(x)

  or

  hasattr(x, 'fn')

  I had thought this was a lot easier than I was making it out to be.
  What I don't know is why using an object derived from object allows
  you to dynamically add methods like this but the base object does not.
  At this point it is more of a curiosity than anything, but if somebody
  knows the answer off the top of their head, that would be great.

 Arbitrary instance attributes are implemented via a dictionary (called
 __dict__), and that incurs a certain overhead which is sometimes better to
 avoid (think gazillion instances of some tiny class). For example, tuples
 are derived from object but don't have a __dict__.
 As a special case, what would happen if dict were to allow attributes? It
 would need a __dict__ which would have a __dict__ which would have...
 As a consequence object could no longer be the base class of all (newstyle)
 classes.

 Peter

Thanks.

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


Re: Can Python Parse an MS SQL Trace?

2007-05-07 Thread Tim Golden
[EMAIL PROTECTED] wrote:
 Can Python parse a trace file created with MS SQL's profiler? There
 are a few thousand lines in the trace file and I need to find the
 insert statements and the stored procedures. Unfortunately, I am not
 an SQL guru and was hoping Python could help.

 Mike

Mike,

Can I suggest that, since the answer is more to
do with parsing and less to do with MSSQL (which
simply generated the output) that you post an example
of a trace file to some web location to see if anyone
wants to pick up the challenge?

I'm not at work so I don't have access to MSSQL, but
I seem to remember that you can output/save as XML,
which may make things easier (or at least interest a
different group of people in having a look).

I'm quite certain it can by done by Python; I did
consider it myself a couple of months back, but my
colleague spotted the problem before I'd really got
into the code!

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


Re: How do I use the config parser?

2007-05-07 Thread Larry Bates
[EMAIL PROTECTED] wrote:
 Hi,
 I need a specific example. I have seen the docs, but I don't all the
 stuffs there.
 
 So basically, I need my config file to be created and read by my
 script.
 
 Here is a snippet
 
 # read old actions
 from ConfigParser import ConfigParser
 
 fp = open(makepath('App\qt_actions.conf'))
 configdict = ConfigParser()
 configdict.readfp(fp)
 
 
 Now I want to know how to read a section, a section attribute's value,
 and to write thoses back after reading.
 
 Thanks
 

The best place to start is always:

import ConfigParser
help(ConfigParser)


Example:

section='INIT'
option='logfile'

logfile=configdict.get(section, option)

most of the methods are self explanitory.

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


Re: msbin to ieee

2007-05-07 Thread revuesbio
On 7 mai, 14:56, John Machin [EMAIL PROTECTED] wrote:
 On May 7, 10:00 pm, revuesbio [EMAIL PROTECTED] wrote:



  On 7 mai, 13:21, John Machin [EMAIL PROTECTED] wrote:

   On May 7, 6:18 pm, revuesbio [EMAIL PROTECTED] wrote:

On 7 mai, 03:52, John Machin [EMAIL PROTECTED] wrote:

 On May 7, 7:44 am, revuesbio [EMAIL PROTECTED] wrote:

  Hi
  Does anyone have the python version of the conversion from msbin to
  ieee?
  Thank u

 Yes, Google has it. Google is your friend. Ask Google. It will lead
 you to such as:

http://mail.python.org/pipermail/python-list/2005-August/337817.html

 HTH,
 John

Thank you,

I've already read it but the problem is always present. this script is
for double precision MBF format ( 8 bytes).

   It would have been somewhat more helpful had you said what you had
   done so far,  even posted your code ...

I try to adapt this script for single precision MBF format ( 4 bytes)
but i don't find the right float value.

for example : 'P\xad\x02\x95' will return '0.00024924660101532936'

   If you know what the *correct* value is, you might like to consider
   shifting left by log2(correct_value/erroneous_value) :-)

   Do you have any known correct pairs of (mbf4 string, decimal_float
   value)? My attempt is below -- this is based on a couple of
   descriptive sources that my friend Google found, with no test data. I
   believe the correct answer for the above input is 1070506.0 i.e. you
   are out by a factor of 2 ** 32

   def mbf4_as_float(s):
   m0, m1, m2, m3 = [ord(c) for c in s]
   exponent = m3
   if not exponent:
   return 0.0
   sign = m2  0x80
   m2 |= 0x80
   mant = (((m2  8) | m1)  8) | m0
   adj = 24 + 128
   num = mant * 2.0 ** (exponent - adj)
   if sign:
   return -num
   return num

   HTH,
   John

  well done ! it's exactly what i'm waiting for !!

  my code was: from struct import *
   x = list(unpack('','P\xad\x02\x95'))
   x
  [80, 173, 2, 149]
   def conversion1(bytes):

  b=bytes[:]
  sign = bytes[-2]  0x80
  b[-2] |= 0x80
  exp = bytes[-1] - 0x80 - 56
  acc = 0L
  for i,byte in enumerate(b[:-1]):
  acc |= (long(byte)(i*8))
  return (float(acc)*2.0**exp)*((1.,-1.)[sign!=0])

 Apart from the 2**32 problem, the above doesn't handle *any* of the
 2**24 different representations of zero. Try feeding \0\0\0\0' to it
 and see what you get.



   conversion1(x)

  0.00024924660101532936

  this script come from google groups but i don't understand bit-string
  manipulation (I'm a  newbie). informations about bit-string
  manipulation with python is too poor on the net.

 The basic operations (and, or, exclusive-or, shift) are not specific
 to any language. Several  languages share the same notation ( | ^ 

 ), having inherited it from C.

  thank you very much for your script.

 Don't thank me, publish some known correct pairs of values so that we
 can verify that it's not just accidentally correct for 1 pair of
 values.

pairs of values :
(bytes string, mbf4_as_float(s) result)right
float value
('P\xad\x02\x95', 1070506.0)
1070506.0
('\x00\x00\x00\x02', 5.8774717541114375e-039) 0.0
('\x00\x00\x00\x81', 1.0)
1.0
('\x00\x00\x00\x82', 2.0)
2.0
('[EMAIL PROTECTED]', 3.0)
3.0
('\x00\x00\x00\x83', 4.0)
4.0
('\x00\x00 \x83', 5.0)
5.0
('\xcd\xcc\x0c\x81', 1.100238418579) 1.1
('\xcd\xcc\x0c\x82', 2.200476837158)  2.2
('33S\x82', 3.299523162842)  3.3
('\xcd\xcc\x0c\x83', 4.400953674316)  4.4
('\x00\x00z\x8a', 1000.0)
1000.0

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


Re: Getting some element from sets.Set

2007-05-07 Thread Andrew McLean
[EMAIL PROTECTED] wrote:
 In the particular case, I have to read an attribute from any one of
 the elements, which one doesn't matter because this attribute value is
 same across all elements in the set.

Someone else pointed out that there might be better data structures. If 
performance was not an issue one approach would be illustrated by the 
following:

  Q=set(['A','a'])
  list(set(x.upper() for x in Q))
['A']

This has the benefit that it does not assume all the elements of the set 
have the same value of the given attribute.

Again not very efficient:

  list(Q)[0]
'A'

I'm guessing this would be quicker

  iter(Q).next()
'A'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with quoted strings while inserting into varchar field of database.

2007-05-07 Thread Stefan Sonnenberg-Carstens
On Mo, 7.05.2007, 11:32, Daniele Varrazzo wrote:
 On 7 Mag, 10:46, Stefan Sonnenberg-Carstens
 [EMAIL PROTECTED] wrote:
 On Mo, 7.05.2007, 10:30, Daniele Varrazzo wrote:

  On 7 Mag, 08:55, krishnakant Mane [EMAIL PROTECTED] wrote:
  On 6 May 2007 11:22:52 -0700, Daniele Varrazzo
  [EMAIL PROTECTED]  Every serious database driver has a
  complete and solid SQL escaping
   mechanism. This mechanism tipically involves putting placeholders
 in
   your SQL strings and passing python data in a separate tuple or
   dictionary. Kinda

   cur.execute(INSERT INTO datatable (data) VALUES (%s);,
   (pickled_data,))

  I will try doing that once I get back to the lab.
  mean while I forgot to mention in my previous email that I use
 MySQLdb
  for python-mysql connection.

 Why not use qmark parameter passing (PEP 249) ?

 cur.execute(INSERT INTO datatable (data) VALUES (?); ,
 (pickled_data,))

 Then the DB driver will take care for you.

 import MySQLdb
 print MySQLdb.paramstyle
 format

 MySQLdb (as many other drivers) use format parameter passing. Not much
 difference w.r.t. qmark, at least when passing positional parameters:
 the placeholder is %s instead of ?. A difference is that format
 also allows named parameters (actually it should have been pyformat,
 but IIRC MySQLdb can also use named placeholders, even if they
 advertise format).

 Anyway it is only a matter of placeholder style: they both allow the
 driver to take care of data escaping, the concept the OT didn't know
 about.

 -- Daniele

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


%s is not a placeholder IMHO.
What happens when using %s is, that the string given will be inserted where
%s is; that is something python does as with every print or such.
By using the qmark style, it is up the the implementation of the
cursor.execute method to decide what to do. python itself, and it's string
implementation, don't know anything to do with the qmark.
So, IMHO it *makes* a difference:
with %s the execute function sees a string and nothing more as the
parameters are consumed away by the % substitution.
with ?, the execute implementation must do it's best, it gets a string and
a list/tuple with values.

Cheers,
Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting some element from sets.Set

2007-05-07 Thread Christopher Arndt
On 4 Mai, 10:23, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
   It is not possible to index set objects. That is OK.
   But, what if I want to find some element from the Set.

 In the particular case, I have to read an attribute from any one of
 the elements, which one doesn't matter because this attribute value is
 same across all elements in the set.

Just to clarify: do you want to just get an *arbitrary* element from
the set or do you want to find a *specific* element in the set?

In the first case you have to convert it to a list (as pointed out
earlier in this thread):

 s = set(range(10))
 list(s)[0]
0

In the second case, just use th in operator:

 10 in s
False
 5 in s
True

Since you have to have a reference to the object for whose membership
you are testing, you can just use this object.

Stupid example:

 class Point:
... def __init__(self, x, y):
... self.x = x
... self.y = y
...
 l = [Point(n,n+2) for n in range(10)]
 s = set(l)
 Point(0,2) in s
False
 l[0] in s
True

 l[0].x,l[0].y
(0, 2)


Chris

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


RE: Strange terminal behavior after quitting Tkinter application

2007-05-07 Thread Hamilton, William
 From: Chris
  I'll admit to being surprised at seeing a claim that a
tkinter
  application, started within an interactive session, without a
mainloop,
  even runs... I could see it maybe happening from Idle, since Idle is
  running a tkinter mainloop, so the application bindings may have
just
  become added widgets to the Idle loop (but of course, a second
  mainloop would conflict heavily).
 
 You can try by building a working Tkinter GUI interactively from the
 standard Python interpreter, and see that the GUI works (i.e.
 processes events) at the same time.
 


If you build it as a class (such as the code in Chris's original post)
it works; if you do it all directly, nothing happens until you run
mainloop().  It works, but I'm not sure that it was intended to work
that way.  I think your problem is related to that difference.

You'll probably be better off creating a new interpreter window as part
of your program, if you really need access to the interpreter alongside
your GUI.  You may be able to extract IDLE's interpreter window and use
it directly.


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


Re: msbin to ieee

2007-05-07 Thread John Machin
On May 7, 10:00 pm, revuesbio [EMAIL PROTECTED] wrote:
 On 7 mai, 13:21, John Machin [EMAIL PROTECTED] wrote:



  On May 7, 6:18 pm, revuesbio [EMAIL PROTECTED] wrote:

   On 7 mai, 03:52, John Machin [EMAIL PROTECTED] wrote:

On May 7, 7:44 am, revuesbio [EMAIL PROTECTED] wrote:

 Hi
 Does anyone have the python version of the conversion from msbin to
 ieee?
 Thank u

Yes, Google has it. Google is your friend. Ask Google. It will lead
you to such as:

   http://mail.python.org/pipermail/python-list/2005-August/337817.html

HTH,
John

   Thank you,

   I've already read it but the problem is always present. this script is
   for double precision MBF format ( 8 bytes).

  It would have been somewhat more helpful had you said what you had
  done so far,  even posted your code ...

   I try to adapt this script for single precision MBF format ( 4 bytes)
   but i don't find the right float value.

   for example : 'P\xad\x02\x95' will return '0.00024924660101532936'

  If you know what the *correct* value is, you might like to consider
  shifting left by log2(correct_value/erroneous_value) :-)

  Do you have any known correct pairs of (mbf4 string, decimal_float
  value)? My attempt is below -- this is based on a couple of
  descriptive sources that my friend Google found, with no test data. I
  believe the correct answer for the above input is 1070506.0 i.e. you
  are out by a factor of 2 ** 32

  def mbf4_as_float(s):
  m0, m1, m2, m3 = [ord(c) for c in s]
  exponent = m3
  if not exponent:
  return 0.0
  sign = m2  0x80
  m2 |= 0x80
  mant = (((m2  8) | m1)  8) | m0
  adj = 24 + 128
  num = mant * 2.0 ** (exponent - adj)
  if sign:
  return -num
  return num

  HTH,
  John

 well done ! it's exactly what i'm waiting for !!

 my code was: from struct import *
  x = list(unpack('','P\xad\x02\x95'))
  x
 [80, 173, 2, 149]
  def conversion1(bytes):

 b=bytes[:]
 sign = bytes[-2]  0x80
 b[-2] |= 0x80
 exp = bytes[-1] - 0x80 - 56
 acc = 0L
 for i,byte in enumerate(b[:-1]):
 acc |= (long(byte)(i*8))
 return (float(acc)*2.0**exp)*((1.,-1.)[sign!=0])

Apart from the 2**32 problem, the above doesn't handle *any* of the
2**24 different representations of zero. Try feeding \0\0\0\0' to it
and see what you get.


  conversion1(x)

 0.00024924660101532936

 this script come from google groups but i don't understand bit-string
 manipulation (I'm a  newbie). informations about bit-string
 manipulation with python is too poor on the net.

The basic operations (and, or, exclusive-or, shift) are not specific
to any language. Several  languages share the same notation ( | ^ 
), having inherited it from C.


 thank you very much for your script.

Don't thank me, publish some known correct pairs of values so that we
can verify that it's not just accidentally correct for 1 pair of
values.



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


Re: how do you implement a reactor without a select?

2007-05-07 Thread Diez B. Roggisch
 Notice that I copied the Twisted terminology, but
 I did not look at Twisted implementation because I did not want to
 use a select (I assume that the GUI mainloops do not use it either).

Why do you assume that? It's a wrong assumption. Yielding a thread/process
until the OS wakes it up because of IO to be performed is the proper way to
go. And at least in unix, IO is _everything_, also mouse-movements and
keyboard events. Most probably the OS will have specialized APIs (or some
wrapper lib has) that allow for reactor registration for events of
different kinds including timers. But basically, it's select - I mean you
could easily offer a timer as a file-object as well. Not sure if that's
done though.

 The trick I use is to store the actions to perform (which are
 callables identified by an integer) in an event dictionary and
 to run them in the mainlooop if the current time is greater than
 the scheduled time.
 I had to add a time.sleep(.001) call in the default_action to avoid
 consuming 100%
 of the CPU in the loop.
 I wonder if real mainloops are done in this way and how bad/good is
 this implementation compared to a serious one. Any suggestion/hint/
 advice
 is well appreciated. Thanks,

It's ok, but of course more wasteful than it needs to be - better would be
full delegation to the OS.

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


Re: Can Python Parse an MS SQL Trace?

2007-05-07 Thread kyosohma
On May 7, 8:34 am, Tim Golden [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  Can Python parse a trace file created with MS SQL's profiler? There
  are a few thousand lines in the trace file and I need to find the
  insert statements and the stored procedures. Unfortunately, I am not
  an SQL guru and was hoping Python could help.
  Mike

 Mike,

 Can I suggest that, since the answer is more to
 do with parsing and less to do with MSSQL (which
 simply generated the output) that you post an example
 of a trace file to some web location to see if anyone
 wants to pick up the challenge?

 I'm not at work so I don't have access to MSSQL, but
 I seem to remember that you can output/save as XML,
 which may make things easier (or at least interest a
 different group of people in having a look).

 I'm quite certain it can by done by Python; I did
 consider it myself a couple of months back, but my
 colleague spotted the problem before I'd really got
 into the code!

 TJG

Good point. Unfortunately, I think our SQL Server must be too old for
xml (we have version 8). The only save options I see is Trace
Template, Trace File, Trace Table and SQL Script.

Mike

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


Unittest Automation

2007-05-07 Thread Calvin Spealman
I'm trying to find a better way, a shell one-liner, that I can use to
recurse through my project, find all my test_ modules, aggregate the
TestCase classes into a suite, and run all my tests. Basically, what
py.test does out of the box. Why am I having such trouble doing it?

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with quoted strings while inserting into varchar field of database.

2007-05-07 Thread Daniele Varrazzo
cur.execute(INSERT INTO datatable (data) VALUES (%s);,
(pickled_data,))

 %s is not a placeholder IMHO.

 What happens when using %s is, that the string given will be inserted where
 %s is; that is something python does as with every print or such.

It is indeed. The behavior you describe would be true if i had used
the % operator. Read better what i have written: There is no %
operator.

cur.execute() receives 2 parameters: a SQL string with placeholders
and a tuple with values: it's not me mangling values into the SQL
string. This is the driver responsibility and it has the chance
because it receives SQL and values as two distinct parameters. The
driver can ask the SQL string to contain placeholders either in qmark
? or in format %s style, but there is no functional difference.
Notice that the placeholder is always %s and not %d or %f for
integers or float: there is always an escaping phase converting each
python object into a properly encoded string and then the placeholders
are replaced with the value. This happens into the execute()
machinery.

 By using the qmark style, it is up the the implementation of the
 cursor.execute method to decide what to do. python itself, and it's string
 implementation, don't know anything to do with the qmark.
 So, IMHO it *makes* a difference:
 with %s the execute function sees a string and nothing more as the
 parameters are consumed away by the % substitution.
 with ?, the execute implementation must do it's best, it gets a string and
 a list/tuple with values.

Again, this would be true for cur.execute(sql % data): what i wrote
is cur.execute(sql, data).

-- Daniele

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


Re: problem with quoted strings while inserting into varchar field of database.

2007-05-07 Thread Stefan Sonnenberg-Carstens
On Mo, 7.05.2007, 16:26, Daniele Varrazzo wrote:
cur.execute(INSERT INTO datatable (data) VALUES (%s);,
(pickled_data,))

 %s is not a placeholder IMHO.

 What happens when using %s is, that the string given will be inserted
 where
 %s is; that is something python does as with every print or such.

 It is indeed. The behavior you describe would be true if i had used
 the % operator. Read better what i have written: There is no %
 operator.

 cur.execute() receives 2 parameters: a SQL string with placeholders
 and a tuple with values: it's not me mangling values into the SQL
 string. This is the driver responsibility and it has the chance
 because it receives SQL and values as two distinct parameters. The
 driver can ask the SQL string to contain placeholders either in qmark
 ? or in format %s style, but there is no functional difference.
 Notice that the placeholder is always %s and not %d or %f for
 integers or float: there is always an escaping phase converting each
 python object into a properly encoded string and then the placeholders
 are replaced with the value. This happens into the execute()
 machinery.

 By using the qmark style, it is up the the implementation of the
 cursor.execute method to decide what to do. python itself, and it's
 string
 implementation, don't know anything to do with the qmark.
 So, IMHO it *makes* a difference:
 with %s the execute function sees a string and nothing more as the
 parameters are consumed away by the % substitution.
 with ?, the execute implementation must do it's best, it gets a string
 and
 a list/tuple with values.

 Again, this would be true for cur.execute(sql % data): what i wrote
 is cur.execute(sql, data).

 -- Daniele

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


Ashes on my head.

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


Re: how do you implement a reactor without a select?

2007-05-07 Thread Alex Martelli
Michele Simionato [EMAIL PROTECTED] wrote:

 I wonder if real mainloops are done in this way and how bad/good is
 this implementation compared to a serious one. Any suggestion/hint/
 advice is well appreciated. Thanks,

Module sched in Python's standard library may suggest one clearly-better
approach: when you know in advance when future events are scheduled for,
sleep accordingly (rather than polling every millisecond).  sched's
sources are simple enough to study, and its architecture clean and
strong enough that it's easy to extend to other cases, e.g. where
previously-unscheduled events may be delivered from other threads,
without necessarily hacking the sources.

Specifically, sched implements the Dependency Injection DP: rather than
just calling time.time and time.sleep, it accepts those two callables
upon initialization.  This makes it easy, among many other
customizations, to pass instead of time.sleep a user-coded callable
(typically a bound method) that sleeps by a wait-with-timeout on a
Queue (so that other threads, by putting an event on the Queue in
question, immediately wake up the scheduler, etc, etc).


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


Re: problem with quoted strings while inserting into varchar field of database.

2007-05-07 Thread Daniele Varrazzo
 Ashes on my head.

My fault: the difference is hard to spot indeed in the rather long
line of the example. I should have been more explicit stating that the
differences were:

 1. missing explicit quotes around the placeholders (they are part of
the escaped values),

 2. no % operator: two parameters are passed instead.

Best regards,

-- Daniele

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


Re: problem with quoted strings while inserting into varchar field of database.

2007-05-07 Thread Carsten Haese
On Mon, 2007-05-07 at 07:26 -0700, Daniele Varrazzo wrote:
 cur.execute(INSERT INTO datatable (data) VALUES (%s);,
 (pickled_data,))
 
  %s is not a placeholder IMHO.
 
  What happens when using %s is, that the string given will be inserted where
  %s is; that is something python does as with every print or such.
 
 It is indeed. The behavior you describe would be true if i had used
 the % operator. Read better what i have written: There is no %
 operator.

This confusion is precisely why I think the (py)format paramstyles
should be deprecated in a future version of the DB-API spec. Question
marks make it immediately obvious that something other than string
formatting is happening, and if I'm not mistaken, question marks are SQL
standard.

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: BUSTED!!! 100% VIDEO EVIDENCE that WTC7 was controlled demolition!! NEW FOOTAGE!!! Ask yourself WHY havn't I seen this footage before?

2007-05-07 Thread James Beck
In article [EMAIL PROTECTED], [EMAIL PROTECTED] 
says...
 On Sat, 05 May 2007 07:54:50 +0100, Eeyore
 [EMAIL PROTECTED] wrote:
 
 
 
 quasi wrote:
 
  Gib Bogle wrote:
 
  Ah, so the firefighters were in on the conspiracy!
 
  No, but the firefighters are very much aware that there is more to
  9/11 than has been officially revealed.
 
  This is even more true at Pentagon. The firefighters there brought
  dogs trained to search for survivors and/or remains
 
 Sounds like good practice.
 
 
  and found nothing.
 
 And the significance of this is ?
 
 The plane was supposed to have passengers.
 
 quasi
 
Yep, and they found them all, therefore, there were none for the dogs to 
find.  

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


Recommended validating XML parser?

2007-05-07 Thread Kirk Strauser
We're looking for a current, supported, validating XML parser.  Since it
seems like there are a few thousand out there, I though we'd see what
everyone else is using.

Bonus points if it can do something like:

 foo = XMLParser(
xml
weight3000/weight
/xml
, dtd=file('/etc/weightfile.dtd'))

 print foo.weight
3000

...or some variant on that theme.
-- 
Kirk Strauser
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with quoted strings while inserting into varchar field of database.

2007-05-07 Thread Stefan Sonnenberg-Carstens
On Mo, 7.05.2007, 16:50, Carsten Haese wrote:
 On Mon, 2007-05-07 at 07:26 -0700, Daniele Varrazzo wrote:
 cur.execute(INSERT INTO datatable (data) VALUES (%s);,
 (pickled_data,))

  %s is not a placeholder IMHO.

  What happens when using %s is, that the string given will be inserted
 where
  %s is; that is something python does as with every print or such.

 It is indeed. The behavior you describe would be true if i had used
 the % operator. Read better what i have written: There is no %
 operator.

 This confusion is precisely why I think the (py)format paramstyles
 should be deprecated in a future version of the DB-API spec. Question
 marks make it immediately obvious that something other than string
 formatting is happening, and if I'm not mistaken, question marks are SQL
 standard.

 --
 Carsten Haese
 http://informixdb.sourceforge.net


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


At least, qmark style is well known to people working with
prepared stmts etc.
They look natural - and avoid (even my!) mistakes.
On python-forum.de there was a discussion regarding inserting
data into a sqlite db recently. If I remember correctly the guy
was using the %s % data approach (yes, % operator) and failed.
The pysqlite driver did the right thing using the qmark style.
Even in the Python phrasebook there are examples of this ugly style.

A deprecation warning for now would be fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you implement a reactor without a select?

2007-05-07 Thread Michele Simionato
On May 7, 4:39 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
 Michele Simionato [EMAIL PROTECTED] wrote:
  I wonder if real mainloops are done in this way and how bad/good is
  this implementation compared to a serious one. Any suggestion/hint/
  advice is well appreciated. Thanks,

 Module sched in Python's standard library may suggest one clearly-better
 approach: when you know in advance when future events are scheduled for,
 sleep accordingly (rather than polling every millisecond).  sched's
 sources are simple enough to study, and its architecture clean and
 strong enough that it's easy to extend to other cases, e.g. where
 previously-unscheduled events may be delivered from other threads,
 without necessarily hacking the sources.

 Specifically, sched implements the Dependency Injection DP: rather than
 just calling time.time and time.sleep, it accepts those two callables
 upon initialization.  This makes it easy, among many other
 customizations, to pass instead of time.sleep a user-coded callable
 (typically a bound method) that sleeps by a wait-with-timeout on a
 Queue (so that other threads, by putting an event on the Queue in
 question, immediately wake up the scheduler, etc, etc).

 Alex

I know about sched (it was the first thing I looked at): the problem
is that sched
adopt a blocking approach and it basically requires threads, whereas I
wanted to
avoid them. Diez B. Roggisch's reply is closer to my expectations:

 Most probably the OS will have specialized APIs (or some
 wrapper lib has) that allow for reactor registration for events of different
 kinds including timers.

But what kind of specialized API do I have at my disposition for
timers on Linux?
It looks like this is the question I should have asked the first
time ;)


Michele Simionato

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


SkimpyGimpy PNG canvas w/ Javascript mouse tracking

2007-05-07 Thread aaronwmail-usenet
ANN: SkimpyGimpy PNG canvas has Javascript mouse tracking

The SkimpyGimpy PNG image canvas now can generate
Javascript data structures which allow HTML pages
to intelligently respond to mouse events over the
image.

Please read about the SkimpyGimpy Canvas and look at
the mouse tracking example here:

http://skimpygimpy.sourceforge.net/canvas.html

The SkimpyGimpy main page is here:

http://skimpygimpy.sourceforge.net/

BACKGROUND:

SkimpyGimpy is a collection of tools for generating
HTML visual, PNG image, and WAVE audio components
for use in web based applications including CAPTCHA
implementations (Completely Automated Public Turing
test to tell Computers and Humans Apart) and PNG
image creation tools with Javascript mouse tracking
support.

  I hope you like.  -- Aaron Watters

===

Sometimes say sometimes.

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


Re: Recommended validating XML parser?

2007-05-07 Thread Stefan Behnel
Kirk Strauser wrote:
 We're looking for a current, supported, validating XML parser.  Since it
 seems like there are a few thousand out there, I though we'd see what
 everyone else is using.

You are asking for lxml, right?

http://codespeak.net/lxml/


 Bonus points if it can do something like:
 
  foo = XMLParser(
 xml
 weight3000/weight
 /xml
 , dtd=file('/etc/weightfile.dtd'))
 
  print foo.weight
 3000
 
 ...or some variant on that theme.

Not currently supported, only document internal DTD references are used. But
you can always validate the document *after* parsing, be it with DTD,
XMLSchema or RNG.

BTW, adding this would be straight forward. The implementation is there, it's
just not available at the API level (and I'm not sure enough how it should
look like...)

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


Re: ftplib acting weird

2007-05-07 Thread Carlos Hanson
On May 4, 3:43 am, Merrigan [EMAIL PROTECTED] wrote:
 Hi All,

 I have written a little script to upload some files to an ftp folder.
 The problem is as follows :

 I wrote the script on my windows laptop, and I want to run it from
 mylinux server. Everything worked fine so I uploaded it to my linux
 machine. Every time I tun the script I get the following error:

 ***

 [EMAIL PROTECTED] ftpsync]# python ftpsync.py
 !!
 The Connection to the Server Could not be established.
 Please Check all neccesary settings and run the script again.
 Thank you
 !!
 Traceback (most recent call last):
   File ftpsync.py, line 194, in ?
 ftplisting()
   File ftpsync.py, line 83, in ftplisting
 ftpconn.cwd(remotedir) #This changes to the remote directory
   File /usr/lib64/python2.4/ftplib.py, line 494, in cwd
 return self.voidcmd(cmd)
   File /usr/lib64/python2.4/ftplib.py, line 245, in voidcmd
 self.putcmd(cmd)
   File /usr/lib64/python2.4/ftplib.py, line 175, in putcmd
 self.putline(line)
   File /usr/lib64/python2.4/ftplib.py, line 170, in putline
 self.sock.sendall(line)
 AttributeError: 'NoneType' object has no attribute 'sendall'
 [EMAIL PROTECTED] ftpsync]#

 ***

 When I copy the same piece of scripting and run it from the python
 command shell, it works...

 what am I doing wrong? I have double checked everything about a
 million times, but to no avail.

 Blessings!

Can you show the code?

--
Carlos Hanson

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


Re: c macros in python.

2007-05-07 Thread Cameron Laird
In article [EMAIL PROTECTED],
Amaury Forgeot d'Arc  [EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] a écrit :
 Hey,
 
 I'm writing a script to generate code. I'm a bit tired of typing
 outfile.write(). Does python have a way to c-like macros? Every
 instance of o(...) in the code will be replaced by outfile.write(...)?

First: Python has no macro facility.
.
.
.
For the sake of completeness, I want to note that the standard
distribution includes Tools/Scripts/ifdef.py, and pyparsing now
has an example macro preprocessor.  Neither of these would be
the correct response to the original question, of course, but 
they might interest other readers who believe they need c-like
macros.
-- 
http://mail.python.org/mailman/listinfo/python-list

Python-URL! - weekly Python news and links (May 7)

2007-05-07 Thread Cameron Laird
QOTW:  As a general rule, *ALL* multithread operations are at least that
troublesome, and most are far more so. - Gary Herron

I'm a recent, belated convert from Perl.  I work in a physics lab and have
been using Python to automate a lot of measurement equipment lately.  It
works fabulously for this purpose. - Dan Lenski


It *is* possible to copy a function--by replication of all its attributes.
John Nagle explains why it's so difficult:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/2dfe7d6b150a0ec/

If you think you need a macro as C knows it in your Python code,
you're almost certainly missing a far easier solution:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/4cda4dc6b78b94a9/

If you think you need difficult quoting to move your data from
Python to a standard database, you're almost certainly missing
an easier standard solution, perhaps involving parameter passing:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/7bf20c46b6e1f29e/

If you think you need abstruse (extended) regular expressions
for your parsing ... well, maybe you're right.  Informed opinion
on this one is divided:
 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/a54607d8f2232a68/

Maxim Veksler exhibits more than a thousand non-blocking sockets
all listening simultaneously.  Jean-Paul Calderone shows how 
twisted does 'em better:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/f0d3dd52e754c1d0/

Microsoft's DLR appears to have substance:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/360c79cf6093d713/

[EMAIL PROTECTED] bounced for a while.  Resend requests that
were lost, please:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/3be0130e02ddcca4/

This is almost Foundational:  how does one receive one element from a
Set?  
 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/4392b09c281feca2/

Many agitate for Python to build in a different GUI toolkit.
Jeremiah Foster makes clear how to work with one of the
alternatives--wxPython for Mac OS X:
 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/f73834fb0238d880/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, Planet Python indexes
much of the universe of Pybloggers.
http://www.planetpython.org/

The Python Papers aims to publish the efforts of Python enthusiats.
http://pythonpapers.org/

Readers have recommended the Planet sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for 

building python from source on HP

2007-05-07 Thread Edwin . Madari
appreciate hints or pointers for building python on HP.

running 'make test'  fails with following cryptic message,  after running 
configure,  make. Attempting to build python from source on HP-UX host name 
B.11.11 U 9000/800 3314646674 unlimited-user license

*** Error exit code 1
Stop.

not sure if output from configure and make would make a difference. If so I can 
send them.

thanks in advance
Edwin




The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

Re: long lists

2007-05-07 Thread half . italian
On May 7, 5:14 am, Merrigan [EMAIL PROTECTED] wrote:
 On May 7, 10:18 am, Steven D'Aprano



 [EMAIL PROTECTED] wrote:
  On Mon, 07 May 2007 00:28:14 -0700, Merrigan wrote:
   1. I have the script popping all the files that need to be checked into
   a list, and have it parsing the list for everything...Now the problem is
   this : The sever needs to check (at the moment) 375 files and eliminate
   those that don't need reuploading. This number will obviously get bigger
   and bigger as more files gets uploaded. Now, the problem that I'm having
   is that the script is taking forever to parse the list and give the
   final result. How can I speed this up?

  By writing faster code???

  It's really hard to answer this without more information. In particular:

  - what's the format of the list and how do you parse it?

  - how does the script decide what files need uploading?

  --
  Steven.

 Hi, Thanx for the reply,

 The Script it available at this url 
 :http://www.lewendewoord.co.za/theScript.py

 P.S. I know it looks like crap, but I'm a n00b, and not yet through
 the OOP part of the tutorial.

 Thanx in advance!

Do you have access to the machine via ssh?  I would try to get away
from FTP and use rsync for this kind of thing if possible.

~Sean

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


Latest errors on pickled objects and blob datatypes in mysql

2007-05-07 Thread krishnakant Mane
hello,
finally the errors for my sql query have changed so I have even
changed the thread subject because I feel now that this is not doable
in mysql and this seams to be a bug, ither in python or the MySQLdb
module or perhaps both.
my table is called testobj and the blob field is called obj.
now following is my query with the cursor named CSRInsert.
CSRInsert.execute(insert into testobj (obj) values (?);,(pickled_object))
the error is,
type error, not all arguments formatted during string formatting .

can some one now figure out what could be the problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


getmtime differs between Py2.5 and Py2.4

2007-05-07 Thread Josef Dalcolmo

I tried this on Windows only:

In Python 2.4 os.path.getmtime returned the local time,
in Python 2.5 it seems to return GMT:

import os, time
print ctime.time(os.path.getmtime(foo))

differs on Python 2.4 and Python 2.5 by the timezone.

Now, the implementation of the two stat calls differs on Windows
between the two versions.

I actually like the new behaviour better, because I believe the
reported time of a file should not depend on the timezone or other
local settings, however the old behaviour is the time also Windows
shows - and there is an incompatibility.

Is this a bug? 

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


Re: how do you implement a reactor without a select?

2007-05-07 Thread [EMAIL PROTECTED]
Michele Simionato wrote:
 Notice that I copied the Twisted terminology, but
 I did not look at Twisted implementation because I did not want to
 use a select (I assume that the GUI mainloops do not use it either).
 The trick I use is to store the actions to perform (which are
 callables identified by an integer) in an event dictionary and
 to run them in the mainlooop if the current time is greater than
 the scheduled time.
 I had to add a time.sleep(.001) call in the default_action to avoid
 consuming 100%
 of the CPU in the loop.

Busy-looping like that is ugly and inefficient, even with the sleep
thrown in.

Most GUI main loops _do_ use either select() or poll().  When Xt/GTK/
Qt/etc have function like gtk_add_input which takes an fd that
you'll get notified about if it's written to while you're in the main
loop, that's just adding another fd to the select() loop.

There are other ways to wait for events on an fd, but they tend to be
less portable.  Depending on your Unix flavor, epoll, /dev/poll,
kqueues, kevent, queued realtime signals, or something else might be
available from the OS (but probably not from Python without futzing
with ctypes or writing an extension).  If you want details, check out
http://www.kegel.com/c10k.html

The alternatives usually aren't really faster unless you have hundreds
of connections, though--select/poll have major portability advantages,
so go with them unless you have a compelling reason.

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


After the Deletion of Google Answers, . U Got Questions Fills the Gap Answering and Asking the Tough Questions

2007-05-07 Thread Leisure . 208
My friend asked some tough questions 
http://ugotquestions.blogspot.com/2007_05_01_archive.html
unlike yahoo answers ( Which Generates Content with Answers ) U got
questions picks only the best, Real Person Questions.,yeah so there is
this second book called E.T. and the BOOK OF THE GREEN PLANET... yeah,
what happens in it... i heard he dies, and what happend to elliot
this has been bugging me for years...so someone please tell
mehttp://ugotquestions.blogspot.com/2007_04_01_archive.html - i start
my car and shut it off 4 to 5 times it starts fine but when i continue
repeat this procedure for another 2 to 3 times then it dies. it doesnt
start at all. the headlights and all other lights dont go dim so might
not be the battery. then i have to wait for 3 to 5 minutes for it to
start again. it does crank slowly sometime then start. the alternator
was replaced 2 years ago so was the battery. the car has 129000miles
its 01 maxima. automatic. as far as i think it could be the
starter...http://ugotquestions.blogspot.com/2007/05/y-alert-yahoo-
answers_7473.html 1- if you ask anyone in the town that: Are you a
wise human? and he says yes, what you can say about him? 2- tree
mathematicians are talking about their trip to this town: 1st man
says: in my trip to the town, I ask John (a people of the town) are
you a wise human? and with his reply, I could not rcognize what is he.
2nd man says: I also ask John are you a loony human? and with his
reply, I could not recognize what is he too. 3rd man says: I also ask
John are you a wise devil? and with his...http://
ugotquestions.blogspot.com/2007/05/y-alert-yahoo-answers_7075.html
Which major should I choose before law school if I want to practice
criminal and civil law and I also want in the future be a judge.The
majors that I like are criminal justice,politcal science and
finance.But I don't know which should I choose.I already know the
speech that law schools don't care about your mayor but I want to know
which one of those three could help me more in my goals fo practice
criminal and civil law and be a judge.Thanks a lothttp://
ugotquestions.blogspot.com/2007/05/y-alert-yahoo-answers_6058.html
Everyday I wake up to my mom yelling about something I did. All she
does is come home from work sit on the couch and watch a movie she
gets from blockbuster everyday while we are suppose to be doing
chores. She dosnt let us watch her movies becuase she pays for them,.
we dont have cable and we havnt gone grocery shopping in two months
becuase she says we dont hav the money.( while she gets take out
everyday at work and a blockbuster movie everyday to. )She told me i
cant wash my clothes for... shaw loves this.

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


Re: Latest errors on pickled objects and blob datatypes in mysql

2007-05-07 Thread Daniele Varrazzo
On 7 Mag, 19:08, krishnakant Mane [EMAIL PROTECTED] wrote:
 hello,
 finally the errors for my sql query have changed so I have even
 changed the thread subject because I feel now that this is not doable
 in mysql and this seams to be a bug, ither in python or the MySQLdb
 module or perhaps both.

And why not also a bug in MySQL? Or a neutrino hitting your CPU
changing a 0 into an 1? Doesn't the Occam razor suggest it may be your
fault? :)

 my table is called testobj and the blob field is called obj.
 now following is my query with the cursor named CSRInsert.
 CSRInsert.execute(insert into testobj (obj) values (?);,(pickled_object))
 the error is,
 type error, not all arguments formatted during string formatting .

 can some one now figure out what could be the problem?

Please, read the fine manual.

if you had read the DBAPI documentation as previously suggested, you
would know that you MUST use %s placeholder, not ? (because
MySQLdb.paramstyle == 'format'). Just replace the placeholder in your
sql string and keep passing sql and values as two distinct arguments.

The second argument of the execute() method MUST be a tuple (or a
mapping for named parameters, but let's stick to the positional ones).
(pickled_object) is not a tuple, it is just an object in
parenthesis. To represent a tuple with a single argument you must
write (pickled_object,), notice the trailing comma.

Try:

CSRInsert.execute(insert into testobj (obj) values (%s);,
(pickled_object,))

-- Daniele

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


Re: Unittest Automation

2007-05-07 Thread bourbaki
On May 7, 7:29 am, Calvin Spealman [EMAIL PROTECTED] wrote:
 I'm trying to find a better way, a shell one-liner, that I can use to
 recurse through my project, find all my test_ modules, aggregate the
 TestCase classes into a suite, and run all my tests. Basically, what
 py.test does out of the box. Why am I having such trouble doing it?

 --
 Read my blog! I depend on your acceptance of my opinion! I am 
 interesting!http://ironfroggy-code.blogspot.com/

See Nose

...

nose provides an alternate test discovery and running process for
unittest, one that is intended to mimic the behavior of py.test as
much as is reasonably possible without resorting to too much magic.

...

http://somethingaboutorange.com/mrl/projects/nose/

Cheers,
--Norm

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


Re: Latest errors on pickled objects and blob datatypes in mysql

2007-05-07 Thread Daniele Varrazzo
On 7 Mag, 19:08, krishnakant Mane [EMAIL PROTECTED] wrote:
 hello,
 finally the errors for my sql query have changed so I have even
 changed the thread subject because I feel now that this is not doable
 in mysql and this seams to be a bug, ither in python or the MySQLdb
 module or perhaps both.

And why not also a bug in MySQL? Or a neutrino hitting your CPU
changing a 0 into an 1? Doesn't the Occam razor suggest it may be your
fault? :)

 my table is called testobj and the blob field is called obj.
 now following is my query with the cursor named CSRInsert.
 CSRInsert.execute(insert into testobj (obj) values (?);,(pickled_object))
 the error is,
 type error, not all arguments formatted during string formatting .

 can some one now figure out what could be the problem?

Please, read the fine manual.

if you had read the DBAPI documentation as previously suggested, you
would know that you MUST use %s placeholder, not ? (because
MySQLdb.paramstyle == 'format'). Just replace the placeholder in your
sql string and keep passing sql and values as two distinct arguments.

The second argument of the execute() method MUST be a tuple (or a
mapping for named parameters, but let's stick to the positional ones).
(pickled_object) is not a tuple, it is just an object in
parenthesis. To represent a tuple with a single argument you must
write (pickled_object,), notice the trailing comma.

Try:

CSRInsert.execute(insert into testobj (obj) values (%s);,
(pickled_object,))

-- Daniele

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


Simulating simple electric circuits

2007-05-07 Thread Bjoern Schliessmann
Hello all,

I'm trying to simulate simple electric logic (asynchronous)
circuits. By simple I mean that I only want to know if I
have current or no current (it's quite digital) and the only
elements need to be (with some level of abstraction to my specific
problem)

- sources (here begin currents)
- ground (here end currents)
- joints
- switches (which are able to let current pass or not, depending on
  outside influence)
- loads (which can signal change in current flow to the outside --
  just like a light bulb)

Is there any library for this? I couldn't find one.

I tried to implement this using objects that are two-way linked;
every object has ports. For every port, there is 

- an input function (that is called by the neighbour if current
comes in)
- a reference to the neighbour's input function, to be able to let
current flow the other way

There is a master current controller object which tells
the source object to start a current by calling its neighbour.
The calls traverse the network until they reach a ground object.
Specifically, the source passes a telegram instance with these
calls, and everyone it passes through registers himself with it
(telegrams are duplicated at joints). Then, the ground object calls
back to the controller with all received telegrams. Like this I'm
already able to get all possible ways through the network. 

But that's where my ideas go out. Let's assume there is a load in
the middle of such a current, e. g. a light bulb. So if the current
flows through it it gets notice of this because there is a telegram
passing through it. But what if a contact before it now cuts the
current, how could I notify all objects behind the cut? I tried
several ways the past few days, but all lead to confusing (and
non-working) code. (I'm sorry I can't provide any working code yet)
Often it boils down to the need to check all possible ways in the
entire network with every change. This shouldn't, in perfomance
terms, be a big problem for me here, but it feels very dirty, and I
smell inconsistencies.

Another way I thought of is

- to let load objects have a timer that resets their state to no
  flow after ~ 200 ms
- pulse the network every ~ 100 ms from all sources to ground
- and reset all load timers on the way.

This feels even more dirty.

There are several professional-grade simulation tools that track
many other parameters, how do they work in general, is there a
different strategy? I wonder if I'm making it too complicated or if
I'm seeing problems where there really aren't any. I also looked at
NetworkX, but I can't see how it might be of use yet. I appreciate
all suggestions.

Thanks for you consideration.

Regards,


Björn

P.S.: This is no homework, it's pure hobby ;)

-- 
BOFH excuse #70:

nesting roaches shorted out the ether cable

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


SOAPpy parameters in sequence

2007-05-07 Thread D Unit

Hi,

I am trying to send a message to a SOAP implementation where the parameters
must in sequence. I am creating a SOAPProxy and then sending the message
with:

proxy.methodName(paramName=value, paramName2=value2)

Is there a way to explicitly set the order of parameters?
If not, is there a way to manually set the SOAP message body and send the
message?

Thanks
-- 
View this message in context: 
http://www.nabble.com/SOAPpy-parameters-in-sequence-tf3705624.html#a10363179
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Simulating simple electric circuits

2007-05-07 Thread Arnaud Delobelle
On May 7, 7:05 pm, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
 Hello all,

 I'm trying to simulate simple electric logic (asynchronous)
 circuits. By simple I mean that I only want to know if I
 have current or no current (it's quite digital) and the only
 elements need to be (with some level of abstraction to my specific
 problem)

 - sources (here begin currents)
 - ground (here end currents)
 - joints
 - switches (which are able to let current pass or not, depending on
   outside influence)
 - loads (which can signal change in current flow to the outside --
   just like a light bulb)

 Is there any library for this? I couldn't find one.

 I tried to implement this using objects that are two-way linked;
 every object has ports. For every port, there is

 - an input function (that is called by the neighbour if current
 comes in)
 - a reference to the neighbour's input function, to be able to let
 current flow the other way

 There is a master current controller object which tells
 the source object to start a current by calling its neighbour.
 The calls traverse the network until they reach a ground object.
 Specifically, the source passes a telegram instance with these
 calls, and everyone it passes through registers himself with it
 (telegrams are duplicated at joints). Then, the ground object calls
 back to the controller with all received telegrams. Like this I'm
 already able to get all possible ways through the network.

Then you can get all 'potential' paths that depend on one or more
switches being on.  Each path could know what switches it depends on
and be 'active' if and only if all those switches are on.  And each
switch would know what paths depend on it. Similarly each lightbulb
would know what paths it depends on and be 'on' if at least one path
is active; and each path would know which lightbulbs it powers

 But that's where my ideas go out. Let's assume there is a load in
 the middle of such a current, e. g. a light bulb. So if the current
 flows through it it gets notice of this because there is a telegram
 passing through it. But what if a contact before it now cuts the
 current, how could I notify all objects behind the cut? I tried
 several ways the past few days, but all lead to confusing (and
 non-working) code. (I'm sorry I can't provide any working code yet)
 Often it boils down to the need to check all possible ways in the
 entire network with every change. This shouldn't, in perfomance
 terms, be a big problem for me here, but it feels very dirty, and I
 smell inconsistencies.

When you turn a switch off, it would send a message to the paths that
depend on it (maybe via the controller?) so that they would be
deactivated.  In turn the lightbulbs on these paths would be informed
that they are no longer active.

When you turn a switch on, it would send a message to the paths that
depend on it so that those who do not have another off switch would be
activated.  In turn the lightbulbs on these paths would be informed
that they have a new power source.

It seems to me that it would work well with the way you started it
out, but I may have misunderstood some aspects or overlooked some
problems ;)

--
Arnaud

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


Re: SOAPpy parameters in sequence

2007-05-07 Thread D Unit

I figured it out.
The SOAPPRoxy class has an attribute 'SOAPPRoxy.config.argsOrdering'
You can set it to a dict. Each key is the name of a method, and the value is
a list with the attributes in the correct order.

-Dave


D Unit wrote:
 
 Hi,
 
 I am trying to send a message to a SOAP implementation where the
 parameters must in sequence. I am creating a SOAPProxy and then sending
 the message with:
 
 proxy.methodName(paramName=value, paramName2=value2)
 
 Is there a way to explicitly set the order of parameters?
 If not, is there a way to manually set the SOAP message body and send the
 message?
 
 Thanks
 

-- 
View this message in context: 
http://www.nabble.com/SOAPpy-parameters-in-sequence-tf3705624.html#a10363807
Sent from the Python - python-list mailing list archive at Nabble.com.

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


is for reliable?

2007-05-07 Thread [EMAIL PROTECTED]
Hi to all I have a question about the for statement of python. I have the
following piece of code where cachefilesSet is a set that contains the
names of 1398 html files cached on my hard disk


for fn in cachefilesSet:
 
fObj = codecs.open( baseDir + fn + '-header.html', 'r', 'iso-8859-1' )
u = fObj.read()

v = u.lower()
rows = v.split('\x0a')

contentType = ''

for r in rows:
if r.find('content-type') != -1:
y = r.find(':')
if y != -1:
z = r.find(';', y)
if z != -1:
contentType = r[y+1:z].strip()
cE = r[z+1:].strip()
characterEncoding = cE.strip('charset = ')
else:
contenType = r[y+1:].strip()
characterEncoding = ''
break

if contentType == 'text/html':
processHTMLfile( baseDir + fn + '-body.html', characterEncoding, 
cardinalita )

fileCnt += 1
if fileCnt % 100 == 0: print fileCnt

this code stops at the 473th file instead of reaching 1398

however I changed the for and substituted it with a while in this way

while cachefilesSet:
fn = cachefilesSet.pop()
...
...

the while loop reaches the 1398th file and is some 3-4 times faster than
the for loop

How is this possible?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simulating simple electric circuits

2007-05-07 Thread Bjoern Schliessmann
Arnaud Delobelle wrote:
 On May 7, 7:05 pm, Bjoern Schliessmann usenet-

 There is a master current controller object which tells
 the source object to start a current by calling its
 neighbour. The calls traverse the network until they reach a
 ground object. Specifically, the source passes a telegram
 instance with these calls, and everyone it passes through
 registers himself with it (telegrams are duplicated at joints).
 Then, the ground object calls back to the controller with all
 received telegrams. Like this I'm already able to get all
 possible ways through the network.
 
 Then you can get all 'potential' paths that depend on one or more
 switches being on.  Each path could know what switches it depends
 on and be 'active' if and only if all those switches are on.  And
 each switch would know what paths depend on it. Similarly each
 lightbulb would know what paths it depends on and be 'on' if at
 least one path is active; and each path would know which
 lightbulbs it powers

In principle, I thought so too, but I didn't like the fact that this
involves all possible circuits be determined only once. But it
seems like there is no reasonable, different way.

 When you turn a switch off, it would send a message to the paths
 that depend on it (maybe via the controller?) so that they would
 be deactivated.  In turn the lightbulbs on these paths would be
 informed that they are no longer active.
 
 When you turn a switch on, it would send a message to the paths
 that depend on it so that those who do not have another off switch
 would be activated.  In turn the lightbulbs on these paths would
 be informed that they have a new power source.

Yep. Looks like I have to do extended bookkeeping for this. I was
looking for a more dynamic, general way.

 It seems to me that it would work well with the way you started it
 out, but I may have misunderstood some aspects or overlooked some
 problems ;)

Thanks for your input. The biggest problem I got until now are the
crummy interfaces for interconnection which quickly get inconcise.
I've had a look at the NetworkX tutorial and it seems like this
could simplify the code a bit.

Regards,


Björn

-- 
BOFH excuse #173:

Recursive traversal of loopback mount points

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


  1   2   >