gcov-like python code coverage

2007-04-25 Thread mathieu
Just in case something already exist for this. Is there some tool,
that can produce gcov-type coverage out of a python code ?

I have an already existing regex code that turn gcov output into XML,
which I'd like to reuse.

thanks !
-Mathieu

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


Freeze vs cx_Freeze

2007-04-06 Thread mathieu
Hello,

   I am currently investigating how to distribute a python based
application on a targeted linux system (debian) and so far I only
found two options:
- Freeze (shipped with python dist)
- cx_Freeze (*)

As far as I understand those two options are very close. According to
the cx_Freeze README cx_Freeze is simply easier to use (no dependencie
of gcc, faster to create binaries) and it is cross-platform (no
interest for me in this case).

Anything else ?

thanks,
-MM

(*) http://python.net/crew/atuining/cx_Freeze/

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


strptime and microseconds

2007-10-18 Thread mathieu
Hi there,

  I am trying to use strptime to parse my microseconds but I was not
able the documentation for it. The only list I found was:

  http://docs.python.org/lib/module-time.html

 So I can get seconds with %S, but nowhere is there a microsecond
symbol...

Thanks for pointer to doc,
-Mathieu


s1 = "20070619"
s2 = "150348.62"
s = s1+s2
d = datetime(*strptime(s, "%Y%m%d%H%M%S.%?"))

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


Re: strptime and microseconds

2007-10-18 Thread mathieu
On Oct 18, 6:36 pm, mathieu <[EMAIL PROTECTED]> wrote:
> On Oct 18, 6:00 pm, mathieu <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi there,
>
> >   I am trying to use strptime to parse my microseconds but I was not
> > able the documentation for it. The only list I found was:
>
> >  http://docs.python.org/lib/module-time.html
>
> >  So I can get seconds with %S, but nowhere is there a microsecond
> > symbol...
>
> > Thanks for pointer to doc,
> > -Mathieu
>
> > s1 = "20070619"
> > s2 = "150348.62"
> > s = s1+s2
> > d = datetime(*strptime(s, "%Y%m%d%H%M%S.%?"))
>
> Getting closer...
>
> s1 = "20070619"
> s2 = "115344.51"
> s3 = "115445.123456"
>
> ms2 = eval(s2) % 1
> mms2 = int(ms2 * 100 + 0.5)
> ms3 = eval(s3) % 1
> mms3 = int(ms3 * 100 + 0.5)
>
> s = s1 + s2
> d1 = datetime(*strptime(s[:12], "%Y%m%d%H%M%S")[0:6])
> d1.replace(microsecond = mms2)
> #print d1.microsecond
>
> s = s1 + s3
> d2 = datetime(*strptime(s[:12], "%Y%m%d%H%M%S")[0:6])
> d2.replace(microsecond = mms3)
> #print d2.microsecond
>
> d = d2 - d1
> print d.seconds
> print d.microseconds
>
> why would d.microseconds be 0 ??
>
> Thanks,
> -Mathieu


D'oh !

Ok final version is simply:

s1 = "20070619"
s2 = "115344.51"
s3 = "115446.123456"

ms2 = eval(s2) % 1
mms2 = int(ms2 * 100 + 0.5)
ms3 = eval(s3) % 1
mms3 = int(ms3 * 100 + 0.5)

s = s1 + s2
d1 = datetime(*strptime(s[:14], "%Y%m%d%H%M%S")[0:6])
d1 = d1.replace(microsecond = mms2)
#
s = s1 + s3
d2 = datetime(*strptime(s[:14], "%Y%m%d%H%M%S")[0:6])
d2 = d2.replace(microsecond = mms3)
#
d = d2 - d1
print d.seconds
print d.microseconds

sorry for the noise :))
-Mathieu




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


Re: strptime and microseconds

2007-10-18 Thread mathieu
On Oct 18, 6:00 pm, mathieu <[EMAIL PROTECTED]> wrote:
> Hi there,
>
>   I am trying to use strptime to parse my microseconds but I was not
> able the documentation for it. The only list I found was:
>
>  http://docs.python.org/lib/module-time.html
>
>  So I can get seconds with %S, but nowhere is there a microsecond
> symbol...
>
> Thanks for pointer to doc,
> -Mathieu
>
> s1 = "20070619"
> s2 = "150348.62"
> s = s1+s2
> d = datetime(*strptime(s, "%Y%m%d%H%M%S.%?"))


Getting closer...

s1 = "20070619"
s2 = "115344.51"
s3 = "115445.123456"

ms2 = eval(s2) % 1
mms2 = int(ms2 * 100 + 0.5)
ms3 = eval(s3) % 1
mms3 = int(ms3 * 100 + 0.5)

s = s1 + s2
d1 = datetime(*strptime(s[:12], "%Y%m%d%H%M%S")[0:6])
d1.replace(microsecond = mms2)
#print d1.microsecond

s = s1 + s3
d2 = datetime(*strptime(s[:12], "%Y%m%d%H%M%S")[0:6])
d2.replace(microsecond = mms3)
#print d2.microsecond

d = d2 - d1
print d.seconds
print d.microseconds

why would d.microseconds be 0 ??

Thanks,
-Mathieu

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


Re: strptime and microseconds

2007-10-19 Thread mathieu
On Oct 18, 10:54 pm, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> On 18 oct, 13:46, mathieu <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Oct 18, 6:36 pm, mathieu <[EMAIL PROTECTED]> wrote:
> > > >   I am trying to use strptime to parse my microseconds but I was not
> > > > able the documentation for it. The only list I found was:
> > Ok final version is simply:
>
> > s1 = "20070619"
> > s2 = "115344.51"
> > s3 = "115446.123456"
>
> > ms2 = eval(s2) % 1
> > mms2 = int(ms2 * 100 + 0.5)
> > ms3 = eval(s3) % 1
> > mms3 = int(ms3 * 100 + 0.5)
>
> > s = s1 + s2
> > d1 = datetime(*strptime(s[:14], "%Y%m%d%H%M%S")[0:6])
> > d1 = d1.replace(microsecond = mms2)
>
> What about this:
>
> py> import datetime
> py> s1 = "20070619 115344.025"
> py> p1, p2 = s1.split(".", 1)
> py> d1 = datetime.datetime.strptime(p1, "%Y%m%d %H%M%S")

python2.3:
from time import strptime

> py> ms = int(p2.ljust(6,'0')[:6])

ljust padds with space only in python 2.3. But thanks anyway your
solution is much cleaner !

-Mathieu

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


PyGILState_Release produces a seg fault

2008-01-10 Thread mathieu
Hello and happy new year folks,

  I am experiencing a seg fault while using the python interface to
the VTK library (debian oldstable, python 2.3). The VTK library is
wrapped by a custom mechanism to provide a python API. In particular
they implemented a way so that a python function can be called in
response to an event(*). Basically all the code is doing is:

{
  PyGILState_STATE state = PyGILState_Ensure();
  // construct arglist from C++ args:
  ...
  // call python function:
  result = PyEval_CallObject(this->obj, arglist);

  PyGILState_Release(state);  // crash happens here
}

  However the event being triggered from the C++ layer is done from
multiple threads. After reading :

  http://docs.python.org/api/threads.html

  I tought that the VTK-python layer was simply missing a call to :
PyEval_InitThreads() just before Py_InitModule(), but now my python
shell appears as hung ! The only solution I found is that if I comment
out the function calls PyGILState_Ensure/PyGILState_Release then
everything goes smoothly.

  Am I reading the docs backward ? I do need to keep the call to
PyGILState_Ensure/PyGILState_Release, right ?

  I am also copying the log from valgrind (VTK lib untouched, no call
to PyEval_InitThreads), UpdateProgress being the function called from
multiple threads:

==20066== Thread 2:
==20066== Invalid read of size 4
==20066==at 0x403232A: sem_post@@GLIBC_2.1 (in /usr/lib/debug/
libpthread-2.5.so)
==20066==by 0x80B0D53: PyEval_ReleaseLock (in /usr/bin/python2.4)
==20066==by 0x80DDB20: PyGILState_Release (in /usr/bin/python2.4)
==20066==by 0x45C7AB4: vtkPythonCommand::Execute(vtkObject*,
unsigned long, void*) (vtkPythonUtil.cxx:2016)
==20066==by 0x483C0DF: vtkSubjectHelper::InvokeEvent(unsigned
long, void*, vtkObject*) (vtkObject.cxx:547)
==20066==by 0x483C18E: vtkObject::InvokeEvent(unsigned long,
void*) (vtkObject.cxx:713)
==20066==by 0x4E67E6A: vtkAlgorithm::UpdateProgress(double)
(vtkAlgorithm.cxx:115)

