Re: bdist_wininst [was: Custom build of Python]

2012-06-21 Thread Mark Hammond

On 22/06/2012 3:10 AM, KACVINSKY Tom wrote:

I found what I was looking for:

 python setup.py bdist_wininst


bdist_wininst is for creating installers for Python packages which 
install into an existing Python directory structure.  It isn't used to 
create a installer for Python itself (which unless I misunderstand, 
seems what you are trying to do).


Apart from generating an "official" MSI like Python itself ships as, 
IIUC, there is no other way to take a built tree and create an 
installer.  On the other hand though, a built tree will generally work 
fine if transplanted somewhere else, so long as a couple of registry 
entries are created.  So you could do something like creating an inno 
installer script that takes your built tree and generates a custom 
installer for your build.


Mark



But... I follow all of the instructions for building Python on Windows and then 
follow the instructions for using bdist_wininst, and I get this:

C:\Users\tky\Python\Python-2.6.8>PCbuild\amd64\python.exe setup.py bdist_wininst
running bdist_wininst
running build
running build_ext
INFO: Can't locate Tcl/Tk libs and/or headers
Traceback (most recent call last):
   File "setup.py", line 2049, in 
 main()
   File "setup.py", line 2044, in main
 'Lib/smtpd.py']
   File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\core.py", line 152, in 
setup
 dist.run_commands()
   File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 975, in 
run_commands
 self.run_command(cmd)
   File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 995, in 
run_command
 cmd_obj.run()
   File 
"C:\Users\tky\Python\Python-2.6.8\lib\distutils\command\bdist_wininst.py", line 
125, in run
 self.run_command('build')
   File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\cmd.py", line 333, in 
run_command
 self.distribution.run_command(command)
   File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 995, in 
run_command
 cmd_obj.run()
   File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\command\build.py", line 
134, in run
 self.run_command(cmd_name)
   File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\cmd.py", line 333, in 
run_command
 self.distribution.run_command(command)
   File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 995, in 
run_command
 cmd_obj.run()
   File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\command\build_ext.py", 
line 340, in run
 self.build_extensions()
   File "setup.py", line 167, in build_extensions
 raise ValueError("No source directory; cannot proceed.")
ValueError: No source directory; cannot proceed.

Does anyone know of a way to get bdist_wininst to work out of the box?   I am 
not comfortable with hacking distutils.  What do the maintainers do in this 
case?

Thanks,

Tom

-Original Message-
From: python-list-bounces+tky=3ds@python.org 
[mailto:python-list-bounces+tky=3ds@python.org] On Behalf Of KACVINSKY Tom
Sent: Wednesday, June 20, 2012 4:29 PM
To: python-list@python.org
Subject: RE: Custom build of Python

Terry,

At this stage, I don't want or need an MSI.  I just want something that will 
bundle the executables/dynamic load libraries + compiled Python files and stick 
them into a compliant directory structure.

Regards,

Tom
-Original Message-
From: python-list-bounces+tky=3ds@python.org 
[mailto:python-list-bounces+tky=3ds@python.org] On Behalf Of Terry Reedy
Sent: Wednesday, June 20, 2012 4:13 PM
To: python-list@python.org
Subject: Re: Custom build of Python

On 6/20/2012 2:24 PM, KACVINSKY Tom wrote:

I had reason to build Python 2.6.8 with Microsoft Visual Studio 2010.
I was able to get the pcbuild solution to build, and I have the
necessary exes/dlls/pyds in the amd64 build directory.  What is not
clear to is how to complete the build and make an installation.  I
could not find any documentation for this.


If you mean 'make a .msi file', I am not sure that is not officially supported 
beyond the inclusion of msilib.


Any help on this matter would be appreciated.


3.3 is now being built with VS2010. Perhaps its repository has something that 
will help you.

--
Terry Jan Reedy



--
http://mail.python.org/mailman/listinfo/python-list
This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systemes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.

For other languages, go to http://www.3ds.com/terms/email-disclaimer
--
http://mail.python.org/mailman/listinfo/python-list
This email and any attachments are intended solely for the use of the 
individual or

Re: changes made to my python coded com servers are not taking effect

2012-07-01 Thread Mark Hammond

On 1/07/2012 7:13 PM, Panceisto wrote:

I assume the old code keeps running in some process somewhere. How to
fix this?



The client of your server still has a reference to the old server.  The 
simplest solution is to restart those clients.


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


Re: exe made by py2exe do not run certain computer

2012-07-03 Thread Mark Hammond

On 4/07/2012 9:46 AM, Miki Tebeka wrote:

It works fine on my computer and some other computer don't have
python interpreter(it's Windows 7). But the same file also do not
work on another computer(it's Windows xp) why does it happen?

My *guess* is that you're missing some DLLs (probably some Visual
Studio runtime ones).

You can run http://www.dependencywalker.com/ on the generated exe and
see which DLLs it uses. If you do it on the machine with the
problems, these DLLs will be highlighted.


Another possibility is that py2exe is erroneously picking up *other* 
DLLs from the OS, which you are packaging and installing.  So check your 
distribution for *all* .dll files - most Python extension modules are 
.pyd, so the actual number of .dll files needed should be quite small 
and relatively stable across different py2exe invocations.


Mark


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


Re: missing python-config and building python on Windows

2012-07-31 Thread Mark Hammond

On 1/08/2012 10:48 AM, Damon Register wrote:

I am attempting to build gtk and glade using mingw/msys.  It seems that
some
of the packages require python.  I installed 2.7.3 using the installer from
python.org.  That worked for some of the packages but now I am trying to do
one that needs python-config which I don't find in the installation
directory.

I tried building from source using mingw/msys but that had too many
problems
so I gave up on that.  I thought I might try building with MSVC 2010 since
it appears to be supported and I have that at work.  There are a few
problems
with this:
1. though I have looked in a few readme files, I don't see instructions for
installing what I have just built using MSVC.  Where can I find the
instructions for installing after building with MSVC?


There is no such process.  In general, you can just run directly from 
the built tree.



2. I have searched the project directory but I don't find
python-config.  Is
this some sort of optional thing that isn't built by default?  I tried
searching this list and although I find a few questions about it, I
don't
see an answer to where I can find it.


I'm afraid I don't know what python-config is.  It appears it might be a 
reflection of how Python was configured and build on *nix systems - if 
that is the case then it is expected that one does not exist for Windows 
(as it doesn't use the *nix build chain).



3. It seems that MSVC doesn't produce the .a library files needed for
linking
into a mingw built program.  Do I have to do that fun trick to
create the
.a from the dll?


I'm surprised MSVC *can* build .a files for mingw - but AFAIK, even if 
MSVC could do that, I believe Python makes no attempt to build with 
support for linking into mingw programs.


Mark

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


Re: Legal: Introduction to Programming App

2012-08-19 Thread Mark Hammond
Your only concern from the Python world will (probably; IANAL) be around 
use of trademarks owned by the PSF - see 
http://www.python.org/psf/trademarks/ for more.


Mark

On 20/08/2012 12:13 PM, Matthew Zipf wrote:

Good evening,

I am considering developing an iOS application that would teach average
people how to program in Python. The app will be sold on the Apple app
store.

May I develop this app? To what extent do I need to receive permission
from the Python Software Foundation? To what extent do I need to
recognize the Python Software Foundation in my app?

Thank you,
Matthew Zipf




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


Re: Why is pylaucher in Python 3.3 being installed in Windows folder?

2012-10-06 Thread Mark Hammond

On 5/10/2012 2:40 AM, Oscar Benjamin wrote:

Having them on PATH means that you can do:

 > py script.py

and the effect will be analogous to (in a unix shell):

 $ ./script.py

Of course the idea with the launcher is that you just do

 > script.py


Unless you want a specific version - particularly for testing - eg:

% py -3.2 script.py

Mark

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


Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-10 Thread Mark Hammond

On 11/12/2012 8:39 AM, bitbucket wrote:

On Monday, December 10, 2012 3:58:33 PM UTC-5, Terry Reedy wrote:

I believe the easiest way to do that is to install the pywin
extensions

http://sourceforge.net/projects/pywin32/?source=directory

I assume it can handle out params.


That definitely looks like a good starting point.  Just hoping
someone knows whether or not it'll support the out params before I
spend too much time digging into it.


"out" params are best supported if the object supplied a typelib - then 
Python knows the params are out and does the right thing automagically. 
 If out params are detected, the result of the function will be a tuple 
of (real_result, out_param1, ...)


Even if no typelib is supported, you can access them with a little pain 
via the win32com.client.Dispatch() object.  You might like to follow up 
to the python-wi...@python.org mailing list where many people will be 
able to help.


HTH,

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


Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-11 Thread Mark Hammond

On 12/12/2012 2:48 AM, bitbucket wrote:

On Monday, December 10, 2012 8:16:43 PM UTC-5, Mark Hammond wrote:

"out" params are best supported if the object supplied a typelib -
then Python knows the params are out and does the right thing
automagically. If out params are detected, the result of the
function will be a tuple of (real_result, out_param1, ...)

Even if no typelib is supported, you can access them with a little
pain via the win32com.client.Dispatch() object.  You might like to
follow up to the python-wi...@python.org mailing list where many
people will be able to help.

HTH,

Mark


Mark, thanks for the reply.  In this case, I have a type library and
attempted to use MakePy but it doesn't seem to be working as
expected.

I was reading through CH12 of your Python Programming on Win32 book
(http://oreilly.com/catalog/pythonwin32/chapter/ch12.html).  I was
hopeful given your description of MakePy that I could get this to
work.  It appears that you're saying MakePy will convert "byref" args
in a function over to return values.

For example, the IDL in the server includes the following 3
functions.

[id(1)] void ShowMessage(BSTR msg); [id(2)] void GetSettingValue(BSTR
settingName, BSTR* settingValue); [id(3)] void SetSettingValue(BSTR
settingName, BSTR settingValue);

The thorny one is the GetSettingValue since it takes the out param.
When I run MakePy, it generates the below.

def ShowMessage(self, msg=defaultNamedNotOptArg): return
self._oleobj_.InvokeTypes(1, LCID, 1, (24, 0), ((8, 0),),msg )

def GetSettingValue(self, settingName=defaultNamedNotOptArg,
settingValue=defaultNamedNotOptArg): return
self._oleobj_.InvokeTypes(2, LCID, 1, (24, 0), ((8, 0), (16392,
0)),settingName , settingValue)

def SetSettingValue(self, settingName=defaultNamedNotOptArg,
settingValue=defaultNamedNotOptArg): return
self._oleobj_.InvokeTypes(3, LCID, 1, (24, 0), ((8, 0), (8,
0)),settingName , settingValue)

I noticed that the argument type is different for the out param
(16392 instead of 8).  However, it doesn't appear to me that its
generating return values instead of args (though I'm not very
experienced in python).

I tried invoking these in python.  The ShowMessage and
SetSettingValue work great.  I can't get the GetSettingValue to work
though.  Perhaps there's a different syntax I need when using the
MakePy generated code?


Seeing the "real" return value is void, it should just be a matter of:

settingValue = ob.GetSettingValue("settingName")

Mark




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


Re: unittest and threading

2012-01-25 Thread Mark Hammond

Let me have a guess :)

On 25/01/2012 7:42 PM, Ross Boylan wrote:

On Tue, 2012-01-24 at 13:54 -0800, Ross Boylan wrote:

...

The code I want to test uses threads, but that is not entirely internal
from the standpoint of the unit test framework.  The unit test will be
executing in one thread, but some of the assertions may occur in other
threads.  The question is whether that will work, in particular whether
assertion failures will be properly captured and logged by the test
framework.


I think it will - so long as your "test" on the main thread hasn't 
returned yet.



Concretely, a test may exercise some code that triggers a callback; the
callback might come in a different thread, and the code that is
triggered might make various assertions.

There are two issues: whether assertions and their failures that happen
in other threads will be correctly received by the test framework, and
whether the framework is robust against several assertions being raised
"simultaneously" in different threads.  The latter seems a bit much to
hope for.


I suspect both will be fine.



I assume that, at a minimum, the my test code will need to use locks or
other coordination mechanisms so the test doesn't end before all code
under test executes.


Yep - that's the only caveat I'd expect .


Finally, I'll mention two senses of threads in tests that my question
does not concern, although they are also interesting.

I am not concerned with testing the performance of my code, in the sense
of asserting  that an operation must complete before x seconds or after
y seconds.  Some potential implementations of such tests might use
threads even if the code under test was single-threaded.

The question also does not concern running lots of unit tests in
parallel.


nose is still worth having a look at - personally I just use it as a 
runner and where possible ignore its api...


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


Re: Registry entries set up by the Windows installer

2012-02-01 Thread Mark Hammond

On 2/02/2012 2:09 AM, Paul Moore wrote:

I'm trying to get information on what registry entries are set up by
the Python Windows installer, and what variations exist. I don't know
enough about MSI to easily read the source, so I'm hoping someone who
knows can help :-)

As far as I can see on my PC, the installer puts entries

HKLM\Software\Python\PythonCore\x.y

with various bits underneath. I think I've seen indications that
sometimes these are in HKCU, presumably for a "per user" install? If I
manually hack around in the registry, and have both HKLM and HKCU,
which one will Python use?


For setting PYTHONPATH it uses both - HKEY_CURRENT_USER is added before 
HKEY_LOCAL_MACHINE.  I can't recall which one distutils generated 
(bdist_wininst) installers will use - it may even offer the choice.



Furthermore, more of a Windows question than Python, but there's a
similar question with regard to the .py and .pyw file associations -
they can be in HKLM\Software\Classes or HKCU\Software\Classes. Which
takes precedence?


No idea I'm afraid, but I'd expect it to use HKCU


I assume that the installer writes to HKLM for all
users and HKCU for per-user installs.


Yep, I think that is correct.


Is there anything else I've missed?


I'm also not sure which one the pylauncher project will prefer, which 
may become relevant should that get rolled into Python itself.



The reason I ask, is that I'm starting to work with virtualenv, and I
want to see what would be involved in (re-)setting the registry
entries to match the currently active virtualenv. virtualenvwrapper-
powershell seems to only deal with HKCU (which is a big plus on
Windows 7, as it avoids endless elevation requests :-)) but that
doesn't work completely cleanly with my all-users install. (Note: I'm
not entirely sure that changing global settings like this to patch a
per-console virtualenv is a good idea, but I'd like to know how hard
it is before dismissing it...)


