PMW widget - skip tabbing to it

2007-03-26 Thread jp
I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
I skip over these widgets when using the tab key?

Thank you,
John

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


Re: PMW widget - skip tabbing to it

2007-03-26 Thread jp
On Mar 26, 11:17 am, [EMAIL PROTECTED] wrote:
> On Mar 26, 10:51 am, "jp" <[EMAIL PROTECTED]> wrote:
>
> > I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
> > I skip over these widgets when using the tab key?
>
> > Thank you,
> > John
>
> I would probably write some custom event handling. Something that
> could tell it was a key-press event and not just an on-focus event.
> Then it would be a simple, if key-press == tab, put focus on next
> widget of interest. Something like that should work.
>
> Mike


Isn't there just a simple configuration option to disable the tab
key?  Like the takfocus option with Tkinter widgets?

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


Re: PMW widget - skip tabbing to it

2007-03-26 Thread jp
On Mar 26, 11:27 am, [EMAIL PROTECTED] wrote:
> On Mar 26, 11:17 am, [EMAIL PROTECTED] wrote:
>
> > On Mar 26, 10:51 am, "jp" <[EMAIL PROTECTED]> wrote:
>
> > > I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
> > > I skip over these widgets when using the tab key?
>
> > > Thank you,
> > > John
>
> > I would probably write some custom event handling. Something that
> > could tell it was a key-press event and not just an on-focus event.
> > Then it would be a simple, if key-press == tab, put focus on next
#> > widget of interest. Something like that should work.
>
> > Mike
>
> I looked in my Tkinter book, and it says that if the widget has the
> "takefocus" option set to true, the widget is placed in the tab group
> and will get focus when they are tabbed to. I assume that this means
> if you set the PMW widgets' "takefocus" option to false, they will be
> skipped over since they won't be in the tab group.
>
> Mike

I've tried using the takefocus option set to 0 and 1 but either way,
the tab key still stops at my EntryField.  Below is my snippet of
code.  What am I doing wrong?

entry=Pmw.EntryField(frame,
 labelpos = 'w',
 value = "",
 label_text =
'Name:')
entry.grid(row=1)
#entry.component('entry').takefocus = 1
entry.component('entry').takefocus = 0

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


Re: PMW widget - skip tabbing to it

2007-03-26 Thread jp
On Mar 26, 12:34 pm, [EMAIL PROTECTED] wrote:
> On Mar 26, 11:35 am, "jp" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Mar 26, 11:27 am, [EMAIL PROTECTED] wrote:> On Mar 26, 11:17 am, [EMAIL 
> > PROTECTED] wrote:
>
> > > > On Mar 26, 10:51 am, "jp" <[EMAIL PROTECTED]> wrote:
>
> > > > > I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
> > > > > I skip over these widgets when using the tab key?
>
> > > > > Thank you,
> > > > > John
>
> > > > I would probably write some custom event handling. Something that
> > > > could tell it was a key-press event and not just an on-focus event.
> > > > Then it would be a simple, if key-press == tab, put focus on next
>
> > #> > widget of interest. Something like that should work.
>
> > > > Mike
>
> > > I looked in my Tkinter book, and it says that if the widget has the
> > > "takefocus" option set to true, the widget is placed in the tab group
> > > and will get focus when they are tabbed to. I assume that this means
> > > if you set the PMW widgets' "takefocus" option to false, they will be
> > > skipped over since they won't be in the tab group.
>
> > > Mike
>
> > I've tried using the takefocus option set to 0 and 1 but either way,
> > the tab key still stops at my EntryField.  Below is my snippet of
> > code.  What am I doing wrong?
>
> > entry=Pmw.EntryField(frame,
> >  labelpos = 'w',
> >  value = "",
> >  label_text =
> > 'Name:')
> > entry.grid(row=1)
> > #entry.component('entry').takefocus = 1
> > entry.component('entry').takefocus = 0
>
> According to the Tkinter book, setting takefocus to 0 (false) should
> work. Are you putting th EntryField into a Grid? If so, that might be
> the problem. I suppose the grid may override its children's settings.
>
> I've never messed too much with skipping widgets in the tab order. You
> could pack the PMW widgets last so that they won't get tabbed to until
> the end.
>
> There's also tk_focusNext & tk_focusPrev. See the following post for
> more info and ideas:
>
> http://www.dbforums.com/archive/index.php/t-1377788.html
>
> Mike


I am using a grid, but even using pack() the takefocus=0 doesn't
work.  The tab key still moves to my EntryField.
I'll look into the focusNext and focusPrev that you suggested.  Thanks!

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


Re: PMW widget - skip tabbing to it

2007-03-27 Thread jp
On Mar 26, 5:41 pm, John McMonagle <[EMAIL PROTECTED]> wrote:
> jp wrote:
> >>> On Mar 26, 10:51 am, "jp" <[EMAIL PROTECTED]> wrote:
> >>>> I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
> >>>> I skip over these widgets when using the tab key?
> >>>> Thank you,
> >>>> John
>
> What version of Pmw are you using ?  Tabbing between widgets works fine
> on my system (Pmw 1.2,  tk 8.4, KDE)
>
> I can change the focus behaviour by using the takefocus option.  You
> were on the right track, you just did it wrong (see code below):
>
> 
> from Tkinter import *
> import Pmw
>
> root = Tk()
> entry = Pmw.EntryField(root, labelpos=W, value="", label_text='Name:')
> entry.grid(row=1)
> entry.component('entry').configure(takefocus=0)
>
> Button(root,text='test1').grid(row=2)
> Button(root,text='test2').grid(row=3)
> Button(root,text='test3').grid(row=4)
>
> root.mainloop()
> #
>
> Regards,
>
> John


Thank you for pointing out my error, John and James.  I had the syntax
of the command messed up.  Using the following does cause the field to
be skipped when tabbing:
entry.component('entry').configure(takefocus=0)

John

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


ANN: nose 0.9.2 released

2007-01-31 Thread JP
nose is a discovery-based unittest extension that provides an
alternate test discovery and running process for unittest, one that is
intended to mimic the behavior of py.test as much as is reasonably
possible without resorting to too much magic.

nose 0.9.2 includes quite a few bug fixes and new features. The most
significant are the new nosetests setuptools command, contributed by
James Casbon, better support for python 2.2 thanks to a patch from
Chad Whitacre, and some useful utilities for testing Twisted programs
and writing decorators contributed by Antoine Pitrou. Thanks to them
all, and the many other folks who contributed patches and filed bug
reports and feature requests.

For more information, see: http://somethingaboutorange.com/mrl/
projects/nose/

nose's project home has moved from python hosting to Google code.
Please update your svn checkouts and bookmarks. To check out the
current trunk:

svn co http://python-nose.googlecode.com/svn/trunk

To file issues, go to the new issues page:

http://code.google.com/p/python-nose/issues/list

To read up on features, writing plugins, and other topics, visit the
new wiki:

http://code.google.com/p/python-nose/w/list

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


cmd i/o stream module

2012-06-27 Thread prakash jp
Hi All,

I am interested to interact with the command prompt, is there a module to
control the input/output stream. Thanks in advance for the pointers

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


get latest from svn

2012-06-01 Thread prakash jp
Hi All,

Can some one suggest me a module to access SVN repository so that i could
download any given branch.

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


help on QUICKFIX

2011-06-10 Thread prakash jp
Hi,

I am using quickfix, would like to start with that

..\quickfix-1.13.3\quickfix\examples\executor\python\executor.py asks for a
configuration file how should it look like.


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


find max and min values from a column of a csv file

2011-07-07 Thread prakash jp
Hi All ,

Could any one help to get max and min values from a specified column of a
csv file. The* csv file is large* and hence the below code did go bad.
*Alternate
methods would be highly appreciated
**
minimum.py*:
import csv
filename = "testLog_4.csv"
f = open(filename)
def col_min(mincname):
with open(filename, 'rb') as f:
reader = csv.reader(f, delimiter=",")
#print reader
#print mincname
col_index = next(reader).index(mincname)
#print col_index
least = min(rec[col_index] for rec in reader)
print least

col_min(str("Server Latency"))
col_min(str("Client Latency"))
f.close()

*maximum.py:*
import csv
filename = "testLog_4.csv"
f = open(filename)
def col_max(maxcname):
with open(filename, 'rb') as f:
reader = csv.reader(f, delimiter=",")
#print reader
#print cname
col_index = next(reader).index(maxcname)
#print col_index
highest = max(rec[col_index] for rec in reader)
print highest

col_max(str("Server Latency"))
col_max(str("Client Latency"))
f.close()


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


Re: find max and min values from a column of a csv file

2011-07-19 Thread prakash jp
Thanks for the suggestions. Felt the thread could be of help on
consolidating the solution.

*Max Value from a csv column:*

import numpy
data1 = numpy.genfromtxt("data.csv",dtype='float',delimiter =
',',skiprows=1, skip_header=0, skip_footer=0,
usecols=11,usemask=True)
#print data1
print data1.max()

Plz go through the below link to understand further on the arguments taken
by numpy.genfromtxt():

http://docs.scipy.org/doc/numpy-1.4.x/reference/generated/numpy.genfromtxt.html




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


how to invoke a bat file on a remote machine

2011-08-07 Thread prakash jp
Hi all,

Want to know how to invoke a bat file on a remote machine.

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


pydev ant build

2011-05-30 Thread prakash jp
Hi all,

Could any one provide relevant url/s on the usage of *pyant* scripts and its
setup as well

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


Re: Metaclasses, decorators, and synchronization

2005-09-25 Thread Jp Calderone
On Sun, 25 Sep 2005 23:30:21 -0400, Victor Ng <[EMAIL PROTECTED]> wrote:
>You could do it with a metaclass, but I think that's probably overkill.
>
>It's not really efficient as it's doing test/set of an RLock all the
>time, but hey - you didn't ask for efficient.  :)

There's a race condition in this version of synchronized which can allow two or 
more threads to execute the synchronized function simultaneously.

>
>  1 import threading
>  2
>  3 def synchronized(func):
>  4 def innerMethod(self, *args, **kwargs):
>  5 if not hasattr(self, '_sync_lock'):

Imagine two threads reach the above test at the same time - they both discover 
there is no RLock protecting this function.  They both entire this suite to 
create one.

>  6 self._sync_lock = threading.RLock()

Now one of them zooms ahead, creating the RLock and acquiring it on the next 
line.  The other one finally manages to get some runtime again afterwards and 
creates another RLock, clobbering the first.

>  7 self._sync_lock.acquire()

Now it proceeds to this point and acquires the newly created RLock.  Woops.  
Two threads now think they are allowed to run this function.

>  8 print 'acquired %r' % self._sync_lock
>  9 try:
> 10 return func(self, *args, **kwargs)

And so they do.

> 11 finally:
> 12 self._sync_lock.release()
> 13 print 'released %r' % self._sync_lock

Of course, when the second gets to the finally suite, it will explode, since it 
will be releasing the same lock the first thread to get here has already 
released.

> 14 return innerMethod
> 15
> 16 class Foo(object):
> 17 @synchronized
> 18 def mySyncMethod(self):
> 19 print "blah"
> 20
> 21
> 22 f = Foo()
> 23 f.mySyncMethod()

To avoid this race condition, you need to serialize lock creation.  This is 
exactly what Twisted's implementation does.  You can read that version at 
<http://svn.twistedmatrix.com/cvs/trunk/twisted/python/threadable.py?view=markup&rev=13745>.
The code is factored somewhat differently: the functionality is presented as 
pre- and post-execution hooks, and there is function decorator.  The concept is 
the same, however.

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


Re: Feature Proposal: Sequence .join method

2005-09-30 Thread Jp Calderone
On Fri, 30 Sep 2005 09:38:25 -0700, Michael Spencer <[EMAIL PROTECTED]> wrote:
>Terry Reedy wrote:
>> "David Murmann" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>
>>>>def join(sep, seq):
>>>>return reduce(lambda x, y: x + sep + y, seq, type(sep)())
>>>
>>>damn, i wanted too much. Proper implementation:
>>>
>>>def join(sep, seq):
>>>if len(seq):
>>>return reduce(lambda x, y: x + sep + y, seq)
>>>return type(sep)()
>>>
>>>but still short enough
>>
>>
>> For general use, this is both too general and not general enough.
>>
>> If len(seq) exists then seq is probably reiterable, in which case it may be
>> possible to determine the output length and preallocate to make the process
>> O(n) instead of O(n**2).  I believe str.join does this.  A user written
>> join for lists could also.  A tuple function could make a list first and
>> then tuple(it) at the end.
>>
>> If seq is a general (non-empty) iterable, len(seq) may raise an exception
>> even though the reduce would work fine.
>>
>> Terry J. Reedy
>>
>>
>>
>For the general iterable case, you could have something like this:
>
>  >>> def interleave(sep, iterable):
>  ... it = iter(iterable)
>  ... next = it.next()
>  ... try:
>  ... while 1:
>  ... item = next
>  ... next = it.next()
>  ... yield item
>  ... yield sep
>  ... except StopIteration:
>  ... yield item
>  ...
>  >>> list(interleave(100,range(10)))
>  [0, 100, 1, 100, 2, 100, 3, 100, 4, 100, 5, 100, 6, 100, 7, 100, 8, 100, 9]
>  >>>
>
>but I can't think of a use for it ;-)

I have this version:

def interlace(x, i):
"""interlace(x, i) -> i0, x, i1, x, ..., x, iN
"""
i = iter(i)
try:
yield i.next()
except StopIteration:
return
for e in i:
yield x
yield e

And I use it for things like interleave(", ", ["foo", bar, "baz"]), where bar 
is not a string, but can be handled along with strings by a lower-level chunk 
of code.

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


Re: Dynamical loading of modules

2005-10-03 Thread Jp Calderone


On Mon, 03 Oct 2005 21:52:21 +0200, Jacob Kroon <[EMAIL PROTECTED]> wrote:
>Hi, I'm having some problems with implementing dynamical module loading.
>First let me
>describe the scenario with an example:
>
>modules/
>fruit/
>__init__.py
>apple.py
>banana.py
>
>apple.py defines a class 'Apple', banana defines a class 'Banana'. The
>problem lies in the
>fact that I want to be able to just drop a new .py-file, for instance
>peach.py, and not change
>__init__.py, and it should automatically pickup the new file in
>__init__.py. I've come halfway
>by using some imp module magic in __init__.py, but the problem I have is
>that the instantiated
>objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild
>I want it to be
>fruit.Apple/fruit.Banana.
>
>Is there a smarter way of accomplishing what I am trying to do ?
>If someone could give me a small example of how to achieve this I would
>be very grateful.