Thanks,
-Mathieu

Original post:
http://public.kitware.com/pipermail/vtk-developers/2008-January/004890.html

(*) See line 1906->2019 at:
http://public.kitware.com/cgi-bin/viewcvs.cgi/Common/vtkPythonUtil.cxx?annotate=1.80
-- 
http://mail.python.org/mailman/listinfo/python-list


regex question

2008-02-13 Thread mathieu
I do not understand what is wrong with the following regex expression.
I clearly mark that the separator in between group 3 and group 4
should contain at least 2 white space, but group 3 is actually reading
3 +4

Thanks
-Mathieu

import re

line = "  (0021,xx0A)   Siemens: Thorax/Multix FD Lab Settings
Auto Window Width  SL   1 "
patt = re.compile("^\s*\(([0-9A-Z]+),([0-9A-Zx]+)\)\s+([A-Za-z0-9./:_
-]+)\s\s+([A-Za-z0-9 ()._,/#>-]+)\s+([A-Z][A-Z]_?O?W?)\s+([0-9n-]+)\s*
$")
m = patt.match(line)
if m:
  print m.group(3)
  print m.group(4)
-- 
http://mail.python.org/mailman/listinfo/python-list


win32com.client / Trendlines

2009-01-28 Thread mathieu
Hi there,

  I am trying to use win32com.client, but I do not think I fully grasp
the concept. So far I copied chunk of code from the net to write my
script. It worked well until I could not find any example on
Trendlines. According to doc it should be as simple as:

wc.Chart.SeriesCollection(1).Trendlines.Add( type=constants.xlLinear,
name="Linear Trend")

But I get an error:

Traceback (most recent call last):
  File "addchart.py", line 65, in ?
wc2.Chart.SeriesCollection(1).Trendlines.Add
( type=constants.xlLinear, name="Linear Trend")
AttributeError: 'function' object has no attribute 'Add'

It looks like Trendlines indeed does not have such member function. Am
I missing something, do I need to generate something particular (eg.
using makepy.py)

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


Re: win32com.client / Trendlines

2009-01-28 Thread mathieu
On Jan 28, 4:21 pm, mathieu  wrote:
> Hi there,
>
>   I am trying to use win32com.client, but I do not think I fully grasp
> the concept. So far I copied chunk of code from the net to write my
> script. It worked well until I could not find any example on
> Trendlines. According to doc it should be as simple as:
>
> wc.Chart.SeriesCollection(1).Trendlines.Add( type=constants.xlLinear,
> name="Linear Trend")
>
> But I get an error:
>
> Traceback (most recent call last):
>   File "addchart.py", line 65, in ?
>     wc2.Chart.SeriesCollection(1).Trendlines.Add
> ( type=constants.xlLinear, name="Linear Trend")
> AttributeError: 'function' object has no attribute 'Add'
>
> It looks like Trendlines indeed does not have such member function. Am
> I missing something, do I need to generate something particular (eg.
> using makepy.py)
>

Ok found it.

trend = wc2.Chart.SeriesCollection(1).Trendlines().Add
(Type=constants.xlLinear, Name="Linear Trend")
trend.DisplayRSquared = True
trend.DisplayEquation = True

Trendlines is a function...

Sorry for the noise, win32com really rocks !

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


Distributing compiled (swig) python modules

2008-10-15 Thread mathieu
Hi there,

  I have prepared binaries of a python module that I wrote. Basically
the lib is written in C++ and wrapped in python using SWIG. Of course
it links to the python dynamic libraries. I found out that this is
version dependant. For instance if I prepare the binaries on my
machine with a python 2.4 installation this module will not load
properly on a python 2.5 / 2.6 installation.

  Is there some documentation (that I missed in my previous google
search) that describe how to prepare python module that can be
redistributed with some kind of backward compatibility (= so that when
prepared on python 2.4, it works on 2.5/2.6 at least) ?

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


'u' Obselete type – it is identical to 'd'. (7)

2009-02-24 Thread mathieu
I did not know where to report that:

'u' Obselete type – it is identical to 'd'. (7)

http://docs.python.org/library/stdtypes.html#string-formatting

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


Re: 'u' Obselete type – it is identical to 'd'. (7)

2009-02-25 Thread mathieu
On Feb 24, 11:06 pm, Steven D'Aprano  wrote:
> mathieu wrote:
> > I did not know where to report that:
>
> > 'u'   Obselete type – it is identical to 'd'. (7)
>
> >http://docs.python.org/library/stdtypes.html#string-formatting
>
> > Thanks
>
> If you google on "python bug tracker" the first link is the correct one.
>
> I don't know what you want to report, but I've reported that obsolete is
> mispelled:
>
> http://bugs.python.org/issue5361

Thanks. Now I know :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: 'u' Obselete type – it is identical to 'd'. (7 )

2009-02-25 Thread mathieu
On Feb 24, 9:24 pm, John Machin  wrote:
> On Feb 25, 4:48 am, mathieu  wrote:
>
> > I did not know where to report that:
>
> > 'u' Obselete type – it is identical to 'd'.   (7)
>
> >http://docs.python.org/library/stdtypes.html#string-formatting
>
> So what's your problem with that? Do you believe that 'u' is not
> accepted? That 'u' is not identical to 'd' and thus the doc should be
> rewritten as "its behaviour is identical to that of 'd'"? That the
> behaviour of 'u' is NOT identical to that of 'd'? That 'u' should not
> be documented? That 'u' should not be described as obselete?
 

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


Distributing 2 python modules with incompatible API

2008-06-04 Thread mathieu
hi there,

  As far as I understand python is not using the usual UNIX system of
soname when two libraries provide incompatible API. So let say I have
a _foo.so version 1.2 and 2.0, all I can (should do) is move them
underneath a subdirectory in site-package:

  pythonX.Y/site-package/foo1.2/_foo.so
  pythonX.Y/site-package/foo1.2/foo.py
and
  pythonX.Y/site-package/foo2.0/_foo.so
  pythonX.Y/site-package/foo2.0/foo.py

Then a central foo.pth would (sytem-wide) define which one is the
default version:

  pythonX.Y/site-package/foo.pth

  If this is correct ? Is there any documentation that I missed ?

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


Re: DICOM library

2008-06-10 Thread mathieu
On Jun 10, 1:05 pm, [EMAIL PROTECTED] wrote:
> Hi everybody!
> I've been looking for a python library wich allows me to work with
> with DICOM files, for medical image processing. Finding nothing at
> first, evenctually i've find thegdcmlibrary, wich is suposed to be
> for c developement, but they say that you can use it with python, as
> "It is automatically wrapped to python (using swig)". So, the cuestion
> is: how can I use this kind of library, wich is suposed to be used
> with c, in python? When I download the tarball there ae only 2 .py
> files. shall I install the whole library for using in C, and then try
> to import thegdcmmodule in python? becouse i'm afraid it won't work.
> Thanks in advance, and sorry for my english, wich is not very good
> actually. Sorry for asking for something before trying everything, but
> i'm almost desperate to find a library like that.

You will get a tons more help directly at GDCM ML:

https://lists.sourceforge.net/lists/listinfo/gdcm-developers

The process is quite simple, GDCM is written using a limited subset of
C++ (not C!) and using SWIG the API can be automagically wrap into
another target language (in your case: python).

If you download the binaries, you are all set (expect maybe adjusting
your PYTHONPATH).

Anyway this is highly GDCM oriented, and we should continue this
discussion directly on the GDCM ML.

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


Managing large python/c++ project

2008-06-20 Thread mathieu
Hi there,

  I am currently involved in managing a large python/c++ project
(using swig to automagically wrap c++ code to python). So far my
current experience was that python was a second class citizen and
extremely little python code was written and everything seemed to
work.

  Now this is the contrary, large portion of code are written python
with a few expection of c++ code for core algorithms. So as you might
have guess I am coming with a c++ background into the python world.

  Let's consider the following layout for project 'A':

  A/
moduleA.py
B/
  moduleB.py
C/
  moduleC.py
  module1.cxx
  module1.h
  module1.i
  A-binary-module-gcc43/
_module1.so
module1.py

  I have the current questions (I guess it's all about convention):

Q1. How should I import module1 (a c++ module that is compiled/wrap
into python) ? Because I have multiple compilers, I have a binary
directory per compiler. My guess was that PYTHONPATH should contain
the toplevel project *source* directory and the toplevel project
*binary* directory.

Possible answers:
A1.  'import module1'...well in that case I should really make sure
that noone ever tries to create a directory names module1 in directory
A/ otherwise 'import module1' statement is changing meaning.

A2. 'import A-binary-module-gcc43.module1' ... well this is safer and
would avoid namespace collision but the python code becomes dependent
(implicitely) of a compiler.

A3. Leave the module1 where it belong : in A/B/C subdirectory ... in
this case I need to have a source directory per compiler, which means
I need either some subttle trick with symlinks (lndir) or be ready to
have out of sync projects.

Q2. How do I import moduleA & moduleB ? Those are a simple python
modules that are located in A/. Behavior should be symmetric.

A1.
  'from A import moduleA'
  'from A.B import moduleB'

A2.
  'from A import moduleA'
  'from B import moduleB'

A3.
  'import moduleA'
  'import moduleB'

Basically A1 to A3 are organized in complexity of PYTHONPATH. A1 is
great because importing a moduleD in the future will just works
(PYTHONPATH is unchanged). A2 & A3 make the layout of the project
impact on the PYTHONPATH.

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


ImportError: No module named dl

2008-04-15 Thread mathieu
Hi there,

  I cannot figure out where did the 'dl' module went when running
python on AMD64 (debian stable).

  According to the documentation, I have :

 
python
>>> import sys
>>> help(sys.setdlopenflags)

...
setdlopenflags(...)

sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)
...

But when -as suggested by the doc- to load dl, I am getting:

>>> import dl
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named dl

dl module is extremely important since I need to load shared lib with
RTLD_GLOBAL (and not RTLD_LOCAL)
Ref:
http://gcc.gnu.org/ml/gcc/2002-05/msg00869.html
& http://lists.apple.com/archives/xcode-users/2006/Feb/msg00234.html

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


Iterating two arrays at once

2008-08-29 Thread mathieu
Hi there,

  just trying to figure out how to iterate over two array without
computing the len of the array:

  A = [1,2,3]
  B = [4,5,6]
  for a,b in A,B: # does not work !
print a,b

It should print:

  1,4
  2,5
  3,6

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


Re: Iterating two arrays at once

2008-08-29 Thread mathieu
On Aug 29, 12:46 pm, Matthias Bläsing <[EMAIL PROTECTED]
aachen.de> wrote:
> Am Fri, 29 Aug 2008 03:35:51 -0700 schrieb mathieu:>
>
> >   A = [1,2,3]
> >   B = [4,5,6]
> >   for a,b in A,B: # does not work !
> > print a,b
>
> > It should print:
>
> >   1,4
> >   2,5
> >   3,6
>
> Hey,
>
> zip is your friend:
>
> for a,b in zip(A,B):
> print a,b
>
> does what you want. If you deal with big lists, you can use izip from
> itertools, which returns a generator.
>
> from itertools import izip
> for a,b in izip(A,B):
> print a,b

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


Re: Test if list contains another list

2008-09-08 Thread mathieu
On Sep 8, 9:32 am, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> mathieu a écrit :
>
> > Hi there,
>
> >   I am trying to write something very simple to test if a list
> > contains another one:
>
> > a = [1,2,3]
>
> > b = [3,2,1,4]
>
> > but 'a in b' returns False.
>
> Indeed. Lists are not sets, and the fact that all elements of list a
> happens to also be part of list b doesn't make the list a itself an
> element of list b.
>
>  >>> a = [1, 2, 3]
>  >>> b = [3,2,1,4]
>  >>> c = [b, a]
>  >>> a in c
> True
>  >>> b in c
> True
>  >>> c
> [[3, 2, 1, 4], [1, 2, 3]]
>  >>>
>
> > How do I check that a is indeed contained
> > in b ?
>
> But that's what you did - you *did* checked if a was contained in b, and
> this is not the case. What you want is to check if *all elements* of a
> are contained in b, which is quite another problem. Now the answer to
> your question : use sets.
>
>  >>> set(a).issubset(set(b))
> True
>  >>>

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


Test if list contains another list

2008-09-08 Thread mathieu
Hi there,

  I am trying to write something very simple to test if a list
contains another one:

a = [1,2,3]

b = [3,2,1,4]

but 'a in b' returns False. How do I check that a is indeed contained
in b ?

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


SONAME for python modules is bad? (aka multiple module version)

2009-07-24 Thread mathieu
As far as I know there has not been any consensus on how to install
multiple version of a same module in python ? What are the recommended
mechanism ?

I could not find any documentation on the subject. Does anyone sees
any issue with using standard SONAME mechanism when installing a
python module ?

Thanks,

ref:
http://mail.python.org/pipermail/pythonmac-sig/2009-January/020936.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Why derivated exception can not be pickled ?

2012-09-04 Thread Mathieu Courtois
Here is my example :


import cPickle

ParentClass = object # works
ParentClass = Exception  # does not

class MyError(ParentClass):
def __init__(self, arg):
self.arg = arg

def __getstate__(self):
print '#DBG pass in getstate'
odict = self.__dict__.copy()
return odict

def __setstate__(self, state):
print '#DBG pass in setstate'
self.__dict__.update(state)

exc = MyError('IDMESS')

fo = open('pick.1', 'w')
cPickle.dump(exc, fo)
fo.close()

fo = open('pick.1', 'r')
obj = cPickle.load(fo)
fo.close()


1. With ParentClass=object, it works as expected.

2. With ParentClass=Exception, __getstate__/__setstate__ are not called.

Does anyone explain me why ?
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why derivated exception can not be pickled ?

2012-09-05 Thread Mathieu Courtois
Thanks for your reply


On Wednesday, September 5, 2012 8:02:55 AM UTC+2, Dieter Maurer wrote:
> 
> The pickle interface is actually more complex and there are several
> 
> ways an object can ensure picklability. For example, there is
> 
> also a "__reduce__" method. I suppose, that "Exception" defines methods
> 
> which trigger the use of an alternative picklability approach (different
> 
> from "__getstate__/__setstate__").

You're right: Exception has __reduce__ & __reduce_ex__ methods. Always read 
carefully the manual ;-)

I must override these methods.


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


Re: Why derivated exception can not be pickled ?

2012-09-05 Thread Mathieu Courtois
Hello,

The simple example works fine using __reduce__:

class MyError(Exception):
def __init__(self, arg):
self.arg = arg

def __reduce__(self):
return (MyError, (self.arg, ))

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


Embedding python : can't find encoding error

2011-02-28 Thread Mathieu CLERICI
Hi,

I'm trying to embed python in a c++ program.
I have compiled python32.lib with msvc 2010 targetting 32bits, i link
it with my program wich is also 32bit.
I get an error when calling Py_Initialize() : "no codec search
functions registered:  can't find encoding"

Py_FileSystemDefaultEncoding value is "mbcs".

_PyCodec_Lookup raise an eror because  len = PyList_Size(interp-
>codec_search_path); returns 0 in codecs.c

Does someone already had this problem ? I have no idea how to solve
that.

Sorry for my bad english.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding python : can't find encoding error

2011-02-28 Thread Mathieu CLERICI
Precisions : I'm trying to embed python 3.2 release.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to retrieve list of installed module (or gentoo bad installation ?)

2005-09-16 Thread mathieu . malaterre
Hello,

   I am trying to build an executable that link against python
libraries. If I only link to python lib I get thoses errors(*). This
machine is a gentoo AMD64. I installed python by doing 'emerge python'
and my USE flags uses 'zlib'.
   I am wondering if there is a 'python-config' like script that would
tell me that I also need to link against zlib libraries in order to
properly link my executable ?

   Has anyone seen this problem before ? Or is this simply that there
is a misconfiguration problem in my gentoo installation ?

Thanks for your advices,
Mathieu

(*)
/usr/lib64/python2.3/config/libpython2.3.a(zlibmodule.o)(.text+0x19f):
In function `PyZlib_compress':
: undefined reference to `deflateInit_'
/usr/lib64/python2.3/config/libpython2.3.a(zlibmodule.o)(.text+0x1c1):
In function `PyZlib_compress':
: undefined reference to `deflateEnd'
/usr/lib64/python2.3/config/libpython2.3.a(zlibmodule.o)(.text+0x2f8):
In function `PyZlib_compress':
: undefined reference to `deflate'
...

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


Re: How to retrieve list of installed module (or gentoo bad installation ?)

2005-09-16 Thread mathieu . malaterre
Yes and it's called python-config...

Sorry for the noise.

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


Simple regex with whitespaces

2006-09-10 Thread mathieu . malaterre
Hello,

  I cannot figure out a way to find a regular expression that would
match one and only one of these two strings:

s1 = '  how are you'
s2 = 'hello world   how are you'

  All I could come up with was:
patt = re.compile('^[ ]*([A-Za-z]+)[  ]+([A-Za-z]+)$')

  Which of course does not work. I cannot express the fact: sentence
have 0 or 1 whitespace, separation of group have two or more
whitespaces.

Any suggestion ? Thanks a bunch !
Mathieu

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


distutil & visual-studio-2005

2007-05-21 Thread Mathieu Gontier
Hello,

Few month ago, I try to build/install additional python packages like 
Numarray, Numpy, etc on Windows with Visual Studio 2005. I realized that 
distutil does not support Visual Studio 2005 and it was not planned to 
be included in the Python release at this moment.
Now, does someone has any news about the integration of Visual Studio 
2005 in distutil?

Many thanks,

-- 
Mathieu Gontier
Product Development Engineer
Free Field Technologies S.A.

Skype Name: mathieu_gontier

Read the attached v-card for telephone, fax, adress
Look at our web-site http://www.fft.be
 

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


Re: Linking debug C++ DLL with python dlls

2007-11-08 Thread Mathieu Gontier
Hello,

I often build Python on Windows.

What I can say is it not so trivial to build debug libraries for Python: 
each debug library must have the postfix *_d.dll/.pyd.

Another useful information. On Windows, a shared library is linked to 
our application though a associated file with the .lib extension. This 
"static library" contains all the information relating to de 
__declspec(import) / __declspec(export) instructions you should add in 
the code. The most important in Python is that the shared libraries 
(usually with the extension .dll) have as extension .pyd.
So, you can change it in Visual Studio.


Mathieu Gontier
Core Development Engineer

Read the attached v-card for telephone, fax, adress
Look at our web-site http://www.fft.be
 



[EMAIL PROTECTED] wrote:
> On Nov 8, 4:07 am, [EMAIL PROTECTED] wrote:
>   
>> I tried to change the code above (just for fun) so in both cases i'll
>> use python25.lib and in debug compilation I got linker errors on
>> unresolved externals. seems like the debug version exports more
>> methods than the release version.
>> 
>
> I usually just build my extensions in release mode and avoid using the
> debugger.  Getting a copy of python24_d.lib (in my case) and building
> a debug version of my extension isn't a big deal, but afaik all my
> other extensions (wxPython, numpy, etc) have to be built in debug mode
> as well in order for things to work.
>
> If you find a good solution, please post it to the group because I'd
> like to know how to do this as well.
>
> -Casey
>
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: do something in time interval

2008-10-06 Thread Mathieu Prevot
2008/10/6 Petr Jakeš <[EMAIL PROTECTED]>:
>> I am not an expert, but why not to use time.sleep(5)?
>> If you are using wxPython, you may also try wx.Timer, in which you could
>> set its interval.
>>
>
> Thanks for your reply.
> During the 5s period my script has to do some stuff instead of sleeping.
> Thats why it runs in the loop and once in 5s period it has to trigger some
> other stuff(function, method, action) to do.
> Petr Jakes

You might want to use threads so you have a very simple code like this:

data data0

thread1:
while True:
  time.sleep(5)
  doSomething(data0)

thread2:
while True:
  time.sleep(0.01)
 doAnotherthing(data0)

thread1 and thread2 can run in parallel; if thread2 take more time,
thread1 won't be impaired.

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


Re: Can this be done in py?

2008-11-07 Thread Mathieu Prevot
2008/11/7 Robert Singer <[EMAIL PROTECTED]>:
> Now, don't get me wrong if this is a trivial question, or even an
> apsurd one. I'm new to python, so my mileage may vary.
>
> I have several exe files, console applications that pretty much run on
> the principle:
>  first.exe
> Enter file name: start.dat
>  
>
>  second.exe
> Enter file name: filename.dat
>  
>
> ... you get the point.
>
> These are old exe programs, not mine (I can't recompile them or modify
> them in any way), but which work fine and I still regularly use them.
> However, I would like to automate this process (since they are not
> just two, and since this process of entering always the same data is
> tiresome.
>
> Is there a way this could be done with a python script ?
> A script which starts the .exe file, enters some predefined data,
> waits for an exe to finish, then again, starts the second .exe file,
> ... ?

Of course. See the subprocess module for this.

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


Popen: NameError: name 'PIPE' is not defined

2008-05-24 Thread Mathieu Prevot
Hi

I import subprocess and use Popen, but PIPE is not defined. I used
2.5.1, 2.5.2, Python 2.6a3+ (trunk:63576, May 24 2008, 12:13:40), it's
always the same. What am I missing ?

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


Re: Popen: NameError: name 'PIPE' is not defined

2008-05-24 Thread Mathieu Prevot
2008/5/24 Diez B. Roggisch <[EMAIL PROTECTED]>:
> Mathieu Prevot schrieb:
>>
>> Hi
>>
>> I import subprocess and use Popen, but PIPE is not defined. I used
>> 2.5.1, 2.5.2, Python 2.6a3+ (trunk:63576, May 24 2008, 12:13:40), it's
>> always the same. What am I missing ?
>
> Without showing code, it's hard to know. A guess is: if you use
>
> import subprocess
>
>
> then use
>
>
> subprocess.PIPE
>
> Or if using
>
> from subprocess import Popen
>
> make sure to do
>
> from subprocess import Popen, PIPE
>
> Diez

Indeed... thank you !

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


PIPE stderr

2008-05-24 Thread Mathieu Prevot
Hi again,

I don't have the same ouptput between 1) and 2) ... what's happening ?

1)
wget http://www.youtube.com/v/A8bwZf3vXjg -O /dev/null 2> file

2)
k = Popen (["wget", "http://www.youtube.com/v/A8bwZf3vXjg";, "-O", "/dev/null"],
stderr=PIPE)
print k.stderr

