Re: Chroot Jail Not Secure for Sandboxing Python?

2007-06-25 Thread David E. Konerding DSD staff
On 2007-06-25, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 On Jun 25, 1:43 am, Martin v. Löwis [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] schrieb:

  This wiki page suggests using a chroot jail to sandbox Python, but
  wouldn't running something like this in your sandboxed Python instance
  still break you out of the chroot jail:

   os.execle ('/usr/bin/python','-c','import os; os.execlp(/bin/sh)',
  {})

 Depending on how the chroot jail is set up, this command might not
 work - in the jail, /bin/sh might not exist.

 I followed up with my ISP.  Here's the answer I got:

 The os.exec call prepends the chroot directory to the absolute path,
 but does NOT provide chroot for the child process.  However, as long
 as the environment is maintained, which contains an LD_PRELOAD, the
 chroot will also be maintained.  If  LD_PRELOAD is removed or
 ignored, then the chroot is ineffective.

 Another way of saying it is that every process is responsible for
 providing and maintaining the chroot through the LD_PRELOAD variable.
 Those processes only maintain the chroot if that variable remains set.

None of this makes any sense to me.  Once an application is running
inside a chroot, there is no easy manipulation the application
can do to break out.  The example you gave above executes a shell that
is in the chroot dir.  That's not really breaking out of the sandbox,
it's just accessing something inside the sandbox.

if your ISP is trying to enforce chroot through an LD_PRELOAD library,
they might be using 'fakechroot' which doesn't look very good to me.

Dave


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


Re: No zlib in Python 2.4.4

2007-04-11 Thread David E. Konerding DSD staff
On 2007-04-11, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 On Apr 11, 9:14 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
 In [EMAIL PROTECTED], shamzz wrote:
  Shouldn't zlib be compiled as a Python module automatically in Python
  2.4.4.  I'm guessing Python is doing some kind of check and not
  compiling zlib for some reason?

 It only gets compiled if the header files can be found.  Is the zlib-dev
 or zlib-devel package installed?

 Thanks for the fast reply... this seems to be going off topic from
 Python so sorry about that.

 But yep, I've just installed (through YAST) the zlib-devel and zlib-
 devel-32 packages (zlib and zlib-32bit are already installed).

 I then did a make clean/configure/make/make install with the Python
 source, but it's still not compiling with zlib.

carefully inspect the configure output.  Where it gets to the zlib output, it
should print a message about whether it found the libraries or not.
Usually, in these situations, I find myself looking closely at the output
in config.log to see exactly what gcc command it tried to run.

If that doesn't help, take a look at the 'make' output.  It might be that there
is no check for zlib in configure, but Python goes to build the module and fails
due to missing headers or libraries.

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


Re: ZSI, SOAP and .NET web services - problem