The __module__ attribute of class objects is mutable.  I don't understand *why* 
this makes a difference, though.  The class's name is a pointer to where it is 
defined: this is useful because it saves a lot of grepping, and unambiguously 
tells the reader where the class came from.  If you start making it mean 
something else, you'll end up confusing people.  If you just want a pretty 
name, use something /other/ than the class's fully qualified Python name.

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


Re: how to debug when "Segmentation fault"

2005-10-04 Thread Jp Calderone
On Tue, 4 Oct 2005 11:22:24 -0500, Michael Ekstrand <[EMAIL PROTECTED]> wrote:
>On Tuesday 04 October 2005 11:13, Maksim Kasimov wrote:
>> my programm sometime gives "Segmentation fault" message (no matter
>> how long the programm had run (1 day or 2 weeks). And there is
>> nothing in log-files that can points the problem. My question is how
>> it possible to find out where is the problem in the code? Thanks for
>> any help.
>
>What extension modules are you using?
>
>I've never seen "stock" Python (stable release w/ only included modules)
>segfault, but did see a segfault with an extension module I was using
>the other week (lxml IIRC, but I'm not sure).
>

[EMAIL PROTECTED]:~$ python
Python 2.4.2c1 (#2, Sep 24 2005, 00:48:19) 
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.setrecursionlimit(1e9)
__main__:1: DeprecationWarning: integer argument expected, got float
>>> (lambda f: f(f))(lambda f: f(f))
Segmentation fault
[EMAIL PROTECTED]:~$ python
Python 2.4.2c1 (#2, Sep 24 2005, 00:48:19) 
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class foo(type):
... def mro(self):
... return [float]
... 
>>> class bar:
... __metaclass__ = foo
... 
Segmentation fault
[EMAIL PROTECTED]:~$ python
Python 2.4.2c1 (#2, Sep 24 2005, 00:48:19) 
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dl
>>> dl.open('libc.so.6').call('memcpy', 0, 0, 1024)
Segmentation fault
[EMAIL PROTECTED]:~$ 

Though to be honest, even I consider the 3rd example a bit of a cheat ;)

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


Re: updating local()

2005-10-05 Thread Jp Calderone


On Wed, 5 Oct 2005 18:47:06 +0200, Sybren Stuvel <[EMAIL PROTECTED]> wrote:
>Flavio enlightened us with:
>> Can anyone tell me why, if the following code works, I should not do
>> this?
>>
>> def fun(a=1,b=2,**args):
>>
>>  print 'locals:',locals()
>>  locals().update(args)
>>  print locals()
>
>Because it's very, very, very insecure. What would happen if someone
>found a way to call that function? It could replace any name in the
>locals dictionary, including functions from __builtins__. In other
>words: probably the whole program could be taken over by other code by
>just one call to that function.
>

If I can call functions in your process space, I've already taken over your 
whole program.

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


Re: Lambda evaluation

2005-10-06 Thread Jp Calderone
On Thu, 06 Oct 2005 16:18:15 -0400, Joshua Ginsberg <[EMAIL PROTECTED]> wrote:
>So this part makes total sense to me:
>
>>>> d = {}
>>>> for x in [1,2,3]:
>... d[x] = lambda y: y*x
>...
>>>> d[1](3)
>9
>
>Because x in the lambda definition isn't evaluated until the lambda is
>executed, at which point x is 3.
>
>Is there a way to specifically hard code into that lambda definition the
>contemporary value of an external variable? In other words, is there a
>way to rewrite the line "d[x] = lambda y: y*x" so that it is always the
>case that d[1](3) = 3?

There are several ways, but this one involves the least additional typing:

>>> d = {}
>>> for x in 1, 2, 3:
... d[x] = lambda y, x=x: y * x
... 
>>> d[1](3)
3

Who needs closures, anyway? :)

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


Re: Python reliability

2005-10-09 Thread Jp Calderone
On Sun, 9 Oct 2005 23:00:04 +0300 (EEST), Ville Voipio <[EMAIL PROTECTED]> 
wrote:
>I would need to make some high-reliability software
>running on Linux in an embedded system. Performance
>(or lack of it) is not an issue, reliability is.
>
>The piece of software is rather simple, probably a
>few hundred lines of code in Python. There is a need
>to interact with network using the socket module,
>and then probably a need to do something hardware-
>related which will get its own driver written in
>C.
>
>Threading and other more error-prone techniques can
>be left aside, everything can run in one thread with
>a poll loop.
>
>The software should be running continously for
>practically forever (at least a year without a reboot).
>Is the Python interpreter (on Linux) stable and
>leak-free enough to achieve this?
>

As a data point, I've had python programs run on linux for more than a year 
using both Python 2.1.3 and 2.2.3.  These were network apps, with both client 
and server functionality, using Twisted.

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


Re: Python reliability

2005-10-09 Thread Jp Calderone
On Mon, 10 Oct 2005 12:18:42 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>George Sakkis wrote:
>
>> Steven D'Aprano wrote:
>>
>>
>>>On Sun, 09 Oct 2005 23:00:04 +0300, Ville Voipio wrote:
>>>
>>>
>>>>I would need to make some high-reliability software
>>>>running on Linux in an embedded system. Performance
>>>>(or lack of it) is not an issue, reliability is.
>>>
>>>[snip]
>>>
>>>
>>>>The software should be running continously for
>>>>practically forever (at least a year without a reboot).
>>>>Is the Python interpreter (on Linux) stable and
>>>>leak-free enough to achieve this?
>>>
>>>If performance is really not such an issue, would it really matter if you
>>>periodically restarted Python? Starting Python takes a tiny amount of time:
>>
>>
>> You must have missed or misinterpreted the "The software should be
>> running continously for practically forever" part. The problem of
>> restarting python is not the 200 msec lost but putting at stake
>> reliability (e.g. for health monitoring devices, avionics, nuclear
>> reactor controllers, etc.) and robustness (e.g. a computation that
>> takes weeks of cpu time to complete is interrupted without the
>> possibility to restart from the point it stopped).
>
>
>Er, no, I didn't miss that at all. I did miss that it
>needed continual network connections. I don't know if
>there is a way around that issue, although mobile
>phones move in and out of network areas, swapping
>connections when and as needed.
>
>But as for reliability, well, tell that to Buzz Aldrin
>and Neil Armstrong. The Apollo 11 moon lander rebooted
>multiple times on the way down to the surface. It was
>designed to recover gracefully when rebooting unexpectedly:
>
>http://www.hq.nasa.gov/office/pao/History/alsj/a11/a11.1201-pa.html
>

This reminds me of crash-only software:

  http://www.stanford.edu/~candea/papers/crashonly/crashonly.html

Which seems to have some merits.  I have yet to attempt to develop any large 
scale software explicitly using this technique (although I have worked on 
several systems that very loosely used this approach; eg, a server which 
divided tasks into two processes, with one restarting the other whenever it 
noticed it was gone), but as you point out, there's certainly precedent.

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


Re: Help with cPickle for deserializing datetime.datetime instances

2005-10-14 Thread Jp Calderone
On Fri, 14 Oct 2005 01:25:27 -0500, Mingus Tsai <[EMAIL PROTECTED]> wrote:
>Hello- please help with unpickling problem:
>
>I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows
>XPhome system.
>
>My problem is with using cPickle to deserialize my pickled arrays of
>datetime.datetime instances.  The following is the code I have written:
>
>   import cPickle, datetime
>   import Numeric
>
>#the file below contains a serialized dict with arrays of datetime
>#objects.  When these three statements run, the IDLE crashes!
>
>   input1 = open('tsm2_outa','r')
>   time1 = cPickle.load(input1)
>   input1.close()
>
>#the file below contains serialized dict with arrays of built-in objects
>#it unpickles without any problem, when I omit the above unpickling
>#operation.
>
>   input2 = open('tsm2_outb','rb')
>   data1 = cPickle.load(input2)
>   input2.close()
>
>My guess is that I need to somehow tell the pickle.load command that it
>is loading datetime instances, but I have no idea how to do this.  Any
>help would be much appreciated.

As I recall, Pickling Numeric arrays is a tricky business.  You probably 
shouldn't even try to do it.  Instead, pickle regular arrays or lists.

For anyone else who's interested, this can easily be reproduced without an 
existing pickle file:

[EMAIL PROTECTED]:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01) 
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Numeric, cPickle, datetime
>>> cPickle.loads(cPickle.dumps(Numeric.array([datetime.datetime.now() for n in 
>>> range(50)])))
Segmentation fault
[EMAIL PROTECTED]:~$ 

Values smaller than 50 randomly mangle memory, but sometimes don't segfault the 
interpreter.  You can get exciting objects like instances of cPickle.Pdata or 
refcnt back from the loads() call in these cases.

So, the summary is, don't do this.

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


Re: write a loopin one line; process file paths

2005-10-18 Thread Jp Calderone
On 18 Oct 2005 14:56:32 -0700, Xah Lee <[EMAIL PROTECTED]> wrote:
>is there a way to condense the following loop into one line?

There is.

exec('696d706f72742072652c206f732e706174680a0a696d6750617468733d5b75272f55736572732f742f7765622f506572696f6469635f646f736167655f6469722f6c616e63692f74342f6f682f4453434e323035396d2d732e6a7067272c0a75272f55736572732f742f7765622f506572696f6469635f646f736167655f6469722f6c616e63692f74342f6f682f4453434e323036326d2d732e6a7067272c0a75272f55736572732f742f7765622f506572696f6469635f646f736167655f6469722f6c616e63692f74342f6f682f4453434e323039376d2d732e6a7067272c0a75272f55736572732f742f7765622f506572696f6469635f646f736167655f6469722f6c616e63692f74342f6f682f4453434e323039396d2d732e6a7067272c0a75272f55736572732f742f7765622f49636f6e735f6469722f69636f6e5f73756d2e676966275d0a0a23206368616e67652074686520696d616765207061746820746f207468652066756c6c2073697a656420696d6167652c206966206974206578697374730a2320746861742069732c20696620696d61676520656e647320696e202d732e6a70672c2066696e64206f6e6520776974686f75742074686520272d73272e0a74656d703d696d6750617468735b3a5d0a696d6750617468733d5b5d0a666f72206d795!
 
061746820696e2074656d703a0a20202020703d6d79506174680a20202020286469724e616d652c2066696c654e616d6529203d206f732e706174682e73706c6974286d7950617468290a202020202866696c65426173654e616d652c2066696c65457874656e73696f6e293d6f732e706174682e73706c69746578742866696c654e616d65290a2020202069662872652e7365617263682872272d7324272c66696c65426173654e616d652c72652e5529293a0a202020202020202070323d6f732e706174682e6a6f696e286469724e616d652c66696c65426173654e616d655b303a2d325d29202b2066696c65457874656e73696f6e0a20202020202020206966206f732e706174682e657869737473287032293a20703d70320a20202020696d6750617468732e617070656e642870290a0a74656d703d5b5d0a7072696e7420696d6750617468730a'.decode('hex'))

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


Re: python gc performance in large apps

2005-10-22 Thread Jp Calderone
On Fri, 21 Oct 2005 16:13:09 -0400, Robby Dermody <[EMAIL PROTECTED]> wrote:
>
>Hey guys (thus begins a book of a post :),
>
>I'm in the process of writing a commercial VoIP call monitoring and
>recording application suite in python and pyrex. Basically, this
>software sits in a VoIP callcenter-type environment (complete with agent
>phones and VoIP servers), sniffs voice data off of the network, and
>allows users to listen into calls. It can record calls as well. The
>project is about a year and 3 months in the making and lately the
>codebase has stabilized enough to where it can be used by some of our
>clients. The entire project has about 37,000 lines of python and pyrex
>code (along with 1-2K lines of unrelated java code).
>
> [snip - it leaks memory]

One thing to consider is that the process may be growing in size, not because 
garbage objects are not being freed, but because objects which should be 
garbage are being held onto by application-level code.

gc.objects may be useful for determining if this is the case, and 
gc.get_objects() may be useful for discovering what kinds of objects are piling 
up.  These may give you a hint as to where to look to allow these objects to be 
released, if this is the problem.

Of course, it's also possible one of the libraries you are using is either 
leaking objects in this fashion, or for the extension modules, may just be 
leaking memory.  The above techniques may help you find an object leak, but 
they won't help you find a memory leak.  For this, you might give Valgrind a 
try (use the suppression file in Python CVS to get rid of the spew PyMalloc and 
friends generate).

Also, I can point out two things: Twisted's URL parsing extension leaked some 
memory in 1.3, but has been fixed since 2.0; and Nevow 0.4.1 made it easy to 
write applications that leaked several page objects per request, which has been 
fixed since 0.5.  If you're using either of these older versions, upgrading may 
fix your difficulties.

Hope this helps,

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


Re: KeyboardInterrupt vs extension written in C

2005-10-22 Thread Jp Calderone
On 22 Oct 2005 22:02:46 +0200, Dieter Maurer <[EMAIL PROTECTED]> wrote:
>"Tamas Nepusz" <[EMAIL PROTECTED]> writes on 20 Oct 2005 15:39:54 -0700:
>> The library I'm working on
>> is designed for performing calculations on large-scale graphs (~1
>> nodes and edges). I want to create a Python interface for that library,
>> so what I want to accomplish is that I could just type "from igraph
>> import *" in a Python command line and then access all of the
>> functionalities of the igraph library. Now it works, except the fact
>> that if, for example, I start computing the diameter of a random graph
>> of ~10 nodes and ~20 edges, I can't cancel it, because the
>> KeyboardInterrupt is not propagated to the Python toplevel (or it isn't
>> even generated until the igraph library routine returns).
>
>Python installs a "SIGINT" handler that just notes that
>such a signal was received. The note is handled during
>bytecode execution. This way, Python handles the (dangerous)
>asynchronous signal synchronously (which is much safer).
>But, it also means that a signal during execution of your C extension
>is only handled when it finished.
>
>What you can do in your wrapper code:
>
>   Temporarily install a new handler for "SIGINT" that
>   uses "longjmp" to quit the C extension execution when
>   the signal occurs.
>
>   Note that "longjmp" is dangerous. Great care is necessary.
>
>   It is likely that SIGINT occurrences will lead to big
>   resource leaks (because your C extension will have no
>   way to release resources when it gets quit with "longjmp").
>

Note that swapcontext() is probably preferable to longjmp() in almost all 
circumstances.  In cases where it isn't, siglongjmp() definitely is.

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


Re: High Order Messages in Python

2005-10-22 Thread Jp Calderone
On 22 Oct 2005 14:12:16 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>I'm reading about "high order messages" in Ruby by Nat Pryce, and
>thinking if it could be  util and if so, if it could be done in Python.
>Someone already tried?

Here's an example of the idea, in Python:

def messageA():
print 'Message A received!'

def messageB(otherMessage):
print 'Message B received!  Sending some other message.'
otherMessage()

messageB(messageA)

Since this is a basic feature of Python, we usually don't call them messages.  
Instead, "functions" or sometimes "methods".

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


Re: High Order Messages in Python

2005-10-22 Thread Jp Calderone
On 22 Oct 2005 15:11:39 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>Hum... I thnk you dont get the ideia: I'm not talking abou High Order
>Functions.
>What ho call "High Order Methods is some like "connecting" some
>'generic' methods created to do things like this:
>claimants.where.retired?.do.receive_benefit 50
>The 2nd and 3rd links that in the first post is the most relevant to
>undestand the concept. Read this too:
>http://www.metaobject.com/papers/Higher_Order_Messaging_OOPSLA_2005.pdf

These are just more involved applications of the same idea.  They're easily 
implemented in Python, using primitives such as HOF, if one desires.

However, I don't see why one would want to write the above mish-mash, rather 
than:

for cl in claimaints:
if cl.retired():
cl.receive_benefit(50)

Or:

[cl.receive_benefit(50) for cl in claimaints if cl.retired())

Or:

map(
ClaimaintType.receive_benefit,
filter(
ClaimaintType.retired,
claimaints),
itertools.repeat(50))

Or:

claimaintGroup.disburse()

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


Re: Extention String returning

2005-10-24 Thread Jp Calderone
On 24 Oct 2005 11:28:23 -0700, Tuvas <[EMAIL PROTECTED]> wrote:
>I have been writing a program that is designed to return an 8 byte
>string from C to Python. Occasionally one or more of these bytes will
>be null, but the size of it will always be known. How can I write an
>extention module that will return the correct bytes, and not just until
>the null? I would think there would be a fairly  easy way to do this,
>but, well... Thanks!

Use PyString_FromStringAndSize instead of PyString_FromString.

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


Re: what is lambda used for in real code?

2004-12-31 Thread Jp Calderone
On Fri, 31 Dec 2004 22:09:49 -0500, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> "Adam DePrince" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> > In sort, we must preserve the ability to create an anonymous function
> > simply because we can do so for every other object type, and functions
> > are not special enough to permit this special case.
> 
> Please show me how to create an anonymous type, module, or class, 
> especially with an expression.  Number, sequences, and dicts have easily 
> printable values.  Functions, like classes and module do not*, so 
> definition names act as a standin and as a pointer to the source code that 
> produced the object.  If functions are not special relative to classes and 
> modules, which is the grouping they belong with, then we should get rid of 
> lambda ;-)

>>> print type('', (object,), {'foo': lambda self: 'spam'})().foo()
spam

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


Re: PEP 288 ponderings

2005-01-01 Thread Jp Calderone
On Sun, 02 Jan 2005 01:04:06 GMT, Steven Bethard <[EMAIL PROTECTED]> wrote:
>PEP 288 was mentioned in one of the lambda threads and so I ended up 
> reading it for the first time recently.  I definitely don't like the 
> idea of a magical __self__ variable that isn't declared anywhere.  It 
> also seemed to me like generator attributes don't really solve the 
> problem very cleanly.  An example from the PEP[1]:
> 
> [snip]

  You may be interested in greenlets.  They solve this problem in a way 
which is conceptually much simpler and cleaner.

  They are available as a third party extension, and unfortunately are 
not terribly well documented yet (but luckily they are quite simple).

  http://codespeak.net/svn/user/arigo/greenlet/

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


Re: Continuations Based Web Framework - Seaside.

2005-01-02 Thread Jp Calderone
On Sun, 2 Jan 2005 13:34:02 -0500, Kendall Clark <[EMAIL PROTECTED]> wrote:
>On Sun, Jan 02, 2005 at 10:03:10AM -0500, Steve Holden wrote:
> 
> > I did actually do some sort-of-related work in this area, which I 
> > presented at PyCon DC 2004 - you can access the paper at
> > 
> >http://www.python.org/pycon/dc2004/papers/18/Setting_A_Context.pdf
> > 
> > An audience member mentioned the Smalltalk and Scheme-based work on web 
> > continuation frameworks, and I was sorry my answer at the time seemed 
> > unduly dismissive. 
> 
> That was me, actually. I remain surprised that there isn't a move
> afoot either to implement something like Seaside or Borges in Python
> or to adapt one of the existing web frameworks to be
> modal/continuation style.

  There is at least one.  I'm sure I could find several, if I looked.
The problem is that there are dozens of "web frameworks" in Python, 
all off in their separate corners ignoring each other for the most 
part, and for the most part being ignored by everyone outside their 
immediate community.

  Maybe PEP 333 will help by making movement between frameworks 
simpler for application developers.  Of course, it may not, since 
it ignores complex things (it certainly comes nowhere close to 
addressing the requirements for a Seaside-alike), and any developer 
who wants to remain portable will not be able to take advantage of 
this technique.

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


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

2005-01-04 Thread Jp Calderone
On Tue, 04 Jan 2005 16:41:05 +0100, Thomas Heller <[EMAIL PROTECTED]> wrote:
>Skip Montanaro <[EMAIL PROTECTED]> writes:
> 
> > michele> BTW what's the difference between .encode and .decode ?
> >
> > I started to answer, then got confused when I read the docstrings for
> > unicode.encode and unicode.decode:
> >
> > [snip - docstrings]
> >
> > It probably makes sense to one who knows, but for the feeble-minded like
> > myself, they seem about the same.
> 
> It seems also the error messages aren't too helpful:
> 
> >>> "ä".encode("latin-1")
> Traceback (most recent call last):
>   File "", line 1, in ?
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x84 in position 0: 
> ordinal not in range(128)
> >>>
> 
> Hm, why does the 'encode' call complain about decoding?
> 
> Why do string objects have an encode method, and why do unicode objects
> have a decode method, and what does this error message want to tell me:
> 
> >>> u"ä".decode("latin-1")
> Traceback (most recent call last):
>   File "", line 1, in ?
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 
> 0: ordinal not in range(128)
> >>>

   The call

   unicode.decode(codec)

   is actually doing this

   unicode.encode(sys.getdefaultencoding()).decode(codec)

   This is not a particularly nice thing.  I'm not sure who thought
it was a good idea.  One possibility is that .encode() and .decode()
are not _only_ for converting between unicode and encoded bytestrings.
For example, there is the zlib codec, the rot13 codec, and applications
can define their own codecs with arbitrary behavior.  It's entirely 
possible to write a codec that decodes _from_ unicode objects _to_ 
unicode objects and encodes the same way.  So unicode objects need both
methods to support this use case.

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


Re: Hlelp clean up clumpsy code

2005-01-04 Thread Jp Calderone


On Tue, 04 Jan 2005 08:18:58 -0800, Scott David Daniels <[EMAIL PROTECTED]> 
wrote:
>Nick Coghlan wrote:
> > A custom generator will do nicely:
> > 
> > Py> def flatten(seq):
> > ...   for x in seq:
> > ... if hasattr(x, "__iter__"):
> > ...   for y in flatten(x):
> > ... yield y
> > ... else:
> > ...   yield x
> 
> Avoiding LBYL gives you:
>  def flatten(seq):
>  for x in seq:
>  try:
>  for y in flatten(x):
>  yield y
>  except TypeError:
>  yield x

  But totally messes up on error handling.  Instead:

def flatten(seq):
for x in seq:
try:
subseq = iter(x)
except TypeError:
yield x
else:
for subx in flatten(subseq):
yield subx

  to avoid catching TypeErrors from .next().

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


Re: get the IP address of a host

2005-01-06 Thread Jp Calderone
On Thu, 06 Jan 2005 14:35:16 +0100, J Berends <[EMAIL PROTECTED]> wrote:
>
>  From several approached I came up with the following code:
> 
> def getipaddr(hostname='default'):
>  """Given a hostname, perform a standard (forward) lookup and return
>  a list of IP addresses for that host."""
>  if hostname == 'default':
>  hostname = socket.gethostname()
>  ips = socket.gethostbyname_ex(hostname)[2]
>  ips = [i for i in ips if i.split('.')[0] != '127']
>  if len(ips) != 0:
>  # check if we have succes in determining outside IP
>  ip = ips[0]
>  elif len(ips) == 0 and hostname == socket.gethostname():
>  # when we want to determine local IP and did not have succes
>  # with gethostbyname_ex then we would like to connect to say... 
> 
>  # google.com and determine the local ip address bound to the
>  # local socket.
>  try:
>  s = socket.socket()
>  s.connect(('google.com', 80))
>  print ('___ connecting to internet to determine local ip')
>  ip = s.getsockname()[0]

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('1.2.3.4', 56))
ip = s.getsockname()[0]


>  del s
>  except:
>  print ('*** cannot connect to internet in order to \
> determine outside IP address')
>  raise Exception
>  if len(ip) != 0:
>  return ip
>  else:
>  print ('*** unable to determine outside IP address')
>  raise Exception
> 
> It returns the IP address with which it connects to the world (not lo), 
> might be a pvt LAN address or an internet routed IP. Depend on where the 
> host is.
> 
> I hate the google trick actually, so any suggestions to something better 
> is always welcome.

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


Re: sorting on keys in a list of dicts

2005-01-06 Thread Jp Calderone
On Thu, 06 Jan 2005 15:31:22 +0100, J Berends <[EMAIL PROTECTED]> wrote:
>Suppose I have a list of dictionaries and each dict has a common keyname 
> with a (sortable) value in it.
> 
> How can I shuffle their position in the list in such way that they 
> become sorted.
> 

  In Python 2.4,

import operator
L.sort(key=operator.itemgetter(key))

  In Python 2.3,

L2 = [(d[key], i, d) for (i, d) in enumerate(L)]
L2.sort()
L = [d for (v, i, d) in L2]

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


Re: Embedding a restricted python interpreter

2005-01-06 Thread Jp Calderone
On Thu, 06 Jan 2005 16:05:50 +0100, Peter Maas <[EMAIL PROTECTED]> wrote:
>Craig Ringer schrieb:
> > That is my understanding. In fact, I'd say with Python it's nearly
> > impossible given how dynamic everything is and the number of tricks that
> > can be used to obfuscate what you're doing. Think of the fun that can be
> > had with str.encode / str.decode and getattr/hasattr .
> 
> It would certainly be difficult to track all harmful code constructs.
> But AFAIK the idea of a sandbox is not to look at the offending code
> but to protect the offended objects: files, databases, URLs, sockets
> etc. and to raise a security exception when some code tries to offend
> them. Jython is as dynamic as C-Python and yet it generates class
> files behaving well under the JVM's security regime.
> 
> > 
> > I looked into this, and my conclusion ended up being "Well, I'm using
> > Python because I want it's power and flexibilty. If I want a secure
> > scripting environment, I should use something like Lua or Qt Script for
> > Applications instead."
> 
> It would be good for Python if it would offer a secure mode. Some
> time ago I asked my hosting provider whether I could use mod_python
> with apache to run Python scripts in the same way as PHP scripts.
> He denied that pointing to Python security issues and to PHP safe.
> mode. Python IS powerful but there are many areas where it is of
> vital interest who is allowed to use its power and what can be done
> with it. I think it would be a pity to exclude Python from these
> areas where a lot of programming/computing is done.

  A Python sandbox would be useful, but the hosting provider's excuse
for not allowing you to use mod_python is completely bogus.  All the 
necessary security tools for that situation are provided by the 
platform in the form of process and user separation.

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


Re: Embedding a restricted python interpreter

2005-01-06 Thread Jp Calderone
On 06 Jan 2005 07:32:25 -0800, Paul Rubin <"http://phr.cx"@nospam.invalid> 
wrote:
>Jp Calderone <[EMAIL PROTECTED]> writes:
> >   A Python sandbox would be useful, but the hosting provider's excuse
> > for not allowing you to use mod_python is completely bogus.  All the 
> > necessary security tools for that situation are provided by the 
> > platform in the form of process and user separation.
> 
> But mod_python is an apache module and runs in the same apache process
> with other users' scripts.

  I am uncertain as to how this differs from mod_php (the alternative 
discussed in the OP's story).  I've been away from PHP for a while, so 
perhaps mod_php has gained some features of which I am unaware?

  Jp

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


Re: Asyncore

2005-01-07 Thread Jp Calderone
On 7 Jan 2005 00:14:26 -0800, [EMAIL PROTECTED] wrote:
>Is there any tutorial and docs with samples how to use asyncore module?

  See these threads:
http://mail.python.org/pipermail/python-list/2004-March/214105.html

http://mail.python.org/pipermail/python-dev/2004-November/049819.html

  Then check out:

http://www.twistedmatrix.com/

  Hope this helps,

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


Re: "A Fundamental Turn Toward Concurrency in Software"

2005-01-08 Thread Jp Calderone
On Sat, 08 Jan 2005 14:22:30 GMT, Lee Harr <[EMAIL PROTECTED]> wrote:
>>> [http://www.gotw.ca/publications/concurrency-ddj.htm]. It argues that the 
> >> continous CPU performance gain we've seen is finally over. And that future 
> >> gain would primary be in the area of software concurrency taking advantage 
> >> hyperthreading and multicore architectures.
> >>
> 
> > Well, yes. However, it's not as bad as it looks. I've spent a good part
> > of my professional life with multiprocessors (IBM mainframes) and
> > I have yet to write a multi-thread program for performance reasons.
> > All of those systems ran multiple programs, not single programs
> > that had to take advantage of the multiprocessor environment.
> > Your typical desktop is no different. My current system has 42
> > processes running, and I'd be willing to bet that the vast majority
> > of them aren't multi-threaded.
> >
> 
> Exactly. If every one of your processes had its own 2 Ghz processor
> running nothing else, I think you would be pretty happy. Your OS
> had better be well-written to deal with concurrent access to
> memory and disks, but I think for general application development
> there will be huge speed boosts with little need for new
> programming paradigms.

  Not likely.  How often do you run 4 processes that are all 
bottlenecked on CPU?  It's not a common usage pattern.  If you
have 16 CPUs, and 15 of them are running mostly idle processes
and that *one* process you'd wish would hurry the heck up and 
finish has the 16th pegged at 100% usage, you are not a happy 
camper.

  For the case where you do have a lot of competing unrelated 
processes, no doubt SMP is a big win automatically, but there 
will still need to be language innovations to make it easier 
to develop software which can benefit from the additional 
hardware for the more common case of individual CPU hungry 
processes.

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


Re: smtplib and TLS

2005-06-21 Thread Jp Calderone
On 21 Jun 2005 08:39:02 -0700, Matthias Kluwe <[EMAIL PROTECTED]> wrote:
>> From: "Paul Rubin" "http://phr.cx"@NOSPAM.invalid
>
>>> "Matthias Kluwe" <[EMAIL PROTECTED]> writes:
>>> After getting a @gmail.com address, I recognized I had to use TLS in my
>>> python scripts using smtplib in order to get mail to the smtp.gmail.com
>>> server.
>
>>> [...]
>
>>> The server accepts and delivers my messages, but the last command
>>> raises
>
>>> socket.sslerror: (8, 'EOF occurred in violation of protocol')
>
>> [...]
>
>> Have you verified that its your end that is broken,  not gmail's,  do other
>> servers give the same response ?
>
>No, I have not -- I should have, as I know now: Connecting, starttls,
>login and sending mail works fine without the above mentioned error
>using my previous mail provider.
>
>Does that mean Gmail is in error here? I don't know...

Most SSL servers and clients (primarily HTTP, but some SMTP as well) are broken 
in this regard: they do not properly negotiate TLS connection shutdown.  This 
causes one end or the other to notice an SSL protocol error.  Most of the time, 
the only thing left to do after the TLS connection shutdown is normal TCP 
connection shutdown, so the error doesn't lead to any problems (which is 
probably why so much software generates this problem).  Of course, there's no 
way to *tell* if this is the case or not, at least programmatically.  If you 
receive an OK response to your DATA, you probably don't need to worry, since 
you have gotten what you wanted out of the conversation.

It's entirely possible that the fault here lies on gmail's end, but it is also 
possible that the fault is in your code or the standard library ssl support.  
Unless you want to dive into Python's OpenSSL bindings or start examining 
network traces of SSL traffic, you probably won't be able to figure out who's 
to blame in this particular case.  The simplest thing to do is probably just 
capture and discard that particular error (again, assuming you are getting an 
OK resposne to your DATA command).

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


Re: Hardening enviroment by overloading __import__?

2005-06-23 Thread Jp Calderone
On Thu, 23 Jun 2005 13:12:12 -0700, Steve Juranich <[EMAIL PROTECTED]> wrote:
>If this is a FAQ, please let me know where the answer is.
>
>I have in some code an 'eval', which I hate, but it's the shortest
>path to where I need to get at this point.  I thought that one way I
>could harden the enviroment against malicious code would be to
>temporarily disable the import statement by overloading __import__,
>but I tried what seemed obvious to me, and it didn't work.
>
>What I want do do is something like this:
>
>def __import__(*args, **kwargs):
>raise ImportError, 'Not so fast, bucko!'
>
>eval(potentially_dangerous_string)
>
>del __import__ # To get the builtin behavior back.
>
>Am I barking up the wrong tree with __import__?? Where should I look
>for this answer?

__builtin__.__import__ is what you need to replace.  Note, of course, that this 
only makes it trivially more difficult for malicious code to do destructive 
things: it doesn't even prevent the code from importing any module it likes, it 
just makes it take a few extra lines of code.

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


Re: webserver application (via Twisted?)

2005-06-24 Thread Jp Calderone
On Fri, 24 Jun 2005 12:35:40 GMT, flupke <[EMAIL PROTECTED]> wrote:
>I need to program and setup serveral webservices.
>If i were still using jsp, i would use Tomcat to make the several
>applications available on a given port.
>How can i accomplish this in Python?
>I was thinking about Twisted but it's not clear to me what parts i need
>to make a webserver listen on a certain port and having it serve
>different application based on the url that i received.
>
>Any advice on this?

Roughly,

from twisted.web import server, resource
from twisted.internet import reactor

root = resource.Resource()
root.putChild("app1", getApp1())
root.putChild("app2", getApp2())
...
site = server.Site(root)
reactor.listenTCP(80, site)
reactor.run()

You might also want to join the twisted-web mailing list: 
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

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


Re: Newbie question: how to keep a socket listening?

2005-06-24 Thread Jp Calderone
On Fri, 24 Jun 2005 21:21:34 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
>ncf wrote:
>> Heh, like I said. I was not at all sure. :P
>>
>> Nevertheless, could this be the problem? =\
>
>You *may* correct, mainly because the OP's code doesn't appear to spawn
>off new threads to handle the client connections, which means he can
>handle only one connection at a time.  Specifically, while he is talking
>to one client he is not also in an accept() call on the server socket,
>which means there will be (because of the listen(1) call) only a single
>pending connection allowed in the backlog.
>
>I haven't attempted a thorough analysis... just this much, trying to see
>whether it is obvious that the listen(1) is at fault -- and it's not
>obvious.  I thought this response might clarify the meaning of listen(1)
>a little bit for some folks nevertheless.

The argument to listen() is only a _hint_ to the TCP/IP stack.  Linux, at 
least, will not create a buffer large enough for only a single connection.  You 
can test this easily: create a socket, bind it to an address, call listen(1) on 
it, and *don't* call accept().  Telnet (or connect somehow) repeatedly, until 
your connection is not accepted.  On my system (Linux 2.6.10), I can connect 
successfully 8 times before the behavior changes.

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


Re: Newbie question: SOLVED (how to keep a socket listening), but still some questions

2005-06-24 Thread Jp Calderone
On Sat, 25 Jun 2005 01:36:56 -, Grant Edwards <[EMAIL PROTECTED]> wrote:
>On 2005-06-25, Giovanni Tumiati <[EMAIL PROTECTED]> wrote:
>
>> (2)Does one have to do a socket.shutdown() before one does a
>> socket.close??
>
>No.
>
>[I've never figured out why one would do a shutdown RDWR
>rather than close the connection, but I haven't put a lot of
>thought into it.]

shutdown actually tears down the TCP connection; close releases the file 
descriptor.

If there is only one file descriptor referring to the TCP connection, these are 
more or less the same.  If there is more than one file descriptor, though, the 
difference should be apparent.

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


Re: Background thread

2005-06-25 Thread Jp Calderone
On Sat, 25 Jun 2005 11:36:57 +0100, Jorge Louis De Castro <[EMAIL PROTECTED]> 
wrote:
>Hi,
>
>I'm new to python and I'm having trouble figuring out a way to have a thread 
>running on the background that over rules the raw_input function. The example 
>I'm working on is something like having a thread that prints "You're taking 
>too long" every 10 seconds, while waiting for input from the user.
>The problem is that I can only read (and in batch) the thread printout 
>messages on the console after giving something to raw_input.
>Is it not possible to have the thread print its stuff and then return to 
>raw_input() ? Any code examples or pseudo-code or documentation directions 
>will be highly appreciated.
>
>Thanks in advance
>

Here's one way you might do it without threads or raw_input()

  from twisted.protocols import basic, policies

  class AnnoyProtocol(basic.LineReceiver, policies.TimeoutMixin):
  from os import linesep as delimiter

  def connectionMade(self):
  self.setTimeout(10)

  def timeoutConnection(self):
  self.resetTimeout()
  self.sendLine("You're taking too long!")

  def lineReceived(self, line):
  self.resetTimeout()
  self.sendLine("Thank you for the line of input!")

  from twisted.internet import reactor, stdio
  stdio.StandardIO(AnnoyProtocol())
  reactor.run()

For fancy line editing support, twisted.conch.recvline might be of interest.

Hope this helps,

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


Re: a dictionary from a list

2005-06-25 Thread Jp Calderone
On Sat, 25 Jun 2005 09:10:33 -0400, Roy Smith <[EMAIL PROTECTED]> wrote:
>Terry Hancock <[EMAIL PROTECTED]> wrote:
>> Before the dict constructor, you needed to do this:
>>
>> d={}
>> for key in alist:
>> d[key]=None
>
>I just re-read the documentation on the dict() constructor.  Why does it
>support keyword arguments?
>
>   dict(foo="bar", baz="blah") ==> {"foo":"bar", "baz"="blah"}
>
>This smacks of creeping featurism.  Is this actually useful in real code?

Constantly.

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


Re: [Twisted-Python] Limiting number of concurrent client connections

2005-06-28 Thread Jp Calderone
On Tue, 28 Jun 2005 10:47:04 +0100, Toby Dickenson <[EMAIL PROTECTED]> wrote:
>Im finding that Win32Reactor raises an exception on every iteration of the
>main loop if I exceed the limit of 64 WaitForMultipleObjects.
>
>I would prefer to avoid this fairly obvious denial-of-service problem by
>limiting the number of concurrent client connections. Is there a standard
>solution for this?
>

Count the number of connections you have accepted.  When you get up to 62 or 63 
or so, stop accepting new ones.  If ServerFactory.buildProtocol() returns None, 
Twisted immediately closes the accepted connection.  If you do this (perhaps in 
conjunction with calling stopListening() on the port returned by listenXYZ()), 
you'll never overrun the 64 object limit.

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


Re: importing packages from a zip file

2005-06-29 Thread Jp Calderone
On Wed, 29 Jun 2005 18:49:10 +, Peter Tillotson <[EMAIL PROTECTED]> wrote:
>cheers Scott
>
>should have been
>from myZip.zip import base.branch1.myModule.py
>
>and no it didn't work, anyone know a reason why this syntax is not
>preferred ??
>
>sorry posted the soln again, it works but feels nasty

Including paths in source files is a disaster.  As soon as you do it, you need 
to account for alternate installation schemes by rewriting portions of your 
source files.

Separating path names from module names lets you avoid most of this mess.

Jp

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


Re: python broadcast socket

2005-06-29 Thread Jp Calderone
On Thu, 30 Jun 2005 00:13:45 +0200, Irmen de Jong <[EMAIL PROTECTED]> wrote:
>Grant Edwards wrote:
>
>> Under Linux, you need to be root to send a broadcase packet.
>
>I don't think this is true.
>

I think you're right.  I believe you just need to set the broadcast SOL_SOCKET 
option.

>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> s.sendto('asdljk', ('255.255.255.255', 12345))
Traceback (most recent call last):
  File "", line 1, in ?
socket.error: (13, 'Permission denied')
>>> s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
>>> s.sendto('asdljk', ('255.255.255.255', 12345))
6
>>> 

Yep, looks like it.

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


Re: Scket connection to server

2005-06-30 Thread Jp Calderone
On Thu, 30 Jun 2005 18:39:27 +0100, Steve Horsley <[EMAIL PROTECTED]> wrote:
>JudgeDread wrote:
>> hello python gurus
>>
>> I would like to establish a socket connection to a server running a service
>> on port 2. the host address is 10.214.109.50. how do i do this using
>> python?
>>
>> many thanks
>>
>>
>
>Off the top of my head (so there could be errors):
>

There are a few:

>import socket
>s = socket.Socket()

s = socket.socket()

>s.connect((10.214.109.50, 2))

s.connect(('10.214.109.50', 2))

>s.send("Hello, Mum\r\n")

s.sendall("Hello, Mum\r\n")

>
>That should point you in the right direction, anyway.
>
>There is a higher level socket framework called twisted that
>everyone seems to like. It may be worth looking at that too -
>haven't got round to it myself yet.

Twisted is definitely worth checking out.

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


Re: Favorite non-python language trick?

2005-07-01 Thread Jp Calderone
On Fri, 01 Jul 2005 15:02:10 -0500, Rocco Moretti <[EMAIL PROTECTED]> wrote:
>Joseph Garvin wrote:
>
>> I'm curious -- what is everyone's favorite trick from a non-python
>> language? And -- why isn't it in Python?
>
>I'm not aware of a language that allows it, but recently I've found
>myself wanting the ability to transparently replace objects. For
>example, if you have a transparent wrapper class around a certain
>object, and then determine that you no longer need to wrap the object,
>you can say the magic incantation, and the wrapper instance is replaced
>by what it is wrapping everywhere in the program. Or you have a complex
>math object, and you realize you can reduce it to a simple integer, you
>can substitue the integer for the math object, everywhere.
>
>I mainly look for it in the "object replaces self" form, but I guess you
>could also have it for arbitrary objects, e.g. to wrap a logging object
>around a function, even if you don't have access to all references of
>that function.
>
>Why isn't it in Python? It's completely counter to the conventional
>object semantics.

Smalltalk supports this with the "become" message.  I have also done an 
implementation of this for Python.

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-01 Thread Jp Calderone
On Fri, 01 Jul 2005 20:36:29 GMT, Ron Adam <[EMAIL PROTECTED]> wrote:
>Tom Anderson wrote:
>
>> So, if you're a pythonista who loves map and lambda, and disagrees with
>> Guido, what's your background? Functional or not?
>
>I find map too limiting, so won't miss it.  I'm +0 on removing lambda
>only because I'm unsure that there's always a better alternative.
>
>So what would be a good example of a lambda that couldn't be replaced?

lambda can always be replaced.  Just like a for loop can always be replaced:

iterator = iter()
while True:
try:
 = iterator.next()
except StopIteration:
break
else:


Let's get rid of for, too.

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-02 Thread Jp Calderone
On Sun, 03 Jul 2005 01:01:18 -0400, Christopher Subich <[EMAIL PROTECTED]> 
wrote:
>Steven D'Aprano wrote:
>> comps. But reduce can't be written as a list comp, only as a relatively
>> complex for loop at a HUGE loss of readability -- and I've never used
>> Lisp or Scheme in my life. I'm surely not the only one.
>
>See my reply to your other post for a more detailed explanation, but I
>don't think that the for-loop solution is much less readable at all, and
>the additional complexity involved is simply setting the initial value
>and result for the accumulator.  The for-loop solution is even more
>flexible, because it can include anonymous code blocks and not just
>expressions.
>
>One caevat that I just noticed, though -- with the for-solution, you do
>need to be careful about whether you're using a generator or list if you
>do not set an explicit initial value (and instead use the first value of
>'sequence' as the start).  The difference is:
>_accum = g.next()
>for i in g: _accum = stuff(_accum,i)
>
>versus
>_accum = g[0]
>for i in g[1:]: _accum = stuff(_accum,i)

In either case, you want to write:

  i = iter(g)
  _accum = i.next()
  for elem in i:
_accum = stuff(_accum, elem)

You also want to catch the StopIteration from that explicit .next() call, but 
that's an unrelated matter.

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


Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-03 Thread Jp Calderone
On Sun, 03 Jul 2005 14:43:14 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
>Steven D'Aprano wrote:
>> Frankly, I find this entire discussion very surreal. Reduce etc *work*,
>> right now. They have worked for years. If people don't like them, nobody
>> is forcing them to use them. Python is being pushed into directions which
>> are *far* harder to understand than map and reduce (currying, decorators,
>> etc) and people don't complain about those.
>
>I find it surreal too, for a different reason.
>
>Python *works*, right now.  It has worked for years.  If people don't
>like the direction it's going, nobody is forcing them to upgrade to the
>new version (which is not imminent anyway).
>
>In the unlikely event that the latest and greatest Python in, what, five
>years or more?, is so alien that one can't handle it, one has the right
>to fork Python and maintain a tried-and-true-and-still-including-reduce-
>-filter-and-map version of it, or even just to stick with the most
>recent version which still has those features.  And that's assuming it's
>not acceptable (for whatever bizarre reason I can't imagine) to use the
>inevitable third-party extension that will provide them anyway.
>
>I wonder if some of those who seem most concerned are actually more
>worried about losing the free support of a team of expert developers as
>those developers evolve their vision of the language, than about losing
>access to something as minor as reduce().

This is a specious line of reasoning.  Here's why:

Lots of people use Python, like Python, want to keep using Python.  Moreover, 
they want Python to improve, rather than the reverse.  Different people have 
different ideas about what "improve" means.  Guido has his ideas, and since 
he's the BDFL, those are the ideas most likely to influence the direction of 
Python's development.

However, Guido isn't the only person with ideas, nor are his ideas the only 
ones that should be allowed to influence the direction of Python's development. 
 Guido himself wouldn't even be silly enough to take this position.  He knows 
he is not the ultimate source of wisdom in the world on all matters programming 
related.

So when people disagree with him, suggesting that they should leave the Python 
community is ridiculous.  Just like Guido (and the overwhelming majority of the 
Python community - heck, maybe even all of it), these people are trying to 
improve the language.

Leaving the community isn't going to improve the language.  Continuing to 
operate actively within it just might.

For my part, I lack the time and energy to participate in many of these 
discussions, but anyone who knows me knows I'm not silent because I see eye to 
eye with Guido on every issue :)  I'm extremely greatful to the people who do 
give so much of their own time to try to further the Python language.

Suggesting people can "like it or lump it" is a disservice to everyone.

(Sorry to single you out Peter, I know you frequently contribute great content 
to these discussions too, and that there are plenty of other people who respond 
in the way you have in this message, but I had to pick /some/ post to reply to)

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


Re: Using regular expressions in internet searches

2005-07-03 Thread Jp Calderone
On 3 Jul 2005 10:49:03 -0700, [EMAIL PROTECTED] wrote:
>What is the best way to use regular expressions to extract information
>from the internet if one wants to search multiple pages? Let's say I
>want to search all of www.cnn.com and get a list of all the words that
>follow "Michael."
>
>(1) Is Python the best language for this? (Plus is it time-efficient?)
>Is there already a search engine that can do this?
>
>(2) How can I search multiple web pages within a single location or
>path?
>
>TIA,
>
>Mike
>

Is a google search for "site:cnn.com Michael" not up to the task?

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


Re: Favorite non-python language trick?

2005-07-03 Thread Jp Calderone
On Sun, 03 Jul 2005 15:40:38 -0500, Rocco Moretti <[EMAIL PROTECTED]> wrote:
>Jp Calderone wrote:
>> On Fri, 01 Jul 2005 15:02:10 -0500, Rocco Moretti
>> <[EMAIL PROTECTED]> wrote:
>>
>>>
>>> I'm not aware of a language that allows it, but recently I've found
>>> myself wanting the ability to transparently replace objects.
>>
>>
>> Smalltalk supports this with the "become" message.  I have also done an
>> implementation of this for Python.
>
>As a pure Python module, or do you have to recompile the interpreter?

Somewhere in between, I guess.  The module is all Python, but relies pretty 
heavily on one particular stdlib extension module.

The code is rather short, and online here:

  http://divmod.org/users/exarkun/become.py

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


Re: looping over a big file

2005-07-03 Thread Jp Calderone
On Sun, 3 Jul 2005 23:52:12 +0200, martian <[EMAIL PROTECTED]> wrote:
>Hi,
>
>I've a couple of questions regarding the processing of a big text file
>(16MB).
>
>1) how does python handle:
>
>> for line in big_file:
>
>is big_file all read into memory or one line is read at a time or a buffer
>is used or ...?

It uses an internal buffer to reach a happy medium between performance and 
memory usage.

>
>2) is it possible to advance lines within the loop? The following doesn't
>work:
>
>> for line in big_file:
> line_after  = big_file.readline()
>