In the case 2) I got:

open file '', mode 'rb' at 0x5a608>

and I want what I get in file from 1) ... how to do this ?

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


Re: Flash Decoder

2008-05-28 Thread Mathieu Prevot
2008/5/28 Diez B. Roggisch <[EMAIL PROTECTED]>:
> Ankit wrote:
>
>> Hi everyone,i wanted to build a flash decoder using python can
>> somebody tell me which library to use and what steps should i follow
>> to make a flash(video) decoder?By a decoder i mean that i need to
>> display all the pixel values of each frame.Waiting for your replies.
>
> Check out libffmpeg. It should be accessible using python by various means,
> including gstreamer or ctypes.
>
> This is however a rather advanced topic.
>
> Diez

I think you might want make an ffmpeg/libffmpeg python wrap. It could
be really useful, and faster than a pure python decoder. Even for fun.

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


Re: Flash Decoder

2008-05-28 Thread Mathieu Prevot
2008/5/28 Ankit <[EMAIL PROTECTED]>:
> Thanks for replying guys but could you be a little more specific like
> in terms of steps i shd follow to make the decoder and also how is
> ffmpeg/libffmpeg going to help..

You can start by getting familiar with ffmpeg [1] by playing with it
and glance at its libraries (I call them libffmpeg, but they have
their specific name) allow you to do. Keep in mind that libraries
contain frequently used functions and are written so they can be
reused, shared by other/news softwares eg. the one you want. Start by
opening a flash video eg one .flv [2] file from youtube with a first
python script that use the right component(s) of libffmpeg. Python
allows you to use C libraries.