2007-03-26 Thread David E. Konerding DSD staff
On 2007-03-22, Jaroslaw Zabiello [EMAIL PROTECTED] wrote:
 I try to connect to web services (written in C#/.NET) with latest ZSI
 2.0rc3 library. It just does not work.

 from ZSI.ServiceProxy import ServiceProxy 
 wsdl = 'http://192.168.0.103/NewWebServices/TemplateInsert.asmx?wsdl' 
 print ServiceProxy(wsdl, tracefile=sys.stdout) 

 C:\opt\Python25\lib\site-packages\zsi-2.0_rc3-py2.5.egg\ZSI\wstools\WSDLTools.py,
 line 1116, in getAddressBinding 
 WSDLError: No address binding found in port. 

 This pythonic library must be stupid, because I have no problem to connect
 with... Ruby:

Actually, it's likely just more tolerant of an error in your WSDL
(leaving out your address binding).

Many of the WSDL toolkits ignore leaving out the address binding in the port 
type.

The java tooling seems to work that way and apparently ruby is the same way.

Try fixing your WSDL, then try again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I print a numpy array?

2006-12-04 Thread David E. Konerding DSD staff
On 2006-12-02, Robert Kern [EMAIL PROTECTED] wrote:
 Beliavsky wrote:
 When I print an array in any language, I (and I think most programmers)
 expect by default to have all elements displayed. Matlab, R, and
 Fortran 95 have somewhat similar arrays to numpy, and that is what they
 do. I don't remember Numeric summarizing arrays by default. R has a
 summary function as well as a print function.

 There are pretty serious problems with interactive use and large arrays.
 Formatting the string for a very large array can take a fair bit of time, 
 often
 much more than the computation that generated it. This has been a 
 long-standing
 frustration of many Numeric users. At the interactive prompt, if the statement
 you just entered is taking a long time to execute and you Ctrl-C, odds are, 
 the
 traceback points you right in the middle of array2string(), not anything in 
 the
 actual computation itself. Since the interactive prompt prints things out
 without the user explicitly asking for it, it's not enough simply to have two
 functions available.

 numarray set the default to summarize, and numpy kept numarray's choice.

I 100% approve of the summarization by default.  It has saved me *many* times.

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


Re: processing the genetic code with python?

2006-03-06 Thread David E. Konerding DSD staff
In article [EMAIL PROTECTED], nuttydevil wrote:
 I have many notepad documents that all contain long chunks of genetic
 code. They look something like this:
 
 atggctaaactgaccaagcgcatgcgtgttatccgcgagaaagttgatgcaaccaaacag
 tacgacatcaacgaagctatcgcactgctgaaagagctggcgactgctaaattcgtagaa
 agcgtggacgtagctgttaacctcggcatcgacgctcgtaaatctgaccagaacgtacgt
 ggtgcaactgtactgccgcacggtactggccgttccgttcgcgtagccgtatttacccaa
 
 Basically, I want to design a program using python that can open and
 read these documents. However, I want them to be read 3 base pairs at a
 time (to analyse them codon by codon) and find the value that each
 codon has a value assigned to it. An example of this is below:
 
 ** If the three base pairs were UUU the value assigned to it (from the
 codon value table) would be 0.296
 
 The program has to read all the sequence three pairs at a time, then I
 want to get all the values for each codon, multiply them together and
 put them to the power of 1 / the length of the sequence in codons
 (which is the length of the whole sequence divided by three).
 

I don't really understand precisely what you're trying to do.  

First off, those aren't base pairs, they're bases.  Only when you have 
double-stranded
DNA (or RNA, or some other oddball cases) would they be base pairs.

Second, I don't know what the codon to value function is, is this frequency (IE 
number n  occurences of codon
X out of N total codons)?  Or is the lookup table provided for you?

Anyay, I can help you with most of the preprocessing.  For example,

However, to make things even more complicated, the notebook sequences
 are in lowercase and the codon value table is in uppercase, so the
 sequences need to be converted into uppercase. Also, the Ts in the DNA
 sequences need to be changed to Us (again to match the codon value
 table). And finally, before the DNA sequences are read and analysed I
 need to remove the first 50 codons (i.e. the first 150 letters) and the
 last 20 codons (the last 60 letters) from the DNA sequence. I've also
 been having problems ensuring the program reads ALL the sequence 3
 letters at a time.

So, if the file is called notepad.txt, I'd do what you did above as:

import string
o = open(notepad.txt)
l = o.readlines()  ## read all lines
l = map(string.strip, l)   ## strip newlines
l = .join(l)  ## join into one string (in case codon boundaries cross lines)
l = l[50:-60]
l = l.upper()
print l

codons = []
for i in range(0, len(l), 3):
codons.append(l[i:i+3])

print codons


That gets you about 30% of the way there.

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


Re: 2D canvas for GTK