Yes, but you need to do it like this:

  fileIter = iter(big_file)
  for line in fileIter:
  line_after = fileIter.next()

  Don't mix iterating with any other file methods, since it will confuse the 
buffering scheme.

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


Re: Use cases for del

2005-07-06 Thread Jp Calderone
On Wed, 06 Jul 2005 09:45:56 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
>Tom Anderson wrote:
>> How about just getting rid of del? Removal from collections could be
>> done with a method call, and i'm not convinced that deleting variables
>> is something we really need to be able to do (most other languages
>> manage without it).
>
>Arguing the case for del: how would I, in doing automated testing,
>ensure that I've returned everything to a "clean" starting point in all
>cases if I can't delete variables?  Sometimes a global is the simplest
>way to do something... how do I delete a global if not with "del"?
>

Unless you are actually relying on the global name not being defined, 
"someGlobal = None" would seem to do just fine.

Relying on the global name not being defined seems like an edge case.

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


Re: DNS access

2005-07-13 Thread Jp Calderone
On 13 Jul 2005 07:44:41 -0700, laksh <[EMAIL PROTECTED]> wrote:
>im looking for some advice regarding DNS lookup using python
>
>is it possible to give parameters like the IP of a DNS server and the
>DNS query to a python program and obtain the response from the DNS
>server ?
>