Mathieu

[1] http://ffmpeg.mplayerhq.hu/documentation.html
[2] http://en.wikipedia.org/wiki/Flv
--
http://mail.python.org/mailman/listinfo/python-list


Re: Flash Decoder

2008-05-28 Thread Mathieu Prevot
2008/5/28 ankit anand <[EMAIL PROTECTED]>:
> hmm i am more interested in .swf format and more specifically i would like
> to have all the pixel values of all the frames can i do that using this
> library?

Not with ffmpeg. You can check out the code from Gnash [1] or Swfdec
[2] or start you swf decoder from scratch using Adobe specification
[3] on the swf format.

Happy coding !
Mathieu

[1] http://en.wikipedia.org/wiki/Gnash
[2] http://en.wikipedia.org/wiki/Swfdec
[3] http://www.adobe.com/devnet/swf/
--
http://mail.python.org/mailman/listinfo/python-list


Re: gcc error in Mac OS X

2008-06-05 Thread Mathieu Prevot
2008/6/5 Zhaojie Boulder <[EMAIL PROTECTED]>:
> Hello,
> I am new to Mac and used python in linux before. What I am trying to do is
> to install "Ipython" and "PyCogent" in Mac OS X.
> For PyCogent, after entering the package path, I typed "python setup.py
> install". The results are as follows:
> Didn't find Pyrex - will compile from .c files
> running install
> running build
> running build_py
> running build_ext
> building 'cogent.align._compare' extension
> gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd
> -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX
> -I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe
> -I/Users/zhaojie/Downloads/PyCogent-1.0.1/include
> -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5
> -c cogent/align/_compare.c -o
> build/temp.macosx-10.5-i386-2.5/cogent/align/_compare.o -w
> unable to execute gcc: No such file or directory
> error: command 'gcc' failed with exit status 1
> After google, I installed Xcode,but it did not help. Also, the Xcode folder
> is not within "applications" folder, but a separate one parallel with
> "applications". Dragging Xcode folder into the applications folder did not
> make a difference, either.
> Hope someone familiar with Mac can help me out.