2006-01-10 Thread David E. Konerding DSD staff
In article [EMAIL PROTECTED], Sandro Dentella wrote:
 Il 2006-01-09, John Bauman [EMAIL PROTECTED] ha scritto:

 Sandro Dentella [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
I need a (decent) canvas for PyGTK. I used tkinter.canvas with real 
pleasure
 in the past but now I need to use the canvas in a Gtk application. Does
 anybody know of one with similar capabilities? It must work on Windows 
 too.
 It must be able to produce postscript output.

 I think that PyCairo might be what you're looking for, at least if you're 
 using gtk 2.8.
 
 No, that's definitely a lower level tool. I need someting that has
 rectangles, lines, possibility to move object around, easy bindings, tags
 for objects, grouping. All that is already in tkinter.canvas but I need to
 use it from a GTK application.
 
 Any other ideas?

If you can afford the include GNOME as a dependency, then gnome-canvas or 
diacanvas2
is your best bet.

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


Re: Guido at Google

2005-12-23 Thread David E. Konerding DSD staff
In article [EMAIL PROTECTED], Greg Stein wrote:
 Guido would acknowledge a query, but never announce it. That's not his
 style.
 
 This should have a positive impact on Python. His job description has a
 *very* significant portion of his time dedicated specifically to
 working on Python. (much more than his previous one day a week jobs
 have given him)

Well, given that he's going to be spending his 80% time working on python,
it makes one wonder how he'll be spending his 20% time :-)

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


Re: Pickle for MPI

2005-12-06 Thread David E. Konerding DSD staff
In article [EMAIL PROTECTED], tooper wrote:
 Hello,
 
 Did anybody tried python pickle module over heterogeneous 32/64 bits
 mpi exchanges to overcome the translation problem ? i.e. pickling on
 one side (let's say a 32-bits OS side), sending the buffer as string
 through mpi and unpickling on the other side (let's say a 64-bits OS
 side)
 
 
 Any well known pitfall or advice before I try this way would be welcome

Why would this be relevant at all?  All the machines in an MPI group
have to be heterogenous.

While I'm at it: using pickles in pyMPI was a really dumb idea.

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


Re: Using graphviz to visualize trace.py output, anybody?

2005-10-31 Thread David E. Konerding DSD staff
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote:
 Hi,
 
 has anybody thought of / already used graphviz to convert the output of
 trace.py into a graph? I looked at PyUMLGraph, but 1. PyUMLGraph does
 not successfully create a dot file, and 2. I don't really want a UML
 representation but a compact representation of program execution.
 
 Maybe there is some other tool that I am not aware of which can create
 this kind of trace. I use eclipse with pydev plugin on MacOS 10.3.9
 
 Regards,
 Svenn
 

Take a look at:
http://dkbza.org/pydot.html

It's a python interface which can produce dot format files (based on its 
internal
graph API) and run graphviz for you.

I'm not sure which trace.py you're referring to, but I assume it dumps some 
output file.
You have a couple of obvious ways to get what you want:

1) modify trace.py to create a pydot graph structure then write to file
2) make a script that parses the trace.py output to create a pydot graph 
structure then write to file

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


Re: Wheel-reinvention with Python