Out of interest, what is the reason forcing you to look at that - 
bdist_wininst installers?  FWIW, my encounters with virtualenv haven't 
forced me to hack the registry - I just install bdist_wininst packages 
into the "parent" Python which isn't ideal but works fine for me.  This 
was a year or so ago, so the world might have changed since then.


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


Re: Help with COM_error

2012-02-06 Thread Mark Hammond
Unfortunately this just means that Word threw an error and it's not 
giving many details about what that might be.  Are you sure out_TOC is 
valid on the other computer?  eg, 
http://stackoverflow.com/questions/3730428/why-cant-i-save-as-an-excel-file-from-my-python-code 
indicates Office fails in that way when the path isn't valid...


Mark

On 4/02/2012 12:10 AM, John Lay wrote:

I am not a programmer, but this past week I have had a crash course in
python scripting am have been rather impressed with myself for having
written a fairly complicated script that among many other processes
reads a database table via SearchCursor, populates a word template via
Bookmarks, then saves the document out as a PDF.

The only problem is that it only works on my computer. When I move the
script to another computer with the same setup, I continue to receive
a Com_error.

The script fails at my SaveAs(out_TOC, FileFormat=wdFormatPDF)
statement. I have tried both win32com.client and comtypes.client and
receive a similar error for both.

win32.client:
com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Word',
u'Command failed', u'C:\\Program Files\\Microsoft Office\\Office12\
\1033\\WDMAIN11.CHM', 36966, ), None)

comtypes.client:
COMError: (-2146824090, None, (u'Command failed', u'Microsoft Word',
u'C:\\Program Files\\Microsoft Office\\Office12\\1033\\WDMAIN11.CHM',
36966, None))

It has been suggested that I try python-docx, but I have not been able
to get the module to work for me and I have been unable to find any
documentation on it.

Can anyone help with the com errors? What do they mean? How do I
resolve them?

Any help would be appreciated.

John


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


Re: PythonWin debugger holds onto global logging objects too long

2012-02-07 Thread Mark Hammond

On 7/02/2012 9:48 PM, Jean-Michel Pichavant wrote:

Vinay Sajip wrote:

On Jan 24, 2:52 pm, Rob Richardson  wrote:

I use PythonWin to debug the Python scripts we write. Our scripts
often use the log2pyloggingpackage. When running the scripts inside
the debugger, we seem to get oneloggingobject for every time we run
the script. The result is that after running the script five times,
the log file contains five copies of every message. The only way I
know to clean this up and get only a single copy of each message is
to close PythonWin and restart it.

What do I have to do in my scripts to clean up theloggingobjects so
that I never get more than one copy of each message in my log files?



I don't know what log2py is - Google didn't show up anything that
looked relevant. If you're talking about the logging package in the
Python standard library, I may be able to help: but a simple script
that I ran in PythonWin didn't show any problems, so you'll probably
need to post a short script which demonstrates the problem when run in
PythonWin.

Regards,

Vinay Sajip

Same here, can't find anything about log2py.
Anyway it's possible that your pythonwin does not spawn a clean python
interpreter for every run, keeping the same one.


That is what everyone's pythonwin does :)  It always works "in process" 
- not ideal, but also likely to not change.


Cheers,

Mark



So you could possibly keep adding log handlers to your loggers because
they may be static objects (like for the standard logging module).
One solution would be to empty your logger handler list before adding any.

I'm just guessing though, difficult to know without any info on log2py.

JM


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


Re: asynchronous downloading

2012-02-23 Thread Mark Hammond

On 23/02/2012 5:58 PM, Plumo wrote:

I want to download content asynchronously. This would be
straightforward to do threaded or across processes, but difficult
asynchronously so people seem to rely on external libraries (twisted
/ gevent / eventlet).


Exactly - the fact it's difficult is why those tools compete.


(I would use gevent under different circumstances, but currently need
to stick to standard libraries.)


As above - use threads or processes - they are fine for relatively 
modest tasks.  If your needs go beyond modest, I'd reevaluate your need 
to stick with just the stdlib - even demanding *sync* http apps often 
wind up using modules outside the stdlib.  Look into virtualenv etc if 
permission to install packages is the issue.


Batteries included free, but turbo-chargers are an extra ;)

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


Re: check if directory is writable in a portable way

2012-02-28 Thread Mark Hammond

On 28/02/2012 9:07 PM, Andrea Crotti wrote:

How should I check if I can create files in a directory?


By trying to create them there :)  Presumably you want to know that so 
you can write something "real" - so just write that something real.


The problem gets quite hard when you consider things like elevation - 
your *user* may have rights to write to a directory but only when 
elevated - think writing into Program Files.  Further, this check can 
only ever be transient - what if you have the rights by virtue of a 
group membership, but tomorrow you are no longer in that group?  Or by 
virtue of being the "owner" of the directory but later losing the ownership?


The only reasonable way to check is to write to it, and you may as well 
skip attempting to write a temp file - just write what you care about 
and handle failure in the most graceful way you can.  This is what 
almost every app does - consider apps with a "save as" dialog - they 
never check the directory is writable, they just attempt the actual 
write and handle the failure.


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


Re: Python 3.2 and MS Outlook

2012-03-07 Thread Mark Hammond

On Thursday, 8 March 2012 1:52:48 AM, Greg Lindstrom wrote:
Is there documentation showing how to read from a Microsoft Outlook 
server using Python 3.2.  I've done it with 2.x, but can't find 
anything to help me with 3.2.


What problems are you having in 3.2?  It should be exactly the same - 
except, obviously, for the general differences between 2 and 3 (ie, any 
differences should not be due to needing to talk to Outlook and would 
exist regardless of the job at hand)


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


Re: OAuth 2.0 implementation

2012-03-28 Thread Mark Hammond

On 28/03/2012 1:18 AM, Roy Smith wrote:

In article
<7909491.0.1332826232743.JavaMail.geo-discussion-forums@pbim5>,
  Demian Brecht  wrote:


OAuth 2.0 is still in draft status (draft 25 is the current one I believe)
and yes, unfortunately every single server available at this point have
varying degrees of separation from the actual spec. It's not a
pseudo-standard, it's just not observed to the letter. Google is the closest
and Facebook seems to be the farthest away (Stack Exchange is in close second
due to building theirs to work like Facebook's).


In practice, OAuth is all about getting your site to work with Facebook.
That is all most web sites care about today because that's where the
money is.  The fact that other sites also use OAuth is of mostly
academic interest at this point.

The next player on the list is Twitter, and they're not even up to using
their own incompatible version of OAuth 2.0.  They're still using OAuth
1.0 (although, I understand, they're marching towards 2.0).


Almost all "social" or "sharing" sites implement OAuth - either 1.0 or 
2.0.  Facebook is clearly the big winner here but not the only player. 
It's also used extensively by google (eg, even their SMTP server 
supports using OAuth credentials to send email)


I'd go even further - most sites which expose an API use OAuth for 
credentials with that API.


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


Re: Generating custom Windows installers

2012-04-05 Thread Mark Hammond
Seeing you are relying on win32com, you might as well add the links 
directly rather than via the intermediate WScript.shell object.  Look in 
win32comext\shell\demos\create_link.py for an example of how to create 
shortcuts directly.


HTH,

Mark

On 6/04/2012 5:23 AM, cesar.covarrub...@gmail.com wrote:

Hello,

I am working on creating an installer of a Python 3.2 application that we 
programmed. The end goal is to create an installer in which we can specify the 
install path, and create shortcuts in the Start Menu and Desktop. Ideally, we 
would like to give the users the option to create the Desktop or Start Menu 
shortcuts.

I was able to create a .msi file with the setup.py and install.py files below. 
This allowed me to specify the custom default path but not create the shortcut 
in the Start Menu.

Can anyone help me figure out what I'm missing?


setup.py


from cx_Freeze import setup, Executable
import sys

productName = "ProductName"
if 'bdist_msi' in sys.argv:
 sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' + productName]
 sys.argv += ['--install-script', 'install.py']

exe = Executable(
   script="main.py",
   base="Win32GUI",
   targetName="Product.exe"
  )
setup(
   name="Product.exe",
   version="1.0",
   author="Me",
   description="Copyright 2012",
   executables=[exe],
   scripts=[
'install.py'
]
   )
-

install.py
--
import os
import sys
import win32com.client as w32client

shortcut_group_name = "Start Menu Dir"
shortcut_name = "Product Name"
shortcut_target = "http://www.microsoft.com";

sh = w32client.Dispatch("WScript.Shell")
p = sh.SpecialFolders("AllUsersPrograms")
assert(os.path.isdir(p))
p = os.path.join(p, shortcut_group_name)
if (not os.path.isdir(p)):
 os.makedirs(p)
lnk = sh.CreateShortcut(os.path.join(p, shortcut_name + ".lnk"))
lnk.TargetPath = shortcut_target
lnk.Save()





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


Re: Generating custom Windows installers

2012-04-06 Thread Mark Hammond

On 7/04/2012 12:57 AM, Cesar Covarrubias wrote:

I'm still getting my feet wet on the Windows side of things with Python,
so I apologize for the noobish question.

If i am reading the create_link.py example correctly, that is created
when the application itself is invoked, not during installation. Is that
correct? If it is, how would I be able to invoke that when generating
the MSI so that the installer creates the shortcut?


Right - I think I misunderstood your question.  If you can't arrange for 
install.py to run then what I suggested isn't going to help that.


Note however that bdist_msi really isn't targeted at creating 
stand-alone installations, but instead at installing Python extension 
modules.  I'd recommend using cx_Freeze to create the app, but looking 
further afield to create the installer for the app (eg, Inno, NSIS, WiX, 
etc)


Mark



Cesar

On Thu, Apr 5, 2012 at 8:42 PM, Mark Hammond mailto:skippy.hamm...@gmail.com>> wrote:

Seeing you are relying on win32com, you might as well add the links
directly rather than via the intermediate WScript.shell object.
  Look in win32comext\shell\demos\__create_link.py for an example of
how to create shortcuts directly.

HTH,

Mark

On 6/04/2012 5:23 AM, cesar.covarrub...@gmail.com
<mailto:cesar.covarrub...@gmail.com> wrote:

Hello,

I am working on creating an installer of a Python 3.2
application that we programmed. The end goal is to create an
installer in which we can specify the install path, and create
shortcuts in the Start Menu and Desktop. Ideally, we would like
to give the users the option to create the Desktop or Start Menu
shortcuts.

I was able to create a .msi file with the setup.py and
install.py files below. This allowed me to specify the custom
default path but not create the shortcut in the Start Menu.

Can anyone help me figure out what I'm missing?


setup.py


from cx_Freeze import setup, Executable
import sys

productName = "ProductName"
if 'bdist_msi' in sys.argv:
 sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' +
productName]
 sys.argv += ['--install-script', 'install.py']

exe = Executable(
   script="main.py",
   base="Win32GUI",
   targetName="Product.exe"
  )
setup(
   name="Product.exe",
   version="1.0",
   author="Me",
   description="Copyright 2012",
   executables=[exe],
   scripts=[
'install.py'
]
   )
--__---

install.py
--
import os
import sys
import win32com.client as w32client

shortcut_group_name = "Start Menu Dir"
shortcut_name = "Product Name"
shortcut_target = "http://www.microsoft.com";

sh = w32client.Dispatch("WScript.__Shell")
p = sh.SpecialFolders("__AllUsersPrograms")
assert(os.path.isdir(p))
p = os.path.join(p, shortcut_group_name)
if (not os.path.isdir(p)):
 os.makedirs(p)
lnk = sh.CreateShortcut(os.path.__join(p, shortcut_name + ".lnk"))
lnk.TargetPath = shortcut_target
lnk.Save()







--
Very Respectfully,
Cesar Covarrubias






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


Re: Right way to initialize python embedded in a multi-threaded application

2012-05-17 Thread Mark Hammond

On 17/05/2012 10:08 PM, shooshx wrote:

I'm embedding python in a multi-threaded C application.
I've taken care to wrap every call to the Python C API with

gstate = PyGILState_Ensure();
// call python code
PyGILState_Release(gstate);

But I'm stumped with what to do in the initialization.
Right after the call to Py_IsInitialized() I've added a call:

PyEval_InitThreads();

