Linking to Python for Windows CE

2006-01-16 Thread Martin Evans
I've just been tasked with porting our desktop embedded Python support 
onto our existing CE offering. I've managed to compile the Python 
sources and have produced an armdbg420\python23.lib file.

When I come to link to the Python library though from our one of our 
DLLs, I am getting the following unresolved externals:

---
embedded.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) int __cdecl WinCE_fclose(void *)"
(__imp_?WinCE_fclose@@[EMAIL PROTECTED]) referenced in function "unsigned long
__cdecl PythonThread(void *)" (?PythonThread@@[EMAIL PROTECTED])

embedded.obj : error LNK2019: unresolved external symbol __imp_LoadLibraryU
referenced in function "unsigned long __cdecl PythonThread(void *)"
(?PythonThread@@[EMAIL PROTECTED])

embedded.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) void * __cdecl WinCE_fopen(char const *,char const
*)" (__imp_?WinCE_fopen@@[EMAIL PROTECTED]) referenced in function "void * 
__cdecl
OpenScriptFile(unsigned short *)" (?OpenScriptFile@@[EMAIL PROTECTED])

---

python23.lib does have entries for WinCE_fopen (part of 
wince-compatibility.c) when looking at the lib file using dumpbin (all 
are undecorated). Have I missed some vital step in producing it?


Just to clarify my environment, I am producing a PocketPC 2003 
application that embeds Python, scripts are launched within our 
application with script output displayed in our own output window. We 
also provide our own Python extension library. All works on ok on the 
desktop version.

Any help would gratefully appreciated. Thanks.

Martin

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


Re: Linking to Python for Windows CE

2006-01-16 Thread Martin Evans
Sorry, false alarm.  It turned out one of my own files was using 
fopen/fclose and this was upseting things. After removing those it 
linked fine.

Martin Evans wrote:

> I've just been tasked with porting our desktop embedded Python support 
> onto our existing CE offering. I've managed to compile the Python 
> sources and have produced an armdbg420\python23.lib file.
> 
> When I come to link to the Python library though from our one of our 
> DLLs, I am getting the following unresolved externals:
> 
> ---
> embedded.obj : error LNK2019: unresolved external symbol
> "__declspec(dllimport) int __cdecl WinCE_fclose(void *)"
> (__imp_?WinCE_fclose@@[EMAIL PROTECTED]) referenced in function "unsigned long
> __cdecl PythonThread(void *)" (?PythonThread@@[EMAIL PROTECTED])
> 
> embedded.obj : error LNK2019: unresolved external symbol __imp_LoadLibraryU
> referenced in function "unsigned long __cdecl PythonThread(void *)"
> (?PythonThread@@[EMAIL PROTECTED])
> 
> embedded.obj : error LNK2019: unresolved external symbol
> "__declspec(dllimport) void * __cdecl WinCE_fopen(char const *,char const
> *)" (__imp_?WinCE_fopen@@[EMAIL PROTECTED]) referenced in function "void * 
> __cdecl
> OpenScriptFile(unsigned short *)" (?OpenScriptFile@@[EMAIL PROTECTED])
> 
> ---
> 
> python23.lib does have entries for WinCE_fopen (part of 
> wince-compatibility.c) when looking at the lib file using dumpbin (all 
> are undecorated). Have I missed some vital step in producing it?
> 
> 
> Just to clarify my environment, I am producing a PocketPC 2003 
> application that embeds Python, scripts are launched within our 
> application with script output displayed in our own output window. We 
> also provide our own Python extension library. All works on ok on the 
> desktop version.
> 
> Any help would gratefully appreciated. Thanks.
> 
> Martin
> 

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


RegEx conditional search and replace

2006-07-05 Thread Martin Evans
Sorry, yet another REGEX question.  I've been struggling with trying to get 
a regular expression to do the following example in Python:

Search and replace all instances of "sleeping" with "dead".

This parrot is sleeping. Really, it is sleeping.
to
This parrot is dead. Really, it is dead.