Not using the built-in hostname resolution functions.  There are a number of 
third-party DNS libraries:

  http://devel.it.su.se/projects/python-dns/

  http://pydns.sourceforge.net/

  http://dustman.net/andy/python/adns-python/

  http://twistedmatrix.com/projects/names/

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


Re: DNS access

2005-07-13 Thread Jp Calderone
On Wed, 13 Jul 2005 15:22:35 -0400, Chris Lambacher <[EMAIL PROTECTED]> wrote:
>reverse dns lookup is not really special compared to a regular dns lookup.
>you just need to look up a special name:
>http://www.dnsstuff.com/info/revdns.htm
>
>to format the ip address properly use something like:
>def rev_dns_string(ip_str):
>nums = ip_str.split('.').reverse()
>nums.extend(('in-addr', 'arpa'))
>return '.'.join(nums)
>

It may not be special, but it is different.  Reverse DNS uses PTR records, not 
A records.  The site you referenced points this out, too:

"""
Reverse DNS entries are set up with PTR records (whereas standard DNS uses A 
records), which look like "25.2.0.192.in-addr.arpa. PTR host.example.com" 
(whereas standard DNS would look like "host.example.com. A 192.0.2.25").
"""

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


Re: threads and sleep?

2005-07-14 Thread Jp Calderone
On 14 Jul 2005 05:10:38 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> 
wrote:
>Andreas Kostyrka <[EMAIL PROTECTED]> writes:
>> Basically the current state of art in "threading" programming doesn't
>> include a safe model. General threading programming is unsafe at the
>> moment, and there's nothing to do about that. It requires the developer
>> to carefully add any needed locking by hand.
>
>So how does Java do it?  Declaring some objects and functions to be
>synchronized seems to be enough, I thought.