The docs say that this function leaves the GIL locked when it returns.
I do some more initializations like importing modules and then I call

PyEval_ReleaseLock();

This seems to cause a problem since not long after a call to
PyGILState_Release(gstate) that's made in a different thread crashes.
with

"Fatal Python error: This thread state must be current when releasing"

If I don't do the call to PyEval_ReleaseLock() in the main thread
right after initialization, the GIL seems to be released
after the first PyGILState_Ensure() - PyGILState_Release() pair.

So what am I doing wrong here?
What is the correct way of initializing a multi-threaded application?


Try replacing the PyEval_ReleaseLock() call with PyEval_SaveThread(); - 
that works for pythoncom, which has the same basic requirement - see 
http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/raw-file/b8c62cf04c5a/com/win32com/src/dllmain.cpp 
for how it works.


HTH,

Mark






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


Re: Compiling debug Python 2.7 on Windows

2012-05-22 Thread Mark Hammond

On 23/05/2012 2:42 AM, Иван Громов wrote:

Hi,

I'm trying to compile a debug version of Python 2.7 on Windows, but I've
encountered some problems while creating a distribution.\
When I run
PCbuild\python.exe setup.py bdist_wininst
I get an error
error: pyconfig.h: No such file or directory
As far as I understand, I need to run something similar to ./configure on Linux,
but I haven't found any information what the command should be. GnuWin32
autoconf also fails with errors. What is the correct way to build Python
distribuiton from source on Windows?


I believe the correct way is still to load the PCBuild/PCBuild.sln file 
as a project in MS Visual Studio 2008.


Cheers,

Mark


--
Best regards, Ivan Gromov






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


Re: Embedding Python27 in C++ on Windows: CRT compatibility issues with VS2010?

2012-05-24 Thread Mark Hammond

On 25/05/2012 2:10 AM, Stephen Lin wrote:

Hello,

I'm a relative python newbie but I've been tasked to figure out how to
embed calls to a python library in an Excel XLL add-in.

The Python/C API for doing this seems pretty straightforward, but I
seem to have read somewhere online that it's important that the C++
program or DLL linking to and embedding Python must be using the same
CRT as what the Python implementation dll is using. Is this true, or
is the Python API written in such a way that there is no dependency on
a common CRT?


It depends on the APIs you use.  eg, some APIs take a "FILE *" and some 
may take ownership of memory - such APIs needs to use the same CRT. 
APIs that don't attempt to share CRT "objects" should be fine.


Mark


If there is a dependency, does that mean that I cannot use VS2010 to
develop this XLL, but should use VS2008 instead, or are there other
workarounds?

Thanks for the help,
Stephen




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


Re: Distutils beginner question - windows

2011-06-05 Thread Mark Hammond

On 3/06/2011 6:57 PM, Seb S wrote:


Hi all,

Just a quick question , I have a simple script I want to convert into a windows 
installer and give to some friends.
I had a look at http://docs.python.org/distutils/introduction.html  and wrote 
this setup script:


#!/usr/bin/env python

from distutils.core import setup

setup(name="C:\data\Sendmailmsg.py",
   version='1.0',
   description='Python Distribution Utilities',
   author='Sebas929',
   author_email=' ',
   url=' ',
   py_modules=['urllib','smtplib'],
  )


I tried to run this  - "C:\Data\Setup.py" bdist_wininst  - in a cmd prompt.
C:\Data\ contains my script Sendmailmsg.py and Setup.py
I am getting the error :


I think you misunderstand what bdist_wininst is for and probably want 
py2exe (where you just tell it you want to package Sendmailmsg.py and it 
finds all other dependent modules like smtplib etc, bundles them up with 
a full python runtime and rolls it into a nice executable)


HTH,

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


Re: Multiple windows services on the same machine

2011-06-06 Thread Mark Hammond

On 6/06/2011 2:54 AM, Massi wrote:

Hi everyone, I'm writing a script which implement a windows service
with the win32serviceutil module. The service works perfectly, but now
I would need to install several instances of the same service on my
machine for testing purpose.
This is hard since the service name is hard-coded in the service class
definition:

class MyService(win32serviceutil.ServiceFramework) :
 _svc_name_ = 'MyService'
 _svc_display_name_ = 'Instance ofMyService'


It is only hard-coded in the HandleCommandLine function - you probably 
just want your own argv parsing and call InstallService directly.


HTH,

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


Re: Python 2.7.2 for Windows reports version as 2.7.0?

2011-06-18 Thread Mark Hammond

On 18/06/2011 1:36 PM, pyt...@bdurham.com wrote:

Hi Benjamin,


The file info is seems correct but I just checked the MSI and it's

reporting that it's 2.7.2. How exactly are you running python.exe and
IDLE- are you calling the full path, just calling "python" and using
whichever python version is first on your path, or are you using an
entry in the start menu? The only thing I can think of is that your
2.7.0 install is in a different location than your 2.7.2 install. So
2.7.2 installed correctly but you're still running the old one.

Within the folder where the python.exe exists, I have tried the
following, all of which report Python 2.7.0 vs. 2.7.2

python
python.exe
c:\python27

Confirming I'm running what I think I'm running:


import sys
sys.hexversion

34013424

sys.executable

'C:\\Python27\\python.exe'




And confirming the exe files in my Python27 folder:

  Directory of C:\Python27

06/12/2011  03:09 PM26,624 python.exe
06/12/2011  03:06 PM27,136 pythonw.exe

Anyone else having the same experience?

Malcolm


The version info comes from the DLL - I wonder if the DLL being found is 
somehow old?


Make sure:

>>> import sys
>>> win32api.GetModuleFileName(sys.dllhandle)

Is the DLL you expect.

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


Re: Dynamically linking python into my vc project - help required

2011-08-05 Thread Mark Hammond

On 3/08/2011 6:58 PM, mrinal...@edss.co.in wrote:

Hi,

I am trying to embed python into my MFC application. I have done this
before by statically linking to the python lib. But I want to change
this now.
The idea is to take the information from the registry for the installed
version of python on the target machine. Then load python using
loadlibrary call and use the functions from python using pointers to
functions returned by GetProcAddress .

...


PyObject* pObject = pFPyEval_EvalCode((PyCodeObject*)pCodeObject,
m_Dictionary, m_Dictionary);
}


I am facing two problems here , though I want to link to python
dynamically I am required to include python.h for my code to compile the
following declaration.

PyObject* pCodeObject




You can probably just define pFPyEval_EvalCode as taking a PyObject * 
(but I'm not sure where you are getting a declaration of PyObject * from)



I tried copying some of the python definitions including PyObject into a
header in my mfc app. Then it complies fine. but Py_CompileString call
fails. so finally I am unable to run script from my MFC application by
linking to python dynamically.


Are you sure you have the calling convention correct on those function 
pointer decls?



How can this be done ? Please help. Is there a different approach to
linking to python dynamically. Please could you write to me ?


py2exe takes the same basic approach as you and might be worth copying 
its declarations for the function pointers?


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


Re: import os or import os.path

2011-09-06 Thread Mark Hammond

On 7/09/2011 7:47 AM, Ian Kelly wrote:

On Tue, Sep 6, 2011 at 3:25 PM, Jabba Laci  wrote:

Hi,

If I want to use the 'os.path' module, it's enought to import 'os':

import os
if os.path.isfile('/usr/bin/bash'):
print 'got it'

In other source codes I noticed that people write 'import os.path' in
this case. Which is better practice?


"import os.path" is better practice.  There is no guarantee in general
that the os module will automatically import os.path, and in future
versions or different implementations it might not.


That's probably a matter of opinion - eg, 
http://docs.python.org/tutorial/interpreter.html has an example of 
importing the os module then accessing os.path.


Personally I think directly importing os.path is a waste of precious 
keystrokes ;)


Cheers,

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


Re: embedding interactive python interpreter

2011-03-27 Thread Mark Hammond

On 26/03/2011 4:37 AM, Eric Frederich wrote:

So I found that if I type ctrl-d then the other lines will print.


I think ctrl-d just causes sys.stdin to see EOF, so things just "fall 
out" as you desire.  exit() will winf up causing the C exit() function 
after finalizing, hence the behaviour you see.



In the mean time is there a way to redefine the exit function in
Python to do the same behavior as "ctrl-d?"


You can just patch exit in builtins with your own function although I'm 
not sure how you would terminate the builtin REPL - another alternative 
may be to look into the code/console modules where you may be able to 
arrange for more control over the REPL.


Cheers,

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


Re: embedding interactive python interpreter

2011-03-27 Thread Mark Hammond

On 28/03/2011 5:28 AM, Eric Frederich wrote:

I'm not talking about the documentation for sys.exit()
I'm talking about the documentation for Py_Main(int argc, char **argv)

http://docs.python.org/c-api/veryhigh.html?highlight=py_main#Py_Main

This C function never returns anything whether in the interpreter I
type "exit(123)" or "sys.exit(123)".
I cannot call any of my C cleanup code because of this.


I think there is a bug in that documentation - the paragraph:

 Note that if an otherwise unhandled SystemError is raised, this
 function will not return 1, but exit the process, as long as
 Py_InspectFlag is not set.

Looks like it should refer to SystemExit, not SystemError.  If you check 
out pythonrun.c in handle_system_exit, you will note the behaviour 
described above is exactly what is implemented for SystemExit.


See also http://bugs.python.org/issue6498

HTH,

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


Re: embedding interactive python interpreter

2011-03-28 Thread Mark Hammond

On 28/03/2011 2:06 PM, Eric Frederich wrote:

I'm not sure that I know how to run this function in such a way that
it gives me an interactive session.
I passed in stdin as the first parameter and NULL as the second and
I'd get seg faults when running exit() or even imnport sys.

I don't want to pass a file.  I want to run some C code, start an
interactive session, then run some more C code once the session is
over, but I cannot find a way to start an interactive Python session
within C that won't exit pre-maturely before I have a chance to run my
cleanup code in C.


Instead of calling Py_Main, arrange for the following code to be executed:

import code
try:
code.interact()
except SystemExit:
pass
print "Done!"

If you save that as a script and run it, you will see that when you call 
quit() or use Ctrl+D, the "Done!" is printed (so the exception is 
caught) and things will return normally (albeit without any return code 
that may have been specified in the SystemExit exception).  If you 
arrange to call that code in your app (either by importing it as a 
module of even by calling PyRun_SimpleString) things should work as you 
need.


HTH,

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


Re: multiple Python 2.7 Windows installations

2011-04-19 Thread Mark Hammond

On 20/04/2011 12:40 AM, Eric Frederich wrote:

Hello,

I am trying to get an installer built with distutils to recognize
multiple installations.
The installer currently finds my installation at C:\Python27
I have a custom Python27 built myself with Visual Studio sitting
somewhere else, say C:\MyPython27.

I looked at PC/bdist_wininst/install.c in the GetPythonVersions
routine and see that it is searching Software\Python\PythonCore.

So, I assume I need to get my Python installation listed in the registry.
I am unfamiliar with the Windows Registry
I tried to create another 2.7 key but regedit wouldn't let me.
So, if I can only have one 2.7 key, it would seem that the routine
GetPythonVersions will only ever get 1 version of 2.7.
Does this mean that it is unsupported to have more than one Python 2.7
installation on Windows?


Yes, it does.  Only 1 such installed version is considered "the" version 
- although you could just have something temporarily adjust the 
InstallPath entry in the registry.



Again, that GetPythonVersions routine looks pretty alien to me so
I may be wrong.


You have it right - although the idea is that if you have a "portable" 
package to install (ie, no C extension modules), that routine will offer 
to install it into *any* Python version.


Cheers,

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


Re: What other languages use the same data model as Python?

2011-05-04 Thread Mark Hammond

On 5/05/2011 11:11 AM, harrismh777 wrote:


The "pass by value" and "pass by reference" parameter passing
mechanisms are pretty well defined, and C uses "pass by value".


Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that helped 
define them


Cool - please tell us more about your involvement in that.  Obviously 
lots of people were in the industry then, but only a select few would be 
able to claim they helped define those terms.



There may be some language somewhere that does pass-by-reference which
is not implemented under the hood as pointers, but I can't think of
any... 'cause like I've been saying, way down under the hood, we only
have direct and indirect memory addressing in today's processors. EOS.


What about Python, where passing an integer to a function passes a 
pointer to an int object, but that function is able to change the value 
of the variable locally without changing the passed object (indeed, it 
is impossible to change the passed integer)?


So given the definitions above, Python uses a by-reference mechanism but 
(in some cases) has by-value semantics.


While I understand exactly how things work (so don't need an 
explanation), the point is that for anything close to a high-level 
language, things aren't as black and white as they are for the low-level 
languages...


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


Re: bdist_wininst: install_script not run on uninstall

2011-05-25 Thread Mark Hammond

On 26/05/2011 5:28 AM, Wilbert Berendsen wrote:

Hi,

according to the docs the installer bdist_wininst creates will run the
install-script on install with -install (which works perfectly) and on
uninstall with the -remove argument (which seemingly never happens).

However I want to cleanup some registry stuff on uninstall so I want the
uninstall script to work.

Studying the source code of the installer[1] in the Run_RemoveScript
function...

[1] http://svn.python.org/view/python/trunk/PC/bdist_wininst/install.c

... it checks for the line '%d Run Script: %s' in the log, which is there. But
can anybody find out why the install script is not run?