Normally gcc is installed in /usr/bin. If you type "which gcc", it
should return "/usr/bin/gcc". Xcode is an IDE that use gcc or another
compiler eg. icc the Intel compiler, hence if you move Xcode in the
application folfer it won't change anything. You install Xcode by
double clicking on a .pkg file from your Leopard DVD.

You also can download gcc from the site and bootstrap/compile it.

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


Re: gcc error in Mac OS X

2008-06-05 Thread Mathieu Prevot
2008/6/6 Mathieu Prevot <[EMAIL PROTECTED]>:
> 2008/6/5 Zhaojie Boulder <[EMAIL PROTECTED]>:
>> Hello,
>> I am new to Mac and used python in linux before. What I am trying to do is
>> to install "Ipython" and "PyCogent" in Mac OS X.
>> For PyCogent, after entering the package path, I typed "python setup.py
>> install". The results are as follows:
>> Didn't find Pyrex - will compile from .c files
>> running install
>> running build
>> running build_py
>> running build_ext
>> building 'cogent.align._compare' extension
>> gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd
>> -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX
>> -I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe
>> -I/Users/zhaojie/Downloads/PyCogent-1.0.1/include
>> -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5
>> -c cogent/align/_compare.c -o
>> build/temp.macosx-10.5-i386-2.5/cogent/align/_compare.o -w
>> unable to execute gcc: No such file or directory
>> error: command 'gcc' failed with exit status 1
>> After google, I installed Xcode,but it did not help. Also, the Xcode folder
>> is not within "applications" folder, but a separate one parallel with
>> "applications". Dragging Xcode folder into the applications folder did not
>> make a difference, either.
>> Hope someone familiar with Mac can help me out.
>
> Normally gcc is installed in /usr/bin. If you type "which gcc", it
> should return "/usr/bin/gcc". Xcode is an IDE that use gcc or another
> compiler eg. icc the Intel compiler, hence if you move Xcode in the
> application folfer it won't change anything. You install Xcode by
> double clicking on a .pkg file from your Leopard DVD.
>
> You also can download gcc from the site and bootstrap/compile it.

Note that you don't need to install Xcode in the "right place", it is
normally installed in /Developer, and installs gcc and other files in
/usr/bin /usr/share etc.

In general, try "locate prog" to try to find where is prog, and check
if the binary prog's path is in your PATH. eg. you can compile and
install a gnu tool by ./configure --prefix=$HOME && make && make
install, and the binaries will be installed in ~/bin/. If you don't
have ~/bin/ in your PATH, it won't execute. Adding 'export
PATH="$PATH:$HOME/bin:"' in your .bashrc will solve the problem (or
'setenv PATH "$PATH:$HOME/bin:' in your .tcshrc)

Using --prefix=$HOME allow you to run and install your binaries and
libraries. You can do this for a group of users without root access,
so you can share, or preserve your OS bin/lib/include/share easily, or
allow alternative use of several versions of libraries/binaries etc.

Other possibilities are the chroot and the sophisticated FreeBSD
jails. Google for them to know more.

Hope that helps,
Mathieu
--
http://mail.python.org/mailman/listinfo/python-list


configure fails

2008-06-05 Thread Mathieu Prevot
Hi,

I have the following error on a OSX.5 OS with CC=icc and using the
python-svn files:

checking size of wchar_t... configure: error: cannot compute sizeof (wchar_t)

I would like to help so we can compile python with icc/OSX.

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


python compilation on macosx with icc

2008-06-13 Thread Mathieu Prevot
Hi,

when I run configure, it fails at:

checking for wchar.h... yes
checking for wchar_t... yes
checking size of wchar_t... configure: error: cannot compute sizeof (wchar_t)

what can I do ?

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


Problem with subprocess.Popen wget within a thread

2008-07-06 Thread Mathieu Prevot
Hi

it seems the script (A) finishes before the downloading ends, and the
(B) version doesn't (wanted behavior) ... this is unexpected. What
happens ?