But not if part of a link or inside a link:

This parrot is sleeping. Really, it 
is sleeping.
to
This parrot is sleeping. Really, it 
is dead.


This is the full extent of the "html" that would be seen in the text, the 
rest of the page has already been processed. Luckily I can rely on the 
formating always being consistent with the above example (the url will 
normally by much longer in reality though). There may though be more than 
one link present.

I'm hoping to use this to implement the automatic addition of links to other 
areas of a website based on keywords found in the text.

I'm guessing this is a bit too much to ask for regex. If this is the case, 
I'll add some more manual Python parsing to the string, but was hoping to 
use it to learn more about regex.

Any pointers would be appreciated.

Martin



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


Re: RegEx conditional search and replace

2006-07-06 Thread Martin Evans
"Juho Schultz" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Martin Evans wrote:
>> Sorry, yet another REGEX question.  I've been struggling with trying to 
>> get
>> a regular expression to do the following example in Python:
>>
>> Search and replace all instances of "sleeping" with "dead".
>>
>> This parrot is sleeping. Really, it is sleeping.
>> to
>> This parrot is dead. Really, it is dead.
>>
>>
>> But not if part of a link or inside a link:
>>
>> This parrot is sleeping. Really, 
>> it
>> is sleeping.
>> to
>> This parrot is sleeping. Really, 
>> it
>> is dead.
>>
>>
>> This is the full extent of the "html" that would be seen in the text, the
>> rest of the page has already been processed. Luckily I can rely on the
>> formating always being consistent with the above example (the url will
>> normally by much longer in reality though). There may though be more than
>> one link present.
>>
>> I'm hoping to use this to implement the automatic addition of links to 
>> other
>> areas of a website based on keywords found in the text.
>>
>> I'm guessing this is a bit too much to ask for regex. If this is the 
>> case,
>> I'll add some more manual Python parsing to the string, but was hoping to
>> use it to learn more about regex.
>>
>> Any pointers would be appreciated.
>>
>> Martin
>
> What you want is:
>
> re.sub(regex, replacement, instring)
> The replacement can be a function. So use a function.
>
> def sleeping_to_dead(inmatch):
>  instr = inmatch.group(0)
>  if needsfixing(instr):
>return instr.replace('sleeping','dead')
>  else:
>return instr
>
> as for the regex, something like
> (]*()?
> could be a start. It is probaly better to use the regex to recognize
> the links as you might have something like
> sleeping.sleeping/sleeping/sleeping.html in your urls. Also you
> probably want to do many fixes, so you can put them all within the same
> replacer function.

Many thanks for that, the function method looks very useful. My first 
working attempt had been to use the regex to locate all links. I then looped 
through replacing each with a numbered dummy entry. Then safely do the 
find/replaces and then replace the dummy entries with the original links. It 
just seems overly inefficient.



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


Re: RegEx conditional search and replace