Works for me in the pywin32 install script - maybe you should make the 
smallest possible example that doesn't work and post the entire thing here?


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


Re: bdist_wininst: install_script not run on uninstall

2011-05-27 Thread Mark Hammond

On 26/05/2011 6:00 PM, Wilbert Berendsen wrote:

Op donderdag 26 mei 2011 schreef Mark:


Wilbert wrote:


can anybody find out why the install script is not run?


Works for me in the pywin32 install script - maybe you should make the
smallest possible example that doesn't work and post the entire thing here?


Sorry, I was wrong.  It apparently does *not* work for me either :( 
This is a bug in distutils/bdist_wininst - I just created 
http://bugs.python.org/issue12200 with the details and your samples, and 
sadly I can't think of a work around you can use until this is fixed 
(which I might get to soon, but not this weekend...)


Cheers,

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


RE: [python-win32] simulate DoEvents by python/wxpython

2005-10-26 Thread Mark Hammond
Build 205 of win32gui does have PeekMessage etc so you can now write the
message loop in Python should the need arise - however, the various
"PumpMessages" and "PumpWaitingMessages" functions do the same thing, but
are implemented in C.  There are versions of these functions in win32gui and
win32ui.  win32ui is the MFC wrapper, and its version does do it the "MFC
way", as opposed to the vanilla Windows way that win32gui exposes.  Your
code below looks like it is MFC based, so the win32ui versions may work
better for you (eg, work correctly with the MFC idle processing).  If you do
truly only need VB DoEvents style processing (which is not MFC aware),
win32gui.Pump(Waiting)Messages should be fine though.

Mark
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of James Hu
Sent: Thursday, 27 October 2005 4:10 AM
To: Python-win32@python.org; python-list@python.org
Subject: [python-win32] simulate DoEvents by python/wxpython


Hi, all gurus,

I  need to simulate DoEvents in VB by python/wxPython,
My application needs to capture live image in a loop until one specific
button pressed
Multi-thread is also not very good solution, for there are big number of
data to exchange between the two threads.

Win32gui doesn't have PeekMessage.

Or translate the folllowinf codes to python?

DoEvents()
{
  MSG msg;
 while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if ( !PumpMessage( ) )
{
::PostQuitMessage( 1 );
return FALSE;
}
}
// let MFC do its idle processing
LONG lIdle = 0;
while ( OnIdle(lIdle++ ) )
;
return TRUE;
}
}


Thanks in advance,
James

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


Re: PyEval_EvalCodeEx return value

2011-09-22 Thread Mark Hammond

On 20/09/2011 8:34 PM, Mateusz Loskot wrote:

Hi,

I'm trying to dig out details about what exactly is the return
value the of PyEval_EvalCodeEx function in Python 3.x
The documentation is sparse, unfortunately.

Perhaps I'm looking at wrong function.
My aim is simple, I need to execute Python code using Python interpreter
embedded in my C++ application.
The Python code is a simple script that always returns single value.
For example:

#! /usr/bin/env python
def foo(a, b):
return a + b
f = foo(2, 3)

But, f can be of different type for different script: one returns
numeric value, another returns a sequence, so the type is not
possible to be determined in advance.

I know how to capture Python stdout/stderr.

I also know how to access the "f" attribute using
PyObject_GetAttrString and then I can convert "f" value to C++ type
depending on PyObject type.

However, I guess there shall be a way to access "f" value
directly from PyEval_EvalCode return object:

PyObject* evalRet = ::PyEval_EvalCode(...);

But, I can't find any details what the "evalRet" actually is.


Eval is to eval an expression.  If you simply eval the expression "f" in 
the context of the module you should get the result returned.  Obviously 
though it is designed to eval more complex expressions and in your 
specific example, doing the getattr thing will also work fine.


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


Re: pyWin build 216

2011-09-23 Thread Mark Hammond

On 24/09/2011 12:25 AM, python wrote:

I have used pyWin for several years now with out issue.   I recently
installed build 216 for python 2.7 on windows XP pro.   The program
crashes every time I exit a wxPython program and has crashed a few
other times.


There are a number of issues using Pythonwin to run a program which uses 
a different UI toolkit (eg, wx, Tkinter) and while these have been 
around for many years I don't plan on trying to fix it.  IOW, "don't do 
that" :)



I does not seem that pyWin has been updated since
February of this year.   Is there a direction change for the windows
extensions?  Is it time I make the move to 3.x?  Mark Hammond has
given much to the Python community and I do not intend for this post
to be negative in any way.


No problem.  There have been no updates as there is very little to 
update (ie, the code hasn't change a huge amount in hg since then). 
There will probably be a new version in the next month or so, but that 
is quite orthogonal to whether you should move to 3.x - the 3.x version 
of Pythonwin hasn't been updated in the same period and is built from 
the same source tree, so is likely to have exactly the same problems 
(infact is likely to have a few more - there are probably a few 3.x 
specific issues still hiding away).


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


Re: Implementing Python-OAuth2

2011-10-11 Thread Mark Hammond

On 11/10/2011 7:16 PM, Kayode Odeyemi wrote:

On Thu, Oct 6, 2011 at 5:15 PM, Jeff Gaynor mailto:jgay...@ncsa.illinois.edu>> wrote:

On 10/06/2011 08:34 AM, Kayode Odeyemi wrote:

Hello friends,

I'm working on a pretty large application that I will like to
use oauth2 on as an authentication and authorization mechanism.

I understand fairly the technology and I have written my own
implementation before I stumbled on python-oauth2.

I need advise on leveraging python-oauth2 api for creating
consumer key, creating consumer secret, access token and token
secret.

This works well, but be advised that the original python oauth
library had some serious issues, so was redone as python-oauth2.
What is confusing is that it refers to OAuth version 1.0a, not the
upcoming OAuth version 2.0, so make sure you read the right spec
before using it, since they are very different indeed.

There are *no* usable OAuth version 2..0 implementation in any
language (usually Java comes first) that I know of, so you will get
to role your own, which is hard. There are a few beta-level versions
E.g. Twitter) but these are special cased to the author's needs. The
spec itself is not quite ready either and since it has changed quite
substantially in the last year, I suspect that everyone is waiting
to see it settle to a steady state.

Jeff, I'm in the middle of a big confusion here and will need your help.

I will like to know, can the request be signed just once and for all
subsequent request made, I can use the stored nonce, signature method
and token? My kind of setup is such that, I want the client app to be
registered once, such that for every request to a resource, as long as
the required parameters are available in the header (which would have
been gotten at the initial request), access is granted.

Is this a correct interpretation of Oauth?


I believe every request must be resigned with a new nonce and new 
timestamp using the tokens it initially fetched during the auth step so 
"replay" attacks can be prevented.  It might be true that some server 
implementations don't check the timestamp or nonce, so it *might* work 
for some servers if the exact same request parameters are used, but such 
servers are simply insecure and broken.


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


Re: need python+windows edit control help

2011-10-21 Thread Mark Hammond

On 22/10/2011 10:30 AM, Eric S. Johansson wrote:

I'm back with yet another attempt at adding accessibility features using
Python and NaturallySpeaking. I've simplified the concepts again and I
really need some help from someone who knows Microsoft Windows and
Python. My goal is developing a template for what I'm trying to do, then
I can take over and generate some useful accessibility tools.


The python-wi...@python.org mailing list might be the best place to look 
for help - although you will probably need to provide much more 
information before anyone can help.  MSDN documents most of what you can 
do with edit control (look for windows messages starting with "EM_"), 
but without checking, I expect you will find programs like Skype don't 
use a Windows edit control at all.


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


Re: logging: warn() methods and function to be deprecated.

2011-10-23 Thread Mark Hammond

On 22/10/2011 11:09 PM, Vinay Sajip wrote:

In response to an issue (#13235) raised on the Python bug tracker, I'm going to
deprecate the warn() methods in the Logger and LoggerAdapter classes in the
stdlib logging package, as well the module-level warn() function.

The warn() variants were synonyms for the warning() methods and function, and a
holdover from before the time that logging was added to Python.They were not
documented; it's probably time to retire them, so I've added a
DeprecationWarning to appear in 3.3, and they'll be completely removed in 3.4
(along with the WARN synonym for WARNING). With this change, all the logging
levels are adjectives which apply to the logged message: DEBUG, INFO, WARNING,
ERROR and CRITICAL.

I don't believe the WARN/warn variants were used much, if at all - but this is
just a heads up for anyone who might have used them.


I think that is a real shame - it seems to be gratuitous breakage for 
almost zero benefit.  That issue shows that Trac makes heavy use of 
.warn, I've use .warn almost exclusively for many years, and 
code.google.com shows it is used extensively in the wild.


Is there still a chance to reconsider?

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


Re: Need Windows user / developer to help with Pynguin

2011-10-30 Thread Mark Hammond

On 30/10/2011 1:43 AM, Lee Harr wrote:

For Windows users who want to just run Pyguin (not modify or tinker
with the source code), it would be best to bundle Pynguin up with
Py2exe


I considered that, but I agree that licensing issues would make it
problematic.


What licensing issues concern you?  The py2exe license shouldn't be a 
problem and py2exe or something like it is good advice.


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


Re: pythoncom on Windows Server 2008

2011-11-29 Thread Mark Hammond

On 30/11/2011 11:12 AM, Nairn, Bruce wrote:

Hi,

I’m trying to move some code to a Windows Server 2008 machine. It runs
on Windows 7 and XP, but fails on Windows Server 2008. The python
installation is seemingly identical (python 2.6.4, 32 bit). The
following replicates the problem:

import pythoncom

IDispatch = pythoncom.CoCreateInstance (‘OPC.Automation’, None,
pythoncom.CLSCTX_SERVER, pythoncom.IID_IDispatch)

On Windows 7 x64 or Windows XP x32:

this returns an PyIDispatch object

On Windows Server 2008 x64 this gives:

com_error: (-2147221005, ‘Invalid class string’, None, None)

Any suggestions would be appreciated!


The OPC.Automation object isn't installed on the Server 2008 box.  I'm 
not sure what this object is so can't advise on how to install it.  Note 
also that you will need the same "bittedness" of the object as Python 
itself has - ie, assuming a 32bit Python, you need the 32bit 
implementation of the COM object, or if a 64bit Python, you need the 
64bit COM object.  Note that both the 32 and 64bit versions of both will 
work fine on a 64bit version of Windows - you just need to make sure 
they match.


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


Re: Losing com pointer

2011-12-07 Thread Mark Hammond

On 7/12/2011 7:22 PM, Matteo Boscolo wrote:

Hi all,
I need some help to a com problem..

I got this class:

class foo(object):
def setComObject(comObject):
self.comO=comObject #This is a com object from a cad application

def showForm(self)
# use the self.comO to read some information from the cad application
# Show the pyqt form as child of cad application
# do somthing with the form
# do somthing with the self.comO <- Here if pass some time I'm not
able to call any method to the com object


What are the symptoms of that?  ie, what error do you get?

I suspect the remote process is going away - it almost certainly has 
nothing to do with Python itself deciding to make the object go away.


Mark



a=foo()
o="get istance of a cad application via com"
a.setComObject(o)
a.showForm() #< here if pass some time I'm not able to call any
method to the com object

but I I' re call the
a.setComObject(o) #Faster and I take less the 30 seconds on the form
object it works well

It seems a problem of the garbage collector .. but I'm not sure how to
debug it ..

any help is really appreciated.. it's the last dangerous bug in our
application ...

Regards,
Matteo


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


Re: thread example question

2012-01-17 Thread Mark Hammond

On 18/01/2012 4:22 PM, Rodrick Brown wrote:

import _thread as thread
import time

class thread_counter(object):
 def __init__(self, thr_cnt, sleep_int):
 self.thr_cnt = thr_cnt
 self.sleep_int = sleep_int

def counter(myId, count):
 for i in range(count):
 time.sleep(1)
 print('[{}] => {}'.format(myId, i))

def main():
 for i in range(5):
 thread.start_new_thread(counter, (i, 5))


I think you meant for the following 2 lines to be outside the loop (ie, 
to be dedented one level).  Once you do that the output is as *I* expect :)


Mark


 time.sleep(6)
 print('Main thread exiting..')

if __name__ == '__main__':
 main()



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


RE: [python-win32] Displaying contents of a file using PyWin

2006-12-21 Thread Mark Hammond
Hi Gabriel,

> [Forwarded from [EMAIL PROTECTED]
>
> At Thursday 21/12/2006 13:51, MiguelS wrote:
>
> >import win32ui
> >from pywin.mfc import docview
> >
> >t = docview.DocTemplate()
> >t.OpenDocumentFile("d:/temp/music.log", True)
> >
> >This caused windows to close PythonWin.
>
> This appears to be a problem with pywin32.
> Using release 209 for Python 2.4 I get an Access Violation.

It was attempting to set a Python error without the GIL held.  I've fixed
that - it now results in:

win32ui: PyCDocument::OnOpenDocument handler does not exist.
>>>

Using:

>>> t.OpenDocumentFile(None)

Opens a document - I'm afraid I can't recall the MFC semantics here at the
moment.

> Also I've noticed that this idiom:
>
> try:
>  win32ui.GetApp().RemoveDocTemplate(template)
> except NameError:
>  # haven't run this before - that's ok
>  pass
>
> doesn't work anymore because RemoveDocTemplate raises a different
> exception now.

I can't recall any change I made that would account for that.  I'm assuming
that the NameError comes from 'template' which is yet to be assigned - but
in that case RemoveDocTemplate should not be called as the NameError happens
before.  I don't recall (and grep doesn't show) that pythonwin ever raises
this exception.