(A) 
class vid(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def download(self):
self.cmd = 'wget
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/7.0/7.0-RELEASE-i386-bootonly.iso'
self.child = subprocess.Popen(self.cmd.split())
def run(self):
self.download()

def main():
w = vid()
w.start()
w.join()

(B) 
class vid(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def download(self):
self.cmd = 'wget
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/7.0/7.0-RELEASE-i386-bootonly.iso'
self.child = subprocess.Popen(self.cmd.split(), 
stderr=subprocess.PIPE)
def run(self):
self.download()
self.child.stderr.readlines()

def main():
w = vid()
w.start()
w.join()

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


Re: Problem with subprocess.Popen wget within a thread

2008-07-07 Thread Mathieu Prevot
2008/7/6 Sebastian lunar Wiesner <[EMAIL PROTECTED]>:
> Mathieu Prevot <[EMAIL PROTECTED]>:
>
>> it seems the script (A) finishes before the downloading ends, and the
>> (B) version doesn't (wanted behavior) ... this is unexpected. What
>> happens ?
>
> "readlines" blocks, until the pipe is closed, which usually happens, if the
> process dies.
>
> On the other hand, spawned processes are usually asynchronous, you have to
> explicitly _wait_ for them.  And you're not waiting for it in example A.
>
> Anyway, the _proper_ way to wait for a child process is ... guess what ...
> the "wait" method of the Popen object ;)

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


do a sed / awk filter with python tools (at least as fast)

2008-07-07 Thread Mathieu Prevot
Hi,

I use in a bourne shell script the following filter:

sed '/watch?v=/! d;s/.*v=//;s/\(.\{11\}\).*/\1/' \
| sort | uniq | awk 'ORS=" "{print $1}'

that give me all sets of 11 characters that follows the "watch?v="
motif. I would like to do it in python on stdout from a
subprocess.Popen instance, using python tools rather than sed awk etc.
How can I do this ? Can I expect something as fast ?

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


Re: do a sed / awk filter with python tools (at least as fast)

2008-07-07 Thread Mathieu Prevot
2008/7/7 Peter Otten <[EMAIL PROTECTED]>:
> Mathieu Prevot wrote:
>
>> I use in a bourne shell script the following filter:
>>
>> sed '/watch?v=/! d;s/.*v=//;s/\(.\{11\}\).*/\1/' \
>> | sort | uniq | awk 'ORS=" "{print $1}'
>>
>> that give me all sets of 11 characters that follows the "watch?v="
>> motif. I would like to do it in python on stdout from a
>> subprocess.Popen instance, using python tools rather than sed awk etc.
>> How can I do this ? Can I expect something as fast ?
>
> You should either do it in Python , e. g.:
>
> def process(lines):
>candidates = (line.rstrip().partition("/watch?v=") for line in lines)
>matches = (c[:11] for a, b, c in candidates if len(c) >= 11)
>print " ".join(sorted(set(matches)))
>
> if __name__ == "__main__":
>import sys
>process(sys.stdin)
>
> or invoke your shell script via subprocess.Popen(). Invoking a python script
> via subprocess doesn't make sense IMHO.

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


Tricky problem: loss of terminal control after python script running (depending on internal parameters)

2008-07-08 Thread Mathieu Prevot
Hi there,

I have a python script that runs subprocesses (task =  ffmpeg for
convertion of videos to images) from threads [1]. I want to run at
most 4 (default) tasks at the same time, and I usually ask the python
script to process 10 files for testing. I'll run it on thousands of
files for primetime.
It seems that when I ask to process < 4 files everything is ok, but if
I ask for > 4 files to process, I loose terminal features (no more
newlines, etc).
What's happening ? What is wrong in my script ?

Thanks,
Mathieu

[1]:
,--  thread -- subprocess
script --|-- thread -- subprocess
|--  thread -- subprocess
'--  thread -- subprocess


youff.py
Description: Binary data
--
http://mail.python.org/mailman/listinfo/python-list

error with configure (svn 64857)

2008-07-10 Thread Mathieu Prevot
Hi,

I have the following error when I run configure:

checking size of wchar_t... configure: error: cannot compute sizeof (wchar_t)

what can I do ?

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


Re: error with configure (svn 64857)

2008-07-10 Thread Mathieu Prevot
2008/7/10 "Martin v. Löwis" <[EMAIL PROTECTED]>:
>> I have the following error when I run configure:
>>
>> checking size of wchar_t... configure: error: cannot compute sizeof (wchar_t)
>>
>> what can I do ?
>
> Study config.log for the source of the problem.

Thank you Martin. How can I remove -lgcc_s and use the Intel equivalent ?

configure:21939: checking for wchar_t
configure:21970: icc -c -g -O2  conftest.c >&5
conftest.c(123): warning #279: controlling expression is constant
  if ((ac__type_new_ *) 0)
  ^

configure:21976: $? = 0
configure:21991: result: yes
configure:21998: checking size of wchar_t
configure:22306: icc -o conftest -g -O2   conftest.c  >&5
ld: library not found for -lgcc_s
configure:22309: $? = 1
configure: program exited with status 1

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


Re: error with configure (svn 64857)

2008-07-11 Thread Mathieu Prevot
2008/7/11 "Martin v. Löwis" <[EMAIL PROTECTED]>:
>> Thank you Martin. How can I remove -lgcc_s and use the Intel equivalent ?
>
> I'm not so sure that there is anything wrong in configure. configure
> doesn't pass -lgcc_s to icc; instead, icc is making this up on its
> own. So I would guess you need to get libgcc_s onto you system in a
> way that the linker finds it. Else you need to read the icc
> documentation (but I'm fairly sure that icc is *required* to link
> with libgcc_s, for interoperability with gcc-compiled binaries).
>
> I'm somewhat puzzled that the wchar_t test is the one where it
> crashes; this test comes fairly late, and configure has run multiple
> compiler invocations before that.
>
> Can you build any binaries at all with your icc installation?

Yes of course, I successfuly built and installed nmap, wget, so I
thought there was something in the python configure process.

If didn't investigate everything but I solved the problem by adding
the "-static-libgcc" option:

CFLAGS="-w -static-intel -static-libgcc"

I think one should commit changes so configure can manage this. I can
I want to help for further diagnosis or improvement. Also it seems
-Wall will be deprecated, and usually we use -w:

   -w  Control diagnostics, where  is one of the following:

 0 -- Display errors (same as -w)

 1 -- Display warnings and errors (default)

 2 -- Display remarks, warnings, and errors


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


Re: error with configure (svn 64857)

2008-07-11 Thread Mathieu Prevot
2008/7/11 WDC <[EMAIL PROTECTED]>:
> On Jul 10, 6:57 pm, "Mathieu Prevot" <[EMAIL PROTECTED]> wrote:
>> 2008/7/10 "Martin v. Löwis" <[EMAIL PROTECTED]>:
>>
>> >> I have the following error when I run configure:
>>
>> >> checking size of wchar_t... configure: error: cannot compute sizeof 
>> >> (wchar_t)
>>
>> >> what can I do ?
>>
>> > Study config.log for the source of the problem.
>>
>> Thank you Martin. How can I remove -lgcc_s and use the Intel equivalent ?
>>
>> configure:21939: checking for wchar_t
>> configure:21970: icc -c -g -O2  conftest.c >&5
>> conftest.c(123): warning #279: controlling expression is constant
>>   if ((ac__type_new_ *) 0)
>>   ^
>>
>> configure:21976: $? = 0
>> configure:21991: result: yes
>> configure:21998: checking size of wchar_t
>> configure:22306: icc -o conftest -g -O2   conftest.c  >&5
>> ld: library not found for -lgcc_s
>> configure:22309: $? = 1
>> configure: program exited with status 1
>>
>> Mathieu
>
> I think he wanted YOU to find the problem. The best way to learn is to
> figure it out yourself! Good luck.

Yes WDC I know, but for some problems 1) we can gain much efficiency
with getting help from guys that are familiar with the environment and
 2) we also allow the committers to know a problem and improve the
sources. That's the way an open source group works IMHO :)

Now that the problem is solved for me, it is for all MacOSX+Intel icc guys.

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


kill thread

2008-08-07 Thread Mathieu Prevot
Hi,

I have a threading.Thread class with a "for i in range(1,50)" loop
within. When it runs and I do ^C, I have the error [1] as many as
loops. I would like to catch this exception (and if possible do some
cleanup like in C pthreads) so the program finishes cleanly. Where and
how can I do this ? in __run__ ? __init__ ? a try/except stuff ?

Thanks,
Mathieu

[1]:
^CException in thread Thread-1:
Traceback (most recent call last):
  File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/threading.py",
line 486, in __bootstrap_inner
self.run()
  File "./youfetch.py", line 148, in run
self.getids()
  File "./youfetch.py", line 145, in getids
self.ids.append(self.getidsatpage(i))
  File "./youfetch.py", line 138, in getidsatpage
self.child = subprocess.Popen(cmd.split(),stdout=subprocess.PIPE)
  File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py",
line 594, in __init__
errread, errwrite)
  File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py",
line 1011, in _execute_child
self.pid = os.fork()
KeyboardInterrupt
--
http://mail.python.org/mailman/listinfo/python-list


Re: kill thread

2008-08-08 Thread Mathieu Prevot
2008/8/8 Miki <[EMAIL PROTECTED]>:
> Hello,
>
>> I have a threading.Thread class with a "for i in range(1,50)" loop
>> within. When it runs and I do ^C, I have the error [1] as many as
>> loops. I would like to catch this exception (and if possible do some
>> cleanup like in C pthreads) so the program finishes cleanly. Where and
>> how can I do this ? in __run__ ? __init__ ? a try/except stuff ?
> You can have a try/except KeyboardException around the thread code.
>
> HTH,
> --
> Miki

Of course, but I don't know where. I placed this inside loop, within
called functions from the loop, I still have the problem.

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


Re: kill thread

2008-08-09 Thread Mathieu Prevot
2008/8/8  <[EMAIL PROTECTED]>:
> On 8 Ago, 10:03, "Mathieu Prevot" <[EMAIL PROTECTED]> wrote:
>> 2008/8/8 Miki <[EMAIL PROTECTED]>:
>>
>> > Hello,
>>
>> >> I have a threading.Thread class with a "for i in range(1,50)" loop
>> >> within. When it runs and I do ^C, I have the error [1] as many as
>> >> loops. I would like to catch this exception (and if possible do some
>> >> cleanup like in C pthreads) so the program finishes cleanly. Where and
>> >> how can I do this ? in __run__ ? __init__ ? a try/except stuff ?
>> > You can have a try/except KeyboardException around the thread code.
>>
>> > HTH,
>> > --
>> > Miki
>>
>> Of course, but I don't know where. I placed this inside loop, within
>> called functions from the loop, I still have the problem.
>>
>> Mathieu
>
> Try this:
>
>  loop_completed = True
>  for i in range(1,50):
>  try:
> # your code here
>  except KeyboardException:
> loop_completed = False
> break # this breaks the loop
>  # end loop
>  if loop_completed:
> # code to be executed in case of normal completion
>  else:
> # code to be executed in case of interruption
>  # code to be executed in both cases

Thanks for answers. My code sheme was the following: main() starts 2
thread trees (threads of threads of ...) and some of these have "for"
loops. These loops needed to be as you recommended:

for ... :
  try:
# instructions
  except KeyboardInterrupt:
# cleaning instructions
break