Multithreaded Java programs have thread-related bugs in them too.  So it 
doesn't seem to be enough.  Like Python's model, Java's is mostly about 
ensuring internal interpreter state doesn't get horribly corrupted.  It doesn't 
do anything for application-level state.  For example, the following (Python, 
because it's way too early to write Java, but a straight port to Java would be 
broken in exactly the same way) program is not threadsafe:

things = []

def twiddle(thing):
if thing in things:
print 'got one'
things.remove(thing)
else:
print 'missing one'
things.append(thing)

The global list will never become corrupted.  stdout will always be fine 
(although perhaps a little weird).  The objects being appended to and removed 
from the list are perfectly safe.

But the program will double append items to the list sometimes, and raise 
ValueErrors from the list.remove() call sometimes.

Java's model isn't really too far from the traditional one.  It's a tiny bit 
safer, perhaps, but that's all.  For something different, take a look at 
Erlang's mechanism (this has been ported to Python, although I have heard 
nothing of the result since its release announcement, I wonder how it's doing?)

Hope this helps,

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


Re: how to get rate of pop3 receiving progress?

2005-07-14 Thread Jp Calderone

On Thu, 14 Jul 2005 17:09:10 +0800, Leo Jay <[EMAIL PROTECTED]> wrote:

when i use POP3.retr() in poplib module, the retr() function will not
return until the  receiving progress is finished

so, is there any way to get the rate of receiving progress?



An extremely rudamentary example of how you might do this using Twisted's POP3 
client support is attached.

Jp


pop3progress.py
Description: application/python
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Filtering out non-readable characters

2005-07-16 Thread Jp Calderone
On Sat, 16 Jul 2005 19:01:50 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
>George Sakkis wrote:
>> "Bengt Richter" <[EMAIL PROTECTED]> wrote:
>>> >>> identity = ''.join([chr(i) for i in xrange(256)])
>>
>> Or equivalently:
>identity = string.maketrans('','')
>
>Wow!  That's handy, not to mention undocumented.  (At least in the
>string module docs.)  Where did you learn that, George?
>

http://python.org/doc/lib/node109.html

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


Re: Need to interrupt to check for mouse movement

2005-07-20 Thread Jp Calderone
On Thu, 21 Jul 2005 00:18:58 -0400, Christopher Subich <[EMAIL PROTECTED]> 
wrote:
>Peter Hansen wrote:
>> stringy wrote:
>>
>>> I have a program that shows a 3d representation of a cell, depending on
>>> some data that it receives from some C++. It runs with wx.timer(500),
>>> and on wx.EVT_TIMER, it updates the the data, and receives it over the
>>> socket.
>>
>>
>> It's generally inappropriate to have a GUI program do network
>> communications in the main GUI thread.  You should create a worker
>> thread and communicate with it using Queues and possibly the
>> AddPendingEvent() or PostEvent() methods in wx.  There should be many
>> easily accessible examples of how to do such things.  Post again if you
>> need help finding them.
>
>I'd argue that point; it's certainly inappropriate to do
>(long-)/blocking/ network communications in a main GUI thread, but
>that's just the same as any blocking IO.  If the main thread is blocked
>on IO, it can't respond to the user which is Bad.
>
>However, instead of building threads (possibly needlessly) and dealing
>with synchronization issues, I'd argue that the solution is to use a
>nonblocking network IO package that integrates with the GUI event loop.
>  Something like Twisted is perfect for this task, although it might
>involve a significant application restructuring for the grandparent poster.
>
>Since blocking network IO is generally slow, this should help the
>grandparent poster -- I am presuming that "the program updating itself"
>is an IO-bound, rather than processor-bound process.

In the particular case of wxWidgets, it turns out that the *GUI* blocks for 
long periods of time, preventing the *network* from getting attention.  But I 
agree with your position for other toolkits, such as Gtk, Qt, or Tk.

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


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Jp Calderone
On Thu, 21 Jul 2005 00:51:45 -0400, Christopher Subich <[EMAIL PROTECTED]> 
wrote:
>Jp Calderone wrote:
>
>> In the particular case of wxWidgets, it turns out that the *GUI* blocks
>> for long periods of time, preventing the *network* from getting
>> attention.  But I agree with your position for other toolkits, such as
>> Gtk, Qt, or Tk.
>
>Wow, I'm not familiar with wxWidgets; how's that work?

wxWidgets' event loop doesn't differentiate between two unrelated (but similar 
sounding) concepts: blocking arbitrary input from the user (as in the case of 
modal dialogs) and blocking execution of code.

When you pop up a modal dialog, your code will not get another chance to run 
until the user dismisses it.  Similarly, as long as a menu is open, your code 
will not get to run.

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


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Jp Calderone
On 20 Jul 2005 22:06:31 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> 
wrote:
>Christopher Subich <[EMAIL PROTECTED]> writes:
>> > In the particular case of wxWidgets, it turns out that the *GUI*
>> > blocks for long periods of time, preventing the *network* from
>> > getting attention.  But I agree with your position for other
>> > toolkits, such as Gtk, Qt, or Tk.
>>
>> Wow, I'm not familiar with wxWidgets; how's that work?
>
>Huh?  It's pretty normal, the gui blocks while waiting for events
>from the window system.  I expect that Qt and Tk work the same way.

But not Gtk? :)  I meant what I said: wxWidgets behaves differently in this 
regard than Gtk, Qt, and Tk.

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


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Jp Calderone
On Thu, 21 Jul 2005 05:42:32 -, Donn Cave <[EMAIL PROTECTED]> wrote:
>Quoth Paul Rubin <http://[EMAIL PROTECTED]>:
>| Christopher Subich <[EMAIL PROTECTED]> writes:
>| > > In the particular case of wxWidgets, it turns out that the *GUI*
>| > > blocks for long periods of time, preventing the *network* from
>| > > getting attention.  But I agree with your position for other
>| > > toolkits, such as Gtk, Qt, or Tk.
>| >
>| > Wow, I'm not familiar with wxWidgets; how's that work?
>|
>| Huh?  It's pretty normal, the gui blocks while waiting for events
>| from the window system.  I expect that Qt and Tk work the same way.
>
>In fact anything works that way, that being the nature of I/O.
>But usually there's a way to add your own I/O source to be
>dispatched along with the UI events -- the toolkit will for
>example use select() to wait for X11 socket I/O, so it can also
>respond to incoming data on another socket, provided along with a
>callback function by the application.
>
>Am I hearing that wxWindows or other popular toolkits don't provide
>any such feature, and need multiple threads for this reason?
>