Mark

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


Re: errno 22 instead of errno 2

2009-01-28 Thread Mark Hammond

On 28/01/2009 6:52 PM, Glenn Linderman wrote:

open("c:\abc","rb")

This simple one-line script, produces errno 22 on Python 2.6, but errno
2 on Python 2.5.2

Is this an unintentional regression? Or is this an intentional bug fix?

The file doesn't exist (errno 2) but I guess on Windows it is also
somewhat an invalid file name (errno 22).

Yes, I'm aware that \a is ASCII 007. Using a valid, non-existent file
name produces errno 2 on both versions.



I think you will find that in Python 2.6, the exception object has both 
'errno' and 'winerror' attributes, which more accurately reflect the 
source of the 2 different error numbers, where Python 2.5 would often 
store the windows error number in the errno field, leading to what you see.


I tend to use something like "winerror = getattr(e, 'winerror', 
e.errno)" to handle both cases...


Cheers,

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


Re: How to call python from a foreign language thread (C++)

2009-02-04 Thread Mark Hammond

On 4/02/2009 4:51 AM, Victor Lin wrote:

It may looks like this.

 void operator() (double time, const AudioData&data) {
 // acquire lock
 m_Function(time, data);
 // release lock
 }


You want something like:

  void operator() (double time, const AudioData&data) {
  PyGILState_STATE old = PyGILState_Acquire();
  m_Function(time, data);
  PyGILState_Release(old);

Note that Phillip is also correct; you will need to initialize threading 
if this is an app which embeds Python...


HTH,

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


Re: How to call python from a foreign language thread (C++)

2009-02-04 Thread Mark Hammond

On 4/02/2009 8:43 PM, I wrote:

PyGILState_STATE old = PyGILState_Acquire();


Make that PyGILState_Ensure();

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


Re: subprocess returncode windows

2009-02-05 Thread Mark Hammond

On 6/02/2009 6:34 AM, Andrew wrote:

Notice how python never gets the correct returncode from asadmin.bat
but I can get the correct returncode from the shell every time. Can
anyone tell me why Python wouldn't be able to get the correct
returncode for asadmin?


I think the problem will be that cmd.exe doesn't return the exit code to 
*its* caller correctly.  You can often work around this by avoiding the 
use of cmd.exe to spawn the child process, but obviously you do need it 
with a .bat file.  I'm not aware of an easy work-around.


Cheers,

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


Re: Using multiprocessing from a Windows service

2009-02-05 Thread Mark Hammond

On 6/02/2009 11:37 AM, Volodya wrote:

Hi all,

I think I've found a small bug with multiprocessing package on
Windows.


I'd actually argue its a bug in pythonservice.exe - it should set 
sys.argv[] to resemble a normal python process with argv[0] being the 
script.  I'll fix it...


Cheers,

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


Re: Using multiprocessing from a Windows service

2009-02-05 Thread Mark Hammond

On 6/02/2009 2:50 PM, Mark Hammond wrote:

On 6/02/2009 11:37 AM, Volodya wrote:

Hi all,

I think I've found a small bug with multiprocessing package on
Windows.


I'd actually argue its a bug in pythonservice.exe - it should set
sys.argv[] to resemble a normal python process with argv[0] being the
script. I'll fix it...


Actually it appears I spoke too soon:

* A bug in pywin32 exists such that when you use 'debug' on a service, 
the argv reflected the full argv of the application, including the 
'-debug' portion of the command-line.  However, even if that is fixed, 
the next argument is actually the name of the service (as declared in 
the .py file for the service), not the .py module itself.  Thus, I could 
make argv a little more sane in this case, but still the initial problem 
would remain as argv[0] would still not be a .py file.


* When the service is started by windows itself, there are usually zero 
additional command-line arguments.  If there *are* arguments, they are 
likely to be the string the user entered via control panel as a special 
case (Windows doesn't actually remember service args - they are used 
once and discarded).  It is important we continue to expose whatever 
argv we actually got from Windows to the service code.


So unfortunately I don't think I can change pythonservice to resolve the 
issue you reported.


Cheers,

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


Re: Using multiprocessing from a Windows service

2009-02-06 Thread Mark Hammond

On 6/02/2009 4:21 PM, Volodymyr Orlenko wrote:

In the patch I submitted, I simply check if the name of the supposed
module ends with ".exe". It works fine for my case, but maybe this is
too general. Is there a chance that a Python module would end in ".exe"?


IIRC, py2exe may create executables where sys.argv[0] is the executable 
itself.  Maybe if we consider and handle both these cases a patch to mp 
might be looked upon in a better light...


Cheers,

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


Re: WIn32api

2009-02-06 Thread Mark Hammond

On 7/02/2009 3:28 AM, K-Dawg wrote:

You might like to seek out the python-win32 mailing list for stuff like 
this where more people tend to pay attention to windows problems.



This works if I call run() specifically. But when I try to initiate the
thread with .start() I get the following error


Unfortunately threads and COM are tricky.  The short story is that you 
can't, in the general case, pass a COM object from one thread to 
another.  You need to google "COM threading models", and if you *really* 
want to pass objects between threads, the impressively named MSCOM 
function CoMarshalInterThreadInterfaceInStream (exposed via the 
pythoncom module).  The above mailing list has had a number of threads 
on this issue over the years...


Cheers,

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


Re: Python binaries with VC++ 8.0?

2009-02-09 Thread Mark Hammond

On 9/02/2009 5:51 PM, Greg Ewing wrote:

Is there anywhere I can download a set of Python
binaries, of any version, that have been built
with Visual C++ 8.0?


IIRC, no.  Python skipped that version of MSVC.  I believe Python 2.5 
builds easily with vc8 project files in svn though.



I'm trying to hook Python up to Sketchup 7 on
Windows, and I think I'm having problems because
Sketchup is linked with msvcr80.dll.


What problems specifically?  The only practical problems you should see 
will arise if you try and pass a "FILE *", or allocate memory you then 
ask python to free (or vice-versa) - both should be avoidable though...


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


Re: TTS in windows

2009-02-11 Thread Mark Hammond

On 12/02/2009 3:58 PM, Jonathan Chacón wrote:

Hello,

I need to use SAPI5 text to speech with python but I don't find anything
that lets me manage speech, tone, volume, etc


Does anybody know anything to do this?


It appears this is doable from COM.  With the pywin32 package:

>>> import win32com.client
>>> o=win32com.client.Dispatch("{96749377-3391-11D2-9EE3-00C04F797396}")
>>> o.Speak("Hello there")
1
>>> o.Volume
100
>>> o.Volume=50
>>> o.Speak("Hello there")
1

Works for me on Vista.  The magic number is the value for CLSID_SpVoice, 
which I found by googling (for some reason, the actual definition of 
that CLSID doesn't appear in the SDK headers...)


HTH,

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


Re: This application has failed to start because the application configuration is incorrect

2009-02-17 Thread Mark Hammond

On 18/02/2009 5:49 AM, Sam Clark wrote:

I am receiving the message "This application has failed to start because
the application configuration is incorrect" when I attempt to run a
compiled Python program on another machine. I have used py2exe on both a
2.6.1 and a 2.6.0 version of the .py and .pyw files. Everything works
great on the machine where Python 2.6 is loaded, but fails on machines
where I copy the .exe to the machine. I'm a beginner at python
programming. In fact this is my first packaged program. Any thoughts at
a beginners level would be helpful.


This will be due to the C runtime library not being installed correctly 
on the target machine.  Python 2.6 has this problem more than earlier 
versions (due to the compiler used to build it) and the best way to 
address it isn't really clear yet unless you are willing to have them 
install these libraries via another Microsoft supplied installer. 
Probably the easiest workaround is to use Python 2.5 in the short term...


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


RE: [Py2exe-users] py2exe 0.6.9 released

2008-11-16 Thread Mark Hammond
> After I "compile" my program with py2exe 0.6.9 with Python 2.6, I'm
> still getting the "Application Did Not Initialize Properly" error
> dialog whenever I run my code.  What am I doing wrong?

This probably means the Microsoft VC90 binaries aren't installed globally on
your machine - which would imply they are installed locally in the \Python26
directory by the python 2.6 installer (I haven't checked that though - I
tend to not use the installers).  In that case, a solution would be to copy
the files Microsoft.VC90.CRT.manifest, msvcm90.dll, msvcp90.dll and
msvcr90.dll from the Python directory into your app's directory.  Your
installer will need to arrange for these to be installed with your app
(assuming you have the rights to redistribute them) or you can download the
installer from MS which installs them globally.

Hope this helps,

Mark

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


Re: How does one get from "ImportError: DLL load failed:..." to a culprit .dll and symbol?

2009-02-23 Thread Mark Hammond

On 23/02/2009 11:41 PM, Chris Cormie wrote:



If that not-very-technical description [all I've ever needed] doesn't
help, you'll need to read the DW help file (HTFF1K) or wait till
someone who knows what they are doing comes along :-)


LOL, I am that person :p


LOL sounds right!


How do you get *Python* to tell you the dll and the problem symbol? Not
external tools, Python. Python at a low level is calling LoadLibrary and
GetProcAddress to resolve symbols and the call fails.


It is the LoadLibrary that is failing; it should be obvious that if it 
was a simple GetProcAddress that was failing, Python would simply throw 
an exception rather than displaying the ugly dialog box you see.


The problem is that some *other* DLL in the chain of dependencies is 
failing to load; please re-adjust your perceptions of your own knowledge 
and re-read John's initial response - if you follow his instructions 
that should all become quite obvious.


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


Re: This application has failed to start because the application configuration is incorrect

2009-02-25 Thread Mark Hammond

On 26/02/2009 4:51 AM, Lorenzo wrote:


PS: Mark, this could be added to a kind of "Deployment" entry in
py2exe wiki, it would be useful.


IIRC, I've never edited the py2exe wiki (despite appearances to the 
contrary sometimes, I don't formally maintain that package!).


But that is the cool thing about Wiki's - *anyone* can add such 
information ;)


Cheers,

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


Re: Eject a Removable USB drive

2009-03-09 Thread Mark Hammond

On 10/03/2009 8:20 AM, Rickey, Kyle W wrote:

Thanks for the link! That code has got me on the right track. I've
almost got it working with one small kink.

After the code runs my drive still shows up on Windows Explorer but as a
removable drive. If I try to double click on it, it tells me to insert a
disk (see screenshot).

So it seems my code is unmounting my volume, but not the actual device.
Any ideas? I've attached the code I've got so far.


Adding the following after your eject code runs:

from win32com.shell import shell, shellcon
shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, 
"F:\\")



seems to work for me (well - I actually did the above interactively 
after your code ran, and the disk magically vanished from explorer...)


Cheers,

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


Re: Mapping 64 bit int from C to Python-2.2

2009-03-10 Thread Mark Hammond

On 10/03/2009 2:51 AM, Explore_Imagination wrote:

Hi

I want to map 64 bit integers from C to python. I must use Python 2.2
BUT There is no support for 64 bits integers in Python2.2 (Supported
in 2.5).

Now the problem is that I have these four variables:

unit32_t a,b,c;
uint64_t w,x,y,z;

I use this funtion to map values:

Py_BuildValue( "(lll)", a,b,c,w,x,y,z );

As I access 32 bit values in Python it works fine BUT 64 bit intergers
in Pythong give garbage values . I think there may be a case of
overflow when 64 bit values in C are mapped to python.

Any Suggestions?


pywin32 had this requirement, and although support was recently removed, 
if you look at:


http://pywin32.cvs.sourceforge.net/viewvc/pywin32/pywin32/win32/src/PyLARGE_INTEGER.cpp?revision=1.11&view=markup

you should find routines that work without 'longlong' support in Python 
itself.


Cheers,

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


Re: Eject a Removable USB drive

2009-03-10 Thread Mark Hammond

On 11/03/2009 12:39 AM, Rickey, Kyle W wrote:

def do_magic():
 from staples import easy_button
 result = easy_button.press()
 return result

:) In all seriousness that code did the trick but only after a short delay. I 
noticed when I first ran it, there was no effect. But when I ran it 
interactively, it succeeded.

Is there any way to check that the drive is still showing up in explorer and 
then re-run the code? Something like:


It is possible to register for device removal notifications - it's 
possible you need to wait until Windows reports the ejection process is 
complete before sending the shell notification.


Cheers,

Mark



while drive_exists:
shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, 
"F:\\")


Right now I've got:

time.sleep(1)
shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, "F:\\")


Thanks for your help!

-Kyle Rickey

-Original Message-
From: python-list-bounces+kyle.rickey=bakerhughes@python.org 
[mailto:python-list-bounces+kyle.rickey=bakerhughes@python.org] On Behalf 
Of Aaron Brady
Sent: Monday, March 09, 2009 6:15 PM
To: python-list@python.org
Subject: Re: Eject a Removable USB drive

On Mar 9, 6:08 pm, Mark Hammond  wrote:

On 10/03/2009 8:20 AM, Rickey, Kyle W wrote:


Thanks for the link! That code has got me on the right track. I've
almost got it working with one small kink.
After the code runs my drive still shows up on Windows Explorer but as a
removable drive. If I try to double click on it, it tells me to insert a
disk (see screenshot).
So it seems my code is unmounting my volume, but not the actual device.
Any ideas? I've attached the code I've got so far.

Adding the following after your eject code runs:

from win32com.shell import shell, shellcon
shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH,
"F:\\")

seems to work for me (well - I actually did the above interactively
after your code ran, and the disk magically vanished from explorer...)


Yay, magically!  import crystalball?
--
http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list


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


Re: PyWin32 for Python 3.x

2009-03-15 Thread Mark Hammond

On 16/03/2009 6:05 AM, John Nagle wrote:

Tim Golden wrote:

John Nagle wrote:

Any idea when PyWin32 will be available for Python 3.x?

John Nagle


Release 213 is out already:

http://sourceforge.net/project/showfiles.php?group_id=78018&package_id=79063&release_id=661475


I think it's still considered a little bit beta. There have been a *lot*
of changes involved.


That "wizard" won't even install unless Python 3.0 is "in the
registry", which apparently means "installed as the default Python".
After giving the user an alert box, it dumps you into a dialog which
says "Python 3.0 is required for this package. Select installation to use".
That's blank, and the form fields "Python Directory" and "Installation
Directory" won't accept input, so it can't even be overridden manually.

Lame.


This would be exactly the same for any version of Python; while the 
distutils create UI does suck, the problem has nothing to do with Python 
3.0.


I'm guessing you built it from source?  If so, and as with every version 
of Python, you really just need the 'InstallPath' set appropriately, but 
probably also want the PythonPath to be setup like other versions.


Cheers,

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


Re: Safe to call Py_Initialize() frequently?

2009-03-20 Thread Mark Hammond

On 21/03/2009 4:20 AM, roschler wrote:

I've created a Python server that embeds Python 2.5 and runs Python
jobs.  I want to be able to completely "flush" the interpreter between
each job.  That means resetting all variables, stopping all user
created threads, and resetting the interpreter sys module path.  If it
does not cause memory leaks, slowdowns, or other problems I would like
to call Py_Initialize() before running each job.  I expect to run a
job about once a second.  Are there any known issues with doing this
or anything else that would make this a bad approach?