The problem with atexit.register is that is doesn't work in case of
system signals catches (http://tinyurl.com/6kdaba)

Thanks,
Mathieu

_
def main():
query1 = Thread1
batch1 = Thread2
while True:
try:
#some code for updating / synchronize / etc threads
except KeyboardInterrupt:
try:
query1.terminate()
batch1.terminate()
except:
pass
finally:
break
_


I used also from http://sebulba.wikispaces.com/recipe+thread2
the following new Thread class:

_
import threading, inspect, ctypes

def _async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed"""
if not inspect.isclass(exctype):
raise TypeError("Only types can be raised (not instances)")
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid,
ctypes.py_object(exctype))
if res == 0:
raise ValueError("invalid thread id")
elif res != 1:
# """if it returns a number greater than one, you're in trouble,
# and you should call it again with exc=NULL to revert the effect"""
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
raise SystemError("PyThreadState_SetAsyncExc failed")

class Thread(threading.Thread):
def _get_my_tid(self):
"""determines this (self's) thread id"""
if not self.isAlive():
raise threading.ThreadError("the thread is not active")

# do we have it cached?
if hasattr(self, "_thread_id"):
return self._thread_id

# no, look for it in the _active dict
for tid, tobj in threading._active.items():
if tobj is self:
self._thread_id = tid
return tid

raise AssertionError("could not determine the thread's id")

def raise_exc(self, exctype):
"""raises the given exception type in the context of this thread"""
_async_raise(self._get_my_tid(), exctype)

def terminate(self):
"""raises SystemExit in the context of the given thread, which should
cause the thread to exit silently (unless caught)"""
self.raise_exc(SystemExit)
_
--
http://mail.python.org/mailman/listinfo/python-list


download limit

2008-08-10 Thread Mathieu Prevot
Hi,

I have a multithreaded script that  mainly creates several wget
processes to download files. I would like to check/see and eventually
limit the bandwidth of the pool of processes. One way to do this is to
change the number of wget instances, but it's a workaround.

What do you recommend to do the following in python:
1) know the bitrate at the script scale
2) control, and limit or not this bitrate

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


Re: threading

2008-08-14 Thread Mathieu Prevot
2008/8/13 Parimala <[EMAIL PROTECTED]>:
> Hello,
>
>I am using python2.5.1 version to run my test scripts. I want to use
> 'threading' module in my tests. As a startup program, I had run the
> following one.
>
> import threading
> import sys
> import time
>
> def hello():
>   i=0
>   try:
> while i<10:
>   print "hi"
>   time.sleep(1)
>   i+=1
>   except KeyboardInterrupt:
> print 'KeyboardInterrupt'
> raise KeyboardInterrupt
>
> try:
>   thread=threading.Thread(target=hello,args=())
>   thread.start()
> except KeyboardInterrupt:
>   print 'KeyboardInterrupt'
>   raise KeyboardInterrupt
>
> once program starts, problem is..
> I am not able to abort the thread using (CTRL+C) KeyboardInterrupt.  While
> running if I press CTRL+C, it won't generate any exception until the end of
> the execution. Once the execution gets over,  it will give "Exception
> exceptions.KeyboardInterrupt in  'C:\python25\lib\threading.py'> ignored" this message and exits.
>
> I had gone through some documents, it says if a thread is joined with
> .join() method then we can't stop that process until it releases the lock
> what it acquired. But in the above program I didn't use .join() method but
> still I am not able to abort the thread.
>
> Could you please suggest me how can I abort the thread at any point in time
> using CTRL+C.

Hi,

a terminate method is given here:
http://sebulba.wikispaces.com/recipe+thread2

so you can terminate the thread by:

(...)
t.start()
(...)

while True:
  try:
#some code
  except KeyboardInterrupt:
t.terminate()
break

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


python 64bits on macosx.5 /leopard

2008-08-14 Thread Mathieu Prevot
Hi,

in order to run django on apache, I need mod_python in apache, and it
runs in 64 on leopard, so I need to run python in 64 bits.
I tryed ./configure --enable-framework OPT="-arch x86_64" but make fails:

===
gcc  -u _PyMac_Error Python.framework/Versions/2.6/Python -o python.exe \
Modules/python.o \
 -ldl
ld: warning in Modules/python.o, file is not of required architecture
===

file Python.framework/Versions/2.6/Python gives me:

===
Python.framework/Versions/2.6/Python: Mach-O dynamically linked shared
library i386
===

Which method do you recommend ?

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


subprocess seems to "detach" / ignore wait()

2008-08-20 Thread Mathieu Prevot
Hi there,

it seems that  child.wait() is ignored when

  print "Server running [PID %s]"%(child.pid)
  fpid.write(child.pid)

are between the process creation child = Popen(cmd.split(),
stderr=flog) and child.wait().
It seems to be a bug, doesn't it ?

Mathieu

(I'm running x11vnv with args in the cmd string on FreeBSD 8.0/CURRENT)

flog = open(logfile, 'w')
fpid = open(pidfile, 'w')
try:
  child = Popen(cmd.split(), stderr=flog)
  print "Server running [PID %s]"%(child.pid)
  fpid.write(child.pid)
  child.wait()
except KeyboardInterrupt:
  print "INT sent to vnc server"
finally:
  fpid.close()
  flog.close()
  os.remove(pidfile)
  os.remove(logfile)
  sys.exit(0)
--
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess seems to "detach" / ignore wait()

2008-08-20 Thread Mathieu Prevot
2008/8/20 Gabriel Genellina <[EMAIL PROTECTED]>:
> En Wed, 20 Aug 2008 12:22:16 -0300, Wojtek Walczak <[EMAIL PROTECTED]> 
> escribió:
>
>> On Wed, 20 Aug 2008 15:09:11 +0200, Mathieu Prevot wrote:
>>
>>>   child = Popen(cmd.split(), stderr=flog)
>>>   print "Server running [PID %s]"%(child.pid)
>>>   fpid.write(child.pid)
>>
>> I think that the problem here is that fpid.write() fails silently
>> (probably TypeError), because it takes string as its first argument,
>> not integer.
>
> Exactly, but it doesn't fail "silently" (that would be a bug). The exception 
> is raised, but due to the finally clause ending in sys.exit(0), it has no 
> chance of being handled.
> This is the original code, for reference:
>
> flog = open(logfile, 'w')
> fpid = open(pidfile, 'w')
> try:
>  child = Popen(cmd.split(), stderr=flog)
>  print "Server running [PID %s]"%(child.pid)
>  fpid.write(child.pid)
>  child.wait()
> except KeyboardInterrupt:
>  print "INT sent to vnc server"
> finally:
>  fpid.close()
>  flog.close()
>  os.remove(pidfile)
>  os.remove(logfile)
>  sys.exit(0)
>
> --
> Gabriel Genellina


Indeed, I got TypeError: argument 1 must be string or read-only
character buffer, not int
and Wojtek's code works. So what is the right thing to do so my script
returns 1 or 0 depending on its state and success ?

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


Re: subprocess seems to "detach" / ignore wait()

2008-08-20 Thread Mathieu Prevot
2008/8/21 Mathieu Prevot <[EMAIL PROTECTED]>:
> 2008/8/20 Gabriel Genellina <[EMAIL PROTECTED]>:
>> En Wed, 20 Aug 2008 12:22:16 -0300, Wojtek Walczak <[EMAIL PROTECTED]> 
>> escribió:
>>
>>> On Wed, 20 Aug 2008 15:09:11 +0200, Mathieu Prevot wrote:
>>>
>>>>   child = Popen(cmd.split(), stderr=flog)
>>>>   print "Server running [PID %s]"%(child.pid)
>>>>   fpid.write(child.pid)
>>>
>>> I think that the problem here is that fpid.write() fails silently
>>> (probably TypeError), because it takes string as its first argument,
>>> not integer.
>>
>> Exactly, but it doesn't fail "silently" (that would be a bug). The exception 
>> is raised, but due to the finally clause ending in sys.exit(0), it has no 
>> chance of being handled.
>> This is the original code, for reference:
>>
>> flog = open(logfile, 'w')
>> fpid = open(pidfile, 'w')
>> try:
>>  child = Popen(cmd.split(), stderr=flog)
>>  print "Server running [PID %s]"%(child.pid)
>>  fpid.write(child.pid)
>>  child.wait()
>> except KeyboardInterrupt:
>>  print "INT sent to vnc server"
>> finally:
>>  fpid.close()
>>  flog.close()
>>  os.remove(pidfile)
>>  os.remove(logfile)
>>  sys.exit(0)
>>
>> --
>> Gabriel Genellina
>
>
> Indeed, I got TypeError: argument 1 must be string or read-only
> character buffer, not int
> and Wojtek's code works. So what is the right thing to do so my script
> returns 1 or 0 depending on its state and success ?

PS: BTW how can I detach my process ie have an equivalent to
`myscript.py&` from the python script ?

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


Re: subprocess seems to "detach" / ignore wait()

2008-08-21 Thread Mathieu Prevot
2008/8/21 Gabriel Genellina <[EMAIL PROTECTED]>:
> En Thu, 21 Aug 2008 02:46:06 -0300, Mathieu Prevot <[EMAIL PROTECTED]> 
> escribió:
>
>>> So what is the right thing to do so my script
>>> returns 1 or 0 depending on its state and success ?
>
> I use something like this:
>
> def main(argv):
>  try:
>try:
>  do_things()
>  return 0
>finally:
>  do_cleanup()
>  except:
>log_exception()
>return 1
>
> if __name__=='__main__':
>  import sys
>  sys.exit(main(sys.argv))
>
>> PS: BTW how can I detach my process ie have an equivalent to
>> `myscript.py&` from the python script ?
>
> There are a few recipes in the Python CookBook at 
> http://code.activestate.com/recipes/langs/python/

The return from main()... it was my thought too.
Thank you Gabriel :)

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