2005-08-15 Thread David E. Konerding DSD staff
In article [EMAIL PROTECTED], Ben Finney wrote:
 Brian Victor [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  Torsten Bronger wrote:
  I've been having a closer look at wxPython which is not Pythonic at
  all and bad documented.  Probably I'll use it nevertheless.
  Aye.  Couldn't agree more.
 
 You know, whenever someone mentions wxPython being badly documented,
 I have to wonder whether they know about the nearly 2000 page PDF of
 wxWidgets documentation, which is available in html at
 http://www.wxwidgets.org/manuals/2.6.1/wx_contents.html
 
 All of which is oriented toward C++ programmers, with all the language
 assumptions inherent to that.

Actually, the real problem with the wxWidgets documentation is that it doesn't 
tell you
*how* to do things.  It does only a barely adequate job as an API reference, 
but what it lacks is
an extensive howto.  I waste too much of my time dinking around deep in 
wxPython demos trying to figure out
what is the 'right way' to do things.

See:
http://www.async.com .br/faq/pygtk/index.py?req=index

for an example of what's needed.

The wxPython Wiki is poorly organized (like nearly all wikis).  It's mandatory 
reading (all of it) but
mainly because it's not obvious where important hints are hidden.

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


Re: wxPython and threads again

2005-08-11 Thread David E. Konerding DSD staff
On 2005-08-10, Bryan Olson [EMAIL PROTECTED] wrote:
  The easiest approach, though, is to use the threadedselectreactor in 
 Twisted (you need
  to check the HEAD branch out with subversion, because that reactor 
 isn't included in any releases).
  With threadedselectreactor, it's easy to incorporate both the GUI 
 event loop and the twisted reactor.
  Twisted already includes lots of code for doing asynchronous 
 callback-style IO for
  IO bound processes like downloading.  Further, you don't even think 
 in an explicitly threaded way-
  createing a whole thread just to manage a download process which is 
 motly IO and a little bookkeeping is
  silly.  Twisted's approach just makes a lot more sense and simplifies 
 the code too.

 I couldn't disagree more about that being easier and simplifying
 the code. Creating a whole thread is trivial.



I've done both styles.  Actually, I greatly prefer the single threaded approach 
now; conceptually,
the threaded approach is very simple, but your program ends up getting complex 
because the data-passing
infrastructure.  And you end up structuring your logic in somewhat more 
convoluted ways.  And
most people have such a hard time dealing with data synch between threads...

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


Re: wxPython and threads again

2005-08-11 Thread David E. Konerding DSD staff
On 2005-08-10, Peter Hansen [EMAIL PROTECTED] wrote:
 David E. Konerding DSD staff wrote:
 Further, calling wx from a thread other than the one running the event 
  loop is deep voodoo and should typically be avoided.

 Typically?  Let's just say always and maybe use the phrase certain 
 to corrupt wx and crash the app instead of deep voodoo. :-)  At least 
 that way the OP won't waste time experimenting...

Not really certain:
http://wxwidgets.org/manuals/2.6.1/wx_threadfunctions.html#threadfunctions

This strongly suggests you can arbitrarily grab the wx GUI lock and call GUI
functions from any thread.  It's still voodoo.  But we're adults here, and 
practicing
voodoo isn't proscribed.


 You need another way to pass completion information between the downloader
 thread and the main thread; the simplest way is to define a custom wx
 Event, and wxPostEvent from the downloader thread when it completes (
 and when the gauge should be updated).  wxPostEvent is safe to call from 
 non-eventloop threads.
 The main thread's wx event loop just spins, properly updating all other
 parts of the GUI, and receiving events from the downloader thread.

 Even simpler for some purposes is wx.CallAfter(), which provides the 
 asynchronous performance of wxPostEvent with the beautifully general 
 approach of passing callables through a Queue which Bryan Olson 
 described in his post.  (That is, you don't need to do polling with a 
 non-blocking get() on the Queue this way.)

Very good point.  I wasn't aware CallAfter had those semantics; I always used 
it from
the main thread.  But won't wx.CallAfter cause a bit of a delay since it will 
wait until
all pending events are processed and only handle the function afterwards, thus 
inducing
an extra event loop cycle/redraw?

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


Re: wxPython and threads again

2005-08-10 Thread David E. Konerding DSD staff
In article [EMAIL PROTECTED], perchef wrote:
 Hi,
 
 I have several files to download and a GUI to update. I know this is a
 frequently asked question but i can't find an appropriate solution.
 My Downloader extends threading.Thread and update a wx.Gauge in GUI
 during the process.
 
 for src in urls:
downloader = Downloader( src, destination, GUI )
downloader.start()
 
 #work with the downloaded files...
 
 If i don't use a downloader.join() in this for loop, I launch several
 threads at the same time and so my wx.Gauge is bouncing up and down.
 If i do add the downloader.join() my GUI is no more updated ( in fact,
 nothing appears, it's frozen )
 How can I wait the end of the thread and also be able to update the GUI

Well, the constraints are this: the main thread is running the wx main loop,
and thus, cannot block by calling join on the downloader thread.  Further, 
calling
wx from a thread other than the one running the event loop is deep voodoo and 
should typically
be avoided.

You need another way to pass completion information between the downloader
thread and the main thread; the simplest way is to define a custom wx
Event, and wxPostEvent from the downloader thread when it completes (
and when the gauge should be updated).  wxPostEvent is safe to call from 
non-eventloop threads.
The main thread's wx event loop just spins, properly updating all other
parts of the GUI, and receiving events from the downloader thread.

ANother approach is to have a thread-safe Queue and have the main thread/event 
loop
poll the queue with queue.get_nowait() periodically (typically 0.1-1 sec).
The downloader thread shares the queue object and puts data structures 
(typically
class instances, strings, or ints) that indicate status updates.

The easiest approach, though, is to use the threadedselectreactor in Twisted 
(you need
to check the HEAD branch out with subversion, because that reactor isn't 
included in any releases).
With threadedselectreactor, it's easy to incorporate both the GUI event loop 
and the twisted reactor.
Twisted already includes lots of code for doing asynchronous callback-style IO 
for
IO bound processes like downloading.  Further, you don't even think in an 
explicitly threaded way-
createing a whole thread just to manage a download process which is motly IO 
and a little bookkeeping is
silly.  Twisted's approach just makes a lot more sense and simplifies the code 
too.

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


Re: Python callbacks PyGILState_Release()

2005-04-25 Thread David E. Konerding DSD staff
In article [EMAIL PROTECTED], Randall Hopper wrote:
 Thomas Heller:
 |  Python - C++ - Python Callback
 |
 | (example attached) an exception raised in the callback doesn't make it back
 | across C++ to Python.
 ...
 | void callback_wrapper( void *user_data )
 | {
 |   // Acquire interpreter lock
 |   PyGILState_STATE gstate = PyGILState_Ensure();
 |   ...
 |   // Call Python
 |   pyresult = PyEval_CallObject( pyfunc, pyargs );
 |   ...
 |
 |if (pyresult == NULL)
 |PyErr_Print();
 |
 |   // Free interpreter lock
 |   PyGILState_Release(gstate);
 | }
 |
 |PyErr_Print() will do the 'right' thing?s.
 
 Thanks for the reply.  However, this won't:
 
a) Stop the main Python script, and
b) Print the full stack trace (including Python and C++ SWIG wrapper)
 
 Is there a clean way to save the full exception state in the callback
 before the PyGILState_Release(), and restore it when we return across the
 C++ wrapper?
 
 If I knew what the proper save and restore exception state code bits
 were, I could easily implement this with exception typemaps in SWIG.
 
 Thanks,
 
 Randall
 
 P.S. Perhaps PyGILState_Release should take an argument instructing it to
 exclude exception state when resetting the interpreter state back to its
 original state.