Calling Py_Initialize() multiple times has no effect.  Calling 
Py_Initialize and Py_Finalize multiple times does leak (Python 3 has 
mechanisms so this need to always be true in the future, but it is true 
now for non-trivial apps.




If it is a safe approach, do I have to pair each Py_Initialize() call
with a Py_Finalize() call?

If it is not a safe approach, is there another way to get what I want?


Start a new process each time?

Cheers,

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


Re: Safe to call Py_Initialize() frequently?

2009-03-23 Thread Mark Hammond

On 23/03/2009 12:14 PM, Graham Dumpleton wrote:

On Mar 21, 10:27 am, Mark Hammond  wrote:

Calling
Py_Initialize and Py_Finalize multiple times does leak (Python 3 has
mechanisms so this need to always be true in the future, but it is true
now for non-trivial apps.


Mark, can you please clarify this statement you are making. The
grammar used makes it a bit unclear.


Yes, sorry - s/this need to/this need not/


Are you saying, that effectively by design, Python 3.0 will always
leak memory upon Py_Finalize() being called, or that it shouldn't leak
memory and that problems with older versions of Python have been fixed
up?


The latter - kindof - py3k provides an enhanced API that *allows* 
extensions to be 'safe' in this regard, but it doesn't enforce it. 
Modules 'trivially' ported from py2k will not magically get this ability 
- they must explicitly take advantage of it.  pywin32 is yet to do so 
(ie, it is a 'trivial' port...)


I hope this clarifies...

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


Re: Problem Python 2.6.1 vs 2.6 & pyWin32

2009-03-25 Thread Mark Hammond

On 25/03/2009 11:06 AM, John Machin wrote:

It would appear that the safest cover-most-bases option for a developer/packager
of pure-Python packages (especially one intended to be runnable on older
versions of Python, some as far back as 2.1) is to use Python 2.5 to make the
bdist_wininst (the exe is linked against msvcr71.dll which is widely available
and doesn't have SxS problems).


Hi John,

  Note that fairly recently (IIRC, 2.6.2/3.1), the bdist_wininst stub 
installers moved to linking the CRT statically, so should avoid this 
problem.  Indeed, if you use the correct magic, you should be able to 
use this version of distutils to build binaries for much earlier 
versions of Python and to allow the installer itself for that version to 
avoid depending on any msvcrt...


Cheers,

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


Re: Problem Python 2.6.1 vs 2.6 & pyWin32

2009-03-25 Thread Mark Hammond

On 25/03/2009 11:41 PM, John Machin wrote:


This all sounds good. I presume that "this version of distutils" means
the 2.6.2/3.1 version.


Yep.



In the meantime, until 2.6.2 final is released, is my suggestion of
using Python 2.5 to build installers reasonable?


Yep.


Is there a better approach?


Not that I'm aware of - hence the fixing of the installer to avoid the 
crt completely.



BTW, the user with the problem has not only confirmed that he did indeed
receive the misspelled German version of the error message :-) but also
has successfully installed the package using a 2.5-built installer that
I provided. It's curious that out of over 250 downloads of the 2.6-built
installer, there's been only 1 report of the installer not working.


IIRC, the installer would work OK if a 'public' or shared copy of the vc 
runtime was installed - but it would seem unusual that 249 out of 250 
people would have that...


Cheers,

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


Re: py2exe - win32com - GetGeneratePath Error

2009-03-25 Thread Mark Hammond

On 26/03/2009 2:19 AM, Christopher Panici wrote:

Has anyone solved the GetGeneratePath Error?

I am getting this when I use
win32com.client.DispatchWithEvents('iTunes.Application',
customEventHandler). I have drilled down to the file and found it in
that path.

Does anyone have any ideas?

HERE IS THE ERROR. If anyone is good at this please email me back.
---
Traceback (most recent call last):
File "AppleHackGUI.pyw", line 376, in 
File "Main.pyc", line 29, in __init__
File "win32com\client\__init__.pyc", line 250, in DispatchWithEvents
File "win32com\client\gencache.pyc", line 520, in EnsureModule
File "win32com\client\gencache.pyc", line 287, in MakeModuleForTypelib
File "win32com\client\makepy.pyc", line 256, in GenerateFromTypeLibSpec
File "win32com\client\gencache.pyc", line 141, in GetGeneratePath
IOError: [Errno 2] No such file or directory:
'C:\\Users\\Neech\\Documents\\PythonProjects\\AppleHack\\src\\dist\\library.zip\\win32com\\gen_py\\__init__.py'


This error is caused by a py2exe application; such applications are 
unable to generate .py files from COM typelibs, but they are capable of 
generating them at build time and distributing them with the app.  You 
should ask whoever put the application together to read the py2exe docs 
to learn how to embed the generated files for ITunes directly inside the 
app.


Cheers,

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


Re: please include python26_d.lib in the installer

2009-03-27 Thread Mark Hammond

Please note: I want to build my own code in Debug mode for debugging.
I don't want to build or use the debug version of Python. I also can't


Python does this on purpose so you don't accidentally mix different 
versions of the C runtime library.  This would happen ff you defined 
DEBUG in your code but use Python built without DEBUG - Python using a 
different name for its lib prevents this.


Note that just shipping the _d.lib wouldn't help - you would need the 
_d.dll itself, plus *all* extension modules you use - *all* .pyd/.dll 
etc files have the trailing _d, and a debug version of Python refuses to 
load the release versions without the _d.


I'd recommend leaving DEBUG etc disbled, but enable debug information 
and disable optimizations while debugging.


Cheers,

Mark

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


Re: Unladen-Swallow: A faster python

2009-03-28 Thread Mark Hammond

On 28/03/2009 9:50 PM, andrew cooke wrote:

Tim Roberts wrote:

[...]  IronPython has certainly shown that Python can be successfully
implemented in a JIT compiled VM in a performant way, but it has issues
running C extension modules.

I'll be curious to see where this project goes.


given the comments on python-dev i wonder if this is the first indication
that python is going to split into separate implementations for windows
and unix (via .net and llvm, respectively)?


What comments are they?  There is no indication that unladen-swallow  is 
fundamentally broken for Windows, just temporarily broken due to the 
lack of windows developers/contributors...


Saying-no-to-fud ly,

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


Re: win32com python AttributeError!

2009-03-31 Thread Mark Hammond
My guess is that you have a hidden instance of excel running (ie, 
without a window).  Check the task manager for instances of excel.exe 
and kill them.


Cheers,

Mark

On 31/03/2009 3:17 PM, Michael wrote:

Hi Python-list -

Has anyone figured this out from Rebecca:


Hi, I am having trouble with win32com for python.  I get the following
error when I try to issue any command after using Dispatch.


xl=win32com.client.Dispatch("Excel.Application")
xl.Visible=0

Traceback (most recent call last):
   File "", line 1, in ?
 xl.Visible=0
   File "D:\Python22\Lib\site-packages\win32com\client\dynamic.py",
line 504, in __setattr__
 raise AttributeError, "Property '%s.%s' can not be set." %
(self._username_, attr)
AttributeError: Property 'Excel.Application.Visible' can not be set.

I have programs that I used to use all the time and they simply won't
run.  Is this an error with python or win32com or my setup?

Thanks,
-rebecca

I have the same problem.

Thus,

myWord = Dispatch("Word.Application")
myWord.Visible = 1   # or, True

opens a word document but

myExcel = Dispatch("Excel.Application")
myExcel.Visible = 1# or, True

causes (as Rebecca notes above):

AttributeError: Property 'Excel.Application.Visible' can
not be set.



Thanks,

Michael


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


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


Re: Would you support adding UNC support to os.path on Windows?

2009-04-22 Thread Mark Hammond

Aahz wrote:

In article ,
Larry Hastings   wrote:
I've written a patch for Python 3.1 that changes os.path so it handles 
UNC paths on Windows.  You can read about it at the Python bug tracker:


   http://bugs.python.org/issue5799

I'd like to gauge community interest in the patch.  After all, it's has 
been declined before; I submitted a similar patch for 1.5.2 way back in 
1999.  (You can read the details of that on the tracker page too.)


You should bring this up on python-dev.


In Larry's defense, I suggested he bring it here first to try and find 
some common noise from the people with the most experience actually 
using these functions - ie, those people here.  My hope was that some 
vague consensus here would offer more ammunition when finally taking it 
to python-dev for consideration (or kill it without taking it there - 
but it's looking good :)


Cheers,

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


Re: Windows Shell Extensions - Out of Proc

2009-04-24 Thread Mark Hammond

Thomas Heller wrote:

Ralf schrieb:

I think that for whatever reasons, explorer always tries to create
shell extensions as InProc.  CoCreateInstance, which is the usual
API to create COM instances, allows to specify which one you want.

Thomas

So there is no way to do this, other than to create a "proxy" COM
object as InProc, which then forwards the requests to my COM object in
the separate process?


Not that I know of - anyone else?


That's my understanding too (and probably for good reason - shell 
extensions can be called lots!)


Mark

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


Re: pythoncom -- ImportError: DLL load failed - Solved, sort of.

2009-04-24 Thread Mark Hammond

Richard Whidden wrote:
I installed a clean copy of Python 2.5, pywin32 and PyGreSQL and it works. 
I'll have to figure out what broke with my 2.6 install.


Make sure you have 2.6.2

Mark

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


Re: Installing Python 2.5.4 from Source under Windows

2009-04-29 Thread Mark Hammond

Paul Franz wrote:

I have looked and looked and looked. But I can not find any directions

on how to install the version of Python build using Microsoft's 
compiler. It builds. I get the dlls and the exe's. But there is no 
documentation that says how to install what has been built. I have read 
every readme and stop by the IRC channel and there seems to be nothing.


Although you asked about 'installing', you should find that the Python 
you built works fine from where it is, and adding packages to your 
site-packages directory will work as you expect.  With the addition of 
an 'InstallPath' registry entry pointing at your directory, other .exe 
installer packages created by distutils will also install correctly.


Hope this helps,

Mark

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


Re: Installing Python 2.5.4 from Source under Windows

2009-04-30 Thread Mark Hammond

Paul Franz wrote:

Mark,
   The problem is that the steps are not in the readme.txt for the 
building Python for Windows.  The python.exe might work from the 
Win32Release directory where it is compiled.


You should find the executables and DLLs directly in the PCBuild 
directory (for an x86 build)



But I would like to have it create the distuils directory,


The distutils directory, and all directories used by distutils should 
already be there (hrm - maybe not the top-level 'scripts' directory...)


and other python packages that are 
normally part of a python distribution. 


You should find all of them there too.

Another person pointed out 
Tools/Msi and I will look in that directory.


IIUC that will simply package up what you just built into an installer 
but this installer package doesn't include anything you don't already 
have.  It will install into a slightly different directory structure and 
it will setup registry and start menu items etc though, so if that is 
what are after it will serve you well...


Cheers,

Mark

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


Re: Fwd: Re: Unable to install Pywin32 for Python 2.6.2

2009-05-11 Thread Mark Hammond
Probably some import statement is finding a .pyd module built against 
Python 2.5 instead of Python 2.6; it might be that PYTHONPATH points 
somewhere wrong, or the registry for Python 2.6 is setup wrong, or 
something else entirely...


Cheers,

Mark

On 12/05/2009 3:13 PM, David Lyon wrote:

Hi,

hmmm... that's annoying..

Whilst I don't have an exact answer I have a few hunches...

Perphaps what has happened is that the windows installer between
the versions of pywin32 has installed newer versions of the same
dlls over the top of older ones.

Or, possibly, the installer hasn't wanted to replace older dll's
because they already exist on the system.

This would result in a mismatch.

You may be lucky and find an install log. This might tell you which
files were actually installed. And you could play around with
moving them around.

Good luck with your night vision task

David


On Tue, 12 May 2009 02:22:56 GMT, David Lees
wrote:

I have no problem installing Python 2.6.2 for windows under XP SP3 and
IDLE and the command line versions work fine.  When I run the pywin32
installer downloaded from sourceforge (pywin32-212.win32-py2.6.exe) I
get the following error message:

Traceback (most recent call last):
File "", line 565, in
File "", line 291, in install
ImportError: Module use of python25.dll conflicts with this version of
Python.
*** run_installscript: internal error 0x ***

I have tried uninstalling Python 2.6 and reinstalling, but still get the
same message.  I do have Python 2.5.4 and its associated Pywin32 on the
same machine, but I have a laptop with pywin32 installed for both python
2.5 and 2.6.

TIA

David Lees


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


Re: Fwd: Re: Unable to install Pywin32 for Python 2.6.2

2009-05-13 Thread Mark Hammond

On 13/05/2009 2:18 PM, David Lyon wrote:

On Wed, 13 May 2009 05:32:16 +0200, "Martin v. Löwis"
wrote:


I think this was a case of obscure misconfiguration of the system.
It is always possible to configure a system in such a way that even
the most resilient installation procedure will break.


Technically, you are right..

but imho.. windows installers are overkill and shouldn't be used
for this sort of thing. That is, installing libraries. And not
the fault of the package authors either...


But if PYTHONPATH was set incorrectly it really doesn't matter how 
Python was installed, it would still fail.  The installer didn't set 
PYTHONPATH, a human did.


Cheers,

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


Re: Which version of MSVC?90.DLL's to distribute with Python 2.6 based Py2exe executables?

2009-12-17 Thread Mark Hammond

On 18/12/2009 7:44 AM, Ross Ridge wrote:

The "P" DLL is for C++ and so the original poster may not actually need
it.  I'm pretty sure Python itself doesn't need it, and py2exe shouldn't
either, but wxPython, or more precisely wxWidgets, almost certainly does.
So in your case you'll probably need to redistribute both DLLs.


FYI, my experience is that an entire manifest must be distributed.  As 
the manifest in question actually lists 3 DLLs, IIUC, you must ship all 
4 files - the 3 DLLs and the manifest, even if only one of the DLLs is 
actually used.


This is from memory some time back though, so apologies in advance if 
I'm mis-remembering.


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


Re: subprocess.Popen and ordering writes to stdout and stderr

2009-12-17 Thread Mark Hammond

On 18/12/2009 9:33 AM, Chris Withers wrote:

exar...@twistedmatrix.com wrote:

libc is probably giving you line buffering when you use os.system
(because the child process inherits the parent's stdio, and the
parent's stdio is probably a pty, and that's the policy libc implements).




Interesting, but do these assertions still hold true when I tell you
that I'm doing all this on Windows? ;-)


Yep.  You can see similar behaviour from just the cmd-prompt and the 
following script:


--
import sys
for i in range(10):
  print "stdout"
  print >> sys.stderr, "stderr"
--

If you execute it "normally" from a command-prompt, you will see things 
written in the correct order.  If you execute it like 'python foo.py > 
out 2>&1', the order will be mixed up.  If you execute it like 'python 
-u foo.py > out 2>&1' the order is restored.


HTH,

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


Re: counting lines of code

2010-01-20 Thread Mark Hammond

On 21/01/2010 5:51 PM, Michele Simionato wrote:

I need a small utility to count the lines of Python code in a
directory, traversing subdirectories and ignoring comments and
docstrings. I am sure there is already something doing that, what do
you suggest?


I suggest typing your subject line into google and hitting the "I feel 
lucky" button :)


HTH,

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


Re: Bug(s) in Python 3.1.1 Windows installation

2009-10-28 Thread Mark Hammond

On 29/10/2009 11:06 AM, Alf P. Steinbach wrote:


So I suggest switching to some other more light-weight installer
technology.


Thanks for the suggestion, but I expect we will stick with MSI even with 
its shortcomings.  Using MSI files has significant other advantages, 
particularly in "managed" environments.



(2) Failure to set up PATH.


This is by design.  If you really care passionately about this, you 
should be able to find a number of discussions here, in python-dev and 
in the python bug tracker.


One example of why the current behaviour is useful is that many people 
install multiple Python versions side-by-side and a "last installed 
wins" strategy isn't a great option.



Even after setting up a correct PATH Tkinter does not work:


I suspect this will be a Python 3.x issue - you probably want to stick 
with 2.x.


HTH,

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


Re: _winreg error on open key (64bit) - proper usage of _winreg.DisableReflectionKey

2009-11-17 Thread Mark Hammond

On 18/11/2009 6:29 AM, Randall Walls wrote:

I don't believe so, but it seems like I'm in a catch 22, where I need to
_winreg.OpenKey the key first before I can pass it to
_winreg.DisableReflectionKey, but it doesn't exist, so I can't open it.

I did find out that I can open the key using:
hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\ODBC\ODBC.INI\
DRSQL2000_mu0100\\", 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY)

The 'trick' was adding _winreg.KEY_WOW64_64KEY, which apparently tells
the system to look in the 64bit key area, and not under the Wow6432Node.
That brings up problem #2, though... I can't seem to CREATE a key in the
above path, and _winreg.CreateKey doesn't accept _winreg.KEY_WOW64_64KEY
(in fact it doesn't accept any options other than key, sub_key).
_winreg.CreateKey does work, it just puts the key in
SOFTWARE\Wow6432Node\ODBC\ODBC.INI. So I'm in a quandry... I'd like to
use one or the other, and not have to account for both.


It looks like _winreg needs to be enhanced to make the RegCreateKeyEx 
API function available.  It can be called via the win32api module of 
pywin32, or could also be called via ctypes.


HTH,

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


Re: reading windows event logs

2009-11-25 Thread Mark Hammond

On 26/11/2009 7:22 AM, EW wrote:

Hi All,
  I'm looking for some guidance on a better way to read eventlogs
from windows servers.  I've written a handy little app that relies on
WMI to pull the logs an in all my testing it worked great.  When I
deployed it, however, WMI choked on servers with a lot of logs.  I've
tried pulling the logs using much smaller VB scripts as well and they
still failed, so I'm pretty sure I'm facing a WMI problem and not a
python or system resources problem.  So I couldn't effectively get
logs off of domain controllers for example or file servers that had
auditing turned on.  Sadly those are exactly the types of servers
whose logs are most interesting.

  So I'm looking for suggestions on a way to grab that data without
using WMI for remote machines.  I know MS has C libraries for this but
I haven't touched C for 10 years so I'm hoping there's a python
equivalent out there somewhere.  Any advice would be appreciated.


Look for the win32evtlog and win32evtlogutil modules which come with 
pywin32 (http://sf.net/projects/pywin32)


Cheers,

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


Re: strange issue with C extension using Py_BuildValue

2010-02-10 Thread Mark Hammond

On 11/02/2010 9:19 AM, bobicanprogram wrote:

I'm am having "strange" problems with the code snip below.

When this code is built on a 64bit Linux,  it would appear to work
flawlessly.When the source is rebuilt on a 32bit Linux it begins
to crack in strange ways.   The issue seems to be associated with the
sender field in the Py_BuildValue call.The fact that sender is a
pointer should mean that its value is an unsigned integer.However,
on the 32 bit build the failure is that the msgPtr->data value is
"messed up".   If the format associated with the sender (a pointer)
from "L" to "i" things work on the 32 bit side but break on the 64 bit
side.


I expect that in a 32bit build of linux, a "long long" (the 'L' format) 
is still 64 bits.  You probably want something like:


Py_BuildValue("iNz#", ret, PyLong_FromVoidPtr(sender), &msgPtr->data, ret);

and PyLong_AsVoidPtr() for the other direction.

HTH,

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


Re: Trouble running pywin32-214.win-amd64-py3.1 on 64-bit Windows 7

2010-02-19 Thread Mark Hammond

On 20/02/2010 5:35 AM, Steven Cohen wrote:

Hello,

I downloaded pywin32-214.win-amd64-py3.1, and it installs just fine
(except that it prints a traceback when it tells me the postinstall
script completed), but then when I try to execute Pythonwin.exe, I get
the following error popup:

The application can not locate win32ui.pyd (or Python) (126)
The specified module could not be found

However, the file win32ui.pyd is right there in the same directory from
which I am executing Pythonwin.exe.  Can anyone help me figure out what
I am doing wrong here?


The pywin32 post-install script seems to break with the current Python 
3.1 builds, and as a result, the pywin32 DLLs were probably not copied 
correctly.


Try re-executing the post install script by:

* Start a command-prompt by right-clicking on the shortcut and selecting 
'Run as Administrator'.


* Execute '\python31\python.exe \python31\scripts\pywin32_postinstall.py 
-install' (changing the paths as necessary).


It should succeed as it is running from a console, and you might find 
that fixes things.


HTH,

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


Re: Saving the Interactive Window with PythonWin

2010-02-21 Thread Mark Hammond

On 22/02/2010 4:28 AM, vsoler wrote:

Hi everyone,

When I run a python script, I know that I can print the results of my
calculations on the Interactive Window. Once the scripts ends, I can
copy/pate these results on an OpenOffice Writer document.

However, I would like to know if I can somehow add some lines to my
script, so that it saves the Interactive Window to a text file. How
could it be done?


The code for the interactive window is in pywin32\framework\interact.py 
- eg:


>>> from pywin.framework import interact
>>> interact.IsInteractiveWindowVisible()
True
>>>

If it is visible, then something like:

>>> len(interact.edit.currentView.GetWindowText())
189
>>>

should get you on the right path.



And, is there a way to programatically clear out the Interactive
Window so that it only shows the last run?


Something like:

interact.edit.currentView.GetWindowText('line1\nline2\nline3')

should work - the first few lines will always be formatted using blue 
text, and the above works a little strangely when attempting it directly 
from the interactive prompt, but might still be useful.  See the source 
file I mentioned above for more clues.


HTH,

Mark


Thank you for your help


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


Re: How to add a library path to pythonpath ?

2010-03-16 Thread Mark Hammond

On 17/03/2010 1:26 AM, Barak, Ron wrote:

Thanks for the suggestion Pable.
However, I really need the $PYTHONPATH to include this additional
library, so all Python scripts could use it.
In Windows I have defined PYTHONPATH as
c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the
Windows registry I have
HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\/version/\PythonPath\ as
C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\;C:\Python26\Lib\lib-tk;
However, even with all the above, the SVMInspecor modules are not found.


You need to create your own sub-key, with any name, under the PythonPath 
key and add your path there.  The reason is that Python only looks for 
that root key when it can't sniff the location of the library itself 
based on the location of the executable - and in most cases it can. 
Python does however enumerate and use the sub-keys in all cases.


HTH,

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


Re: win32 design pattern: COM localserver?

2010-12-09 Thread Mark Hammond
If you are implementing a COM object using win32com, then Python will 
never be unloaded from the host process, which works in your favour. 
Just have the COM object use a thread and a queue for this processing. 
The 'report' method would just stick the params and filenames in the 
queue and return immediately - your thread should stay alive and working 
away so long as the host process remains alive.  You probably need to 
deal with the face the thread will be unexpectedly terminated when the 
host process terminates or add a new method designed explicitly to block 
the host process until everything is complete - the host program would 
then call this method just before it terminates.


Also note there is a python-wi...@python.org mailing list where you 
might get better or more advice...


Cheers,

Mark


On 8/12/2010 8:03 PM, kirby.ur...@gmail.com wrote:

Greetings gurus.

I'm faced with the challenge of having a single-threaded proprietary
Win32
language wanting to do multiple calls against a Python COM object.

Something like...

loObj = CREATEOBJECT("map_maker")
loObj.report( params, filename)

do while .True.
   yadda yadda
enddo

RETURN

I.e. the client program continues execution while loObj churns away
somewhere doing work in Python, say accessing a MySQL database
and building a map, embedding it in a PDF.

Am I right that the COM object will need to "serve forever" i.e. be
built around some non-terminating loop?  Will the client's call then
spawn a process or thread that continues until finished?

All it has to do is leave a file on disk somewhere, then die.  But
the client can't be kept on the hook until that's all done.

I've had good luck doing an InProcess COM object the generates
a PDF from ReportLab.  But this "stay alive while returning control
to the client" challenge looks like it might be a job for sockets?

Gee I hope not.

Quick links to favorite blog articles will give me a sense of the
ballpark...  Any clues welcome.  Yes, I have the Win32 book from
O'Reilly.

Kirby

PS:  my thanks to Ethan Furman for performing maintenance and
upgrades on his dbf module on PyPI.  The FoxPro gods thank you.
http://pypi.python.org/pypi/dbf/0.88.16

PPS:  some thoughts about IronPython filed here, after trying to
catch up some, sorry about my formatting, here too.
http://mail.python.org/pipermail/edu-sig/2010-December/010138.html



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


Re: user rights and python com servers

2010-04-15 Thread Mark Hammond

On 15/04/2010 6:05 PM, sniffer wrote:

hi all,
i am facing a peculiar problem with a python com server i've developed
the com server runs fine in winxp  standalone systems but if the
system is part of a domain then until the logged in user is given
power user rights i am unable to register the dll using regsvr32 , a
similar problem i face on vista system here unless and untill the app
utilising the dll is run with admin privelleges the dll does not get
registered and does not function as a result.


This is a "feature" of Vista and later - you must have elevated 
permissions to write to the place in the registry where "global" COM 
objects are stored.  By default, the standard win32com registration code 
will attempt to elevate and register if necessary.


Note that it is also possible in theory to register COM objects just for 
a single user, but while win32com doesn't support that directly it 
shouldn't be hard to support this with a few changes to 
win32com\server\register.py


HTH,

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


Re: py2exe saga continues...

2010-04-15 Thread Mark Hammond

On 16/04/2010 10:52 AM, Alex Hall wrote:

1. Is there a way to start with no command line window popping up? My
main script is a pyw, but it still shows a dos window when the
generated .exe file is clicked. Leaving out the "console" parameter of
setup, though, results in no .exe file at all, so I had to put it
back. I want what I have heard called a "silent startup", where the
program starts but it does not pop up anything. My users will know
because I will speak a message, but I want to dump the dos window.


You probably want to use the 'windows=' option instead of the 'console=' 
option (or both if you like - in which case you probably also need to 
specify a 'dest_base' value for one of them.



2. Is there a way to put the exe in a higher-level dir, then put all
the pyd, dll, zip, and other files into a subdirectory so the .exe is
not mixed in with all these files that most users will not care about?
Thank you for all your help over the last few days!!


I *think* that if you specify the 'zipfile' param to include a directory 
portion then all libs will be stored in that same dir.  Eg, spambayes 
includes:


  zipfile = "lib/spambayes.modules",

which causes the .zip file to be named as specified, but all the .pyd 
files also wind up in the 'lib' directory.  Use of the 'dest_base' param 
causes all executables to be placed in a 'bin' directory, so we have 2 
separate dirs holding things.  Spambayes has a complicated setup file 
which may offer some insights - find the spambayes source at sourceforge 
then look for the spambayes/spambayes/windows/py2exe/setup_all.py file 
for inspiration...


HTH,

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


Re: python wia and RegisterEvent

2010-04-15 Thread Mark Hammond

On 16/04/2010 7:15 AM, gelonida wrote:

Hi,

I'd like to register an event in order to be informed, whenever a
Windows WIA device is connected or disconnected.

In python I can use WIA devices, but I don't know how to register
events

I have existing C# code, which works and looks like.

class MgrHandlerClass
 {
 public void devManager_OnEvent(string eventID, string
deviceID, string itemID)
 {} // her emy handler code

 public void addhandler(DeviceManager manager)
 {
 Console.WriteLine("adding handler!");
 manager.OnEvent += new
WIA._IDeviceManagerEvents_OnEventEventHandler(
 devManager_OnEvent);
 }

 static void Main(string[] args)
 {

 MgrHandlerClass mgrhndlr;
 mgrhndlr = new MgrClass();
 DeviceManager manager;

  manager = new DeviceManagerClass();

manager.RegisterEvent(WIA.EventID.wiaEventDeviceConnected, "*");

manager.RegisterEvent(WIA.EventID.wiaEventDeviceDisconnected, "*");
  mgrhndlr.addhandler(manager);
 // wait for callbacks or do other stuff
 }


Now in python I'm stuck

import win32com.client
import wia_defs # created with makepy.py
manager = win32com.client.Dispatch("WIA.DeviceManager")
mgrhndlr = MgrClass()
manager.RegisterEvent(EventID=constants.wiaEventDeviceConnected,DeviceID=u'*')
manager.RegisterEvent(EventID=constants.wiaEventDeviceDisconnected,DeviceID=u'*')
mgrhndlr.addhandler(manager)


class MgrHandlerClass:
 def OnEvent(self, EventID=defaultNamedNotOptArg,
DeviceID=defaultNamedNotOptArg, ItemID=defaultNamedNotOptArg):
 print "Called back with (%s) (%s) (%s)" %
(EventID,DeviceID,ItemID)

 def addhandler(self,manager):
 # here I'm stuck :-(
 # the following line doesn't work as it seems, that manager
does not have attr
 # onevent

manager.OnEvent.append( 
WIA._IDeviceManagerEvents_OnEventEventHandler(self.OnEvent) )


The model used by pywin32 is more "low level" than that exposed by some 
of the MS languages.  You probably need something closer to:



 class MgrHandlerClass:
  def OnEvent(self, EventID=defaultNamedNotOptArg, ...):
  print "Called back with ..."


manager = win32com.client.DispatchWithEvents("WIA.DeviceManager", 
MgrHandlerClass)

manager.RegisterEvent(EventID=constants.wiaEventDeviceConnected,DeviceID=u'*')
manager.RegisterEvent(EventID=constants.wiaEventDeviceDisconnected,DeviceID=u'*')

And magically your OnEvent should be called when the event happens. 
Googling for 'DispatchWithEvents' might find some good hits for more 
information.


HTH,

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


Re: user rights and python com servers

2010-04-15 Thread Mark Hammond

On 16/04/2010 2:40 PM, sniffer wrote:

Thanks Mark,
  just one question does the explanation given above by you also apply
to winxp systems in a domain,


Yeah - IIRC, domain users can't change much of the registry by default, 
primarily as they aren't in the 'administrators' or 'power user' groups 
by default like local users are - but it all depends on various security 
policies and attributes of each user.



if so then what is the minimum level of
user rights required for the com server to run without hiccups.


Any user can *run* the server - just not all can register it.  To 
register it, the user needs the ability to write to the 
HKEY_CLASSES_ROOT hive in the registry.  This is the same problem 
forcing may installation programs to insist on being run as an 
administrator even if the program itself doesn't need to be.


Cheers,

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


Re: Windows debugging symbols for python 2.5.4 and pywin32 214

2010-04-22 Thread Mark Hammond

On 22/04/2010 7:23 AM, Alexandre Fayolle wrote:

Hi everyone,

I have a production server running a Windows Service written in Python, which
uses python 2.5.4 (yes I know it is old, but I am somewhat stuck with this for
now) and pywin32 214.

Given a set of manipulations, I get a stack overflow in the service, and a bad
crash. The same operation when running without
win32serviceutil.ServiceFramework does not trigger the bug. I'm looking for
some debugging tools (debug build of the interpreter and the pywin32
libraries) that some good soul could have kept from a previous debugging
session to try to get a C stack trace and understand what causes this.


I expect the problem might be that pythonservice.exe isn't linked with a 
large enough stack - python itself builds with a larger than default 
stack.  That difference could cause a recursive function to hard-crash 
before Python itself detected the recursion as being too deep.


You could test this by playing with the sys.setrecursionlimit function - 
at some limit I expect you would find the hard-crash would be replaced 
with a max recursion exception.  Let me know if that is the case and 
I'll be sure to adjust the stack size for the next pywin32 build.



Any hint towards what could cause that stack overflow would be welcome too.
The application is multithreaded (and uses pyro and twisted). I can provide
more information for the curious.


Some parts of twisted are written such that server responses are 
processed recursively, and very large input can cause the recursion 
limit to be hit.  I'm still occasionally bitten by this in the IMAP 
client code...


HTH,

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


Re: Print file via file association using os.system or subprocess? (Windows)

2010-07-18 Thread Mark Hammond

On 19/07/2010 3:46 AM, pyt...@bdurham.com wrote:

Under Windows: Is there a way to print a file using the file's file
extension association using either the os.system or subprocess modules
(vs. win32 extensions)?
Use case: print PDF or Office documents to default printer without
having to distribute win32 extensions.
Thanks,
Malcolm


You probably want to use the windows ShellExec function with a 'print' verb.

Mark


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


Re: pre-uninstall script in bdist_wininst

2010-08-05 Thread Mark Hammond

On 6/08/2010 4:26 AM, Nils wrote:

Hi.
I am using a postinstall-script like this:
setup(
 ...
 scripts=['scripts\install.py'],
 options = {
 ...
 "bdist_wininst" : {
 "install_script" : "install.py",
 ...
 },
 }
)

According to the docs in [1] this script is
a) called after install (with the "-install" parameter) - this works
fine for me...
b) called before uninstall (with tho "-remove" parameter) - this
however does not work.


According to a comment in pywin32's post-install script:

elif arg == "-remove":
# bdist_msi calls us before uninstall, so we can undo what we
# previously did.  Sadly, bdist_wininst calls us *after*, so
# we can't do much at all.

So it seems possible your script is failing due to an import error as 
your module has already been removed.  Maybe a .msi would work better 
for you.



btw: With that I am trying to register a com-server on install and de-
register on uninstall - so if other ideas are around I'd love to hear
them, too...


I'd suggest using py2exe to package the object and inno installer or 
similar to handle the install and uninstall parts.


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


Re: Managing a multiple threaded service

2009-06-16 Thread Mark Hammond

On 17/06/2009 4:23 PM, Paul Hemans wrote:

Hi,
New to Python 
I've got 2 threads 1 is the SimpleHTTPRequestHandler, the other polls a site
for data. I want to run the program as a windows service.
My questions are:
Should both of them run as threads and then just have an infinite loop with
a sleep in the main thread in order to stop the main program from just
terminating?


No need for a loop - just have the main thread wait forever for the stop 
request.  The main problem I forsee is asking the socketserver thread to 
terminate as it is likely to be inside 'accept' or some other blocking 
function.


HTH,

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


Re: Windows 7 : any problems installing or running Python ?

2009-08-11 Thread Mark Hammond

On 9/08/2009 10:42 PM, Tim Roberts wrote:

Dave WB3DWE wrote:


Anybody tried it ?
Is anything broken, ie is the whole shootin' match good to go ?
I'm esp interested in WConio for 3.0/3.1 which I use heavily.


I've been running the 32-bit builds of Python 2.5, PyWin32, and wxPython on
Windows 7 64-bit for many months.  No problems at all.

I hated Vista; I would only run it if my clients insisted on having their
drivers tested on it.  Vista SP1 was somewhat better, but I don't mind
Windows 7 at all.  I might even upgrade my primary development machine from
XP.  A number of the usually cranky driver developers have expressed the
same opinion.  Microsoft might actually have a winner here.


"Me too" :)

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


Re: [Python-Dev] Mercurial migration: help needed

2009-08-18 Thread Mark Hammond

On 18/08/2009 6:20 PM, Dirkjan Ochtman wrote:

On Tue, Aug 18, 2009 at 10:12, "Martin v. Löwis"  wrote:

In this thread, I'd like to collect things that ought to be done
but where Dirkjan has indicated that he would prefer if somebody else
did it.


I think the most important item here is currently the win32text stuff.
Mark Hammond said he would work on this; Mark, when do you have time
for this? Then I could set apart some time for it as well.


I can make time, somewhat spasmodically, starting fairly soon.  Might I 
suggest that as a first task I can resurrect my old stale patch, and you 
can arrange to install win32text locally and start experimenting with 
how mixed line-endings can work for you.  Once we are all playing in the 
same ballpark I think we should be able to make good progress.


I-said-ballpark-yet-I-call-myself-an-aussie? ly,

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


Re: using python interpreters per thread in C++ program

2009-09-07 Thread Mark Hammond

On 7/09/2009 10:50 PM, MRAB wrote:

sturlamolden wrote:

On 7 Sep, 13:53, ganesh  wrote:


I need to use these to get the proper concurrency in my multi-threaded
application without any synchronization mechanisms.


Why will multiple interpreters give you better concurrency? You can
have more than one thread in the same interpreter.

Here is the API explained:

http://docs.python.org/c-api/init.html
http://www.linuxjournal.com/article/3641


CPython's GIL means that multithreading on multiple processors/cores has
limitations. Each interpreter has its own GIL, so processor-intensive
applications work better using the multiprocessing module than with the
threading module.


I believe you will find the above is incorrect - even with multiple 
interpreter states you still have a single GIL.


Mark

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


Re: using python interpreters per thread in C++ program

2009-09-07 Thread Mark Hammond

On 8/09/2009 9:16 AM, Grant Edwards wrote:

On 2009-09-07, Mark Hammond  wrote:


CPython's GIL means that multithreading on multiple
processors/cores has limitations. Each interpreter has its own
GIL, so processor-intensive applications work better using the
multiprocessing module than with the threading module.


I believe you will find the above is incorrect - even with
multiple interpreter states you still have a single GIL.


Please explain how multiple processes, each with a separate
Python interpreter, share a single GIL.



Sorry, my mistake, I misread the original - using multiple Python 
processes does indeed have a GIL per process.  I was referring to the 
'multiple interpreters in one process' feature of Python which is 
largely deprecated, but if used, all 'interpreters' share the same GIL.


To clarify: in a single process there will only ever be one GIL, but in 
multiple processes there most certainly will be multiple GILs.


Apologies for the confusion...

Cheers,

Mark

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


  1   2   >