use str as variable name

2008-09-04 Thread Mathieu Prevot
Hi,

I have a program that take a word as argument, and I would like to
link this word to a class variable.

eg.
class foo():
  width = 10
  height = 20

a=foo()
arg='height'
a.__argname__= new_value

rather than :

if arg == 'height':
  a.height = new_value
elif arg == 'width';
  a.width = new_value

Can I do this with python ? How ?

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


Re: use str as variable name

2008-09-04 Thread Mathieu Prevot
2008/9/4 Chris Rebert <[EMAIL PROTECTED]>:
> On Thu, Sep 4, 2008 at 12:25 AM, Mathieu Prevot
> <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I have a program that take a word as argument, and I would like to
>> link this word to a class variable.
>>
>> eg.
>> class foo():
>
> You should subclass 'object', so that should be:
>class Foo(object):
>
>>  width = 10
>>  height = 20
>>
>> a=foo()
>> arg='height'
>> a.__argname__= new_value
>
> You're looking for the setattr() built-in function. In this exact case:
>setattr(a, arg, new_value)
>
> This is probably covered in the Python tutorial, please read it.
>
> Regards,
> Chris

Indeed.

I'll use:
a.__setattr__(height, new_value)

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


Re: use str as variable name

2008-09-04 Thread Mathieu Prevot
2008/9/4 Fredrik Lundh <[EMAIL PROTECTED]>:
> Bruno Desthuilliers wrote:
>
>> You wouldn't write something like 2.__add__(3), would you ?
>
> Don't give the "it's only OO if I write obj.method(args)" crowd more bad
> ideas, please ;-)
>
> (...as Bruno implies, setattr(), len() et al can be and should be viewed as
> generic functions.  A specific Python implementation may use custom code to
> implement behaviour for a given object; behaviour that's more efficient than
> a full Python-level method call.  For example, in CPython, len(L) is about
> twice as fast as L.__len__() for built-in sequences.)

Got it. Thanks :)
Mathieu
--
http://mail.python.org/mailman/listinfo/python-list


path slashes cleaning

2008-09-04 Thread Mathieu Prevot
Hi,

for scripts that take arguments, I would like to remove the trailing
slash if it's present.

Is there something else than:

a='/usr/local/lib/'
if a[-1] == '/':
  a = list(a)
  a.pop()
  ''.join(a)

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


Re: path slashes cleaning

2008-09-04 Thread Mathieu Prevot
2008/9/4 Mathieu Prevot <[EMAIL PROTECTED]>:
> Hi,
>
> for scripts that take arguments, I would like to remove the trailing
> slash if it's present.
>
> Is there something else than:
>
> a='/usr/local/lib/'
> if a[-1] == '/':
>  a = list(a)
>  a.pop()
>  ''.join(a)

A dummy

a.rstrip('/')

Sorry for the noise
Mathieu
--
http://mail.python.org/mailman/listinfo/python-list


Canonical way to build Python 2.6/svn on MacIntel/MacOSX10.5 with icc 32bits 10.1.014

2008-09-06 Thread Mathieu Prevot
Hi,

I would like to build Python (svn) on Macosx 10.5 with icc in
/opt/intel/cc (32 bit). Can you help me to determine the right way to
do this ?

I got a prototype with:

export CC=icc
export CXX=icpc
export CFLAGS="-w"
./configure --with-framework-name=PythonIntel

1) It seems to be unsufficient. Does someone have links/mail
archives/patches/scripts ?

2) Python needs gettext for _locale package, but I fail to compile it with icc.

3) How can I build an autonomous and sufficient distribution (a dmg
file with everything in it) ?

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


Failure in building ctypes with intel icc

2008-09-06 Thread Mathieu Prevot
Hi,

I got this error in compilation, and I don't know how to solve it:

*** WARNING: renaming "_ctypes" since importing it failed:
dlopen(build/lib.macosx-10.3-i386-2.6/_ctypes.so, 2): Symbol not
found: ___builtin_dwarf_cfa
  Referenced from:
/Users/mathieuprevot/svn/python/build/lib.macosx-10.3-i386-2.6/_ctypes.so
  Expected in: dynamic lookup

Any hints ?

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


Re: how to build a MacOS universal python package including external dependencies

2008-09-24 Thread Mathieu Prevot
2008/9/24 Jaime Huerta Cepas <[EMAIL PROTECTED]>:
> Hi all,
>
> I have developed a set python libraries that provide several scientific
> methods to analyse and visualize certain type of biological data.  This
> libraries are based on many external python modules, such as python-mysql
> python-sip or python-qt4. I use GNU/linux to develop my tools and I found no
> problems into installing all dependencies, however it does not seem to be
> that easy on MacOS. I am sure that all the dependencies (qt4, pyqt4 ,
> mysqldb, scipy, numpy) are cross platform, but when you are trying to
> publish your tool in an academic journal, most referees (many of them using
> MacOS) expect some kind of straightforward installation process for the
> tool.
>
> I wonder if there would be a way in which I could compile all the
> dependencies and libraries in a MacOs system and then building a static
> universal binary that I can distribute. I guess  it should be possible, but
> I am not sure how difficult it might be, and whether all dependencies (qt4
> is huge) can be packaged together.

IMHO this is too complex to commit. Macport is a way to do what you
want, but packages may not be up to date enough. Maybe the easiest and
simplest way for you to do this is to write a script that will
download, compile and install everything.

The script should work like:

sudo all_in_one_script.py

and then wait for jobs to be done. Your script will need to know if a
package was sucessfully installed and then continue or take steps and
say it. For a complex set of dependencies, I recommend you to write
Makefiles.

For instance, in pseudo-code:
if /usr/local/lib/libfoo.dylib doesn't exist
  download foo
  install foo

if python-module foo doesn't exist
  download foo
  python foo/setup.py install

etc

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


SSL certificate of a server on Windows

2017-05-23 Thread COPIN Mathieu.
Hi, 

I want to get a server certificate from the host-name.

I know I could do something like :
> call(openssl, s_client, -showcerts, -connect, hostname:port)


But the thing is to do it without openssl because I want to run the script on 
Windows.

Any suggestions ?
Mathieu
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SSL certificate of a server on Windows

2017-05-24 Thread COPIN Mathieu.
Le mardi 23 mai 2017 19:10:11 UTC+2, Irmen de Jong a écrit :
> On 23-5-2017 10:19, COPIN Mathieu. wrote:
> > Hi, 
> > 
> > I want to get a server certificate from the host-name.
> > 
> > I know I could do something like :
> >> call(openssl, s_client, -showcerts, -connect, hostname:port)
> > 
> > 
> > But the thing is to do it without openssl because I want to run the script 
> > on Windows.
> > 
> > Any suggestions ?
> > Mathieu
> > 
> 
> I guess you mean: without calling "openssl.exe"
> 
> 
> import ssl
> cert = sll.get_server_certificate(("www.google.com", 443))
> 
> See
> https://docs.python.org/3.6/library/ssl.html#ssl.get_server_certificate
> 
> 
> 
> Irmen

That's what I neeeded, thank you !
-- 
https://mail.python.org/mailman/listinfo/python-list