Other popular toolkits do.  wxWindows doesn't.

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


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Jp Calderone
On Thu, 21 Jul 2005 02:33:05 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
>Jp Calderone wrote:
>> In the particular case of wxWidgets, it turns out that the *GUI* blocks
>> for long periods of time, preventing the *network* from getting
>> attention.  But I agree with your position for other toolkits, such as
>> Gtk, Qt, or Tk.
>
>Are you simply showing that there are two points of view here, that one
>can look at the wx main loop as being "blocking", waiting for I/O, even
>though it is simply doing asynchronous event-driven processing the same
>as Twisted?  Or am I missing something?  Allowing for the fact that wx
>blocks, not just for long periods of time, but *indefinitely* (as long
>as no events are arriving) I still don't see how that makes it different
>from Twisted or from any other typical GUI framework, which do exactly
>the same thing.  (And since there is even a wxPython main loop
>integrated with and provided in Twisted, surely you aren't arguing that
>what wx does is somehow unusual or bad.)

Providing wx support in Twisted has been orders of magnitude more difficult 
than providing Tk, Qt, or Gtk support has been.  And wxsupport and wxreactor 
are each broken in slightly different ways, so I wouldn't say we've been 
successful, either.

Blocking inside the mainloop while waiting for events is fine.  It's blocking 
elsewhere that is problematic.

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


Re: Buffering problem using subprocess module

2005-07-21 Thread Jp Calderone
On 21 Jul 2005 06:14:25 -0700, "Dr. Who" <[EMAIL PROTECTED]> wrote:
>I am using the subprocess module in 2.4.  Here's the fragment:
>
>bufcaller.py:
>   import sys, subprocess
>   proc = subprocess.Popen('python bufcallee.py', bufsize=0, shell=True,
>stdout=subprocess.PIPE)
>   for line in proc.stdout:
>   sys.stdout.write(line)
>
>bufcallee.py:
>   import time
>   print 'START'
>   time.sleep(10)
>   print 'STOP'
>
>Although the documentation says that the output should be unbuffered
>(bufsize=0) the program (bufcaller) pauses for 10 seconds and then
>prints START immediately followed by 'STOP' rather than pausing 10
>seconds in between them.  Note that I made bufcallee a Python script
>for ease of the example but in the real-world problem I am trying to
>solve it is simply an executable.
>
>Any ideas?

There are a few places buffering can come into play.  The bufsize parameter to 
Popen() controls buffering on the reading side, but it has no effect on 
buffering on the writing side.  If you add a sys.stdout.flush() after the 
prints in the child process, you should see the bytes show up immediately.  
Another possibility is to start Python in unbuffered mode (pass the -u flag, or 
set PYTHONUNBUFFERED in the environment), but obviously this only applies to 
Python programs.  Still another possibility (generally the nicest) is to use a 
PTY instead of a pipe: when the C library sees stdout is a pipe, it generally 
decides to put output into a different buffering mode than when it sees stdout 
is a pty.  I'm not sure how you use ptys with the subprocess module.

Hope this helps,

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


Re: Stupid question: Making scripts python-scripts

2005-07-21 Thread Jp Calderone
On Thu, 21 Jul 2005 16:34:30 +0200, Jan Danielsson <[EMAIL PROTECTED]> wrote:
>Hello all,
>
>   How do I make a python script actually a _python_ in unix:ish
>environments?
>
> [snip]

Put "#!/usr/bin/python".  Install the program using distutils: if necessary, 
distutils will rewrite the #! line to fit the configuration of the system the 
program is being installed on.

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


Re: Overriding a built-in exception handler

2005-07-21 Thread Jp Calderone
On 21 Jul 2005 07:39:10 -0700, [EMAIL PROTECTED] wrote:
>I'm having a tough time figuring this one out:
>
>
>class MyKBInterrupt( . ):
>   print "Are you sure you want to do that?"
>
>if __name__ == "__main__":
>   while 1:
>   print "Still here..."
>
>
>So this thing keeps printing "Still here..." until the user hits ctl-c,
>at which time the exception is passed to MyKBInterrupt to handle the
>exception, rather than to whatever the built-in handler would be.
>
>I've Read-TFM, but I only see good info on how to create my own class
>of exception;  I don't see anything on how to override an existing
>exception handler.
>
>Thanks in advance for any help.

See excepthook in the sys module documentation: 

  http://python.org/doc/lib/module-sys.html

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


Re: Simple Problem

2005-07-24 Thread Jp Calderone
On 24 Jul 2005 18:14:13 -0700, ncf <[EMAIL PROTECTED]> wrote:
>I know I've seen this somewhere before, but does anyone know what the
>function to escape a string is? (i.e., encoding newline to "\n" and a
>chr(254) to "\xfe") (and visa-versa)
>
>Thanks for helping my ignorance :P

Python 2.4.1 (#2, Mar 30 2005, 21:51:10) 
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> '\n\xfe'.encode('string-escape')
'\\n\\xfe'
>>> '\\n\\xfe'.decode('string-escape')
'\n\xfe'
>>> 

  Introduced in Python 2.3

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


RE: Terminate a thread that doesn't check for events

2005-08-02 Thread Jp Calderone
On Tue, 2 Aug 2005 09:51:31 -0400, Liu Shuai <[EMAIL PROTECTED]> wrote:
>Can someone please comment on this?
>
> [snip - how to stop a thread without its cooperation?]

There's no way to do this with threads, sorry.

Perhaps you could use a child process, instead.  Those are typically easy to 
terminate at arbitrary times.

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


Re: Creating a graphical interface on top of SSH. How?

2005-08-16 Thread Jp Calderone
On 16 Aug 2005 07:10:25 -0700, "John F." <[EMAIL PROTECTED]> wrote:
>I want to write a client app in Python using wxWindows that connects to
>my FreeBSD server via SSH (using my machine account credentials) and
>runs a python or shell script when requested (by clicking a button for
>instance).
>
>Can someone give me some advice on how to create a "graphical shell"
>per se?

tkconch might be interesting to look at.  
http://www.twistedmatrix.com/projects/conch/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic Server/Client socket pair not working

2005-08-29 Thread Jp Calderone
On Mon, 29 Aug 2005 21:30:51 +0200, Michael Goettsche <[EMAIL PROTECTED]> wrote:
>Hi there,
>
>I'm trying to write a simple server/client example. The client should be able
>to send text to the server and the server should distribute the text to all
>connected clients. However, it seems that only the first entered text is sent
>and received. When I then get prompted for input again and press return,
>nothing gets back to me. Any hints on what I have done would be very much
>appreciated!

You aren't handling readiness notification properly.  Twisted is a good way to 
not have to deal with all the niggling details of readiness notification.  I 
haven't trotted out this example in a while, and it's /almost/ appropriate here 
;) so...

http://www.livejournal.com/users/jcalderone/2660.html

Of course, that's highly obscure and not typical of a Twisted application.  
Nevertheless, I believe it satisfies your requirements.  You might want to take 
a look at http://twistedmatrix.com/projects/core/documentation/howto/index.html 
for a gentler introduction, though.  In particular, the client and server 
HOWTOs.

I'll comment on your code below.

>
>Here's my code:
>
> SERVER ##
>import socket
>import select
>
>mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>mySocket.bind(('', 1))
>mySocket.listen(1)
>
>clientlist = []
>
>while True:
>   connection, details = mySocket.accept()
>   print 'We have opened a connection with', details
>   clientlist.append(connection)
>   readable = select.select(clientlist, [], [])
>   msg = ''
>   for i in readable[0]:

You'll need to monitor sockets for disconnection.  The way you do this varies 
between platforms.  On POSIX, a socket will become readable but reading from it 
will return ''.  On Win32, a socket will show up in the exceptions set (which 
you are not populating).  With the below loop, your server will go into an 
infinite loop whenever a client disconnects, because the chunk will be empty 
and the message will never get long enough to break the loop.

>  while len(msg) < 1024:
> chunk = i.recv(1024 - len(msg))
> msg = msg + chunk

Additionally, select() has only told you that at least /one/ recv() call will 
return without blocking.  Since you call recv() repeatedly, each time through 
the loop after the first has the potential to block indefinitely, only 
returning when more bytes manage to arrive from the client.  This is most 
likely the cause of the freezes you are seeing.  Instead, call recv() only once 
and buffer up to 1024 (if this is really necessary - I do not think it is) over 
multiple iterations through the outermost loop (the "while True:" loop).

>
>   for i in clientlist:
>  totalsent = 0
>  while totalsent < 1024:
> sent = i.send(msg)
> totalsent = totalsent + sent

This isn't quite right either - though it's close.  You correctly monitor how 
much of the message you have sent to the client, since send() may not send the 
entire thing.  However there are two problems.  One is trivial, and probably 
just a think-o: each time through the loop, you re-send `msg', when you 
probably meant to send `msg[totalsent:]' to avoid duplicating the beginning of 
the message and losing the end of it.  The other problem is that the send() 
call may block.  You need to monitor each socket for write-readiness (the 2nd 
group of sockets to select()) and only call send() once for each time a socket 
appears as writable.

>
>## CLIENT 
>import socket
>import select
>
>socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>socket.connect(("127.0.0.1", 1))
>
>while True:
>text = raw_input("Du bist an der Reihe")
>text = text + ((1024 - len(text)) * ".")
>totalsent = 0
>while totalsent < len(text):
>sent = socket.send(text)
>totalsent = totalsent + sent

Similar problem here as in the server-side send() loop - 
`send(text[totalsent:])' instead of sending just `text'.

>
>msg = ''
>while len(msg) < 1024:
>chunk = socket.recv(1024 - len(msg))
>msg = msg + chunk

This is problematic too, since it means you will only be able to send one 
message for each message received from the server, and vice versa.  Most chat 
sessions don't play out like this.

>
>print msg

I encourage you to take a look at Twisted.  It takes care of all these little 
details in a cross-platform manner, allowing you to focus on your unique 
application logic, rather than solving the same boring problems that so many 
programmers before you have solved.

Hope this helps,

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


Re: python and ajax

2005-08-29 Thread Jp Calderone
On Mon, 29 Aug 2005 12:04:46 -0700 (PDT), Steve Young <[EMAIL PROTECTED]> wrote:
>Hi, I was wondering if anybody knew of any good
>tutorial/example of AJAX/xmlhttprequest in python.
>Thanks.
>

There's a short example of Nevow's LivePage online here: 
http://divmod.org/svn/Nevow/trunk/examples/livepage/livepage.py

It's not a tutorial by itself, but if you poke around some of the other 
examples and read http://divmod.org/projects/nevow and some of the documents it 
references, you should be able to figure things out.

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


Re: Using select on a unix command in lieu of signal

2005-08-29 Thread Jp Calderone
 Success!  Pass on our output.
self.onCompletion.callback(''.join(self.output)))

# Misc. cleanup
self.onCompletion = None
self.output = None

def runCmd(executable, args, timeout=None, **kw):
d = defer.Deferred()
p = TimeoutOutputProcessProtocol(d, timeout)
reactor.spawnProcess(p, executable, args, **kw)
return d

And there you have it.  It's a bit longer, but that's mostly due to the 
comments.  The runCmd function has a slightly different signature too, since 
spawnProcess can control a few more things than Popen3, so it makes sense to 
make those features available (these include setting up the child's environment 
variables, the UID and GID it will run as, whether or not to allocate a PTY for 
it, and the working directory it is given).  The return value differs too, of 
course: it's a Deferred instead of a two-tuple, but it will eventually fire 
with roughly the same information.

Hope this helps,

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


Re: Sockets: code works locally but fails over LAN

2005-08-31 Thread Jp Calderone
On 31 Aug 2005 06:03:00 -0700, n00m <[EMAIL PROTECTED]> wrote:
>import socket, thread
>host, port = '192.168.0.3', 1434
>s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>s2.connect((host, 1433))
>s1.bind((host, port))
>s1.listen(1)
>cn, addr = s1.accept()
>
>def VB_SCRIPT():
>while 1:
>data = cn.recv(4096)
>if not data: return
>s2.send(data)
>print 'VB_SCRIPT:' + data + '\n\n'
>
>def SQL_SERVER():
>while 1:
>data = s2.recv(4096)
>if not data: return
>cn.send(data)
>print 'SQL_SERVER:' + data + '\n\n'
>
>thread.start_new_thread(VB_SCRIPT,())
>thread.start_new_thread(SQL_SERVER,())

This is about the same as:

mktap portforward --port 1434 --host 192.168.0.3 --dest_port 1433
twistd -f portforward.tap

You'll find the code behind these two commands here:

<http://cvs.twistedmatrix.com/cvs/trunk/twisted/tap/portforward.py?view=markup&rev=13278>

and here:

<http://cvs.twistedmatrix.com/cvs/trunk/twisted/protocols/portforward.py?view=markup&rev=12914>

And of course, the main Twisted site is <http://twistedmatrix.com/>.

Some differences between portforward.tap and your code include:

portforward.tap will accept multiple connections, rather than just one.  
portforward.tap won't print out all the bytes it receives (I assume this is 
just for debugging purposes anyway - if not, a simple modification will cause 
it to do this).  portforward.tap won't non-deterministically drop traffic, 
since Twisted checks the return value of send() and properly re-transmits 
anything which has not actually been sent.

Hope this helps,

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


Re: threading.Thread vs. signal.signal

