Download Mail Via Python

2005-09-12 Thread Albert Leibbrandt








I am busy writing a little prog to download mail and put the
contents of the emails into a database. The problem that I am currently facing
is that I can view the message body only if it was sent with a mail client
other than MS outlook or outlook express. What am I missing, any reading material
I can have a look at? Examples perhaps?

 

Thanks in advance.

Albert

 

 






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

Would you pls tell me a tool to step debug python program?

2005-09-12 Thread Johnny Lee
Hi,
   I've met a problem to understand the code at hand. And I wonder
whether there is any useful tools to provide me a way of step debug?
Just like the F10 in VC...

Thanks for your help.

Regards,
Johnny

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


Re: how to get the return value of a thread?

2005-09-12 Thread Antoon Pardon
Op 2005-09-09, Leo Jay schreef <[EMAIL PROTECTED]>:
> Dear all,
>
> i would like to get the return value of all threads
>
> e.g.
> def foo(num):
> if num>10:
> return 1
> elif num>50:
> return 2
> else
> return 0
>
>
> after i invoked 
> t = thread.start_new_thread(foo,(12,))
> how to get the return value of `foo'?
>
> Thanks
>

Maybe you should have a look at the Future class
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/84317

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


Re: Would you pls tell me a tool to step debug python program?

2005-09-12 Thread Adriaan Renting
try Eric3 F6-F10 will probably do exactly what you want.

www.die-offenbachs.de/detlev/eric3.html

 
>>>"Johnny Lee" <[EMAIL PROTECTED]> 09/12/05 9:12 am >>> 
Hi, 
  I've met a problem to understand the code at hand. And I wonder 
whether there is any useful tools to provide me a way of step debug? 
Just like the F10 in VC... 
 
Thanks for your help. 
 
Regards, 
Johnny 
 
-- 
http://mail.python.org/mailman/listinfo/python-list 

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


Re: PEP-able? Expressional conditions

2005-09-12 Thread Antoon Pardon
Op 2005-09-09, Terry Hancock schreef <[EMAIL PROTECTED]>:
> On Thursday 08 September 2005 04:30 am, Paul Rubin wrote:
>> Terry Hancock <[EMAIL PROTECTED]> writes:
>> > > Not the same at all.  It evaluates both the true and false results,
>> > > which may have side effects.
>> > 
>> > If you are depending on that kind of nit-picking behavior,
>> > you have a serious design flaw, a bug waiting to bite you,
>> > and code which shouldn't have been embedded in an expression
>> > in the first place.
>> 
>> Are you kidding?  Example (imagine a C-like ?: operator in Python):
>> 
>>x = (i < len(a)) ? a[i] : None# make sure i is in range
>>
>> Where's the design flaw? 
>
> It's a syntax error. See?
>
 x = (i < len(a)) ? a[i] : None# make sure i is in range
>   File "", line 1
> x = (i < len(a)) ? a[i] : None# make sure i is in range
>  ^
> SyntaxError: invalid syntax
>
> That's a pretty serious design flaw.
>
> You see, I'm not discussing an imaginary Python interpreter here.

Nobody is, but the general consensus about a ternary operator
has always been that it should have lazy evaluataion.
That is even mentioned in the PEP.
http://www.python.org/peps/pep-0308.html

The BDFL's position is that short-circuit behavior is essential
for an if-then-else construct to be added to the language.

And you did claim that depending on side effects was a serious design
flaw. And as far as I understand what you wrote that was independant
of the language used.


>> Where's the bug waiting to bite?  That's a
>> completely normal use of a conditional expression.  If the conditional
>> expression works correctly, this does the right thing, as intended.
>> If both results get evaluated, it throws a subscript out of range
>> error, not good.
>
> No. It throws a syntax error, as I demonstrated.

Which is a dishonest remark. The way you made the remark, made it
a claim about algorithmic design, independant of the language
chosen or the specific construct chosen to interpret it.

That Paul chose a construct that is not syntactic python to dispute
your claim, is beside the point.

>> Every time this topic comes up, the suggestions that get put forth are
>> far more confusing than just adding conditional expressions and being
>> done with it.
>
> If it's so easy, then do it, and quit whining. You could easily
> have published an alternative "better" ternary function instead
> of just complaining that mine "isn't right", by which you mean
> only that it doesn't work exactly as it would in C, or in your
> imaginary Python interpreter.

There have been alternatives enough that have been published.
It is not a matter of publishing yet an other alternative.
It is just that the BDFL has declare this a no no.

> Myself, I just can't see how writing:
>
> if (i < len(a)): x = a[i]
> else:  x = None
>
> is gonna kill you.  It's also not by any means a solution so obvious
> that I would not want to see the special case on it's own line.

And how do I do this in a list comprehension?

Myself I couldn't see how writing:

  def fun(...):
 ...

  fun = deco(fun)

Would kill anyone, but decorator syntax appeared anyway.

> After all, in most cases where I would use a limiter like this, I'd
> want the special case to be handled by something other than None. Or
> I'd want to raise an exception, even.  Which, come to think of it,
> I wouldn't even have to code, would I?  The thing is, if you return
> None like this, you won't be able to treat it the same as the normal
> output, so you're still going to have to check the result. Which just
> means you've moved the complexity upwards  (almost always a bad move 
> which replicates effort -- another design flaw).

Examples given here, are done so to make a point. The example itself
may never been used in actual code, but code that is similar enough
in behaviour, may. Try to look at the argument one is trying to make
instead of looking at insignificant details.

> If you want to go and argue with Guido over this, go ahead. I'm all
> for a ternary operator.
>
> But IIRC, that parrot is dead. It's an ex-parrot.

Yes probably, but the fact that it is a dead parrot, doesn't make
the idea bad. I sometimes get the impression that just because
Guido declared a subject dead, some people feel obligated to
argue how bad it would have been anyway.

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


read stdout/stderr without blocking

2005-09-12 Thread Jacek Popławski
Popen from subprocess module gives me access to stdout, so I can read 
it. Problem is, that I don't know how much data is available... How can 
I read it without blocking my program?

example:

import subprocess
import time

command="ls -l -R /"

p=subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)

while (p.poll()==None):
 print "."
 r=p.stdout.read()


when you comment out read() - you will notice that loop is working, with 
read() loop is blocked
Of course I don't need to read() inside loop, but... if output is very 
long (like from "make") and I don't read from stdout - command will 
block itself! I tried to increase bufsize, but it didn't help.

Is there a way to read only available data from stdout/stderr?
Is there a way to not block Popen command without reading stdout/stderr?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: read stdout/stderr without blocking

2005-09-12 Thread Adriaan Renting
Check out the select module, for an example on how to use it:
pexpect.sourceforge.net


 
 
>>>Jacek Pop*awski <[EMAIL PROTECTED]> 09/12/05 10:07 am >>> 
Popen from subprocess module gives me access to stdout, so I can read 
it. Problem is, that I don't know how much data is available... How can 
I read it without blocking my program? 
 
example: 
 
import subprocess 
import time 
 
command="ls -l -R /" 
 
p=subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
 
 
while (p.poll()==None): 
print "." 
r=p.stdout.read() 
 
 
when you comment out read() - you will notice that loop is working, with 
read() loop is blocked 
Of course I don't need to read() inside loop, but... if output is very 
long (like from "make") and I don't read from stdout - command will 
block itself! I tried to increase bufsize, but it didn't help. 
 
Is there a way to read only available data from stdout/stderr? 
Is there a way to not block Popen command without reading stdout/stderr? 
-- 
http://mail.python.org/mailman/listinfo/python-list 

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


Re: Download Mail Via Python

2005-09-12 Thread Adriaan Renting
You could maybe give some more information about what you're doing, like if you 
use POP or IMAP, the kind of mail server used, etc. I know the at least Outpook 
used some odd MS specific formatting when sending stuff trough Exchange 
(non-HTML/RTF/plain text) for the body. This is the "Rich text" setting, which 
does not produce RTF, but TNEF. When using Word as the e-mail editor you also 
get funky stuff.

http://support.microsoft.com/default.aspx?scid=KB;en-us;q269186
 
>>>"Albert Leibbrandt" <[EMAIL PROTECTED]> 09/12/05 9:14 am >>> 

 I am busy writing a little prog to download mail and put the contents of the 
emails into a database. The problem that I am currently facing is that I can 
view the message body only if it was sent with a mail client other than MS 
outlook or outlook express. What am I missing, any reading material I can have 
a look at? Examples perhaps?   
 
 Thanks in advance.   
 Albert   
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: packaging python for install.

2005-09-12 Thread Daniel Dittmar
J wrote:
> I have created an App that embedds the python interpreter and I am
> now in the process of creating an installer. I am currently linking
> python24.lib, but it is only 184k and I suspect that it imports other
> dlls... I am also using numarray. Does anyone have any experiences in
> packaging python with an application in a single installer ? Has that
> been done before ?

- you need python24.dll (probably in %windir%\system32)
- you need some of the *.pyd found in you Pythondir\DLLs. You can use 
Proces Explorer from www.sysinternals.com to see all the loaded DLLs and 
.pyd that your running program accesses
- you need a large part of the Python library. Best: compile them to 
.pyc files using Pythondir\Lib\compileall.py, pack them into one .zip 
file and then add that .zip file to %PYTHONPATH%

Hint: Python will search for the Library files through the registry key 
HKEY_LOCAL_MACHINE\SOFTWARE\PythonCore\. You don't have to set 
this entry with your installer (and you shouldn't, as it would break an 
already existing Python installation). But you could rename it on your 
machine as this allows you to test your installation without having to 
copy everything to a clean machine.

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


Enter as Tab in wxPython

2005-09-12 Thread lux
Hi,
how to modify the Enter key behavior
in order to be equal to the Tab Key.
I need navigate between the ctrl
only with the Enter Key.

Tanks, Luca

PS: sorry for my English

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


Re: Redundant code in multiple methods

2005-09-12 Thread bruno modulix
Rob Conner wrote:
> No you don't need to know Zope to help me. The whole reason I'd even
> want to do this is because of Zope though. I made a Zope product, and
> now want to perfect it.
> 
> some simple example code...
> 
> 
> class User:
> 
> def View(self):
> # play with data here
> myHtmlDoc = "pretend this is a uper profile"
> return myHtmlDoc
> index_html = View
> 
> def Edit(self):
> # play with data here
> myHtmlDoc = "editing the user"
> return myHtmlDoc
> 
> 
> So when visiting "website.com/User" zope will call User.index_html() or
> when you visit "website.com/User/View" zope will call User.View() In
> all of the testing/learning I've done on Zope I'm pretty sure that last
> item (index_html or View) must be a method,

Anything that returns HTML is ok. Can be a method, a data attribute, a
class attribute pointing to a ZPT or DTML file (like you do for ZMI
forms), and even any aquired component ! (the view and index_html
attributes doesnt need to live in the class...)

> 
> The problem comes when I want to have code put into every method.
> Perhaps a counter I want to increment on every visit to a User page.
> I can do this..
> 
> 
> def View(self):
> incrementCounter()
> # play with data here
> myHtmlDoc = "pretend this is a uper profile"
> return myHtmlDoc
> index_html = View
> 
> def Edit(self):
> incrementCounter()
> # play with data here
> myHtmlDoc = "editing the user"
> return myHtmlDoc
> 
> 
> ... but in reality in my real code that one counter increment line ends
> up being 20 lines long. 

This is typically what AOP is all about - and Python offers a quite
usable support for "ad hoc" aspects, via the function wrapper idiom. The
simplest way is to use closures:

def wrapper(fun, wargs):
  def wrapped(fargs):
 do_something_before_funcall(wargs, fargs)
 res = fun(fargs)
 do_something_after_funcall(wargs, fargs)
 return res
  return wrapped

class Machin(object):
  def to_be_wrapped(self, args):
 # code here...
  # Zope 2.x uses Python 2.3.x, so no @decorator syntax
  to_be_wrapped = wrapper(to_be_wrapped, wargs)

If you need something more complex, see Sam's example with a callable
object.

(snip longer code exemple)


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python script under windows

2005-09-12 Thread Marco Aschwanden
>   Can you help me ?  Or better is there some info for unix person how
> to survive with python on windows ;-)

Use py2exe to transform your app into a service...

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


Re: Would you pls tell me a tool to step debug python program?

2005-09-12 Thread Franz Steinhaeusler
On 12 Sep 2005 00:12:29 -0700, "Johnny Lee" <[EMAIL PROTECTED]>
wrote:

>Hi,
>   I've met a problem to understand the code at hand. And I wonder
>whether there is any useful tools to provide me a way of step debug?
>Just like the F10 in VC...
>
>Thanks for your help.
>

What about the "new" winpdb debugger.
It looks really nice.

http://sourceforge.net/projects/winpdb/
http://www.digitalpeers.com/pythondebugger/

create a shortcut like:
C:\Python24\python.exe C:\Python24\Lib\site-packages\winpdb.py -t

the -t switch is important, otherwise it starts in an
encrypted mode".

I have patched winpdb.py (about Line420):

AC_CHAR = "\t"
AC_EXIT = "Alt-X"
AC_BREAK = "F4"
AC_GO = "F5"
AC_NEXT = "F10"
AC_STEP = "F11"
AC_GOTO = "Ctrl+F10"
AC_TOOGLE = "F9"
AC_RETURN = "Shift+F11"

to accomodate the shortcuts to VC Debugger.


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


exceptions from logging on Windows

2005-09-12 Thread Oliver Eichler
Hi,

I experience several exceptions from python's logging system when using the
rollover feature on Windows.

Traceback (most recent call last):
  File "c:\Python24\lib\logging\handlers.py", line 62, in emit
if self.shouldRollover(record):
  File "c:\Python24\lib\logging\handlers.py", line 132, in shouldRollover
self.stream.seek(0, 2)  #due to non-posix-compliant Windows feature
ValueError: I/O operation on closed file

Googeling revealed that this has been experienced by others, too, however no
workaround or solution has been provided. Is this the latest status on this
topic? Do I miss something?

Thanks for help,

Oliver

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


Re: exceptions from logging on Windows

2005-09-12 Thread Simon Dahlbacka
I ended up monkey-patching doRollover to do a number of retries before
giving up. (In our case the failures is due to our log browser
happening to read the latest changes when logging wants to rollover)

(Actually, I implemented a simple QueueHandler and do all file
operations from a different logging thread)

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


Re: Would you pls tell me a tool to step debug python program?

2005-09-12 Thread Varghjärta
I myself used/use "Komodo" for all my developing, it's the best and
easiest to use graphical IDE for python i've found thus far.


On 12/09/05, Franz Steinhaeusler <[EMAIL PROTECTED]> wrote:
> On 12 Sep 2005 00:12:29 -0700, "Johnny Lee" <[EMAIL PROTECTED]>
> wrote:
> 
> >Hi,
> >   I've met a problem to understand the code at hand. And I wonder
> >whether there is any useful tools to provide me a way of step debug?
> >Just like the F10 in VC...
> >
> >Thanks for your help.
> >
> 
> What about the "new" winpdb debugger.
> It looks really nice.
> 
> http://sourceforge.net/projects/winpdb/
> http://www.digitalpeers.com/pythondebugger/
> 
> create a shortcut like:
> C:\Python24\python.exe C:\Python24\Lib\site-packages\winpdb.py -t
> 
> the -t switch is important, otherwise it starts in an
> encrypted mode".
> 
> I have patched winpdb.py (about Line420):
> 
> AC_CHAR = "\t"
> AC_EXIT = "Alt-X"
> AC_BREAK = "F4"
> AC_GO = "F5"
> AC_NEXT = "F10"
> AC_STEP = "F11"
> AC_GOTO = "Ctrl+F10"
> AC_TOOGLE = "F9"
> AC_RETURN = "Shift+F11"
> 
> to accomodate the shortcuts to VC Debugger.
> 
> 
> --
> Franz Steinhaeusler
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


read from label

2005-09-12 Thread [EMAIL PROTECTED]
HI,
It may be a very elementry question, but I need to know that how can I
get text of a label.

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


which is more 'pythonic' / 'better' ?

2005-09-12 Thread gabor
hi,

there are 2 versions of a simple code.
which is preferred?


===
if len(line) >= (n+1):
text = line[n]
else:
text = 'nothing'
===


===
try:
text = line[n]
except IndexError:
text = 'nothing'
===


which is the one you would use?

thanks,
gabor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: read stdout/stderr without blocking

2005-09-12 Thread Jacek Popławski
Adriaan Renting wrote:
> Check out the select module, for an example on how to use it:
> pexpect.sourceforge.net

Two problems:
- it won't work on Windows (Cygwin)
- how much data should I read after select? 1 character? Can it block if 
I read 2 characters?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which is more 'pythonic' / 'better' ?

2005-09-12 Thread Steven D'Aprano
On Mon, 12 Sep 2005 12:52:52 +0200, gabor wrote:

> hi,
> 
> there are 2 versions of a simple code.
> which is preferred?
> 
> 
> ===
> if len(line) >= (n+1):
>   text = line[n]
> else:
>   text = 'nothing'
> ===
> 
> 
> ===
> try:
>   text = line[n]
> except IndexError:
>   text = 'nothing'
> ===
> 
> 
> which is the one you would use?

Personally, I would use either. You say po-ta-to, I say pot-at-o.

try...except... blocks are quick to set up, but slow to catch the
exception. If you expect that most of your attempts will succeed, then the
try block will usually be faster than testing the length of the list
each time.

But if you expect that the attempts to write the line will fail more
frequently, then testing will be quicker.

You will need to do your own testing before hand to find the exact
cut-off, and expect that cut-off to vary according to the Python
implementation and version. But a rough rule of thumb is, if you expect
your code to fail more often than succeed, then test first, otherwise
catch an exception.



-- 
Steven.

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


OCR librarys

2005-09-12 Thread Timothy Smith
i'm looking for ocr librarys with reasonably free licensing and the 
ablity to use python with them. c library's that i can call from python 
are acceptable.
so far all i have run into is voodoo and wild claims. i've tried gocr, 
and it wasn't very impressive. i'm like to be able to ocr handwriting 
but it's not a major requirment. anyone with any pointers or idea's i'm 
all ears. i'd really not like to have to use somthing like imagemagick 
and start from scratch.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: read from label

2005-09-12 Thread Steven D'Aprano
On Mon, 12 Sep 2005 03:43:04 -0700, [EMAIL PROTECTED] wrote:

> HI,
> It may be a very elementry question, but I need to know that how can I
> get text of a label.

Rotate the bottle or jar towards you until the label is facing you, then
read it. 

:-)

Seriously though, perhaps you would like to give a little more detail
about your problem. What sort of label? I assume you are using a GUI
toolkit -- which one?

You might also like to read this:

http://www.catb.org/~esr/faqs/smart-questions.html


-- 
Steven.

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


Re: which is more 'pythonic' / 'better' ?

2005-09-12 Thread Will McGugan
gabor wrote:
> hi,
> 
> there are 2 versions of a simple code.
> which is preferred?
> 
> 
> ===
> if len(line) >= (n+1):
> text = line[n]
> else:
> text = 'nothing'
> ===
> 
> 
> ===
> try:
> text = line[n]
> except IndexError:
> text = 'nothing'
> ===
> 
> 
> which is the one you would use?

I would actualy use the following for this particular case..

text = line[n:n+1] or 'nothing'

But in general I think it is best to use exceptions like that only where 
  you expect the code to _not_ throw the exception the majority of 
times. Otherwise the simple condition is better. Although I expect there 
is not much difference either way..


Will McGugan
--
http://www.kelpiesoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Expected Value

2005-09-12 Thread Steven D'Aprano
On Sat, 10 Sep 2005 17:50:06 -0700, George wrote:

> How would I get the expected value out of this information. I have
> tried many times to understand this but am unable to.

Do you have a specific Python problem here, or do you need help with the
maths? If Python, please tell us what your problem is. If your problem is
with the maths, then a statistics and/or probability forum is probably
going to be more useful to you.

If you are having a problem with the code, not the maths, I frequently
find that it helps to reduce the problem. Instead of calculating the
expectation of a discrete pdf with one hundred thousand values, start with
a toy problem: write code that calculates the expectation of a pdf with
only five values. That is small enough that you can experiment using the
interactive Python interpreter, and if need be calculate the correct
answer with paper and pencil.

You might also find it useful to read this:

http://www.catb.org/~esr/faqs/smart-questions.html


-- 
Steven.

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


Re: read stdout/stderr without blocking

2005-09-12 Thread Adriaan Renting
I was not aware you were using Windows, you might need to find something 
similar to select and pty that works in Windows or maybe go though Cygwin, I 
don't know. I'm on Linux, the only help I can offer is showing you my working 
code, that's a mix of Pexpect, subProcess and Parseltongue.
I'm not sure if this is 100% correct, it just happens to work and might help 
you in solving a similar problem:

 in spawn()
(self._errorpipe_end, self._errorpipe_front) = os.pipe() ## need to 
handle stderr separate from stdout
try:
(self._pid, self._child_fd) = pty.fork()
except OSError, e:
raise Exception ('fork failed')
if self._pid == 0: ## the new client
try:
os.dup2(self._errorpipe_front, 2) ## we hardcoded assume stderr 
of the pty has fd 2
os.close(self._errorpipe_end)
os.close(self._errorpipe_front) ## close what we don't need
os.execvp(self.task, self.inputs)
except:
sys.stderr.write('Process could not be started: ' + self.task)
os._exit(1)
else: ## the parent
os.close(self._errorpipe_front) ## close what we don't need
fcntl.fcntl(self._child_fd, fcntl.F_SETFL, os.O_NONBLOCK)

 in handle_messages()
tocheck=[]
if not self._fd_eof:
tocheck.append(self._child_fd)
if not self._pipe_eof:
tocheck.append(self._errorpipe_end)
ready = select.select(tocheck, [], [], 0.25) ##continues after 0.25s
for file in ready[0]:
try:
text = os.read(file, 1024)
except: ## probalby Input/Output error because the child died
text = ''
if text:
for x in self._expect:
if x[0] in text: ## we need to do something if we see this 
text
returntext = x[1](text)
if returntext:
os.write(file, returntext)
self.handle_text(text)
else:
if file == self._child_fd:
self._fd_eof   = 1
elif file == self._errorpipe_end:
self._pipe_eof = 1
return 1
if self._fd_eof or self._pipe_eof: # should be an and not an or, but 
python 2.3.5 doesn't like it
return 0
if len(ready[0]) == 0: ## no data in 0.25 second timeout
return 1
return 0
 
 in finish()
(pid, status) = os.waitpid(self._pid, os.WNOHANG) ## clean up the zombie
assert(pid == self._pid)
if os.WIFEXITED(status) or os.WIFSIGNALED(status):
self._pid   = 0
self.exitstatus = status
assert(self.finished())
del self._pid
os.close(self._child_fd)
os.close(self._errorpipe_end)


|>>>Jacek Pop*awski <[EMAIL PROTECTED]> 09/12/05 1:14 pm >>> 
|Adriaan Renting wrote: 
|>Check out the select module, for an example on how to use it: 
|>pexpect.sourceforge.net 
| 
|Two problems: 
|- it won't work on Windows (Cygwin) 
|- how much data should I read after select? 1 character? Can it block if 
|I read 2 characters? 
|-- 
|http://mail.python.org/mailman/listinfo/python-list 

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


Premature wakeup of time.sleep()

2005-09-12 Thread Erich Schreiber
In the Python Library Reference the explanation of the time.sleep()
function reads amongst others:

> The actual suspension time may be less than that requested because 
> any caught signal will terminate the sleep() following execution 
> of that signal's catching routine. Also, the suspension time may 
> be longer than requested by an arbitrary amount because of the 
> scheduling of other activity in the system.

I don't understand the first part of this passage with the premature
wakeup. What signals would that be?

I've written a script that tries to bench the responsiveness of a
virtual Linux server. My script sleeps for a random time and on waking
up calculates the difference of the proposed and actual wakeup time.

The essential code fragment is

while True:
ts = tDelay()
t1 = time.time()
time.sleep(ts)
t2 = time.time()
twu = str(datetime.datetime.utcfromtimestamp(t1 + ts))
logResults(LOGFILE, twu, ts, int((t2-t1-ts)*1000))

Whereas tDelay() returns a (logarithmically) randomly distributed real
number in the range [0.01, 1200] which causes the process to sleep
from 10 ms to 20 minutes.

In the logs I see a about 1% of the wake-up delays beeing negative
from -1ms to about -20ms somewhat correlated with the duration of the
sleep. 20 minute sleeps tend to wake-up earlier then sub-second
sleeps. Can somebody explain this to me? 

Regards,

Erich Schreiber

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


[Fwd: Sept 14 Fredericksburg, VA ZPUG: Packaging with zpkg, review of Python Cookbook 2nd ed]

2005-09-12 Thread Benji York
Please join us September 14, 7:30-9:00 PM, for the fourth meeting of
the Fredericksburg, VA Zope and Python User Group ("ZPUG").

This meeting has three features of note.

- Fred Drake, Zope Corp Senior Software Engineer, Python core
developer, and Python documentation maintainer and editor will  present
a discussion of zpkg, the Zope Packaging Tools (http://
www.zope.org/Members/fdrake/zpkgtools/).

- Gary Poster, Zope Corp Senior Software Engineer, will present a brief
review of the second edition of the O'Reilly Python Cookbook
(http://www.oreilly.com/catalog/pythoncook2/).

- We will serve delicious fruit, cheese, and soft drinks.

We've had a nice group for all the meetings.  Please come and bring
friends! An RSVP would be appreciated if you are coming, but is not
necessary.

More information http://www.zope.org/Members/poster/fxbgzpug_announce_4
and below.

Upcoming meetings are already tentatively planned for presenters
(although we can still use more, particularly lightning talks): see
http://www.zope.org/Members/poster/fxbgzpug_announce_5 and
http://www.zope.org/Members/poster/fxbgzpug_announce_6

Hope to see you there!


General ZPUG information

When: second Wednesday of every month, 7:30-9:00.

Where: Zope Corporation offices. 513 Prince Edward Street;
Fredericksburg, VA 22408 (tinyurl for map is http://tinyurl.com/duoab).

Parking: Zope Corporation parking lot; entrance on Prince Edward Street.

Topics: As desired (and offered) by participants, within the
constraints of having to do with Python.

Contact: Gary Poster ([EMAIL PROTECTED])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Premature wakeup of time.sleep()

2005-09-12 Thread jepler
Is your system running something like ntpd?  I'm not sure how use of
ntp, which will slowly adjust the system's time to match the network
time, will interact with calls to sleep().

This is almost certainly an OS question, though, not a Python question.
Python's time.sleep() is a bit complicated, but on Linux it looks like
it'll favor use of select(2) with a timeout argument.  Perhaps you can
duplicate these results with a pure "C" program and then ask around on a
mailing list or newsgroup about Linux or the specific virtual Linux
server setup you're using.

Jeff


pgpd6ehhe7W4O.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: read stdout/stderr without blocking

2005-09-12 Thread Jacek Popławski
> ready = select.select(tocheck, [], [], 0.25) ##continues after 0.25s
> for file in ready[0]:
> try:
> text = os.read(file, 1024)

How do you know here, that you should read 1024 characters?
What will happen when output is shorter?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do Pythoneers reinvent the wheel?

2005-09-12 Thread A.M. Kuchling
On Sat, 10 Sep 2005 12:35:37 -0400, 
Mike Meyer <[EMAIL PROTECTED]> wrote:
> I think the manual does need a section on how to find code other than
> the library. But where do you put it?

The tutorial's final section (http://docs.python.org/tut/node14.html) 
mentions PyPI.  A link to the ASPN cookbook should also be added; anything
else that should go in this section of the tutorial?

Similar text could be added to the introductory section of the library
reference, but I doubt that many users would see it because people probably
dive into the LibRef for a particular module instead of reading it straight
through.

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


Re: packaging python for install.

2005-09-12 Thread Miki
Hello J,
>I have created an App that embedds the python interpreter and I am
>now in the process of creating an installer. I am currently linking
>python24.lib, but it is only 184k and I suspect that it imports other
>dlls... I am also using numarray. Does anyone have any experiences in
>packaging python with an application in a single installer ? Has that
>been done before ?

http://starship.python.net/crew/theller/moin.cgi/ShippingEmbedded

HTH,
Miki

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


First release of Shed Skin, a Python-to-C++ compiler.

2005-09-12 Thread Mark Dufour
>Obviously, neither the 0 nor the message following should have been
>displayed. It's a pity that this assumption was made, but given the short
>time the project's been going I can understand it, hopefully Mark will
>continue towards greater python compliance :)

The latter is certainly my goal. I just haven't looked into supporting
exceptions yet, because I personally never use them. I feel they
should only occur in very bad situations, or they become goto-like
constructs that intuitively feel very ugly. In the 5500 lines of the
compiler itself, I have not needed to use a single exception. For
example, I prefer to check whether a file exists myself, rather than 
executing code that can suddenly jump somewhere else. There's probably
some use for exceptions, but I don't (want to?) see it.

Seeing how often exceptions are used by other people though, it's
probably one of the first things I should look into.. :-)


thanks!
mark.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which is more 'pythonic' / 'better' ?

2005-09-12 Thread Pierre Barbier de Reuille
Will McGugan a écrit :
> gabor wrote:
> 
>> hi,
>>
>> there are 2 versions of a simple code.
>> which is preferred?
>>
>>
>> ===
>> if len(line) >= (n+1):
>> text = line[n]
>> else:
>> text = 'nothing'
>> ===
>>
>>
>> ===
>> try:
>> text = line[n]
>> except IndexError:
>> text = 'nothing'
>> ===
>>
>>
>> which is the one you would use?
> 
> 
> I would actualy use the following for this particular case..
> 
> text = line[n:n+1] or 'nothing'

... and you would get either a list of one element or a string ...
I think you wanted to write :

text = (line[n:n+1] or ['nothing'])[0]

However, I wouldn't use that because it is hard to read ... you have to
know Python in great detail to know that:

 1 - is the expressions "line[i:j]", i and j are replaced with
"len(line)" if they are greater than "len(line)"
 2 - so if n > len(line), then line[n:n+1]" == len[len(line):len(line)]
== []
(it is not evident that line[n:n+1] can give an empty list ...)
 3 - empty list evaluate to "False"
 4 - the "or" operator returns the first argument evaluating to "true"

So, in the end, you use 3 side-effects of Python in the same small
expression ... (1, 2 and 4)

> 
> But in general I think it is best to use exceptions like that only where
>  you expect the code to _not_ throw the exception the majority of times.
> Otherwise the simple condition is better. Although I expect there is not
> much difference either way..
> 
> 
> Will McGugan
> -- 
> http://www.kelpiesoft.com

What I would do is the following:
 - if this happen in a loop, I would, if possible, remove any test and
catch the exception outside the loop !
 - otherwise, I would go for the test, as it is more straitforward to read.

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

First release of Shed Skin, a Python-to-C++ compiler.

2005-09-12 Thread Mark Dufour
>First the good news: ShedSkin (SS) more or less works on Windows. After
>patching gc6.5 for MinGW, building it, and testing it on WinXP with
>some succuess, and after patching my local copy of SS, I can get the
>test.py to compile from Python to C++, and it seems that I can get
>almost all the unit tests in unit.py to pass.

Thank you so much for your efforts! I will try to download your
patches this afternoon on a roommate's Windows computer, and try to
see if I can fix the remaining tests.

>Moreover, and since the GC system you used only works in "recent
>versions of Windows", it follows that this solution will not work in
>all versions. I tested  it on Win98 and both GC tests and SS's unit.py
>tests crash; although SS can still seem to compile the tests to C++.

Thanks!! Since adding GC support took about 10 lines of C++ code, I
guess it won't be hard to switch to a different system.. I'll try and
see if I can add support for a version that works with Win98..

BTW if anyone is interested in running Shed Skin under OSX.. I got
this comment on my blog (http://shed-skin.blogspot.com)

(why doesn't everybody just run Gentoo? :P)

>Wow, very cool. Congratulations!
>
>Here's what I had to do to get it working on the Mac (OS X 10.4):
>
>1. Install the garbage collector from
>http://www.hpl.hp.com/personal/Hans_Boehm/gc/
>
>2. Add #include  above #include  in builtin_.hpp
>
>3. Change makelib to: g++ -dynamiclib -o libss.dylib builtin_.cpp
sets_.cpp >random_.cpp math_.cpp copy_.cpp -lgc -lm
>
>4. Edit ss to use the appropriate path
>
>5. Use python 2.4 instead of the version 2.2 or 2.3 that comes with
OS X (in my >case, I just had to put /usr/local at the start of my
path)
>
>6. Run ./ss test.py
>
>7. Compile the resulting cpp file with: g++ -L. test.cpp -lss -lgc
>
>8. Run ./a.out and watch in awe.


thanks!
mark.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encryption with python

2005-09-12 Thread Steven D'Aprano
Thank you to Mike Meyer, Kirk Sluder, and anyone who made constructive
comments and/or corrections to my earlier post about generating student
IDs as random numbers.

Especially thanks to Marc Rintsch who corrected a stupid coding mistake I
made. Serves me right for not testing the code.

Kirk pointed out that there is a good usage case for using a one-way
encryption function to encrypt a Social Security Number to the student ID:

> you are prepared to deal with the inevetable, "I lost my
> password/student ID, can you still look up my records?"  

Whether the usefulness of that use outweighs the risks is not something we
can decide, but I hope the original poster is considering these issues and
not just blindly going for the technical solution.

For example, this is one possible way of dealing with students who have
lost their student ID:

- ask student for their name, d.o.b. and SSN;
- search the database for students whose name, d.o.b. and SSN match;
- if you have more than one match, there is a serious problem;
- otherwise you may consider that the student has proven their own
identity to you sufficiently, so you can safely tell them the student ID.

No need for a function that calculates the ID from the SSN, with the
associated risk that Black Hats will break the algorithm and use the
student ID to steal students' SSNs.

In effect, this scheme uses the algorithm "look it up in a secure
database" as the one-way function. It is guaranteed to be
mathematically secure, although it is vulnerable to bad guys cracking
into the database.


Thanks also to James Stroud for his amusing extension to the one-time pad
algorithm. If you have a need to be able to reconstruct the data, then
of course you need some sort of cryptographic function that can encrypt
the data and decrypt it. But that begs the question of whether or not you
actually do need to be able to reconstruct the data. The point of my post
was that you may not need to, in which case a random number is as good as
any other ID.

James also protested that passwords are "security through obscurity",
since "All they have to do is to get that secret key and all those
records are easily readable."

Of course this is technically correct, but that's not what security
through obscurity means to folks in the security business. The difference
between security through obscurity and security through a secret key is
profound: if I reverse-engineer your secret algorithm, I can read
every record you have. But if I discover the secret key belonging to one
person, I can only read that person's messages, not anyone else's.

As James says, "The point is that *something has to be kept secret* for
encryption security to work." Absolutely correct. But now think of the
difference between having keys to your door locks, compared to merely
keeping the principle of the door handle secret.



-- 
Steven.

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


How to protect Python source from modification

2005-09-12 Thread Frank Millman
Hi all

I am writing a multi-user accounting/business system. Data is stored in
a database (PostgreSQL on Linux, SQL Server on Windows). I have written
a Python program to run on the client, which uses wxPython as a gui,
and connects to the database via TCP/IP.

The client program contains all the authentication and business logic.
It has dawned on me that anyone can bypass this by modifying the
program. As it is written in Python, with source available, this would
be quite easy. My target market extends well up into the mid-range, but
I do not think that any CFO would contemplate using a program that is
so open to manipulation.

The only truly secure solution I can think of would involve a radical
reorganisation of my program, so I am writing to see if anyone has a
simpler suggestion. Here is the idea.

1. Write a socket server program that runs on the server. The socket
server is the only program that connects to the database. The client
program connects to the server, which authenticates the client against
the database and then listens for requests from the client.

2. Devise my own protocol for communication between client and server.
For selects, the client sends a request, the server checks permissions,
then retrieves the data from the database and passes it to the client.
For updates, the client passes up the data to be updated, the server
checks it against its business logic, and then updates the database.

There is the question of where state should be maintained. If on the
server, I would have to keep all the client/server connections open,
and maintain the state of all the sessions, which would put quite a
load on the server. If on the client, I would have to reorganise my
thinking even more, but this would have an advantage - I will
eventually want to write a browser interface, and this would be much
closer in concept, so the two approaches would be quite similar.

This raises the question of whether I should even bother with a gui
client, or bite the bullet and only have a browser based front end.
Judging from recent comments about new technologies such as Ajax, a lot
of the disadvantages have been overcome, so maybe this is the way to
go.

It would be a shame to scrap all the effort I have put into my
wxPython-based front end. On the other hand, it would be pointless to
continue with an approach that is never going to give me what I want.
Any advice which helps to clarify my thinking will be much appreciated.

Thanks

Frank Millman

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


Re: which is more 'pythonic' / 'better' ?

2005-09-12 Thread Will McGugan
Pierre Barbier de Reuille wrote:

>>
>>I would actualy use the following for this particular case..
>>
>>text = line[n:n+1] or 'nothing'
> 
> 
> ... and you would get either a list of one element or a string ...
> I think you wanted to write :
> 
> text = (line[n:n+1] or ['nothing'])[0]

I was assuming that 'line' would be a string, not a list. Seems more 
likely give the name and context.

Will McGugan
--
http://www.kelpiesoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dual processor

2005-09-12 Thread Robin Becker
Robin Becker wrote:
> Robin Becker wrote:
> 
>>Paul Rubin wrote:
>>
> 
> 
>>>This module might be of interest:  http://poshmodule.sf.net
>>>
>>
>>It seems it might be a bit out of date. I've emailed the author via sf, but 
>>no 
>>reply. Does anyone know if poshmodule works with latest stuff?
> 
from the horse's mouth comes confirmation that POSH is in a Norwegian Blue 
condition

from [EMAIL PROTECTED]

> Hi,
> 
> Sorry for the late reply; You're right in that the project is close to dead.
> That's simply because I haven't had the time and motivation to maintain it,
> or rather, to improve it to the point where it's more usable and bug-free.
> Currently, I view POSH as a proof of concept that transparent access to
> Python objects allocated in shared memory is feasible.  The main limitation
> of POSH is that it relies on the semantics of fork() to preserve the exact
> same memory layout in parent and child processes; porting POSH to Windows or
> other platforms without a fork() system call would be a challenge.  Besides
> that, the implementation could use a more efficient memory allocator, and
> some features that sacrifice performance for flexibility probably need to be
> rethought.   It also badly needs a shared-memory blocking queue
> implementation to support common programming models involving queues, and a
> portable lock implementation for more architectures.  These latter
> improvements should be rather straightforward, but I don't know how to avoid
> the fundamental limitation of relying on fork().
> 
> Feel free to repost these comments on comp.lang.python if you want.
> 
> Cheers,
> Steffen


-- 
Robin Becker

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


Re: Launching Python programs from Linux shell script

2005-09-12 Thread Ernesto
Thanks!  How do you add Python in Linux to the path?  Similar to
setting environment variables in Windows.  I want to be able to type
"python" when I'm in any directory to launch the interpreter.  Thanks!

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


Re: How to protect Python source from modification

2005-09-12 Thread Gerhard Häring
Frank Millman wrote:
> Hi all
> 
> I am writing a multi-user accounting/business system. Data is stored in
> a database (PostgreSQL on Linux, SQL Server on Windows). I have written
> a Python program to run on the client, which uses wxPython as a gui,
> and connects to the database via TCP/IP.
> 
> The client program contains all the authentication and business logic.
> It has dawned on me that anyone can bypass this by modifying the
> program. As it is written in Python, with source available, this would
> be quite easy. My target market extends well up into the mid-range, but
> I do not think that any CFO would contemplate using a program that is
> so open to manipulation. [...]

My suggestion is to use py2exe or cx_Freeze to package your application. 
It's then not as trivial to modify it. Btw. you don't need to ship the 
.py source code files, it's enough to ship only .pyc bytecode files.

Using py2exe it's not even obvious that your application is written in 
Python at all.

It's not a silver bullet, but at least it makes recompiling/modifiying 
your app not easier than with Java (and/or .NET I suppose).

That being said, even if you continue with the GUI approach, it may 
still be a good idea to factor out all the business logic in a separate 
module so you can eventually switch to a web application or a three-tier 
model without too much effort.

Also, there's no need at all to put in countless hours implementing your 
own network protocol. If you really want to separate client and app 
server, then why not use something simple as PyRO, or even XML/RPC.

HTH,

-- Gerhard

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


Re: read stdout/stderr without blocking

2005-09-12 Thread Adriaan Renting
The line only means it will read a maximum of 1024 characters, most of the 
output I try to catch is much shorter. I think that if the output is longer as 
1024, it will read the rest after another call to select.select, but I think I 
have not yet come across that case and have not tested it.

I set the error pipe to OS_NONBLOCKing earlier in the code, but I can't 
remember if that has anything to do with the os.read(). 

Note: I'm using Python 2.3.4/2.3.5, not tested on 2.4.x yet.
 
>>>Jacek Pop*awski <[EMAIL PROTECTED]> 09/12/05 2:39 pm >>> 
>ready = select.select(tocheck, [], [], 0.25) ##continues after 0.25s 
>for file in ready[0]: 
>try: 
>text = os.read(file, 1024) 
 
How do you know here, that you should read 1024 characters? 
What will happen when output is shorter? 
-- 
http://mail.python.org/mailman/listinfo/python-list 

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


Re: How to protect Python source from modification

2005-09-12 Thread Peter Hansen
Frank Millman wrote:
> I am writing a multi-user accounting/business system. Data is stored in
> a database (PostgreSQL on Linux, SQL Server on Windows). I have written
> a Python program to run on the client, which uses wxPython as a gui,
> and connects to the database via TCP/IP.
> 
> The client program contains all the authentication and business logic.
> It has dawned on me that anyone can bypass this by modifying the
> program. As it is written in Python, with source available, this would
> be quite easy. My target market extends well up into the mid-range, but
> I do not think that any CFO would contemplate using a program that is
> so open to manipulation.
> 
> The only truly secure solution I can think of would involve a radical
> reorganisation of my program

Please define what "truly secure" means to you.

I think you'll find that the only "truly secure" solution is to install 
the critical authentication and business logic stuff that you want to 
protect on a server to which the user does not have physical access.

People wanting to protect critical algorithms often conclude that they 
need to have a "black box" server which cannot be physically opened by 
the user.

Or do you think this issue is in some way unique to Python?  You might 
not realize that the only difference from a security point of view 
between shipping such a program written in Python and one written in, 
say, C++, is that "modifying the program" is somewhat more tedious with 
C++.  That's no better than security by obscurity; maybe it should be 
called "security by adiposity". ;-)

But the real answer does depend a lot on *exactly* what kind of security 
you want (or, ultimately, what it turns out you really need, once you've 
clarified your thinking based on the feedback you do get here).  Issues 
like: are you more concerned about detecting changes, or in preventing 
them in the first place? (the latter is much harder); what is the nature 
of software that competes with yours?  (is it really any more secure, or 
only apparently so? maybe this is just a marketing issue); and is there 
any intellectual property that you are trying to protect here, or are 
you just interested in avoiding casual disruption of normal operation?

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


Re: Printer List from CUPS

2005-09-12 Thread Mike Tammerman
Thanks, a lot, this helped me so much. It was so easy, to compile,
install and use the cupsext module.

-Mike

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


Re: read stdout/stderr without blocking

2005-09-12 Thread Grant Edwards
On 2005-09-12, Jacek Pop?awski <[EMAIL PROTECTED]> wrote:
>> ready = select.select(tocheck, [], [], 0.25) ##continues after 0.25s
>> for file in ready[0]:
>> try:
>> text = os.read(file, 1024)
>
> How do you know here, that you should read 1024 characters?
> What will happen when output is shorter?

It will return however much data is available.

-- 
Grant Edwards   grante Yow!  I'm a fuschia bowling
  at   ball somewhere in Brittany
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First release of Shed Skin, a Python-to-C++ compiler.

2005-09-12 Thread Fuzzyman

Mark Dufour wrote:
> >Obviously, neither the 0 nor the message following should have been
> >displayed. It's a pity that this assumption was made, but given the short
> >time the project's been going I can understand it, hopefully Mark will
> >continue towards greater python compliance :)
>
> The latter is certainly my goal. I just haven't looked into supporting
> exceptions yet, because I personally never use them. I feel they
> should only occur in very bad situations, or they become goto-like
> constructs that intuitively feel very ugly. In the 5500 lines of the
> compiler itself, I have not needed to use a single exception. For
> example, I prefer to check whether a file exists myself, rather than
> executing code that can suddenly jump somewhere else. There's probably
> some use for exceptions, but I don't (want to?) see it.
>
> Seeing how often exceptions are used by other people though, it's
> probably one of the first things I should look into.. :-)
>

In general it's considered quite pythonic to catch exceptions :-)

It's a particularly useful way of implementing duck typing for example.

I'm not sure if I've got *any* code that doesn't use exceptions
somewhere

;-)

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml


> 
> thanks!
> mark.

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


ANNOUNCEMENT: The ring of the friendly serpent in business suite: Python, Zope, Plone

2005-09-12 Thread jegenye2001
Hi everybody,

Since I couldn't find a (working) webring with such a profile, I
started my own one:

The ring of the friendly serpent in business suite: Python, Zope, Plone
http://www.jegenye.com/

Anyone (companies or individual programmers/consultants) are welcome to
join if they offer services or products which are related to
Python/Zope/Plone in some ways.
The webring is meant to be mainly about business but non-profit
activites/sites will not be turned down either if Python is involved.
I'll set up an internal forum/mailing list, too, if there's enough
traffic and interest. 

Thanks for your attention.
 
Cheers, 
  Miklos

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


ZPT and "incompatible version None" error :(

2005-09-12 Thread Jaroslaw Zabiello
I got strange errors in Zope 2.7.

METALError
macro 'context/base' has incompatible version None, at line 1, column 1

One ZPT file (named 'base') defines some simply slots:

http://www.w3.org/1999/xhtml";
xml:lang="en-US"
lang="en-US"
i18n:domain="plone"
metal:use-macro="here/main_template/macros/master">
  

  
   [up]
   [middle]
   [bottom]
  

  


Another ZPT file try to fill one slot:


  Search|Read|Compare|History


When I try to open it, I get the error mentioned above. Any idea?

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


Re: python callbacks and windows

2005-09-12 Thread davidstummer
cheers for the replies.

so far using ctypes, i have managed to load a dll, and have the dll
call a function in my python code using function pointers.

what i now need to do is load an .exe that contains a windows procedure
(window is hidden).

how can i load an .exe using python like i loaded the dll.

will winmain be executed?

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


Re: ANNOUNCEMENT: The ring of the friendly serpent in business suite: Python, Zope, Plone

2005-09-12 Thread Richie Hindle

[Miklos]
> The ring of the friendly serpent in business suite: Python, Zope, Plone
> http://www.jegenye.com/

Did you mean "business suit"?

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


pcapy listen on multiple devices

2005-09-12 Thread billiejoex
Hi all. I noticed that with the original pcap sniffing library it is 
possible to listen on multiple devices by using "select()" or "poll()" 
function.
These function aren't present in pcapy module. Do you got any suggestion to 
avoid this problem?


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


Re: First release of Shed Skin, a Python-to-C++ compiler.

2005-09-12 Thread Brian Quinlan
Mark Dufour wrote:
> The latter is certainly my goal. I just haven't looked into supporting
> exceptions yet, because I personally never use them. I feel they
> should only occur in very bad situations, or they become goto-like
> constructs that intuitively feel very ugly. In the 5500 lines of the
> compiler itself, I have not needed to use a single exception. For
> example, I prefer to check whether a file exists myself, rather than 
> executing code that can suddenly jump somewhere else. There's probably
> some use for exceptions, but I don't (want to?) see it.

I don't understand your example here. When you check that a file exists, 
you feel safe that openning it will succeed? What if:

o you don't have permission to open the file
o the file is deleted in the time between you checking for it's
   existance and opening it (possible race condition)
o the system doesn't have sufficient resources to open the file
   e.g. too many open file handles
o the file is already open with exclusive read/write permission

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


Re: make sure entire string was parsed

2005-09-12 Thread Steven Bethard
Paul McGuire wrote:
>>>I have to differentiate between:
>>>  (NP -x-y)
>>>and:
>>>  (NP-x -y)
>>>I'm doing this now using Combine.  Does that seem right?
> 
> If your word char set is just alphanums+"-", then this will work
> without doing anything unnatural with leaveWhitespace:
> 
> from pyparsing import *
> 
> thing = Word(alphanums+"-")
> LPAREN = Literal("(").suppress()
> RPAREN = Literal(")").suppress()
> node = LPAREN + OneOrMore(thing) + RPAREN
> 
> print node.parseString("(NP -x-y)")
> print node.parseString("(NP-x -y)")
> 
> will print:
> 
> ['NP', '-x-y']
> ['NP-x', '-y']

I actually need to break these into:

['NP', '-x-y'] {'tag':'NP', 'word:'-x-y'}
['NP', 'x', 'y'] {tag:'NP', 'functions':['x'], 'word':'y'}

I know the dict syntax afterwards isn't quite what pyparsing would 
output, but hopefully my intent is clear.  I need to use the dict-style 
results from setResultsName() calls because in the full grammar, I have 
a lot of optional elements.  For example:

(NP-1 -a)
   --> {'tag':'NP', 'id':'1', 'word':'-a'}
(NP-x-2 -B)
   --> {'tag':'NP', 'functions':['x'], 'id':'2', 'word':'-B'}
(NP-x-y=2-3 -4)
   --> {'tag':'NP', 'functions':['x', 'y'], 'coord':'2', 'id':'3', 
'word':'-4'}
(-NONE- x)
   --> {'tag':None, 'word':'x'}



STeVe

P.S.  In case you're curious, here's my current draft of the code:

# some character classes
printables_trans = _pp.printables.translate
word_chars = printables_trans(_id_trans, '()')
word_elem = _pp.Word(word_chars)
syn_chars = printables_trans(_id_trans, '()-=')
syn_word = _pp.Word(syn_chars)
func_chars = printables_trans(_id_trans, '()-=0123456789')
func_word = _pp.Word(func_chars)
num_word = _pp.Word(_pp.nums)

# tag separators
dash = _pp.Literal('-')
tag_sep = dash.suppress()
coord_sep = _pp.Literal('=').suppress()

# tag types (use Combine to guarantee no spaces)
special_tag = _pp.Combine(dash + syn_word + dash)
syn_tag = syn_word
func_tags = _pp.ZeroOrMore(_pp.Combine(tag_sep + func_word))
coord_tag = _pp.Optional(_pp.Combine(coord_sep + num_word))
id_tag = _pp.Optional(_pp.Combine(tag_sep + num_word))

# give tag types result names
special_tag = special_tag.setResultsName('tag')
syn_tag = syn_tag.setResultsName('tag')
func_tags = func_tags.setResultsName('funcs')
coord_tag = coord_tag.setResultsName('coord')
id_tag = id_tag.setResultsName('id')

# combine tag types into a tags element
normal_tags = syn_tag + func_tags + coord_tag + id_tag
tags = special_tag | _pp.Combine(normal_tags)
def get_tag(orig_string, tokens_start, tokens):
 tokens = dict(tokens)
 tag = tokens.pop('tag')
 if tag == '-NONE-':
 tag = None
 functions = list(tokens.pop('funcs', []))
 coord = tokens.pop('coord', None)
 id = tokens.pop('id', None)
 return [dict(tag=tag, functions=functions,
  coord=coord, id=id)]
tags.setParseAction(get_tag)

# node parentheses
start = _pp.Literal('(').suppress()
end = _pp.Literal(')').suppress()

# words
word = word_elem.setResultsName('word')

# leaf nodes
leaf_node = tags + _pp.Optional(word)
def get_leaf_node(orig_string, tokens_start, tokens):
 try:
 tag_dict, word = tokens
 word = cls._unescape(word)
 except ValueError:
 tag_dict, = tokens
 word = None
 return cls(word=word, **tag_dict)
leaf_node.setParseAction(get_leaf_node)

# node, recursive
node = _pp.Forward()

# branch nodes
branch_node = tags + _pp.OneOrMore(node)
def get_branch_node(orig_string, tokens_start, tokens):
 return cls(children=tokens[1:], **tokens[0])
branch_node.setParseAction(get_branch_node)

# node, recursive
node << start + (branch_node | leaf_node) + end

# root node may have additional parentheses
root_node = node | start + node + end
root_nodes = _pp.OneOrMore(root_node)

# make sure nodes start and end string
str_start = _pp.StringStart()
str_end = _pp.StringEnd()
cls._root_node = str_start + root_node + str_end
cls._root_nodes = str_start + root_nodes + str_end
-- 
http://mail.python.org/mailman/listinfo/python-list


Is it possible to detect if files on a drive were changed without scanning the drive?

2005-09-12 Thread Claudio Grondi
It is maybe not a pure Python question, but I think
it is the right newsgroup to ask for help, anyway.

After connecting a drive to the system (via USB
or IDE) I would like to be able to see within seconds
if there were changes in the file system of that drive
since last check (250 GB drive with about four million
files on it).

How to accomplish this? (best if providing
directly a Python receipe for it :-)
Do available file systems have something like
archive attribute assigned to the root directory
of the drive?
I suppose not. Am I right?

I ask this question having Microsoft Windows 2000
and Windows proprietary NTFS file system in mind,
but I am also interested to know it about Linux or
Unix file systems.

I know, that looking for the archive attribute of the
top directories doesn't help when the change
happened to files somewhere deeper in the
hierarchy of directories.

Any hints are welcome.

Claudio


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


Socket options

2005-09-12 Thread Tor Erik Sønvisen
Hi

For an online game I'm developing I need some advice concerning tcp-sockets, 
and especially which socket options to set and not.
What I want is a connection where nothing is buffered (but are sent 
immediatly), and I also want to keep the connections persistent until 
explicitly closed.
The server-side socket will receive multiple incomming requests from 
clients...

regards tores 


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


Re: Grouping lists

2005-09-12 Thread PyPK
hmm thanks for that..but kind of not sure how this groupby works.. also
if I want to group elements with one value apart how would this
change.Should this change in groupby part or in the loop?
something like...
lst = [1,1,2,1,3,5,1,1,1,1,2,7,7]
returns (0,3),4,5,(6,10),(11,12)
so its something like if there is 1,1,2 then the grouping is done..
I am asking this as I could not quit follow what exactly groupby does..

Also if someone could explain me what exactly this groupby is doing
that would be helpful.

Thanks again.

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


Re: which is more 'pythonic' / 'better' ?

2005-09-12 Thread Steven Bethard
Steven D'Aprano wrote:
> try...except... blocks are quick to set up, but slow to catch the
> exception. If you expect that most of your attempts will succeed, then the
> try block will usually be faster than testing the length of the list
> each time.
> 
> But if you expect that the attempts to write the line will fail more
> frequently, then testing will be quicker.
> 
> You will need to do your own testing before hand to find the exact
> cut-off, and expect that cut-off to vary according to the Python
> implementation and version. But a rough rule of thumb is, if you expect
> your code to fail more often than succeed, then test first, otherwise
> catch an exception.

FWIW, these are almost exactly my criteria too.  Exceptions are for 
"exceptional" conditions, that is, things that you expect to happen 
infrequently[1].  So if I think the code is going to fail frequently, I 
test the condition, but if I think it won't, I use exceptions.

STeVe

[1] Note though that what is "infrequent" in Python might be still 
considered "frequent" in other languages.  For example, Java's iterators 
check the result of a .hasNext() method before each .next() call, while 
Python's iterators assume the .next() call will succeed, and simply test 
for the "exceptional" condition of a StopIteration exception.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCEMENT: The ring of the friendly serpent in business suite: Python, Zope, Plone

2005-09-12 Thread jegenye2001
Oops, "suit" indeed.
Though it might be considered as a pun if you really want to. :-)

Anyway, thanks, I will correct it.

Cheers, 
   Miklos

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


Python Database Scripts

2005-09-12 Thread Chuck
Hello,

Can anyone provide any kind of python database (mysql) code or point me
to a link that has this?  Just simple things as maybe using a driver,
opening up a db, an insert and select.  Any help would be greatly
appreciated!

Thanks,
--Chuck

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


fully-qualified namespaces?

2005-09-12 Thread Lenny G.
Suppose I have a python module named Hippo.  In the Hippo module is a
class named Crypto.  The Crypto class wants to 'from Crypto.Hash import
SHA' which refers to the module/classes in python-crypto.  Other
classes in the Hippo module want to 'import Crypto' referring to
Hippo.Crypto.

How do I do this?  For now, I just renamed my Hippo.Crypto to
Hippo.HippoCrypto and everything is okay as long as I use 'HippoCrypto'
to refer to that class.  But, this is of course redundant.  What I
really want to do is use

'import Crypto' # to refer to python-crypto
'import Hippo.Crypto'   # to refer to Hippo.Crypto

but the 2nd item doesn't seem to work from within the Hippo module.
What am I missing?

  Thanks,
  Lenny G.

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


Re: which is more 'pythonic' / 'better' ?

2005-09-12 Thread Steve Holden
Will McGugan wrote:
> Pierre Barbier de Reuille wrote:
> 
> 
>>>I would actualy use the following for this particular case..
>>>
>>>text = line[n:n+1] or 'nothing'
>>
>>
>>... and you would get either a list of one element or a string ...
>>I think you wanted to write :
>>
>>text = (line[n:n+1] or ['nothing'])[0]
> 
> 
> I was assuming that 'line' would be a string, not a list. Seems more 
> likely give the name and context.
> 
I'd say it's much more likely that line is a list of lines, since it 
seems improbable that absence of a character should cause a value of 
"nothing" to be required.

so-i-say-po-tay-to-ly y'rs  - steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: How to protect Python source from modification

2005-09-12 Thread Frank Millman

Gerhard Häring wrote:
> Frank Millman wrote:
> > Hi all
> >
> > I am writing a multi-user accounting/business system. Data is stored in
> > a database (PostgreSQL on Linux, SQL Server on Windows). I have written
> > a Python program to run on the client, which uses wxPython as a gui,
> > and connects to the database via TCP/IP.
> >
> > The client program contains all the authentication and business logic.
> > It has dawned on me that anyone can bypass this by modifying the
> > program. As it is written in Python, with source available, this would
> > be quite easy. My target market extends well up into the mid-range, but
> > I do not think that any CFO would contemplate using a program that is
> > so open to manipulation. [...]
>
> My suggestion is to use py2exe or cx_Freeze to package your application.
> It's then not as trivial to modify it. Btw. you don't need to ship the
> .py source code files, it's enough to ship only .pyc bytecode files.
>
> Using py2exe it's not even obvious that your application is written in
> Python at all.
>
> It's not a silver bullet, but at least it makes recompiling/modifiying
> your app not easier than with Java (and/or .NET I suppose).
>

My problem is that, if someone has access to the network and to a
Python interpreter, they can get hold of a copy of my program and use
it to knock up their own client program that makes a connection to the
database. They can then execute any arbitrary SQL command.

> That being said, even if you continue with the GUI approach, it may
> still be a good idea to factor out all the business logic in a separate
> module so you can eventually switch to a web application or a three-tier
> model without too much effort.
>

Agreed

> Also, there's no need at all to put in countless hours implementing your
> own network protocol. If you really want to separate client and app
> server, then why not use something simple as PyRO, or even XML/RPC.
>

Perhaps 'protocol' is the wrong word. I already have a simple socket
server program running. If explain how I do it, perhaps you can
indicate whether PyRO or XML/RPC would make my life easier.

The server program is currently programmed to accept a number of
message types from the client program. Each message's data string
starts with a numeric prefix, which indicates the type of message,
followed by a pickled tuple of arguments. The server program reads the
string, extracts the numeric prefix, and passes the rest of the string
to the appropriate function using a subthread.

For example, I keep track of who is currently logged in. On startup,
the client connects to my server and sends a '1' followed by their
userid and other information. The server receives this and passed the
data to a 'login' function, which uses a Python dictionary to store the
information. If the server detects that the user is already logged in,
it sends back an error code and the client program displays a message
and terminates. Otherwise it sends back an 'ok' code, and the client
can continue. When the client logs off, it sends a '2' followed by
their userid, which the server receives and passes it to a 'logoff'
function, which deletes the entry from the dictionary.

The system of numeric prefixes and associated data string making up a
message is what I mean by a protocol.

> HTH,
> 
> -- Gerhard

Thanks

Frank

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


Re: which is more 'pythonic' / 'better' ?

2005-09-12 Thread Michael Hoffman
Steven Bethard wrote:

 > Exceptions are for
> "exceptional" conditions, that is, things that you expect to happen 
> infrequently[1].  So if I think the code is going to fail frequently, I 
> test the condition, but if I think it won't, I use exceptions.

I think there exceptions (no pun intended) to that rule as well. A 
classic example is writing to a file. Even if you expect this to be 
impossible, it's best to just create it and trap the exception, thereby 
avoiding a race condition.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Launching Python programs from Linux shell script

2005-09-12 Thread Steve Holden
Ernesto wrote:
> Thanks!  How do you add Python in Linux to the path?  Similar to
> setting environment variables in Windows.  I want to be able to type
> "python" when I'm in any directory to launch the interpreter.  Thanks!
> 
You will (or should) have a shell intialisation file variously called 
.profile, .bashrc or several other possible names. Consult your shell 
documentation (or ask another user who knows) to find out which.

You will need to add a line which typically reads something like

export PATH=$PATH:/path/to/directory/containing/python

making the obvious substitution of the correct path. Interestingly I 
couldn't quickly formulate a Google search specifically containing 
Python, but a search for

 unix add to path

gives the quite helpful

 http://www.ee.surrey.ac.uk/Teaching/Unix/unix8.html

as its first result.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: fully-qualified namespaces?

2005-09-12 Thread George Sakkis
"Lenny G." <[EMAIL PROTECTED]> wrote:

> Suppose I have a python module named Hippo.  In the Hippo module is a
> class named Crypto.  The Crypto class wants to 'from Crypto.Hash import
> SHA' which refers to the module/classes in python-crypto.  Other
> classes in the Hippo module want to 'import Crypto' referring to
> Hippo.Crypto.
>
> How do I do this?  For now, I just renamed my Hippo.Crypto to
> Hippo.HippoCrypto and everything is okay as long as I use 'HippoCrypto'
> to refer to that class.  But, this is of course redundant.  What I
> really want to do is use
>
> 'import Crypto' # to refer to python-crypto
> 'import Hippo.Crypto'   # to refer to Hippo.Crypto
>
> but the 2nd item doesn't seem to work from within the Hippo module.
> What am I missing?

The (optional) renaming of the imported modules/classes I would guess:

# Hippo.py

import Crypto as PythonCrypto

class Crypto:
pass

h1 = PythonCrypto.Hash
h2 = Crypto.Hash# refers to Hippo.Crypto


HTH,
George


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


Re: which is more 'pythonic' / 'better' ?

2005-09-12 Thread Will McGugan
Steve Holden wrote:

> I'd say it's much more likely that line is a list of lines, since it 
> seems improbable that absence of a character should cause a value of 
> "nothing" to be required.

You may be right. I always use plural nouns for collections. To me 
'line' would suggest there was just one of them, so I assumed it was string.


Will McGugan
-- 
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in 
"jvyy*jvyyzpthtna^pbz")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Database Scripts

2005-09-12 Thread Peter Decker
On 12 Sep 2005 08:28:39 -0700, Chuck 

> Can anyone provide any kind of python database (mysql) code or point me
> to a link that has this?  Just simple things as maybe using a driver,
> opening up a db, an insert and select.  Any help would be greatly
> appreciated!

It might be more than you're looking for, but there is a Python
framework called Dabo that makes working with databases, including
MySQL, very, very easy. Their URL is http://dabodev.com.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to detect if files on a drive were changed without scanning the drive?

2005-09-12 Thread Tom Anderson
On Mon, 12 Sep 2005, Claudio Grondi wrote:

> It is maybe not a pure Python question, but I think it is the right 
> newsgroup to ask for help, anyway.

You might try comp.arch.storage or comp.sys.ibm.pc.hardware.storage, or a 
newsgroup specific to the operating system you're working on.

> After connecting a drive to the system (via USB or IDE) I would like to 
> be able to see within seconds if there were changes in the file system 
> of that drive since last check (250 GB drive with about four million 
> files on it).
>
> How to accomplish this?

I don't think there's a portable way to do this. I also don't think 
there's a way to do this at all on most disks. I think there might be a 
way to do this using journalled filesystems, but i'm not certain, it would 
definitely involve fiddling with low-level filesystem APIs (or even 
on-disk structures), and, UIVMM, these are a minority of disks anyway.

Sorry i couldn't be more helpful!

tom

-- 
The revolution will not be televised. The revolution will be live.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Database Scripts

2005-09-12 Thread jegenye2001
import MySQLdb

# Create a connection object and create a cursor
conn = MySQLdb.Connect(host="localhost", port=3306, user="mysql",
passwd="pwd123", db="mytest")
c = conn.cursor()

# execute some SQL
c.execute("SELECT * FROM  mystuff")

# Fetch all results from the cursor into a sequence
results = c.fetchall()
for r in results:
  do_something(r)

# close the connection
conn.close()



Cheers,
   Miklos
--
Software development: Python,Zope,Plone,PDF,XML,MivaScript
http://www.jegenye.com

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


Re: make sure entire string was parsed

2005-09-12 Thread Steven Bethard
Steven Bethard wrote:
> Paul McGuire wrote:
> 
 I have to differentiate between:
  (NP -x-y)
 and:
  (NP-x -y)
 I'm doing this now using Combine.  Does that seem right?
>>
>>
>> If your word char set is just alphanums+"-", then this will work
>> without doing anything unnatural with leaveWhitespace:
>>
>> from pyparsing import *
>>
>> thing = Word(alphanums+"-")
>> LPAREN = Literal("(").suppress()
>> RPAREN = Literal(")").suppress()
>> node = LPAREN + OneOrMore(thing) + RPAREN
>>
>> print node.parseString("(NP -x-y)")
>> print node.parseString("(NP-x -y)")
>>
>> will print:
>>
>> ['NP', '-x-y']
>> ['NP-x', '-y']
> 
> 
> I actually need to break these into:
> 
> ['NP', '-x-y'] {'tag':'NP', 'word:'-x-y'}
> ['NP', 'x', 'y'] {tag:'NP', 'functions':['x'], 'word':'y'}

Oops, sorry, the last line should have been:

['NP', 'x', '-y'] {tag:'NP', 'functions':['x'], 'word':'-y'}

Sorry to introduce confusion into an already confusing parsing problem. ;)

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


Ctypes Install in Linux

2005-09-12 Thread Ernesto
I'm trying to install ctypes for Python in Linux.  Linux won't let me
create /usr/local/lib/python2.4/site-packages/ctypes ... "Permission
denied" ... Anyone know how I could get it to work?  It's probably
something I need to chmod or change permissions on... Thanks!

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


Re: ZPT and "incompatible version None" error :(

2005-09-12 Thread bruno modulix
Jaroslaw Zabiello wrote:
> I got strange errors in Zope 2.7.

2.7.?

> 
> METALError
> macro 'context/base' has incompatible version None, at line 1, column 1
> 
(snip)
> 
> When I try to open it, I get the error mentioned above. Any idea?
> 
yes : try posting on a Zope/Plone related mailing-list. This is a Zope
Page Template specific problem, and you'll get better answers if you ask
 in the right place.

Also, googling for ZPT + macro + "incompatible version" may be helpful too.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ctypes Install in Linux

2005-09-12 Thread jegenye2001
Most likely you're trying to do this as a non-root user and
/usr/local/lib/python2.4/site-packages  must be writable only with root
privileges.

If you cannot go root on that machine then you could just install the
package in some directory you can write to and add the directory name
to your PYTHONPATH environment variable.


Cheers,
   Miklos
--
Software development: Python,Zope,Plone,PDF,XML,MivaScript
http://www.jegenye.com

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


Re: How to protect Python source from modification

2005-09-12 Thread bruno modulix
Frank Millman wrote:
> Hi all
> 
> I am writing a multi-user accounting/business system. Data is stored in
> a database (PostgreSQL on Linux, SQL Server on Windows). I have written
> a Python program to run on the client, which uses wxPython as a gui,
> and connects to the database via TCP/IP.
> 
> The client program contains all the authentication and business logic.
> It has dawned on me that anyone can bypass this by modifying the
> program. 

If your program relies on a RDBMS, then it's the RDBMS job to enforce
security rules.

> As it is written in Python, with source available, this would
> be quite easy. 

Then there's probably something wrong with the way you manage security.

NB: splitting business logic from the GUI is still a good idea anyway.

-- 
bruno desthuilliers - unpythonic sig:
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket options

2005-09-12 Thread billiejoex
If you are intrested in speed my personal advice is to use UDP insted of 
TCP.
The great majority of network games use it.
Here's a simple UDP implementation:
http://www.evolt.org/article/Socket_Programming_in_Python/17/60276/

> For an online game I'm developing I need some advice concerning 
> tcp-sockets, and especially which socket options to set and not.
> What I want is a connection where nothing is buffered (but are sent 
> immediatly), and I also want to keep the connections persistent until 
> explicitly closed.
> The server-side socket will receive multiple incomming requests from 
> clients...
>
> regards tores


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


Re: Ctypes Install in Linux

2005-09-12 Thread Ernesto
Thanks for the help.  I'm kind of new to Linux, but I am the only user
of this machine (just installed Red Hat).  How do I make myself a
"root-user"?

For the second method you mentioned, how do I add access the PYTHONPATH
environment variable? 

Thanks again!

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


Re: How to protect Python source from modification

2005-09-12 Thread Frank Millman

Peter Hansen wrote:
> Frank Millman wrote:
> > I am writing a multi-user accounting/business system. Data is stored in
> > a database (PostgreSQL on Linux, SQL Server on Windows). I have written
> > a Python program to run on the client, which uses wxPython as a gui,
> > and connects to the database via TCP/IP.
> >
> > The client program contains all the authentication and business logic.
> > It has dawned on me that anyone can bypass this by modifying the
> > program. As it is written in Python, with source available, this would
> > be quite easy. My target market extends well up into the mid-range, but
> > I do not think that any CFO would contemplate using a program that is
> > so open to manipulation.
> >
> > The only truly secure solution I can think of would involve a radical
> > reorganisation of my program
>
> Please define what "truly secure" means to you.
>

Fair question. I am not expecting 'truly' to mean 100% - I know that is
impossible. I will try to explain.

Here are some assumptions -
1. A system adminstrator is responsible for the system.
2. There is a single userid and password for connecting to the
database. This must be stored somewhere so that the client program can
read it to generate the appropriate connection string. The users do not
need to know  this userid and password.
3. Each user has their own userid and password, which is stored in the
database in a 'users' table. I use this in my program for
authentication when a user tries to connect.
4. The client program can be run from anywhere on the network that has
access to the program and to a Python interpreter.

[snip]

>
> But the real answer does depend a lot on *exactly* what kind of security
> you want (or, ultimately, what it turns out you really need, once you've
> clarified your thinking based on the feedback you do get here).  Issues
> like: are you more concerned about detecting changes, or in preventing
> them in the first place? (the latter is much harder); what is the nature
> of software that competes with yours?  (is it really any more secure, or
> only apparently so? maybe this is just a marketing issue); and is there
> any intellectual property that you are trying to protect here, or are
> you just interested in avoiding casual disruption of normal operation?
>

I am not concerned about anyone reading my code - in fact I am looking
forward to releasing the source and getting some feedback.

My concern is this. I have all this fancy authentication and business
logic in my program. If someone wants to bypass this and get direct
access to the database, it seems trivially easy. All they have to do is
read my source, find out where I get the connection string from, write
their own program to make a connection to the database, and execute any
SQL command they want.

If I move all the authentication and business logic to a program which
runs on the server, it is up to the system administrator to ensure that
only authorised people have read/write/execute privileges on that
program. Clients will have no privileges, not even execute. They will
have their own client program, which has to connect to my server
program, and communicate with it in predefined ways. I *think* that in
this way I can ensure that they cannot do anything outside the bounds
of what I allow them.

The only problem is that this is very different from the way my program
works at present, so it will be quite a bit of work to re-engineer it.
If someone can suggest a simpler solution obviously I would prefer it.
But if the consensus is that I am thinking along the right lines, I
will roll up my sleeves and get stuck in.

> -Peter

I hope this explains my thinking a bit better.

Thanks

Frank

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


Re: Is it possible to detect if files on a drive were changed without scanning the drive?

2005-09-12 Thread Alessandro Bottoni
Claudio Grondi wrote:
> After connecting a drive to the system (via USB
> or IDE) I would like to be able to see within seconds
> if there were changes in the file system of that drive
> since last check (250 GB drive with about four million
> files on it).
> 
> How to accomplish this? (best if providing
> directly a Python receipe for it :-)
> Do available file systems have something like
> archive attribute assigned to the root directory
> of the drive?
> I suppose not. Am I right?

On Linux there is the FAM (File Alteration Module) for this, as long as I
know. Maybe Python has a wrapper/binding for it.

> I ask this question having Microsoft Windows 2000
> and Windows proprietary NTFS file system in mind,
> but I am also interested to know it about Linux or
> Unix file systems.

As long as I know, on Windows there are a few specific "hooks" to perform
such a task. They are provided by the MS API for the NTFS/HPFS file
systems. I do not think Python implements anything so "low level", anyway.
Check the docu to be sure.

> I know, that looking for the archive attribute of the
> top directories doesn't help when the change
> happened to files somewhere deeper in the
> hierarchy of directories.

Right. It does not help.

Consider this: if are accessing a network file system, you can intercepts
the calls to the virtualization layer (NFS or NetBIOS). Most likely, Python
can support you in performing this task.

HTH
---
Alessandro Bottoni
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to protect Python source from modification

2005-09-12 Thread bruno modulix
Frank Millman wrote:
> Peter Hansen wrote:
> 
>>Frank Millman wrote:
>>
(snip)
>>>The only truly secure solution I can think of would involve a radical
>>>reorganisation of my program
>>
>>Please define what "truly secure" means to you.
>>
> 
> 
> Fair question. I am not expecting 'truly' to mean 100% - I know that is
> impossible. I will try to explain.
> 
> Here are some assumptions -
> 1. A system adminstrator is responsible for the system.
> 2. There is a single userid and password for connecting to the
> database. This must be stored somewhere so that the client program can
> read it to generate the appropriate connection string. The users do not
> need to know  this userid and password.
> 3. Each user has their own userid and password, 
> which is stored in the
> database in a 'users' table. I use this in my program for
> authentication when a user tries to connect.

Why not simply using the security system of your RDBMS ? If you set up
appropriate privileges in the RDBMS, you won't have to store any
userid/password in the program, and no user will be able to bypass
anything, even if connecting directly (like with a CLI DB client) to the
RDBMS.


> [snip]
> 
> 
(snip more)
>
> I am not concerned about anyone reading my code - in fact I am looking
> forward to releasing the source and getting some feedback.
> 
> My concern is this. I have all this fancy authentication and business
> logic in my program. If someone wants to bypass this and get direct
> access to the database, it seems trivially easy. All they have to do is
> read my source, find out where I get the connection string from, write
> their own program to make a connection to the database, and execute any
> SQL command they want.

That's why RDBMS have an authentication and security system. This
doesn't means your program doesn't have or cannot add it's own security
management, but it should be based on the RDBMS one.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why do Pythoneers reinvent the wheel?

2005-09-12 Thread Claudio Grondi
Here some of my thougts on this subject:

I think that this question adresses only a tiny
aspect of a much more general problem the
entire human race has in any area.
Reinventing the wheel begins when the grandpa
starts to teach his grandchild remembering well
that he has done it already many times before
to own children.

As any of us takes the chance to be somehow
different and writing program code does need
much understanding how and why something
works, it is very probably, that what is there is hard
to understand (Python as a programming language
is not really an exception here). There is not much
around of so universal value, that it can be
taken any time by anyone.

When I am coming myself back to what I have created
in the past I often see what trash I have produced.
The unique discoveries of the kind "wow! today I would
do it the same way or even less smart not given enough
time" don't change the general picture.

So the question is here, where are the tools making
it possible to find a piece of code solving a
problem when the problem is formulated only
using natural language? I am finding myself reinventing
the wheel all the time only because I am not able to find
appropriate pieces of code in the collection I have put
together (am I alone here? bad memory? lack of
proper filing system?).

It seems, that posting to a newsgroup is usually
the best choice, but even this needs much work
in advance before it is possible to communicate what the
problem is, that one has.
In case of the OpenCV interface to Python even that
seem not to help ... (I am pretty sure there is someone
out there who would be able to put me in the right
direction).

Are there any tools in Python based on associations
looking for specific types of code?
Something similar to http://www.qknow.com , but addressed
towards specific needs of a programmer looking for code
snippets? (not a kind of search engine or system of
folders with cross links, but a system able to find a chain
of snippets required to solve a problem).

To name a simplest example:
What should I do to find a piece of code taking an
integer and giving a string with binary form of a
number? How to put some available pieces of code
together if the binary form is needed and the integer
is provided as a string holding its hexadecimal form?
What if the string is the binary representation of the
integer value as internally stored in memory?
What if I would like the binary form to be splitted
in nibbles separated with one space and bytes with
two spaces?

How can I avoid to reinvent the wheel, when I
don't have the tools to find what I am looking
for?

Saying it in words of the Beatles song:
"Help me if you can, I'm feeling down.
And I do appreciate you being round.
Help me, get my feet back on the ground,
Won't you please, please help me,
help me, help me, oh. "

Claudio


"Stefano Masini" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
On 8 Sep 2005 08:24:50 -0700, Fuzzyman <[EMAIL PROTECTED]> wrote:
> What is pythonutils ?
> =
> ConfigObj - simple config file handling
> validate - validation and type conversion system
> listquote - string to list conversion
> StandOut - simple logging and output control object
> pathutils - for working with paths and files
> cgiutils - cgi helpers
> urlpath - functions for handling URLs
> odict - Ordered Dictionary Class

Fuzzyman, your post reminded me of something I can't stop thinking
about. Please don't take this as a critique on your work. I place
myself on the same side of yours.
I just wanted to share this thought with everybody had an opinion about it.

I wonder how many people (including myself) have implemented their own
versions of such modules, at least once in their pythonic life. I
indeed have my own odict (even same name! :). My own pathutils
(different name, but same stuff). My own validate... and so forth.

This is just too bad.
There are a few ares where everybody seems to be implementing their
own stuff over and over: logging, file handling, ordered dictionaries,
data serialization, and maybe a few more.
I don't know what's the ultimate problem, but I think there are 3 main
reasons:
1) poor communication inside the community (mhm... arguable)
2) lack of a rich standard library (I heard this more than once)
3) python is such an easy language that the "I'll do it myself" evil
side lying hidden inside each one of us comes up a little too often,
and prevents from spending more time on research of what's available.

It seems to me that this tendency is hurting python, and I wonder if
there is something that could be done about it. I once followed a
discussion about placing one of the available third party modules for
file handling inside the standard library. I can't remember its name
right now, but the discussion quickly became hot with considerations
about the module not being "right" enough to fit the standard library.
The points were right, but in some sense it's a pity because by be

Re: fully-qualified namespaces?

2005-09-12 Thread Lenny G.
Thanks George.  But I have to apologize -- I think I used the wrong
term in my question.  Hippo is actually a package, not a module.  So I
have:

Hippo/
  __init__.py
  Crypto.py
  Potamus.py

And inside Crypto.py, I need to access python-crypto's Crypto.Hash
package.  Inside Potamus.py, I need to access Hippo.Crypto, e.g.,

Hippo/
  __init__.py
  Crypto.py# wants to import python-crypto's Crypto.Hash
  Potamus.py   # wants to import Hippo's Crypto

Can I do this?  Crypto.py can't seem to access python-crypto's Crypto
namespace, because it's own namespace takes precendence.  I tried using
the renaming trick inside of Crypto.py, but it still can't find the
original python-crypto Crypto.  Maybe there's something I can do in the
__init__.py?  Maybe something with __path__?  Is there a better way to
access namespaces from the module files themselves?

  Thanks,
  Lenny G.

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


Re: How to protect Python source from modification

2005-09-12 Thread Frank Millman

bruno modulix wrote:
> Frank Millman wrote:
> > Hi all
> >
> > I am writing a multi-user accounting/business system. Data is stored in
> > a database (PostgreSQL on Linux, SQL Server on Windows). I have written
> > a Python program to run on the client, which uses wxPython as a gui,
> > and connects to the database via TCP/IP.
> >
> > The client program contains all the authentication and business logic.
> > It has dawned on me that anyone can bypass this by modifying the
> > program.
>
> If your program relies on a RDBMS, then it's the RDBMS job to enforce
> security rules.
>

Two possible responses to this -

1. You are right (90% probability)

2. I have certain requirements which can not easily be expressed in the
RDBMS, so it is easier to use the application to enforce certain rules
(10% probability)

Unfortunately I am stuck with number 2 at present.

> > As it is written in Python, with source available, this would
> > be quite easy.
>
> Then there's probably something wrong with the way you manage security.
>

Probably - I am learning the hard way 

> NB: splitting business logic from the GUI is still a good idea anyway.
>

I do have it fairly well split, but it all ends up being processed on
the client, which I think is the root of my problem.

> --
> bruno desthuilliers - unpythonic sig:
> python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
> p in '[EMAIL PROTECTED]'.split('@')])"

Thanks

Frank

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


Re: Ctypes Install in Linux

2005-09-12 Thread jegenye2001
Uh, I suppose you need a bit of reading up on Linux. ;)

http://www.northernjourney.com/opensource/newbies/
http://www.linuxhelp.net/
etc.

> How do I make myself a "root-user"?

To become root, use the "su" command. Obviously you'll need the root
password which you do know, don't you?

>how do I add access the PYTHONPATH environment variable?

If you use the "bash" shell  (probably you do) then type this in:
export PYTHONPATH=/path/to/dir1:/path/to/dir1

Mind you this setting will be valid only in that particular shell.
There are various ways to make this setting accessible to all shells
started.  To find about these, that's left to the OP as an exercise.
:-)


Cheers,
   Miklos
--
The ring of the friendly serpent in business suit: Python, Zope, Plone
http://www.jegenye.com

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


Re: Is it possible to detect if files on a drive were changed without scanning the drive?

2005-09-12 Thread Claudio Grondi

"Alessandro Bottoni" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> Claudio Grondi wrote:
> > After connecting a drive to the system (via USB
> > or IDE) I would like to be able to see within seconds
> > if there were changes in the file system of that drive
> > since last check (250 GB drive with about four million
> > files on it).
> >
> > How to accomplish this? (best if providing
> > directly a Python receipe for it :-)
> > Do available file systems have something like
> > archive attribute assigned to the root directory
> > of the drive?
> > I suppose not. Am I right?
>
> On Linux there is the FAM (File Alteration Module) for this, as long as I
> know. Maybe Python has a wrapper/binding for it.
>
> > I ask this question having Microsoft Windows 2000
> > and Windows proprietary NTFS file system in mind,
> > but I am also interested to know it about Linux or
> > Unix file systems.
>
> As long as I know, on Windows there are a few specific "hooks" to perform
> such a task. They are provided by the MS API for the NTFS/HPFS file
> systems. I do not think Python implements anything so "low level", anyway.
> Check the docu to be sure.
>
> > I know, that looking for the archive attribute of the
> > top directories doesn't help when the change
> > happened to files somewhere deeper in the
> > hierarchy of directories.
>
> Right. It does not help.
>
> Consider this: if are accessing a network file system, you can intercepts
> the calls to the virtualization layer (NFS or NetBIOS). Most likely,
Python
> can support you in performing this task.
>
> HTH
> ---
> Alessandro Bottoni

Thank you for your response.

To be more clear I should maybe add, that I have not to do with
drives beeing altered while the system is running. The drives content
can be altered e.g. by the computer of a friend who I gave the drive
out to.
I tell it here, because it seems, that the answer is biased
towards detecting changes done to files on a drive while
running on a system able to monitor the drives activity.

Claudio


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


Re: How to protect Python source from modification

2005-09-12 Thread Bugs
As a side question Frank, how was your experiences using wxPython for 
your GUI?
Any regrets choosing wxPyton over another toolkit?
Was it very buggy?
How was it to work with in general?
Any other real-world wxPython feedback you have is appreciated.

Frank Millman wrote:
> I am writing a multi-user accounting/business system. Data is stored in
> a database (PostgreSQL on Linux, SQL Server on Windows). I have written
> a Python program to run on the client, which uses wxPython as a gui,
> and connects to the database via TCP/IP.
> 

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


Re: fully-qualified namespaces?

2005-09-12 Thread Michael Hoffman
Lenny G. wrote:

> Hippo/
>   __init__.py
>   Crypto.py
>   Potamus.py
> 
> And inside Crypto.py, I need to access python-crypto's Crypto.Hash
> package.  Inside Potamus.py, I need to access Hippo.Crypto, e.g.,
> 
> Hippo/
>   __init__.py
>   Crypto.py# wants to import python-crypto's Crypto.Hash
>   Potamus.py   # wants to import Hippo's Crypto
> 
> Can I do this?  Crypto.py can't seem to access python-crypto's Crypto
> namespace, because it's own namespace takes precendence.  I tried using
> the renaming trick inside of Crypto.py, but it still can't find the
> original python-crypto Crypto.  Maybe there's something I can do in the
> __init__.py?  Maybe something with __path__?  Is there a better way to
> access namespaces from the module files themselves?

The *best* way would surely be to rename Hippo/Crypto.py to something 
else. This will save you some grief.

If you wanted to load based on filenames, you can use the imp module in 
the stdlib.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First release of Shed Skin, a Python-to-C++ compiler.

2005-09-12 Thread Mark Dufour
On 9/12/05, Brian Quinlan <[EMAIL PROTECTED]> wrote:
> Mark Dufour wrote:
> > The latter is certainly my goal. I just haven't looked into supporting
> > exceptions yet, because I personally never use them. I feel they
> > should only occur in very bad situations, or they become goto-like
> > constructs that intuitively feel very ugly. In the 5500 lines of the
> > compiler itself, I have not needed to use a single exception. For
> > example, I prefer to check whether a file exists myself, rather than
> > executing code that can suddenly jump somewhere else. There's probably
> > some use for exceptions, but I don't (want to?) see it.
> 
> I don't understand your example here. When you check that a file exists,
> you feel safe that openning it will succeed? What if:
> 
> o you don't have permission to open the file
> o the file is deleted in the time between you checking for it's
>existance and opening it (possible race condition)
> o the system doesn't have sufficient resources to open the file
>e.g. too many open file handles
> o the file is already open with exclusive read/write permission

You're right, I don't feel safe about that. It's a bad example. I just
prefer error codes, because the code usually becomes cleaner (at least
to me). I would really like it if I could do something like this:

f = file(name) 
if not f:
print 'error opening file %s: %s', name, str(f.error)
sys.exit()

Error codes may be more work in some cases, but I really like the
(subjectively) cleaner code.  Again, exceptions are probably useful in
some programs, but I wouldn't know.. :)


thanks!
mark.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fully-qualified namespaces?

2005-09-12 Thread Lenny G.
Thanks Michael.  That's actually what I already have, e.g.,

Hippo/
  __init__.py
  HippoCrypto.py
  Potamus.py

Of course, this has the disadvantage of not really taking advantage of
the Hippo namespace -- I might as well have:

HippoCrypto.py
Hippo/
  __init__.py
  Potamus.py

or even get rid of the namespace altogether:

HippoCrypto.py
HippoPotamus.py

Since Hippo.HippoCrypto was already in the Hippo namespace (and clearly
unambiguous with the top-level Crypto namespace from python-crypto), I
thought there might be some way to use this fact to shorten up the name
by removing the redundancy (as can be done in java/C++/etc namespaces).

It sounds like you are saying that there either isn't a way to make the
interpreter utilize this type of namespace difference, or that doing so
is so convoluted that it is certainly worse than just living with
Hippo.HippoCrypto.  I can live with these facts (with a little bit of
discomfort ;) ) -- just wanted to make sure that I understood.

  Lenny G.

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


Re: How to handle very large MIME Messages with the email package?

2005-09-12 Thread Larry Bates
I have found that the SmtpWriter class "hides" all the
complexity in creating emails like you want to send.
It accepts a list of filenames that will be attachments
to the email you generate.

Check it out here:

http://motion.sourceforge.net/related/send_jpg.py

As an aside.  Email was not really designed to send
messages this large and is VERY inefficient at sending
something that large.  Most SMTP servers won't accept
email messages larger than 4Mb.  Are you sure that this
is the best approach to solving your problem?  You
should probably be using ftp instead.  It is a much
better way to send 100Mb files.

Larry Bates

[EMAIL PROTECTED] wrote:
> Looking at the email package, it seems all the MIMExxx classes takes
> string but not file object as the payload. I need to handle very large
> MIME messages say up to 100M. And possibly many of them. Is email
> package sufficient. If not is it possible to extend it?
> 
> Looking at a previous thread it seems the standard library is not
> sufficient.
> 
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/7d1754c1ead54f33/5b6bd38a049e7f6c?q=mime+email+file+object&rnum=5&hl=en#5b6bd38a049e7f6c
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Leo 4.3.2 beta 1

2005-09-12 Thread Edward K. Ream
Leo 4.3.2 beta 1  is now available at:

http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106

To learn about Leo, see: http://webpages.charter.net/edreamleo/intro.html

The highlights of 4.3.2:
---

- Improved Leo's documentation:
- A tutorial introduction to Leo:
  http://webpages.charter.net/edreamleo/intro.html
- A 5-minute guide to programming with Leo:
  
http://webpages.charter.net/edreamleo/intro.html#quick-start-for-programmers

- The new rst3 plugin creates .html and .tex files from reStructuredText
  embedded in Leo files. Any node of the source outline may contain options 
for
  the rst3 plugin, which makes this plugin much more useful and flexible 
than
  the previous rst plugins. All of Leo's documentation was created using 
this
  plugin from sources in LeoDocs.leo. For full documentation for rst3 see:
  http://webpages.charter.net/edreamleo/rstplugin3.html

- The spellpyx (spell checking) plugin is now much easier to use.

- The vim and openWith plugins now use Python's subprocess module if it is 
present.

- Improved the Pretty Printing command.

- The usual assortment of bug fixes.

Edward K. Ream

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


Re: fully-qualified namespaces?

2005-09-12 Thread Michael Hoffman
Lenny G. wrote:

> It sounds like you are saying that there either isn't a way to make the
> interpreter utilize this type of namespace difference, or that doing so
> is so convoluted that it is certainly worse than just living with
> Hippo.HippoCrypto.  I can live with these facts (with a little bit of
> discomfort ;) ) -- just wanted to make sure that I understood.

There are some steps to solve this issue outlined here:

http://www.python.org/peps/pep-0328.html

But the fix was not included in Python 2.4 as planned. Maybe in Python 2.5?
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Software bugs aren't inevitable

2005-09-12 Thread Paddy
A work colleague circulated this interesting article about reducing
software bugs by orders of magnitude:
  http://www.spectrum.ieee.org/WEBONLY/publicfeature/sep05/0905ext.html

Some methods they talk about include removing error prone and ambiguous
expressions from their ADA based language Sparc - The example they give
is on why they removed the increment operators x++, x-- .

A bit of googling shows that they have, in the past mentioned Python in
Job specs, but only as one of many languages.

I was wondering what Praxis thought of Python, and how good it would be
if a Praxis engineer gave a critique of Python as a part of a flow for
producing low bug-count software.

In this sidebar to the main article:

http://www.spectrum.ieee.org/WEBONLY/publicfeature/sep05/0905extsb1.html

It seems that they use one equation from the Z notation model and add
it as a comment to their main programming languages function definition
as a comment, then have a means of automatically testing the comment
against the function body.

This is rather like how doctest can check the test and expected result
given in a doc-string against the implementation given in the function;
indeed I wrote up such an example at work and circulated it amongst the
resident perl mongers. - Gosh it fealt good :-)

So, How do I get feedback from Praxis, Do they already read
comp.lang.py?

Cheers,  Paddy.

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


Re: OCR librarys

2005-09-12 Thread Larry Bates
You need to specify a "platform" you will be running on.  I've had
good experience with ExperVision's RTK toolkit on Windows.  It is not
free, but it is very, very good.  Sometimes software is actually
worth paying for ;-).

Larry Bates


Timothy Smith wrote:
> i'm looking for ocr librarys with reasonably free licensing and the
> ablity to use python with them. c library's that i can call from python
> are acceptable.
> so far all i have run into is voodoo and wild claims. i've tried gocr,
> and it wasn't very impressive. i'm like to be able to ocr handwriting
> but it's not a major requirment. anyone with any pointers or idea's i'm
> all ears. i'd really not like to have to use somthing like imagemagick
> and start from scratch.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Grouping lists

2005-09-12 Thread Kay Schluehr

PyPK wrote:
> If I have a list say
>
> lst = [1,1,1,1,3,5,1,1,1,1,7,7,7]
> I want to group the list so that it returns groups such as
> [(0,3),4,5,(6,9),(10,12)]. which defines the regions which are similar.
>
> Thanks,

Hi,

I got a solution without iterators and without comparing adjecent
elements! O.K. it is neither the most efficient nor the most obvious
solution but I didn't want to get bored ;)

import sets

l = [1,1,8,1,1,3,5,1,1,1,1,7,7,7]
regions = []

for x in sets.Set(l):
start = l.index(x,0)
cnt = 0
while 1:
try:
idx = l.index(x,start)
if idx!=start:
regions.append((start-cnt,start-1))
cnt   = 0
start = idx
else:
cnt+=1
start+=1
except ValueError:
regions.append((start-cnt,start-1))
break

regions.sort()

This returns [(0, 3), (4, 4), (5, 5), (6, 9), (10, 12)]

Now splitting l in regions:

>>> [l[i:j+1] for (i,j) in regions]
[[1, 1, 1, 1], [3], [5], [1, 1, 1, 1], [7, 7, 7]] 

Kay

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


Re: Is it possible to detect if files on a drive were changed without scanning the drive?

2005-09-12 Thread Oren Tirosh
> After connecting a drive to the system (via USB
> or IDE) I would like to be able to see within seconds
> if there were changes in the file system of that drive
> since last check (250 GB drive with about four million
> files on it).

Whenever a file is modified the last modification time of the directory
containing it is also set. I'm not sure if the root directory itself
has a last modification time field but you can just store and compared
the last mod time of all subdirectories directly under the root
directory.

If you trust the clock of all machines mounting this drives is set
correctly (including time zone) you can store just a single timestamp
and compare for files or directories modified after that time.
Otherwise you will need to store and compare for any changes, not just
going forward.

  Oren

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


Re: Is it possible to detect if files on a drive were changed without scanning the drive?

2005-09-12 Thread Grant Edwards
On 2005-09-12, Oren Tirosh <[EMAIL PROTECTED]> wrote:

> Whenever a file is modified the last modification time of the directory
> containing it is also set.

Nope.

   $ ls -ld --time-style=full-iso .
   drwxr-xr-x  2 grante grante 4096 2005-09-12 12:38:04.749815352 -0500 ./
   
   $ touch asdf
   
   $ ls -ld --time-style=full-iso .
   drwxr-xr-x  2 grante grante 4096 2005-09-12 12:39:35.657995208 -0500 ./
   
   $ echo "hi" >asdf
   
   $ ls -ld --time-style=full-iso .
   drwxr-xr-x  2 grante grante 4096 2005-09-12 12:39:35.657995208 -0500 ./
   
   $ echo "foo" >asdf
   
   $ ls -ld --time-style=full-iso .
   drwxr-xr-x  2 grante grante 4096 2005-09-12 12:39:35.657995208 -0500 ./

Notice that writing to the file did not change the modification
date of the directory contining it.
   
-- 
Grant Edwards   grante Yow!  - if it GLISTENS,
  at   gobble it!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Unfortunate newbie questions!

2005-09-12 Thread CPIM Ronin

Hi Folks,

I'm brand spanking new to Python, busy reading docs and going through two of 
the ubiquitous O'Reilly books--"Learning Python" by Lutz/Ascher and "Python 
Programming on Win32" by Hammond/Robinson.


Still I have a just few newbie questions:

   -In the Windows Python version, how can it be configured
   to save all keyboard input for later review and revision?
   And how do I get to it?

   -   What book or doc would you recommend for a thorough
  thrashing of object oriented programming (from a Python
  perspective) for someone who is weak in OO? In other
  words, how can someone learn to think in an OO sense,
  rather than the old linear code sense? Hopefully, heavy
  on problems and solutions!

-  In college, I came to admire the Schaum's Outline book
  approach--again heavy on problems and solutions! What's
  the closest Python equivalent?

Thanks.

RC

_
Don’t just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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

wxPython MainLoop exception handling problem

2005-09-12 Thread Kreedz
Hi,

I'm making some intelligent logging module that redirects stdout and
stderr of a wxPython GUI. I am logging the exceptions in a wx TreeCtrl.
My problem is that when an exception is thrown, there are many calls to
stderr that are made which gives this kind of result:

Traceback (most recent call last):
  File "C:\somefolder\logger.py", line 711, in onTimer
a.index('notinlist')
ValueError
:
list.index(x): x not in list

(That is a test exception I made...)

Obviously I would not want it to use so many lines in the TreeCtrl, and
the lonely ":" on its line looks weird.

I looked through the wx App and saw the "OnExceptionInMainLoop"
function but could not override it successfully. Anybody have an idea
on how I could handle the exception myself so that I dont get lots of
calls to stderr ?

Thanks a lot!

- Kreedz

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


Re: Creating BibTex files with XdkBibTeX

2005-09-12 Thread Fernando Perez
Rob Cowie wrote:

> I'm looking for a module that is able to create valid BibTex documents.
> I'm currently using string substitution to create the content, but it
> is not validated in any way.
> 
> The only BibTex creation module available in Python (that I can find)
> is XdkBibTeX
> (http://artis.imag.fr/Membres/Xavier.Decoret/resources/xdkbibtex/). It
> is a python wrapper around a C library.
> 
> Has anyone used this? More interestingly to me... has anyone
> successfully installed it on Mac OS X?
> 
> Also, can anyone suggest an alternative?


http://pybliographer.org/

Cheers,

f

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


defining __repr__

2005-09-12 Thread sven
hi list,
i'd like to define __repr__ in a class to return the standardrepr
a la "<__main__.A instance at 0x015B3DA0>"
plus additional information.
how would i have to do that?
how to get the standardrepr after i've defined __repr__?

sven.

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


Re: How to protect Python source from modification

2005-09-12 Thread Steve M
This is a heck of a can of worms. I've been thinking about these sorts
of things for awhile now. I can't write out a broad, well-structured
advice at the moment, but here are some things that come to mind.

1. Based on your description, don't trust the client. Therefore,
"security", whatever that amounts to, basically has to happen on the
server. The server should be designed with the expectation that any
input is possible, from slightly tweaked variants of the normal
messages to a robotic client that spews the most horrible ill-formed
junk frequently and in large volumes. It is the server's job to decide
what it should do. For example, consider a website that has a form for
users to fill out. The form has javascript, which executes on the
client, that helps to validate the data by refusing to submit the form
unless the user has filled in required fields, etc. This is client-side
validation (analagous to authentication). It is trivial for an attacker
to force the form to submit without filling in required fields. Now if
the server didn't bother to do its own validation but just inserted a
new record into the database with whatever came in from the form
submission, on the assumption that the client-side validation was
sufficient, this would constitute a serious flaw. (If you wonder then
why bother putting in client-side validation at all - two reasons are
that it enhances the user experience and that it reduces the average
load on the server.)

2. If you're moving security and business logic to the server you have
to decide how to implement that. It is possible to rely solely on the
RDBMS e.g., PostgreSQL. This has many consequences for deployment as
well as development. FOr example, if you need to restrict actions based
on user, you will have a different PgSQL user for every business user,
and who is allowed to modify what will be a matter of PgSQL
configuration. The PgSQL is mature and robust and well developed so you
can rely on things to work as you tell them to. On the other hand, you
(and your clients?) must be very knowledgeable about the database
system to control your application. You have to be able to describe
permissions in terms of the database. They have to be able to add new
users to PgSQL for every new business user, and be able to adjust
permissions if those change. You have to write code in the RDBMS
procedural language which, well, I don't know a lot about it but I'm
not to thrilled about the idea. Far more appealing is to write code in
Python. Lots of other stuff.
Imagine in contrast that user authentication is done in Python. In this
scenario, you can have just a single PgSQL user for the application
that has all access, and the Python always uses that database user but
decides internally whether a given action is permitted based on the
business user. Of course in this case you have to come up with your own
security model which I'd imagine isn't trivial.  You could also improve
security by combining the approaches, e.g. have 3 database users for 3
different business "roles" with different database permissions, and
then in Python you can decide which role applies to a business user and
use the corresponding database user to send commands to the database.
That could help to mitigate the risks of a flaw in the Python code.

3. You should therefore have  a layer of Python that runs on the server
and mediates between client and database. Here you can put
authentication, validation and other security. You can also put all
business logic. It receives all input with the utmost suspicion and
only if everything is in order will it query the database and send
information to the client. There is little or no UI stuff in this
layer. To this end, you should check out Dabo at www.dabodev.com. This
is an exciting Python project that I haven't used much but am really
looking forward to when I have the chance, and as it becomes more
developed. My impression is that it is useable right now. They
basically provide a framework for a lot of stuff you seem to have done
by hand, and it can give you some great ideas about how to structure
your program. You may even decide to port it to Dabo.

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


  1   2   >