Randall:

It's not the job of the PyGILState_* functions to manage exception details for 
you.

I always solved this problem a different way, by saving the exception in an 
instance variable
within the Python callback, and using a condition variable so that the main 
thread could abort on a callback's
failure.  Notably, our callsbacks are always invoked from a C++ thread that the 
main Python interepreter didn't
create, and our main Python intepreter is blocked on a mutex most of the time.

I saved the exception state by retrieveing it from sys.exc_info(), which 
contains all the traceback object data as Python variable.
I think you can get the same info from your C++ callback wrapper, and use 
PyErr_Fetch and PyErr_Restore to save and restore the
exception sate.

Dave

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


Re: any Python equivalent of Math::Polynomial::Solve?

2005-02-27 Thread David E. Konerding DSD staff
On 2005-02-26, Just [EMAIL PROTECTED] wrote:
 While googling for a non-linear equation solver, I found 
 Math::Polynomial::Solve in CPAN. It seems a great little module, except 
 it's not Python... I'm especially looking for its poly_root() 
 functionality (which solves arbitrary polynomials). Does anyone know of 
 a Python module/package that implements that?

 Just

Although I dont' really work on it any more, the Py-ML module which interfaces
Python to Mathematica would almost certain be able to do this, although you'd 
need an installation of 
Mathematica.

http://sourceforge.net/projects/py-ml/

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


Re: What strategy for random accession of records in massive FASTA file?

2005-01-12 Thread David E. Konerding DSD staff
In article [EMAIL PROTECTED], Chris Lasher wrote:
 Hello,
 I have a rather large (100+ MB) FASTA file from which I need to
 access records in a random order. The FASTA format is a standard format
 for storing molecular biological sequences. Each record contains a
 header line for describing the sequence that begins with a ''
 (right-angle bracket) followed by lines that contain the actual
 sequence data. Three example FASTA records are below:

Use biopython.  They have dictionary-style classes which wrap FASTA files using 
indexes.

http://www.biopython.org

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