2006-07-06 Thread Martin Evans
"mbstevens" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Thu, 06 Jul 2006 08:32:46 +0100, Martin Evans wrote:
>
>> "Juho Schultz" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>> Martin Evans wrote:
>>>> Sorry, yet another REGEX question.  I've been struggling with trying to
>>>> get
>>>> a regular expression to do the following example in Python:
>>>>
>>>> Search and replace all instances of "sleeping" with "dead".
>>>>
>>>> This parrot is sleeping. Really, it is sleeping.
>>>> to
>>>> This parrot is dead. Really, it is dead.
>>>>
>>>>
>>>> But not if part of a link or inside a link:
>>>>
>>>> This parrot is sleeping. 
>>>> Really,
>>>> it
>>>> is sleeping.
>>>> to
>>>> This parrot is sleeping. 
>>>> Really,
>>>> it
>>>> is dead.
>>>>
>>>>
>>>> This is the full extent of the "html" that would be seen in the text, 
>>>> the
>>>> rest of the page has already been processed. Luckily I can rely on the
>>>> formating always being consistent with the above example (the url will
>>>> normally by much longer in reality though). There may though be more 
>>>> than
>>>> one link present.
>>>>
>>>> I'm hoping to use this to implement the automatic addition of links to
>>>> other
>>>> areas of a website based on keywords found in the text.
>>>>
>>>> I'm guessing this is a bit too much to ask for regex. If this is the
>>>> case,
>>>> I'll add some more manual Python parsing to the string, but was hoping 
>>>> to
>>>> use it to learn more about regex.
>>>>
>>>> Any pointers would be appreciated.
>>>>
>>>> Martin
>>>
>>> What you want is:
>>>
>>> re.sub(regex, replacement, instring)
>>> The replacement can be a function. So use a function.
>>>
>>> def sleeping_to_dead(inmatch):
>>>  instr = inmatch.group(0)
>>>  if needsfixing(instr):
>>>return instr.replace('sleeping','dead')
>>>  else:
>>>return instr
>>>
>>> as for the regex, something like
>>> (]*()?
>>> could be a start. It is probaly better to use the regex to recognize
>>> the links as you might have something like
>>> sleeping.sleeping/sleeping/sleeping.html in your urls. Also you
>>> probably want to do many fixes, so you can put them all within the same
>>> replacer function.
>>
>> ... My first
>> working attempt had been to use the regex to locate all links. I then 
>> looped
>> through replacing each with a numbered dummy entry. Then safely do the
>> find/replaces and then replace the dummy entries with the original links. 
>> It
>> just seems overly inefficient.
>
> Someone may have made use of
> multiline links:
>
> _
> This parrot
>  href="sleeping.htm"
> target="new"   >
> is sleeping
> .
> Really, it is sleeping.
> _
>
>
> In such a case you may need to make the page
> into one string to search if you don't want to use some complex
> method of tracking state with variables as you move from
> string to string.  You'll also have to make it possible
> for non-printing characters to have been inserted in all sorts
> of ways around the '>' and '<' and 'a' or 'A'
> characters using ' *' here and there in he regex.

I agree, but luckily in this case the HREF will always be formated the same 
as it happens to be inserted by another automated system, not a user. Ok it 
be changed by the server but AFAIK it hasn't for the last 6 years. The text 
in question apart from the links should be plain (not even  is allowed I 
think).

I'd read about back and forward regex matching and thought it might somehow 
be of use here ie back search for the "" 
but of course this would easily match in between two links.



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


Invalid thread state for this thread

2007-05-24 Thread Martin Evans
I know this has been seen before but it is not making too much sense (after 
reading many posts). It all appears to work fine but then dies after about 
40 invocations.

My app has Python embedded, it is embedded as part of a dll which 
initializes python and finalizes on load and unload (see below). When a 
script needs to be run, I create a new thread, let the script complete and 
close the thread.

The thread contains the following type arrangement:

PythonThread()
{
  hScriptFile = OpenScriptFile(m_szActiveScript);
  PyEval_AcquireLock();
  pInterpreter = Py_NewInterpreter();
  Py_SetProgramName(szModuleFileName);
  PyRun_SimpleFile(hScriptFile,m_szActiveScript);
  PyErr_Clear();
  Py_EndInterpreter(pInterpreter);
  PyEval_ReleaseLock();
}

This appears to work fine accept that after around 30-40 invocations I 
always get the "Invalid thread state for this thread". ie the app and dll 
stay loaded and I click my "run" button manually about 40 times. In this 
test it is a simple "hello world" type script. The size of the script does 
not appear to matter.

The dll is coded something like this:

DllLoad()
{
  Py_Initialize();
  PyEval_InitThreads();
  m_mainThreadState = PyThreadState_Get();
  PyEval_ReleaseLock();
}

DllUnload() (not called as part of this test)
{
  PyEval_AcquireLock();
  PyThreadState_Swap(m_mainThreadState);
  Py_Finalize();
}

The app has been designed to allow a second interpreter to run independently 
(thus the need for multiple thread support) and this also appears to work 
fine, but for this test only this one thread was used. I have a compiled 
version of 2.4.2.