2005-09-17 Thread Jp Calderone
On Sat, 17 Sep 2005 19:24:54 -0400, Jack Orenstein <[EMAIL PROTECTED]> wrote:
>I'd like to create a program that invokes a function once a second,
>and terminates when the user types ctrl-c. So I created a signal
>handler, created a threading.Thread which does the invocation every
>second, and started the thread. The signal handler seems to be
>ineffective. Any idea what I'm doing wrong? This is on Fedora FC4 and
>Python 2.4.1. The code appears below.
>
>If I do the while ... sleep in the main thread, then the signal
>handler works as expected. (This isn't really a satisfactory
>implementation because the function called every second might
>take a significant fraction of a second to execute.)
>
>Jack Orenstein
>
>
>import sys
>import signal
>import threading
>import datetime
>import time
>
>class metronome(threading.Thread):
> def __init__(self, interval, function):
> threading.Thread.__init__(self)
> self.interval = interval
> self.function = function
> self.done = False
>
> def cancel(self):
> print '>>> cancel'
> self.done = True
>
> def run(self):
> while not self.done:
> time.sleep(self.interval)
> if self.done:
> print '>>> break!'
> break
> else:
> self.function()
>
>def ctrl_c_handler(signal, frame):
> print '>>> ctrl c'
> global t
> t.cancel()
> sys.stdout.close()
> sys.stderr.close()
> sys.exit(0)
>
>signal.signal(signal.SIGINT, ctrl_c_handler)
>
>def hello():
> print datetime.datetime.now()
>
>t = metronome(1, hello)
>t.start()

The problem is that you allowed the main thread to complete.  No longer 
running, it can no longer process signals.  If you add something like this to 
the end of the program, you should see the behavior you wanted:

while not t.done:
time.sleep(1)

Incidentally, the last 3 lines of ctrl_c_handler aren't really necessary.

That said, here's a simpler version of the same program, using Twisted:

import datetime
from twisted.internet import reactor, task

def hello():
print datetime.datetime.now()

task.LoopingCall(hello).start(1, now=False)
reactor.run()

Hope this helps!

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


Re: Can someone explain what I've done wrong...

2005-09-17 Thread Jp Calderone
On Sun, 18 Sep 2005 02:10:50 +0100, Jason <[EMAIL PROTECTED]> wrote:
>Hi,
>
>I'm following a tutorial about classes, and have created the following
>(well, copied it from the manual buy added my own and wifes names)...
>
>class Person:
> population=0
>
> def __init__(self,name):
> self.name=name
> print '(Initialising %s)' % self.name
> Person.population += 1
>
> def __del__(self):
> print "%s says bye." % self.name
>
> Person.population -= 1
>
> if Person.population == 0:
> print "I am the last one"
> else:
> print "There are still %d people left." % Person.population
>
> def sayHi(self):
> '''Greeting by the person.
>
> That's all it does.'''
> print "Hi, my name is %s" % self.name
>
> def howMany(self):
> if Person.population==1:
> print "I am on the only person here."
> else:
> print "We have %d persons here." % Person.population
>
>Jason=Person("Jason")
>Jason.sayHi()
>Jason.howMany()
>
>Sophie=Person("Sophie")
>Sophie.sayHi()
>Sophie.howMany()
>
>Jason.sayHi()
>
>The code, when run, should produce the following...
>
>Hi, my name is Jason.
>I am the only person here.
>(Initializing Sophie)
>Hi, my name is Sophie.
>We have 2 persons here.
>Hi, my name is Jason.
>We have 2 persons here.
>Jason says bye.
>There are still 1 people left.
>Sophie says bye.
>I am the last one.
>
>But what I actually get is...
>
>(Initialising Jason)
>Hi, my name is Jason
>I am on the only person here.
>(Initialising Sophie)
>Hi, my name is Sophie
>We have 2 persons here.
>Hi, my name is Jason
>We have 2 persons here.
>Jason says bye.
>There are still 1 people left.
>Sophie says bye.
>Exception exceptions.AttributeError: "'NoneType' object has no attribute
>'popula
>tion'" in 0x0097B53
>0>> ignored
>
>I've looked through the code but can't find anything obvious.
>
>I also want to apologise if this isn't the write newsgroup to post on,
>but it's the only one I know of.  IF anyone knows a good newsgroup, I'd
>appreciate it.
>
>TIA

The __del__ method is not a reliable cleanup mechanism.  It runs when an object 
is garbage collected, but garbage collection is unpredictable and not 
guaranteed to ever occur.

In your particular case, __del__ is running during interpreter shut down.  
Another part of interpreter shutdown is to set the attributes of all modules to 
None.  Your code executes after this, tries to change None.population (since 
Person is now None), and explodes.

Your best bet is not to use __del__ at all.  Instead, add a method to be 
invoked when a person is going away, and then invoke it.

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


Re: Crypto.Cipher.ARC4, bust or me doing something wrong?

2005-09-20 Thread Jp Calderone
On Tue, 20 Sep 2005 16:08:19 +0100, Michael Sparks <[EMAIL PROTECTED]> wrote:
>Hi,
>
>
>I suspect this is a bug with AMK's Crypto package from
>http://www.amk.ca/python/code/crypto , but want to
>check to see if I'm being dumb before posting a bug
>report.
>
>I'm looking at using this library and to familiarise myself writing
>small tests with each of the ciphers. When I hit Crypto.Cipher.ARC4 I've
>found that I can't get it to decode what it encodes. This might be a
>case of PEBKAC, but I'm trying the following:
>
>>>> from Crypto.Cipher import ARC4 as cipher
>>>> key = ""
>>>> obj = cipher.new(key)
>>>> obj.encrypt("This is some random text")
>')f\xd4\xf6\xa6Lm\x9a%}\x8a\x95\x8ef\x00\xd6:\x12\x00!\xf3k\xafX'
>>>> X=_
>>>> X
>')f\xd4\xf6\xa6Lm\x9a%}\x8a\x95\x8ef\x00\xd6:\x12\x00!\xf3k\xafX'
>>>> obj.decrypt(X)
>'\x87\xe1\x83\xc1\x93\xdb\xed\x93U\xe4_\x92}\x9f\xdb\x84Y\xa3\xd4b\x9eHu~'
>
>Clearly this decode doesn't match the encode. Me being dumb or bug?
>
>Any comments welcome :)
>

You need two ARC4 instances.  Performing any operation alters the internal 
state (as it is a stream cipher), which is why your bytes did not come out 
intact.

  >>> import Crypto.Cipher.ARC4 as ARC4
  >>> o = ARC4.new('hello monkeys')
  >>> p = ARC4.new('hello monkeys')
  >>> p.decrypt(o.encrypt('super secret message of doom'))
  'super secret message of doom'
  >>>

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


Re: Threading, real or simulated?

2005-09-21 Thread Jp Calderone
On Wed, 21 Sep 2005 18:23:33 -0500, Sam <[EMAIL PROTECTED]> wrote:
>I'm using Python 2.3.5 with pygtk 2.4.1, and I'm using the second threading 
>approach from pygtk's FAQ 20.6 - invoking "gtk.gdk.threads_init()", and 
>wrapping all gtk/gdk function calls with 
>gtk.threads_enter()/gtk.threads_leave()
>
>I start a thread, via thread.Threading.start().  The thread then calls a 
>particularly time consuming C function, from an extension module.  I find 
>that when the thread is running the C code, the GUI hangs even though I'm 
>not inside the threads_enter/threads_leave territory.
>

  Does the extension module release the GIL?  It sounds like it does not.  Of 
course, there are a dozen other mistakes that could be made which would have 
roughly this symptom.  It's difficult to say which is the problem without 
actually seeing any code.

>It looks like thread.Threading() only simulates threading, by having the 
>python interpreter multiplex between running threads.  Is real threading 
>possible, so that I do something time-consuming in the thread, without 
>hanging the GUI?
>

Assuming you mean threading.Thread, this is a native thread.  It is not a 
simulation.  Something else is going wrong.

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


Re: [PATCH] Re: frozenset() without arguments should return a singleton

2005-02-12 Thread Jp Calderone
On Sat, 12 Feb 2005 23:21:58 +0100, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>
> 
> Raymond Hettinger wrote:
>  >Stefan Behnel wrote:
> >>I stumbled over the fact that 'frozenset()' doesn't return a constant but
> >>creates a new object everytime. Since it is immutable, I wrote to  c.l.py 
> >>that this behaviour is different from what tuple() & Co do.
> > 
> > It is not quite correct to say that this is what all immutables do:
> > 
> > 
> >.>>>x = 500
> >.>>>y = 600 - 100
> >.>>>x is y
> > False
> 
> I know. The same is true for concateneted strings, etc. But whenever an 
> immutable object is created directly ('by hand'), it holds. It also holds, 
> btw, for tuple() - as opposed to ().
> 