Any ideas would be appreciated.

Martin 


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


Re: Invalid thread state for this thread

2007-05-25 Thread Martin Evans
Just in case anyone else has seen this problem, after upgrading to 2.4.4 the 
problem appears to have resolved itself.

>I know this has been seen before but it is not making too much sense (after 
>reading many posts). It all appears to work fine but then dies after about 
>40 invocations.
>
> My app has Python embedded, it is embedded as part of a dll which 
> initializes python and finalizes on load and unload (see below). When a 
> script needs to be run, I create a new thread, let the script complete and 
> close the thread.
>
> The thread contains the following type arrangement:
>
> PythonThread()
> {
>  hScriptFile = OpenScriptFile(m_szActiveScript);
>  PyEval_AcquireLock();
>  pInterpreter = Py_NewInterpreter();
>  Py_SetProgramName(szModuleFileName);
>  PyRun_SimpleFile(hScriptFile,m_szActiveScript);
>  PyErr_Clear();
>  Py_EndInterpreter(pInterpreter);
>  PyEval_ReleaseLock();
> }
>
> This appears to work fine accept that after around 30-40 invocations I 
> always get the "Invalid thread state for this thread". ie the app and dll 
> stay loaded and I click my "run" button manually about 40 times. In this 
> test it is a simple "hello world" type script. The size of the script does 
> not appear to matter.
>
> The dll is coded something like this:
>
> DllLoad()
> {
>  Py_Initialize();
>  PyEval_InitThreads();
>  m_mainThreadState = PyThreadState_Get();
>  PyEval_ReleaseLock();
> }
>
> DllUnload() (not called as part of this test)
> {
>  PyEval_AcquireLock();
>  PyThreadState_Swap(m_mainThreadState);
>  Py_Finalize();
> }
>
> The app has been designed to allow a second interpreter to run 
> independently (thus the need for multiple thread support) and this also 
> appears to work fine, but for this test only this one thread was used. I 
> have a compiled version of 2.4.2.
>
> Any ideas would be appreciated.
>
> Martin 


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


py2exe, library.zip and python.exe

2007-02-28 Thread Martin Evans
I have converted a Python script using py2exe and have it set to not bundle 
or compress. The result is my exe and all the support files including 
library.zip (exactly as planned - nice job py2exe).

Question:  My py2exe application needs to be able to execute extra copies of 
python.exe. I have placed python.exe in the same directory. It obviously 
picks up the main python24.dll but how can I configure things so that it 
would use the same library.zip for all the library files?  This would save 
me having two sets of files.

(The py2exe application happens to be a twisted server app running as a 
service which has the ability to launch python scripts as a logged on user)

Thanks,  Martin.


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


Re: py2exe, library.zip and python.exe

2007-02-28 Thread Martin Evans
"Thomas Heller" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Martin Evans schrieb:
>> I have converted a Python script using py2exe and have it set to not 
>> bundle
>> or compress. The result is my exe and all the support files including
>> library.zip (exactly as planned - nice job py2exe).
>>
>> Question:  My py2exe application needs to be able to execute extra copies 
>> of
>> python.exe. I have placed python.exe in the same directory. It obviously
>> picks up the main python24.dll but how can I configure things so that it
>> would use the same library.zip for all the library files?  This would 
>> save
>> me having two sets of files.
>>
>> (The py2exe application happens to be a twisted server app running as a
>> service which has the ability to launch python scripts as a logged on 
>> user)
>>
>> Thanks,  Martin.
>>
>>
> You have to put library.zip on sys.path.  Maybe you could create a site.py 
> file
> in that directory which can do this, I assume the python.exe will try to 
> load that.
>
> There may be other possibilities as well.
>
> Thomas
>

Many thanks for the tip, it got me thinking. When python.exe is loaded, 
sys.path already had python24.zip in it so changing the specified library in 
py2exe from the default libary.zip to python24.zip solved it!

Martin


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