$ python
Python 2.3.5c1 (#2, Feb  4 2005, 10:10:56) 
    [GCC 3.3.5 (Debian 1:3.3.5-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> long() is long()
False
>>> 

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


Sequence of empty lists

2005-02-22 Thread JP. Baker
I give up (and have prepared myself for replies telling
me which search strings to use on Google etc)!

How *should* I create a sequence of N empty lists (buckets)?

I obviously can't use

a = [[]]*N

and I have found various solutions and am currently using

a = map(lambda x: [], range(N))

but can't help feeling that I have missed something obvious.

nhoJ
-- 
John P Baker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replacing words from strings except 'and' / 'or' / 'and not'

2004-11-28 Thread Jp Calderone
On 28 Nov 2004 15:33:13 -0800, [EMAIL PROTECTED] (John Machin) wrote:
>Skip Montanaro <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> > >> > Is there a reason to use sets here? I think lists will do as well.
> > >> 
> > >> Sets are implemented using dictionaries, so the "if w in KEYWORDS"
> > >> part would be O(1) instead of O(n) as with lists...
> > >> 
> > >> (I.e. searching a list is a brute-force operation, whereas
> > >> sets are not.)
> > 
> > Jp>   And yet... using sets here is slower in every possible case:
> > ...
> > Jp>   This is a pretty clear example of premature optimization.
> > 
> > I think the set concept is correct.  The keywords of interest are best
> > thought of as an unordered collection.  Lists imply some ordering (or at
> > least that potential).  Premature optimization would have been realizing
> > that scanning a short list of strings was faster than testing for set
> > membership and choosing to use lists instead of sets.
> > 
> > Skip
> 
> Jp scores extra points for pre-maturity by not trying out version 2.4,
> by not reading the bit about sets now being built-in, based on dicts,
> dicts being one of the timbot's optimise-the-snot-out-of targets ...
> herewith some results from a box with a 1.4Ghz Athlon chip running
> Windows 2000:
> 
> [snip - builtin `set' faster than sets.Set]

  John,

Thanks for pointing out the existence of the new, built-in set type.  I was 
well aware of it and the performance improvements it brings, but others may not 
have been.  Since Python 2.4 hasn't actually be released yet, I don't think it 
could be of any help to the original poster, although I am well aware of the 
proclivity of a significant portion of the Python community to eagerly begin 
developing against pre-release versions of Python.

Since the code I was claiming suffered from premature optimization didn't 
use the set type, I'm not sure of the relevance of this point.  In fact, it is 
trivially _more_ work to convert from usage of sets.Set to usage of set than it 
is to convert from usage of lists to usage of set.  If anything, the list 
version would have been easier to migrate, once 2.4 was a suitable deployment 
platform.

As Skip pointed out, though, Sets can be seen as a conceptually better fit 
for the problem, so the performance or simplified migration of lists over 
set.Sets is hardly a justification for the use of lists.  My post was intended 
solely to rebut the position that sets.Set would desirable because they were 
more efficient, as the poster to whom I was responding had claimed.  I also 
tried to emphasize the fact that optimization is senseless without first 
identifying bottlenecks and that the function in question almost certainly was 
not even a blip on the performance radar of the program to which it belonged, 
but perhaps I was not sufficiently clear on that point.

  In any case, thanks for the points.  I'll try to exchange them for some alms 
at the next town. :)

  Hope this resolves some confusion,

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


Re: Closing files

2004-11-28 Thread Jp Calderone
On Sun, 28 Nov 2004 18:59:31 -0600, [EMAIL PROTECTED] (Henrik Holm) wrote:
>I have recently started playing around with Python.  Some of the things
> I have done have involved reading files.  The way I do this is along the
> lines of
> 
> [snip]

  http://www.google.com/search?q=site%3Amail.python.org+file+closing

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


Re: asynchat and threading

2004-11-29 Thread Jp Calderone
On Mon, 29 Nov 2004 16:05:14 -0500, "Eric S. Johansson" <[EMAIL PROTECTED]> 
wrote:
> If I could simply do: py-get twisted
> and have all of the dependencies resolved, it would be wonderful.  as a 
> prototype, I would suggest wrapping apt-get with a python envelope which 
>   automatically invokes apt-get with a python specific configuration 
> file for .pydeb files as well as a private repository and database etc.. 
>   Since apt-get exists for almost every version of Linux and should be 
> portable to other platforms, this distribution method should be 
> relatively distribution portable.
> 
> One can also handle upgrades of the core image of Python and ancillary 
> packages as well by leaving a breadcrumb file indicating which packaging 
> system is native and the package currently installed. <<- idea needs work
> 
> yea? nay?
> 

  Why not use apt-get?

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


Re: Class methods in Python/C?

2004-11-30 Thread Jp Calderone
On Tue, 30 Nov 2004 22:39:15 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote:
>Craig Ringer wrote:
> > Hi folks
> > 
> > I've been doing some looking around, but have been unable to find out
> > how to implement class methods on Python objects written in C. "Why are
> > you using C?" you ask?
> > 
> > Yeah, so do I. However, I need to provide bindings for an application
> > that Python is embedded into, and thanks to Qt the bindings are going to
> > be both simple and quite powerful. However, I need a way to do class
> > methods...
> > 
> > If anybody has any tips on this, It'd be much appreciated.
> 
> You probably want to look at staticmethod(). (classmethod() is slightly 
> different, and probably not what you want. In fact, classmethod() is 
> practically 
> *never* what you want. Guido wrote it himself, and even he ended up not using 
> it)

  Funny, I find the exact opposite to be the case... ;)  Static methods are 
glorified free functions, but class methods participate usefully in inheritence 
hierarchies - why would anyone want the former?

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


Re: SOAPpy/ZSI/Twisted SOAP over stdin/stdout?

2004-11-30 Thread Jp Calderone
On Tue, 30 Nov 2004 14:25:50 GMT, Harry George <[EMAIL PROTECTED]> wrote:
>Normally the SOAP Servers are designed to take control of a port and
> run their own sockets via inheritance from SocktServer.
> 
> But under inetd and xinetd, the port is controlled elsewhere and the
> service just gets the stdin/stdout. I need to configure (or tweak) one
> of the SOAP servers to use that connection.
> 
> Has anyone done this with any of the above named SOAP servers?
> Recommmendations or hints if I try it myself?
> 

  Twisted can run any protocol over stdio.

  Check out

http://twistedmatrix.com/documents/current/examples/stdin.py

  and

http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

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


Re: module imports and memory usage

2004-11-30 Thread Jp Calderone
On Tue, 30 Nov 2004 10:02:27 -0500, Brad Tilley <[EMAIL PROTECTED]> wrote:
>When memory usage is a concern, is it better to do:
> 
> from X import Y
> 
> or
> 
> import X

  There is no difference.  If you are concerned about memory usage, you 
probably need to take a look at the data structures holding your application's 
data, and find a way to make them smaller (most commonly, this is done by 
selecting a new algorithm that works on a sparser data structure).  This isn't 
specific to Python, of course.

> 
> Also, is there a way to load and unload modules as they are needed. I 
> have some scripts that sleep for extended periods during a while loop 
> and I need to be as memory friendly as possible. I can post a detailed 
> script that currently uses ~ 10MB of memory if anyone is interested.

  Not really, no.  Deleting all references to a module may cause the module 
object to be collected by the vm, but there is no guarantee that the memory it 
used will be released to the platform.  It's possible Python will re-use it for 
the next object it needs memory for, which may help your memory problems if you 
are loading many (_many_) more modules than you ever use at once.

  On a reasonable platform, if your program is sleeping, much of the memory it 
uses will be swapped out, especially if other processes need it.  Are you sure 
you have good reason to be concerned over the size of the program?

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


Re: pre-PEP generic objects

2004-11-30 Thread Jp Calderone
On Tue, 30 Nov 2004 17:52:33 -0500, =?iso-8859-1?Q?Fran=E7ois?= Pinard <[EMAIL 
PROTECTED]> wrote:
>[Scott David Daniels]
> 
> > You can simplify this:
> > class Hash(object):
> > def __init__(self, **kwargs):
> > for key,value in kwargs.items():
> > setattr(self, key, value)
> 
> Might it be:
> 
> def __init__(self, **kwargs):
> self.__dict__.update(kwargs)
> 

  One thing I notice with both of these versions:

>>> Hash(self=10)
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: __init__() got multiple values for keyword argument 'self'

  __self would be better; a version that doesn't preclude the use of any key 
would be best.

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


Re: IMAP UTF-7, any codec for that anywhere?

2004-12-01 Thread Jp Calderone
On Wed, 01 Dec 2004 10:35:59 +0100, Max M <[EMAIL PROTECTED]> wrote:
>Brian Quinlan wrote:
>  > Max M wrote:
>  >
>  >> Is there any codec available for handling The special UTF-7 codec for
>  >> IMAP?
> 
>  > Is there something special do you need or is recipe OK?
>  >
>  >  >>> u"\u00ff".encode('utf-7')
>  > '+AP8-'
> 
> 
> A recipe would be excellent. Unfortunately yours is no right. It should 
> have looke like:
> 
>  >>> imapUTF7Encode(u"\u00ff")
> '&AP8-'
> 
> I believe you missed the 'special' in "The special UTF-7 codec for IMAP?"
> 
> Imap folders use a non-standard version of utf-7, where some characters 
> are different.
> 
> I found som messages from 2001 on the net between a few Python unicode 
> developers, where they discuss implementing it. But I cannot find an 
> implementation anywhere.
> 
> I found a perl module that converts to/from the codec, but as usual that 
> is regex hell. Well ok its not that difficult, but I still need to think 
> to hard to parse Perl regex'

  Twisted's IMAP4 support includes an implementation of this codec.  Most of 
the API also happily accepts unicode objects and encodes them as necessary, too.

http://www.twistedmatrix.com/

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


Re: non blocking read()

2004-12-01 Thread Jp Calderone
On Wed, 01 Dec 2004 19:39:45 +0100, Uwe Mayer <[EMAIL PROTECTED]> wrote:
>Hi,
> 
> I use select() to wait for a file object (stdin) to become readable. In that
> situation I wanted to read everything available from stdin and return to
> the select statement to wait for more.
> 
> However, the file object's read method blocks if the number of bytes is 0 or
> negative. 
> 
> Is there no way to read everything a channel's got currently got without
> blocking?

def nonBlockingReadAll(fileObj):
bytes = []
while True:
b = fileObj.read(1024)
bytes.append(b)
if len(b) < 1024:
        break
return ''.join(bytes)

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


Re: non blocking read()

2004-12-01 Thread Jp Calderone
On 01 Dec 2004 15:55:18 -0500, David Bolen <[EMAIL PROTECTED]> wrote:
>Jp Calderone <[EMAIL PROTECTED]> writes:
> 
> > def nonBlockingReadAll(fileObj):
> > bytes = []
> > while True:
> > b = fileObj.read(1024)
> > bytes.append(b)
> > if len(b) < 1024:
> > break
> > return ''.join(bytes)
> 
> Wouldn't this still block if the input just happened to end at a
> multiple of the read size (1024)?

  Only if the file has not been put into non-blocking mode.  But the function 
as given is wrong, I left out the exception handling in the case you mention.  
Rather than blocking forever, fileObj.read(1024) will raise IOError (EAGAIN) if 
the input happened to be a multiple of 1024 bytes long.  Here is the corrected 
version:

def nonBlockingReadAll(fileObj):
bytes = []
while True:
try:
b = fileObj.read(1024)
except IOError, e:
if e.args[0] == errno.EAGAIN:
break
raise
bytes.append(b)
if len(b) < 1024:
break
return ''.join(bytes)

  Arguably, there is no longer any point to checking the length of b in this 
version, since at worst you will break on the next iteration of the loop.  It 
doesn't hurt, though.

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


Re: installing wxPython on Linux and Windows

2004-12-02 Thread Jp Calderone
On Thu, 02 Dec 2004 15:29:53 +0100, Peter Maas <[EMAIL PROTECTED]> wrote:
>Diez B. Roggisch schrieb:
> >>Same task on Win2k: download wxPython-setup.exe, double-click, done.
> >>Took me approx. 1 minute. This strikes me. Why are some tasks so hard
> >>on Linux and so easy on Windows? After all wxPython/Win and wxPython/Lin
> >>are made by the same developers. My guess: the software deployment
> >>infrastructure on Linux needs to be improved.
> > 
> > 
> > On debian, it 
> > 
> > apt-get install wxPython2.5.3
> > 
> 
> I have heard praises of Debian's install system but Debian is quite
> conservative with latest versions. There are some packages (e.g. Python,
> PostgreSQL, Subversion) where I'd like to have the latest versions.
> I don't want to be too tightly bound to the update cycles of the
> Linux distribution.
> 

[EMAIL PROTECTED]:~$ apt-cache show python2.4
Package: python2.4
Priority: optional
Section: python
Installed-Size: 10972
Maintainer: Matthias Klose <[EMAIL PROTECTED]>
Architecture: i386
Version: 2.3.97-2
Provides: python2.4-cjkcodecs
Depends: libbz2-1.0, libc6 (>= 2.3.2.ds1-4), libdb4.2, libncurses5 (>= 5.4-1), 
libreadline4 (>= 4.3-1), libssl0.9.7, zlib1g (>= 1:1.2.1)
Suggests: python2.4-iconvcodec | python2.4-japanese-codecs, 
python2.4-iconvcodec | python2.4-korean-codecs, python2.4-doc
Conflicts: python2.4-dev (<< 2.3.95-2)
Filename: pool/main/p/python2.4/python2.4_2.3.97-2_i386.deb
Size: 3503764
MD5sum: 519ed28c52bff645b311b8d5d27b2318
Description: An interactive high-level object-oriented language (version 2.4)
 Version 2.4 of the high-level, interactive object oriented language,
 includes an extensive class library with lots of goodies for
 network programming, system administration, sounds and graphics.

Package: python2.4
Status: install ok installed
Priority: optional
Section: python
Installed-Size: 9764
Maintainer: Matthias Klose <[EMAIL PROTECTED]>
Version: 2.3.90-1
Replaces: python2.4-xmlbase
Provides: python2.4-xmlbase
Depends: libbz2-1.0, libc6 (>= 2.3.2.ds1-4), libdb4.2, libncurses5 (>= 5.4-1), 
libreadline4 (>= 4.3-1), libssl0.9.7, zlib1g (>= 1:1.2.1)
Recommends: python2.4-iconvcodec | python2.4-cjkcodecs | 
python2.4-japanese-codecs, python2.4-iconvcodec | python2.4-cjkcodecs | 
python2.4-korean-codecs
Suggests: python2.4-doc
Conflicts: python2.4-xmlbase, python2.4-csv
Conffiles:
 /etc/python2.4/site.py b448b0f87294e041b8276ea3459df4a8
Description: An interactive high-level object-oriented language (version 2.4)
 Version 2.4 of the high-level, interactive object oriented language,
 includes an extensive class library with lots of goodies for
 network programming, system administration, sounds and graphics.

  This is a long and obnoxious way of pointing out that Python 2.4 is already 
available as a Python package :)  How much more up to date software can you ask 
for?

  And even if there are packages that aren't available, don't you think effort 
put into a packaging system would better be put into apt than an entirely new 
system that is guaranteed to be less useful than apt for many years?

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


Re: pre-PEP generic objects

2004-12-02 Thread Jp Calderone
On Thu, 02 Dec 2004 12:26:31 -0800, Scott David Daniels <[EMAIL PROTECTED]> 
wrote:
>Nick Craig-Wood wrote:
> > Scott David Daniels <[EMAIL PROTECTED]> wrote:
> >> You can simplify this:
> >> class Hash(object):
> >>  def __init__(self, **kwargs):
> >>  for key,value in kwargs.items():
> >>  setattr(self, key, value)
> >>  __getitem__ = getattr
> >>  __setitem__ = setattr
> > That doesn't work unfortunately...
> >>>>h['a']
> > 
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > TypeError: getattr expected at least 2 arguments, got 1
> > 
> > I'm not exactly sure why though!
> 
> I could have sworn I tested this, but I must have accidentally
> tested h.a rather than h['a'].  I don't know why it doesn't work either.
> For example:
> 
>  def gattr(*args): return getattr(*args)
>  def sattr(*args): return setattr(*args)
>  class Hash(object):
>   def __init__(self, **kwargs):
>   for key,value in kwargs.items():
>   setattr(self, key, value)
>   __getitem__ = gattr
>   __setitem__ = sattr
> 
> does work.

>>> def getattr2(obj, name, value):
... return getattr(obj, name, value)
... 
>>> class X:
... a = getattr
... b = getattr2
... 
>>> X.a

>>> X.b

>>> type(getattr)

>>> type(getattr2)

>>> 

  When the class object is created, the namespace is scanned for instances of 
.  For those and only those, a descriptor is created which 
will produce bound and unbound methods.  Instances of other types, such as 
 or , are ignored, leading to 
the critical difference in this case:

>>> X().a

>>> X().b
>
>>> 

  No bound method for getattr, hence trying to call it with two arguments 
fails, as it has no self on which to operate.

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


Re: decorators ?

2004-12-02 Thread Jp Calderone
On Thu, 02 Dec 2004 18:30:15 -0800, Josiah Carlson <[EMAIL PROTECTED]> wrote:
>
> [snip]
> 
> Technically, everything can be performed in assembly.  The point of
> syntactic sugar (or ammonia) is to make things less painful.  While
> everything was possible before, adding the decorators /after/ defining
> the function hid the decorators, and was susceptible to mistyping.
> 
> I previously posted about Philip Eby's use of decorators in PyObjC.  In
> his case, it saved him from typing 40-character function names 3
> times.

  Bob Ippolito, you mean.  And, no offense to Bob, but woopidy freaking doo.  
Now the vast hordes of PyObjC developers get to use their editor's name 
completion feature a little bit less.  What an awesome justification for adding 
a whole new syntactic construct to the language.

  
hoping-to-start-another-1000-message-thread-to-rehash-all-the-same-arguments'ly,

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


Re: finding byte order

2004-12-03 Thread Jp Calderone
On Fri, 03 Dec 2004 19:19:48 +0100, "Diez B. Roggisch" <[EMAIL PROTECTED]> 
wrote:
>>   I would like to have a test to tell me if the current machine is
   ^^^
> > using big or small endian, this way I could use the array module in
> > the first case and the *slower* struct module on the second. I looked
> > but did not find. Is there a python function to know that?
> 
> There is no such test, as it's domain-specific if there _can_ be such a test
> or not. If your data is composed in a way that you can infer the endianess
> by reading e.g. a header at the beginning that has well-known fields, then
> it might work. But only you can do that.
> 
> For a pure binary file, there is absolutely no way of telling the endianess.

  I think you misread the question.

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


Re: using cmd.exe as a telnet client

2004-12-03 Thread Jp Calderone
On Fri, 03 Dec 2004 16:31:40 -0600, Donnal Walter <[EMAIL PROTECTED]> wrote:
>Several months ago I tried using the telnet module (on Windows XP) to 
> communicate with a proprietary host on our network. This was 
> unsuccessful due to problems with "option negotiation", and I gave up on 
> the project for a while. I still have need for this, however, so I 
> recently started thinking about alternatives. I suppose I could dig deep 
> enough into option negotiation to use the socket module (with telnet as 
> a guide), but I am hoping to find a way to use fewer synapses.
> 
> Using the Windows C:> prompt (cmd.exe) I can telnet into this host with 
> no problems (the Windows telnet client performs option negotiation just 
> fine). Is there a straightforward way of using os.popen() (or os.fork() 
> or os.exec*() or os.wait*()) to connect to the host from Python via the 
> Windows telnet client?
> 

  cmd.exe is not a command line program.  It's a terminal (emulator).  
You might be able to use the telnet program, though.  Before doing this, 
I'd recommend looking at Twisted's telnet support (both the version in 1.3 
and the version that will be in 2.0), which actually supports option 
negotiation in a reasonable way.

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


Re: using cmd.exe as a telnet client

2004-12-04 Thread Jp Calderone
On Sat, 4 Dec 2004 03:31:12 -0800 (PST), Eyal Lotem <[EMAIL PROTECTED]> wrote:
> 
> You simple have to run PyInvoke's server.py on the
> server, and then in the client, you can Pythonically
> control anything on the server:
> 
> client = pyinvoke.connect(('some_server', some_port))
> client.modules.shutil().rmtree('/tmp/blah')

  This seems terribly, terribly insecure; the kind of thing no one should ever 
run on any server or desktop anywhere for any reason.

  What am I missing?

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


  1   2   3   >