From ferdinandsousa at gmail.com Sun Feb 1 15:25:22 2009 From: ferdinandsousa at gmail.com (Ferdinand Sousa) Date: Sun, 1 Feb 2009 14:25:22 +0000 Subject: [python-win32] Windows Service, user activity and timed message box Message-ID: Hi , first of all, thanks to Harald Armin Massa for the timed message box code (attached as text for reference). I'll tweak it to my requirements. Also, my thanks to Tim J Golden for his help. As regards the following: > B] How do we check duration since last user activity -- Assuming that the >> screen is set to turn off/display a screensaver after a certain duration, >> I >> wouldn't mind checking if this has indeed occurred (I know how to use >> win32gui .SystemParametersInfo to check if either >> of >> these has occurred). However, I would prefer to check the time elapsed >> since >> last user activity. >> > > I don't know that there's a function to do that for > the entire system. GetLastInputInfo will do it for your > own application, but you'd probably need to install some > system hooks and roll your own to get this at system level. > (And that sounds like overkill for what you're after). > > Perhaps a more precise description of your requirement would help? > I couldn't find the GetLastInputInfo function (pywin32 212, python 2.5.2 on Xp). What I'm putting together is a script that uses Adobe Acrobat COM. It opens a port and listens for connections on the LAN. When a pdf is sent to the port, my script opens it in Acrobat and performs some operations. If Acrobat is not currently open (checks for an open window with 1st 26 characters of title text =="Adobe Acrobat Professional"), the script opens Acrobat (in hidden mode, no visible window) performs the operations and closes it. If Acrobat is already open, a dialog asks for user's permission before continuing (because it is made invisible). It processes the file and closes it, and the user gets back control of Acrobat as it was, with all the files that were opened by the user as they were. The issue I want to handle is if Acrobat is open, but, say, the user is away from his desk. It just occurred to me, the timed message box and user activity solve the same problem (sometimes you're so keen on how-can-I-do-A-and-B that you don't realise that either of them solve the same issue :-) ). Guess it is overkill, just like you said, but I'm trying to learn as many new ways to do things as possible. Thanks very much, Ferdi -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- import threading, time, ctypes, ctypes.wintypes import win32con import Queue WM_CLOSE = 0x0010 MB_OK = 0 def find_messagebox(title, threadid, processid): hwnd = ctypes.windll.user32.FindWindowA(None, title) if hwnd: p = ctypes.wintypes.DWORD() t = ctypes.windll.user32.GetWindowThreadProcessId(hwnd, ctypes.byref(p)) if p.value == processid and t == threadid: return hwnd return 0 def closer(title, timeout, threadid, processid, abort): # give windows some time to create the message box time.sleep(0.1) hwnd = 0 while timeout > 0: if abort.isSet(): return if not hwnd: hwnd = find_messagebox(title, threadid, processid) if hwnd: ctypes.windll.user32.SetWindowTextA(hwnd, "%s - (%d Sekunden)" % (title, int(timeout))) wait = min(timeout, 1) time.sleep(wait) timeout -= wait if hwnd: ctypes.windll.user32.PostMessageA(hwnd, WM_CLOSE, 0, 0) def MessageBoxTimeout(hwnd, text, title, flags=MB_OK, timeout=30): class MBT(threading.Thread): def run(self): threadid = ctypes.windll.kernel32.GetCurrentThreadId() processid = ctypes.windll.kernel32.GetCurrentProcessId() abort = threading.Event() t = threading.Thread(target=closer, args = (title, timeout, threadid, processid, abort)) t.setDaemon(True) t.start() result = ctypes.windll.user32.MessageBoxA(hwnd, text, title, flags) abort.set() x=MBT() x.start() return x From mail at timgolden.me.uk Sun Feb 1 15:32:17 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 01 Feb 2009 14:32:17 +0000 Subject: [python-win32] Windows Service, user activity and timed message box In-Reply-To: References: Message-ID: <4985B271.5040908@timgolden.me.uk> Ferdinand Sousa wrote: > I couldn't find the GetLastInputInfo function (pywin32 212, python 2.5.2 on > Xp). That's because it's not there . You'd have to use ctypes or roll your own extension for that. > What I'm putting together is a script that uses Adobe Acrobat COM. It opens > a port and listens for connections on the LAN. When a pdf is sent to the > port, my script opens it in Acrobat and performs some operations. If Acrobat > is not currently open (checks for an open window with 1st 26 characters of > title text =="Adobe Acrobat Professional"), the script opens Acrobat (in > hidden mode, no visible window) performs the operations and closes it. If > Acrobat is already open, a dialog asks for user's permission before > continuing (because it is made invisible). It processes the file and closes > it, and the user gets back control of Acrobat as it was, with all the files > that were opened by the user as they were. The issue I want to handle is if > Acrobat is open, but, say, the user is away from his desk. That's a lot clearer; as you point out, sometimes being forced to explain one's own situation is enough to clarify certain things about to oneself. Which then helps one determine what to ask other people. If your users are going away and leaving their desktops unlocked then you're down to some sort of (over-the-top) hooks mechanism[*]. If, however, you're prepared to say: I'll skip the dialog box if the desktop's locked, then you can use this kind of technique which is a lot simpler: http://timgolden.me.uk/python/win32_how_do_i/see_if_my_workstation_is_locked.html TJG [*] And a security problem, methinks. From bgailer at gmail.com Mon Feb 2 00:21:18 2009 From: bgailer at gmail.com (bob gailer) Date: Sun, 01 Feb 2009 18:21:18 -0500 Subject: [python-win32] BUG? Edit -> Replace does not work in interactive window. Message-ID: <49862E6E.9020902@gmail.com> BUG? Edit -> Replace does not work in interactive window. -- Bob Gailer Chapel Hill NC 919-636-4239 From vernondcole at gmail.com Mon Feb 2 05:15:57 2009 From: vernondcole at gmail.com (Vernon Cole) Date: Sun, 1 Feb 2009 21:15:57 -0700 Subject: [python-win32] Pythonwin crashes everytime In-Reply-To: <1204b5030901300759t1ebbfaas9d448effa141dacd@mail.gmail.com> References: <1204b5030901300756ia2b7b6dmbe13c09e39637f12@mail.gmail.com> <1204b5030901300759t1ebbfaas9d448effa141dacd@mail.gmail.com> Message-ID: Are you using a Chinese character set by default? If so, you may be the second person to discover a bug which was described recently. I quote: I tracked down the source of the problem. > > I am using Windows XP, SP3. Two days ago I changed Control Panel, Regional > and Language Options, Advanced tab, "Select a language to match the language > version of the non-Unicode programs you want to use:" from "English (United > States)" to "Chinese (PRC)" to work with Python 2.6 and 3.0 Unicode scripts > dealing with Chinese characters at the console prompt. I was able to fix > the problem by returning the setting to English, and reproduce the problem > by setting it back to Chinese. It turns out typing any command that throws > an exception will crash PythonWin with this setting, and any valid command > hangs the interactive prompt. The fix for this is in test and should be included in the next version of pywin32 (very soon). -- Vernon On Fri, Jan 30, 2009 at 8:59 AM, David Xiao wrote: > Hi pythonwin users, > > Pythonwin crashes everytime when I simply type several lines of text > in it. What could be the reason? > vista, python 2.6.1, pywin32 build 212. > > BTW, i have tried on XP sp3, python 2.5.4, crashed as well! > > > BR, David > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From adit99 at gmail.com Tue Feb 3 00:51:11 2009 From: adit99 at gmail.com (Aditya Jayraman) Date: Mon, 2 Feb 2009 15:51:11 -0800 Subject: [python-win32] NTLM authentication using win32security and sspi Message-ID: Hi I am a newbie to pywin32 and windows programming. I am trying to achieve NTLM authentication using the win32security and sspi modules. Basically what I need to do is "verify the client's response to the server's challenge", like what a DC would do to complete the NTLM authentication between a client and a server. Any help is appreciated Thanks -- -Aditya -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Tue Feb 3 02:57:33 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 03 Feb 2009 12:57:33 +1100 Subject: [python-win32] NTLM authentication using win32security and sspi In-Reply-To: References: Message-ID: <4987A48D.8060006@gmail.com> On 3/02/2009 10:51 AM, Aditya Jayraman wrote: > > Hi > > I am a newbie to pywin32 and windows programming. > > I am trying to achieve NTLM authentication using the win32security and > sspi modules. > Basically what I need to do is "verify the client's response to the > server's challenge", like what a DC would do > to complete the NTLM authentication between a client and a server. I'm afraid it's not that simple - authentication is a multi-step process and needs to be done as the sspi samples do. The win32\Demos\security\sspi\socket_server.py sample should put you on the right track though - it implements a server that performs NTLM authentication with clients. Cheers, Mark From adit99 at gmail.com Tue Feb 3 03:04:58 2009 From: adit99 at gmail.com (Aditya Jayraman) Date: Mon, 2 Feb 2009 18:04:58 -0800 Subject: [python-win32] NTLM authentication using win32security and sspi In-Reply-To: <4987A48D.8060006@gmail.com> References: <4987A48D.8060006@gmail.com> Message-ID: Mark, Thanks for replying. I just found the examples just after posting the question. They are quite useful. Thanks Aditya On Mon, Feb 2, 2009 at 5:57 PM, Mark Hammond wrote: > On 3/02/2009 10:51 AM, Aditya Jayraman wrote: > >> >> Hi >> >> I am a newbie to pywin32 and windows programming. >> >> I am trying to achieve NTLM authentication using the win32security and >> sspi modules. >> Basically what I need to do is "verify the client's response to the >> server's challenge", like what a DC would do >> to complete the NTLM authentication between a client and a server. >> > > I'm afraid it's not that simple - authentication is a multi-step process > and needs to be done as the sspi samples do. The > win32\Demos\security\sspi\socket_server.py sample should put you on the > right track though - it implements a server that performs NTLM > authentication with clients. > > Cheers, > > Mark > -- -Aditya -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Feb 3 10:26:56 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 03 Feb 2009 09:26:56 +0000 Subject: [python-win32] Unexpected feature in win32security? Message-ID: <49880DE0.90904@timgolden.me.uk> I *think* this is a bug (or at least an unfortunate effect) but I'll post here first for a sanity check. I'm looking at Windows security: descriptors, ACLs, etc. The conventional wisdom is that a DACL (or an SACL but less commonly) can be one of three things within a security descriptor: 1) Not there 2) There but NULL 3) There and a (possibly empty) list of ACEs When calling the GetSecurityDescriptorDacl Win32 API, the first and second situations are distinguished by the lpbDaclPresent parameter which receives 0 or 1. From that result, the pDacl parameter is either meaningless or NULL/pointer to a list. Within the win32security module, the GetSecurityDescriptorDacl method of the PySECURITY_DESCRIPTOR object returns None in both of the first two cases and I can't see any other way to distinguish the cases without dropping down to ctypes or a hand-built extension. The offending code is in PySECURITY_DESCRIPTOR.cpp: // get Dacl from SD if (!::GetSecurityDescriptorDacl(psd, &bDaclPresent, &pdacl, &bDaclDefaulted)) return PyWin_SetAPIError("GetSecurityDescriptorDacl"); if (!bDaclPresent || pdacl == NULL) { Py_INCREF(Py_None); return Py_None; } return new PyACL(pdacl); which returns None, as you see, in either case. The equivalent code for SACL does the same thing. I've not got an easy workaround. In general, it's very unlikely that a DACL isn't present at all; and it's equally unlikely (I'm not sure it's even meaningful) to have a NULL SACL. So I can fudge around things a bit. But I'd prefer something more robust. However, it's difficult to see what change to suggest without breaking the interface. The only possibility I could come up with would be a separate pair of functions whose only job would be to report the presence of the ACL in the SD. Have I missed anything? TJG From rwupole at msn.com Tue Feb 3 12:34:26 2009 From: rwupole at msn.com (Roger Upole) Date: Tue, 3 Feb 2009 06:34:26 -0500 Subject: [python-win32] Unexpected feature in win32security? Message-ID: Tim Golden wrote: >I *think* this is a bug (or at least an unfortunate effect) > but I'll post here first for a sanity check. > > I'm looking at Windows security: descriptors, ACLs, etc. The > conventional wisdom is that a DACL (or an SACL but less commonly) > can be one of three things within a security descriptor: > > 1) Not there > 2) There but NULL > 3) There and a (possibly empty) list of ACEs > > When calling the GetSecurityDescriptorDacl Win32 API, the first > and second situations are distinguished by the lpbDaclPresent > parameter which receives 0 or 1. From that result, the pDacl > parameter is either meaningless or NULL/pointer to a list. > > Within the win32security module, the GetSecurityDescriptorDacl > method of the PySECURITY_DESCRIPTOR object returns None in > both of the first two cases and I can't see any other way to > distinguish the cases without dropping down to ctypes or a > hand-built extension. > In practice, cases 1 and 2 are functionally identical . Once a security descriptor has been applied to an object, the SE_DACL_PRESENT flag is always set. If for some reason you really need this info, you can call GetSecurityDescriptorControl and check for presence of the SE_DACL_PRESENT flag. > The offending code is in PySECURITY_DESCRIPTOR.cpp: > > > // get Dacl from SD > if (!::GetSecurityDescriptorDacl(psd, &bDaclPresent, &pdacl, > &bDaclDefaulted)) > return PyWin_SetAPIError("GetSecurityDescriptorDacl"); > > if (!bDaclPresent || pdacl == NULL) > { > Py_INCREF(Py_None); > return Py_None; > } > > return new PyACL(pdacl); > > > > which returns None, as you see, in either case. The equivalent code > for SACL does the same thing. > > > I've not got an easy workaround. In general, it's very unlikely that > a DACL isn't present at all; and it's equally unlikely (I'm not sure > it's even meaningful) to have a NULL SACL. So I can fudge around things > a bit. But I'd prefer something more robust. However, it's difficult to > see what change to suggest without breaking the interface. The only > possibility I could come up with would be a separate pair of functions > whose only job would be to report the presence of the ACL in the SD. > Have I missed anything? > It's quite common for either of these to be NULL. Most often files don't specify their own security, and just inherit from the parent directory. SACL's are often NULL also, although they don't show a difference in behaviour between NULL and empty as DACL's do. Roger From mail at timgolden.me.uk Tue Feb 3 12:54:14 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 03 Feb 2009 11:54:14 +0000 Subject: [python-win32] Unexpected feature in win32security? In-Reply-To: References: Message-ID: <49883066.5090805@timgolden.me.uk> Roger Upole wrote: Thanks very much for responding to this, Roger. >> 1) Not there >> 2) There but NULL >> 3) There and a (possibly empty) list of ACEs > In practice, cases 1 and 2 are functionally identical . Once a security > descriptor has > been applied to an object, the SE_DACL_PRESENT flag is always set. If for > some reason you really need this info, you can call > GetSecurityDescriptorControl > and check for presence of the SE_DACL_PRESENT flag. That's the key bit I missed. My use case is a bit abstruse, as I'm writing some wrapper code to allow slightly easier access to the security stuff and my unit tests are failing. Therefore what I'm doing is a bit artificial but (to me) necessary :) > It's quite common for either of these to be NULL. > Most often files don't specify their own security, and just inherit from > the parent directory. That's clearly the case, but I thought that this meant that their DACL was an effective copy of the parent DACL, not a NULL, eg the following code gives me a PyACL object, not None: from win32security import * # # Create file with no special security, effectively # inheriting from its parent # open ("c:/temp/blah.txt", "w").close () sd = GetNamedSecurityInfo ( "c:/temp/blah.txt", SE_FILE_OBJECT, DACL_SECURITY_INFORMATION ) print sd.GetSecurityDescriptorDacl () Despite my question here, I don't recall ever actually coming across a NULL DACL on a file -- which is where most of my activity is -- but they may be more common on kernel objects or registry keys or whatever. > SACL's are often NULL also, although they > don't show a difference in behaviour between NULL and empty as > DACL's do. That I can believe; it's only, as I say, for testing reasons that I necessarily care. In any case, your pointer to the descriptor control has effectively answered my main question, so thanks very much. TJG From adit99 at gmail.com Wed Feb 4 02:46:38 2009 From: adit99 at gmail.com (Aditya Jayraman) Date: Tue, 3 Feb 2009 17:46:38 -0800 Subject: [python-win32] Kerberos Authentication Message-ID: I am trying to create server that needs to authenticate clients using Kerberos. Assuming the clients are presenting a Kerberos Service Ticket to the Server, I need a way to: 1. Unpack the ticket 2. Decrypt the encrypted part and recover the Session Key. (Assuming I have have access to my Server's Master Key) I was wondering if there any way I can achieve this using pywin32 The sspi module is helpful, but does not help me in case the client is not a Windows Machine. For instance, Linux clients "separately" acquiring a Service Ticket and then presenting it to my server. Any help is appreciated. Thanks -- -Aditya -------------- next part -------------- An HTML attachment was scrubbed... URL: From mc at mclaveau.com Wed Feb 4 15:18:56 2009 From: mc at mclaveau.com (Michel Claveau) Date: Wed, 4 Feb 2009 15:18:56 +0100 Subject: [python-win32] cmp oleobj & instance with Python 2.6.1 et pywin32 Message-ID: <9BE2BB57F4C34863B9D55F6D7ED8B032@MCI1330> Hi! (sorry for my "bizzaroid" english) I have a script who use DOM objects (COM-subobjects from win32com.client.Dispatch('InternetExplorer.Application'). These objects are in instances properties. And, I compare with other instances/python_objects. e.g. a line like : if form.conteneurcourant != containeur: With Python 2.5, it's OK. With Python 2.6.1 (who run with the genious Mark Hammond's python26.dll), I have an error, if one of the two variables are not a COM object. The traceback : Traceback (most recent call last): File "C:\Ponx\pluie\ex05-image.py", line 126, in utilisefiche() File "C:\Ponx\pluie\ex05-image.py", line 40, in utilisefiche image = fiche.element('IMG',cadre) File "C:\Ponx\pluie\pluie.py", line 293, in __init__ if form.conteneurcourant != containeur: File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 205, in __cmp__ return cmp(self._oleobj_, other) TypeError: The Python instance can not be converted to a COM object I solved the problem, by replace != by not(...is...) ; then, it's OK for me. But, I think than the error in cmp can affect others scripts developers. It's for that what I publish this message. @-salutations -- Michel Claveau From snowman7186 at hotmail.com Wed Feb 4 17:55:37 2009 From: snowman7186 at hotmail.com (=?ISO-8859-1?Q?Dave_Pich=E9?=) Date: Wed, 04 Feb 2009 11:55:37 -0500 Subject: [python-win32] Visio.SaveAsWebObject problem Message-ID: Sorry for my bad english, I am trying to write a script to make automatic conversion of Microsoft Visio documents to html. I want to do it by using COM objects. When I try to create an instance of "SaveAsWeb.VisSaveAsWeb" object I got this error: >>> import win32com.client >>> win32com.client.Dispatch("SaveAsWeb.VisSaveAsWeb") Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch com_error: (-2147024770, 'The specified module could not be found.', None, None) >>> However, I am able to create instance of the "Visio.Application" object but when I try to use is "SaveAsWebObject" property I get a generic COM Object that seem useless. Thanks in advance, Dave From adit99 at gmail.com Wed Feb 4 19:09:09 2009 From: adit99 at gmail.com (Aditya Jayraman) Date: Wed, 4 Feb 2009 10:09:09 -0800 Subject: [python-win32] Kerberos Authentication In-Reply-To: References: Message-ID: In other words, Im asking if there is any module that will help with encoding/decoding SPNEGO Tokens (aka security blobs) Thanks, Aditya On Tue, Feb 3, 2009 at 5:46 PM, Aditya Jayraman wrote: > I am trying to create server that needs to authenticate clients using > Kerberos. > > Assuming the clients are presenting a Kerberos Service Ticket to the > Server, I need a way to: > 1. Unpack the ticket > 2. Decrypt the encrypted part and recover the Session Key. (Assuming I have > have access to my Server's Master Key) > > I was wondering if there any way I can achieve this using pywin32 > > The sspi module is helpful, but does not help me in case the client is not > a Windows Machine. > For instance, Linux clients "separately" acquiring a Service Ticket and > then presenting it to my server. > > Any help is appreciated. > > Thanks > -- > -Aditya > -- -Aditya -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Wed Feb 4 19:10:35 2009 From: vernondcole at gmail.com (Vernon Cole) Date: Wed, 4 Feb 2009 11:10:35 -0700 Subject: [python-win32] [pywin32-checkins] py3k status In-Reply-To: <017501c98681$972a8860$c57f9920$@com.au> References: <01bc01c946aa$fc846710$f58d3530$@com.au> <679924.94924.qm@web36201.mail.mud.yahoo.com> <00e501c9845b$1343a360$39caea20$@com.au> <017501c98681$972a8860$c57f9920$@com.au> Message-ID: Okay, group, I'm opening this up for discussion... Is my routine wrong, or is the test flawed? This test works fine at my house, U.S. Mountain Standard Time. When I change my Windows time zone to Brisbane, it fails here like it does for Mark. The test is: def testDateObjectFromCOMDate(self): cmd=self.tc.DateObjectFromCOMDate(37435.7604282) t1=time.gmtime(time.mktime((2002,6,28,12,14,1, 4,31+28+31+30+31+28,-1))) t2=time.gmtime(time.mktime((2002,6,28,12,16,1, 4,31+28+31+30+31+28,-1))) assert t1 The code under test is: > def DateObjectFromCOMDate(self,comDate): > 'Returns ticks since 1970' > if isinstance(comDate,datetime.datetime): > return comDate.timetuple() > elif isinstance(comDate,DateTime): > fcomDate = comDate.ToOADate() > else: > fcomDate = float(comDate) > secondsperday=86400 # 24*60*60 > #ComDate is number of days since 1899-12-31, gmtime epoch is > 1970-1-1 = 25569 days > t=time.gmtime(secondsperday*(fcomDate-25569.0)) > return t > #year,month,day,hour,minute,second,weekday,julianday,daylightsaving=t > I don't want to re-invent the wheel here. Does one of you gurus have better code? -- Vernon On Tue, Feb 3, 2009 at 9:32 PM, Mark Hammond wrote: > Thanks Vernon, > > I seem to be having issues with 2.x which I can't put down to the pywin32 > changes - the failures relate to use of the time module. > > > > Default Date Converter is 0x0294B530> > > ...............F................................. > > ====================================================================== > > FAIL: testDateObjectFromCOMDate (__main__.TestPythonTimeConverter) > > ---------------------------------------------------------------------- > > Traceback (most recent call last): > > File "adodbapitest.py", line 671, in testDateObjectFromCOMDate > > assert t1 > AssertionError: "time.struct_time(tm_year=2002, tm_mon=6, tm_mday=28, > tm_hour=18, tm_min=15, tm_sec=0, tm_wday=4, tm_yday=179, tm_isdst=0)" should > be about 2002-6-28 12:15:01 > > > > ---------------------------------------------------------------------- > > Ran 49 tests in 1.281s > > > > FAILED (failures=1) > > Changed dateconverter to > > > > ...............F................................. > > ====================================================================== > > FAIL: testDateObjectFromCOMDate (__main__.TestPythonTimeConverter) > > ---------------------------------------------------------------------- > > Traceback (most recent call last): > > File "adodbapitest.py", line 671, in testDateObjectFromCOMDate > > assert t1 > AssertionError: "time.struct_time(tm_year=2002, tm_mon=6, tm_mday=28, > tm_hour=18, tm_min=15, tm_sec=0, tm_wday=4, tm_yday=179, tm_isdst=0)" should > be about 2002-6-28 12:15:01 > > > > ---------------------------------------------------------------------- > > > > I suspect it is timezone related: FYI: > > > > >>> import adodbapi > > >>> tc=adodbapi.pythonTimeConverter() > > >>> tc.DateObjectFromCOMDate(37435.7604282) > > time.struct_time(tm_year=2002, tm_mon=6, tm_mday=28, tm_hour=18, tm_min=15, > tm_sec=0, tm_wday=4, tm_yday=179, tm_isdst=0) > > >>> time.gmtime(time.mktime(_)) > > time.struct_time(tm_year=2002, tm_mon=6, tm_mday=28, tm_hour=8, tm_min=15, > tm_sec=0, tm_wday=4, tm_yday=179, tm_isdst=0) > > > > If you get the same result as me in that last line I think the fix should > be easy? > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From z_m at volny.cz Wed Feb 4 23:40:36 2009 From: z_m at volny.cz (Zdenek Mejzlik) Date: Wed, 04 Feb 2009 23:40:36 +0100 Subject: [python-win32] EOFError in gencache.py Message-ID: <498A1964.2010606@volny.cz> Hello, My script running on Windows XP Professional SP2 is sometimes hit with the following problem. I use Python 2.5.1.1 (from ActiveState) and Python 2.5 pywin32-210. The script uses the Sensormatic's Intellex API consisting of COM components. PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on win32. Portions Copyright 1994-2006 Mark Hammond - see 'Help/About PythonWin' for further copyright information. Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\altworx_core\api_servers\intellex_configuration\read_intellex_status.py", line 6, in import pythoncom, win32com.client File "c:\python25\lib\site-packages\win32com\client\__init__.py", line 12, in import dynamic, gencache, pythoncom File "c:\python25\lib\site-packages\win32com\client\gencache.py", line 662, in __init__() File "c:\python25\lib\site-packages\win32com\client\gencache.py", line 54, in __init__ _LoadDicts() File "c:\python25\lib\site-packages\win32com\client\gencache.py", line 109, in _LoadDicts version = p.load() EOFError If I uninstall both pywin and Python and install them again the problem disappears. But it is only temporary solution the problem returns back after several days. Please, help me to find the definitive solution. Thanks Zdenek Mejzlik. From blade.eric at gmail.com Thu Feb 5 06:00:21 2009 From: blade.eric at gmail.com (Eric Blade) Date: Thu, 5 Feb 2009 00:00:21 -0500 Subject: [python-win32] win32file.ReadDirectoryChangesW in asynch mode? Message-ID: <59ce684e0902042100h55ca0d64o51918357bbf33943@mail.gmail.com> It appears that sometime in the last year, year and a half or so, someone made the necessary changes to win32file to get ReadDirectoryChangesW up and working in Asynch mode, which is something that I would find very nice to be able to use right now .. however, the docs are making my head swim. Anyone know of an example of this somewhere, or at least a link that actually explains it? Thanks much! -- Cheers, - Eric From skippy.hammond at gmail.com Thu Feb 5 06:34:49 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 05 Feb 2009 16:34:49 +1100 Subject: [python-win32] cmp oleobj & instance with Python 2.6.1 et pywin32 In-Reply-To: <9BE2BB57F4C34863B9D55F6D7ED8B032@MCI1330> References: <9BE2BB57F4C34863B9D55F6D7ED8B032@MCI1330> Message-ID: <498A7A79.1030303@gmail.com> On 5/02/2009 1:18 AM, Michel Claveau wrote: > return cmp(self._oleobj_, other) > TypeError: The Python instance can not be converted to a COM object > > > I solved the problem, by replace != by not(...is...) ; then, it's OK for > me. > > > But, I think than the error in cmp can affect others scripts developers. > It's for that what I publish this message. Yes, thanks for the report, but I already found that myself 2 days ago and have checked in a fix. It was related to the new rich-comparison work for py3k. If this is blocking you please let me know and I'll update a new build (although I'm very close to a *real* build...) Cheers, Mark From skippy.hammond at gmail.com Thu Feb 5 06:39:37 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 05 Feb 2009 16:39:37 +1100 Subject: [python-win32] win32file.ReadDirectoryChangesW in asynch mode? In-Reply-To: <59ce684e0902042100h55ca0d64o51918357bbf33943@mail.gmail.com> References: <59ce684e0902042100h55ca0d64o51918357bbf33943@mail.gmail.com> Message-ID: <498A7B99.90606@gmail.com> On 5/02/2009 4:00 PM, Eric Blade wrote: > It appears that sometime in the last year, year and a half or so, > someone made the necessary changes to win32file to get > ReadDirectoryChangesW up and working in Asynch mode, which is > something that I would find very nice to be able to use right now .. > however, the docs are making my head swim. > > Anyone know of an example of this somewhere, or at least a link that > actually explains it? > > Thanks much! There is some "real" code at http://bazaar.launchpad.net/~tortoisebzr-developers/tortoisebzr/trunk/annotate/head%3A/tbzrlib/watcher/win32watcher.py - so although its not as clear as a "sample" or "demo" would be (eg, it only watches paths for a fairly short period of time, etc), you should be able to get the idea... Cheers, Mark From skippy.hammond at gmail.com Thu Feb 5 06:48:21 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 05 Feb 2009 16:48:21 +1100 Subject: [python-win32] EOFError in gencache.py In-Reply-To: <498A1964.2010606@volny.cz> References: <498A1964.2010606@volny.cz> Message-ID: <498A7DA5.5040007@gmail.com> On 5/02/2009 9:40 AM, Zdenek Mejzlik wrote: > File "c:\python25\lib\site-packages\win32com\client\gencache.py", line > 109, in _LoadDicts > version = p.load() > EOFError This is an error loading 'dicts.dat' from the win32com\gen_py directory. The management of this file is very crude and doesn't protect against threads or processes stomping on other. Does you app create COM objects on different threads, or are there multiple instances of your app starting at the same time? If so, we might like to instrument the code to see if this indeed the problem. > If I uninstall both pywin and Python and install them again the problem > disappears. But it is only temporary > solution the problem returns back after several days. Please, help me to > find the definitive solution. A quicker workaround should be to remove dicts.dat, or indeed, the contents of the entire gen_py directory (but don't remove the directory itself, or makepy will assume it can't write to win32com and use a gen_py under %TEMP%.) Cheers, Mark From blade.eric at gmail.com Thu Feb 5 06:58:45 2009 From: blade.eric at gmail.com (Eric Blade) Date: Thu, 5 Feb 2009 00:58:45 -0500 Subject: [python-win32] win32file.ReadDirectoryChangesW in asynch mode? In-Reply-To: <498A7B99.90606@gmail.com> References: <59ce684e0902042100h55ca0d64o51918357bbf33943@mail.gmail.com> <498A7B99.90606@gmail.com> Message-ID: <59ce684e0902042158r165f5178r980f70afb3b26de@mail.gmail.com> Thanks, Mark. That's a lot more complex than what I need to implement, and it'll take some time to digest, but even so, it's way better than the docs that look like someone updated them a bit at a time. On Thu, Feb 5, 2009 at 12:39 AM, Mark Hammond wrote: > On 5/02/2009 4:00 PM, Eric Blade wrote: >> >> It appears that sometime in the last year, year and a half or so, >> someone made the necessary changes to win32file to get >> ReadDirectoryChangesW up and working in Asynch mode, which is >> something that I would find very nice to be able to use right now .. >> however, the docs are making my head swim. >> >> Anyone know of an example of this somewhere, or at least a link that >> actually explains it? >> >> Thanks much! > > There is some "real" code at > http://bazaar.launchpad.net/~tortoisebzr-developers/tortoisebzr/trunk/annotate/head%3A/tbzrlib/watcher/win32watcher.py > - so although its not as clear as a "sample" or "demo" would be (eg, it only > watches paths for a fairly short period of time, etc), you should be able to > get the idea... > > Cheers, > > Mark > -- Cheers, - Eric From mhammond at skippinet.com.au Thu Feb 5 07:12:31 2009 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 5 Feb 2009 17:12:31 +1100 Subject: [python-win32] win32file.ReadDirectoryChangesW in asynch mode? In-Reply-To: <59ce684e0902042158r165f5178r980f70afb3b26de@mail.gmail.com> References: <59ce684e0902042100h55ca0d64o51918357bbf33943@mail.gmail.com> <498A7B99.90606@gmail.com> <59ce684e0902042158r165f5178r980f70afb3b26de@mail.gmail.com> Message-ID: <01c701c98758$bd1f59b0$375e0d10$@com.au> > Thanks, Mark. That's a lot more complex than what I need to > implement, and it'll take some time to digest, but even so, it's way > better than the docs that look like someone updated them a bit at a > time. Actually, win32\test\test_win32file.py's example might be simpler to digest - if you look in that file you will notice the asynch version is the only test enabled for reasons vaguely mentioned in that file... Mark From mc at mclaveau.com Thu Feb 5 08:33:30 2009 From: mc at mclaveau.com (Michel Claveau) Date: Thu, 5 Feb 2009 08:33:30 +0100 Subject: [python-win32] cmp oleobj & instance with Python 2.6.1 et pywin32 In-Reply-To: <498A7A79.1030303@gmail.com> References: <9BE2BB57F4C34863B9D55F6D7ED8B032@MCI1330> <498A7A79.1030303@gmail.com> Message-ID: <2CFB4CB9D80F4951B13C41F516504474@MCI1330> Hi! >> return cmp(self._oleobj_, other) >> TypeError: The Python instance can not be converted to a COM object > Yes, thanks for the report, but I already found that myself 2 days ago and > have checked in a fix. It was related to the new rich-comparison work for > py3k. If this is blocking you please let me know and I'll update a new > build (although I'm very close to a *real* build...) Thanks for your answer. It is OK for me. I can wait. I have found a (temporary) solution. I prefer that you keep your normal working rhythm. And, I am sorry to have disturbed this rhythm. @-salutations -- Michel Claveau From skippy.hammond at gmail.com Thu Feb 5 08:39:14 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 05 Feb 2009 18:39:14 +1100 Subject: [python-win32] cmp oleobj & instance with Python 2.6.1 et pywin32 In-Reply-To: <2CFB4CB9D80F4951B13C41F516504474@MCI1330> References: <9BE2BB57F4C34863B9D55F6D7ED8B032@MCI1330> <498A7A79.1030303@gmail.com> <2CFB4CB9D80F4951B13C41F516504474@MCI1330> Message-ID: <498A97A2.8010306@gmail.com> On 5/02/2009 6:33 PM, Michel Claveau wrote: > And, I am sorry to have > disturbed this rhythm. Not at all - I put these builds up exactly for this reason - it was just luck that I stumbled across the issue first (surprisingly, the test suite never actually tested a com object against None and I found the issue "accidentally"...) Cheers, Mark From mail at timgolden.me.uk Thu Feb 5 09:48:35 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 05 Feb 2009 08:48:35 +0000 Subject: [python-win32] win32file.ReadDirectoryChangesW in asynch mode? In-Reply-To: <59ce684e0902042100h55ca0d64o51918357bbf33943@mail.gmail.com> References: <59ce684e0902042100h55ca0d64o51918357bbf33943@mail.gmail.com> Message-ID: <498AA7E3.2030404@timgolden.me.uk> Eric Blade wrote: > It appears that sometime in the last year, year and a half or so, > someone made the necessary changes to win32file to get > ReadDirectoryChangesW up and working in Asynch mode, which is > something that I would find very nice to be able to use right now .. > however, the docs are making my head swim. I've got an example here, but I've had problems running it between a Vista client and a win2k3 server; your mileage may vary. http://winsys.googlecode.com/svn/branches/it-support/winsys/fs.py (Look for "class _DirWatcher" and the code below it) TJG From skippy.hammond at gmail.com Thu Feb 5 13:14:14 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 05 Feb 2009 23:14:14 +1100 Subject: [python-win32] [pywin32-checkins] py3k status In-Reply-To: References: <01bc01c946aa$fc846710$f58d3530$@com.au> <679924.94924.qm@web36201.mail.mud.yahoo.com> <00e501c9845b$1343a360$39caea20$@com.au> <017501c98681$972a8860$c57f9920$@com.au> Message-ID: <498AD816.6050701@gmail.com> On 5/02/2009 5:10 AM, Vernon Cole wrote: > Okay, group, I'm opening this up for discussion... > > Is my routine wrong, or is the test flawed? > > This test works fine at my house, U.S. Mountain Standard Time. > When I change my Windows time zone to Brisbane, it fails here like it > does for Mark. I'm starting to think the Python time module is as badly broken as pywin32's time object :) This blog entry has some insight and I expect Windows works exactly the same as described for Linux (ie, incorrectly in the southern hemisphere). I expect win32timezone will be able to help, but I'm out of time for now... http://blogs.gnome.org/jamesh/2006/12/31/python-timetimezone-timealtzone-edge-case/ Cheers, Mark From vernondcole at gmail.com Thu Feb 5 17:50:55 2009 From: vernondcole at gmail.com (Vernon Cole) Date: Thu, 5 Feb 2009 09:50:55 -0700 Subject: [python-win32] [pywin32-checkins] py3k status In-Reply-To: <498AD816.6050701@gmail.com> References: <01bc01c946aa$fc846710$f58d3530$@com.au> <679924.94924.qm@web36201.mail.mud.yahoo.com> <00e501c9845b$1343a360$39caea20$@com.au> <017501c98681$972a8860$c57f9920$@com.au> <498AD816.6050701@gmail.com> Message-ID: Okay, I will proceed using the hypothesis that the problem is in the python time module and not in adodbapi, and that a fix is unimportant. The workaround is simple: do nothing! Adodbapi will use datetime.datetime by default. Only if you explicitly ask it to switch over to the old python time format will it actually use this convertion, so only antipodeans actually asking to use the obsolete time encoding are affected. I will note this as a restriction and check in the code without attempting to fix this problem at this time. Later I'll find a fix to do this convertion without calling time.gmtime(). Intrestingly, this was also a problem in IronPython. I had to file two separate bug reports to get time.gmtime working there. -- Vernon On Thu, Feb 5, 2009 at 5:14 AM, Mark Hammond wrote: > On 5/02/2009 5:10 AM, Vernon Cole wrote: > >> Okay, group, I'm opening this up for discussion... >> >> Is my routine wrong, or is the test flawed? >> >> This test works fine at my house, U.S. Mountain Standard Time. >> When I change my Windows time zone to Brisbane, it fails here like it >> does for Mark. >> > > > I'm starting to think the Python time module is as badly broken as > pywin32's time object :) This blog entry has some insight and I expect > Windows works exactly the same as described for Linux (ie, incorrectly in > the southern hemisphere). I expect win32timezone will be able to help, but > I'm out of time for now... > > > http://blogs.gnome.org/jamesh/2006/12/31/python-timetimezone-timealtzone-edge-case/ > > Cheers, > > Mark > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Fri Feb 6 02:15:46 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 06 Feb 2009 12:15:46 +1100 Subject: [python-win32] GetWindowsVersion on Longhorn In-Reply-To: <249A89BAA060C94FA0B93EA6135CC93C06D7189D@xmb-rtp-20b.amer.cisco.com> References: <249A89BAA060C94FA0B93EA6135CC93C06D7189D@xmb-rtp-20b.amer.cisco.com> Message-ID: <498B8F42.6060009@gmail.com> On 23/01/2009 11:40 AM, Matt Herbert (matherbe) wrote: > Hey all, > > Just wondering if there is a way to differentiate Windows Server 2008 > from Windows Vista? All the normal methods I would use aren't cutting > it. For instance, sys.getwindowsversion() and platform.uname() are > returning exactly the same thing for Vista and Windows 2008. This was a while ago now, but I also just needed to determine this information. If you ask win32api to give you an OSVERSIONINFOEX tuple, you can get the 'wProductType' field. eg, on Vista: >>> win32api.GetVersionEx(1) (6, 0, 6001, 2, 'Service Pack 1', 1, 0, 256, 1, 30) on 2008: (6, 0, 6001, 2, 'Service Pack 1', 1, 0, 274, 2, 30) The 2nd-last item is wProductType and defined as: VER_NT_DOMAIN_CONTROLLER=0x0000002 VER_NT_SERVER=0x0000003 VER_NT_WORKSTATION=0x0000001 Vista reports itself as a 'workstation', where 2008 will report itself as a server or a DC (and I did indeed run the above test on a 2008 DC) For-the-archives ly, Mark From mc at mclaveau.com Fri Feb 6 14:11:46 2009 From: mc at mclaveau.com (Michel Claveau) Date: Fri, 6 Feb 2009 14:11:46 +0100 Subject: [python-win32] GetWindowsVersion on Longhorn In-Reply-To: <498B8F42.6060009@gmail.com> References: <249A89BAA060C94FA0B93EA6135CC93C06D7189D@xmb-rtp-20b.amer.cisco.com> <498B8F42.6060009@gmail.com> Message-ID: <1C4A71E65E2B4751BBD910A6705BB236@MCI1330> Hi! >>> win32api.GetVersionEx(1) >>>(6, 0, 6001, 2, 'Service Pack 1', 1, 0, 256, 1, 30) >>> >>> on 2008: >>> (6, 0, 6001, 2, 'Service Pack 1', 1, 0, 274, 2, 30) And, on Seven (for collectors): print win32api.GetVersionEx(1) > (6, 1, 7000, 2, '', 0, 0, 256, 1, 0) @-salutations -- Michel Claveau From siddhartha.veedaluru at gmail.com Fri Feb 6 17:58:28 2009 From: siddhartha.veedaluru at gmail.com (siddhartha veedaluru) Date: Fri, 6 Feb 2009 22:28:28 +0530 Subject: [python-win32] Unable to connect to MSSQL Database(x64) using pyodbc 32bit & python 32bit Message-ID: <424b71ec0902060858k2cd19923ye0a25a4336dd0e82@mail.gmail.com> Hi all, I trying to connect to MSSQl 2005 Database which is on a x64 bit machine. i have installed 32bit python2.5 and pyodbc.pywin32-211 i have created a odbc DSN. When i'm using this DSN in the script it errors out saying ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0)') Here is my script import pyodbc,sys,os conString = "DSN=int2003r2-64bit;UID=sa;PWD=kbuilder" try: con = pyodbc.connect(conString) except pyodbc.Error, erno: mesg = "Error:Unable to establish connection to Database" print mesg print erno sys.exit(1) cur = con.cursor() query = "select id from CLIENT where name = 'int2003r2-64bit'" try: cur.execute(query) except pyodbc.Error, erno: mesg = "Unable to execute %s query" % query print mesg sys.exit(1) for row in cur: clientId = row[0] Please Help. Thanks Sid -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Fri Feb 6 18:22:30 2009 From: vernondcole at gmail.com (Vernon Cole) Date: Fri, 6 Feb 2009 10:22:30 -0700 Subject: [python-win32] Unable to connect to MSSQL Database(x64) using pyodbc 32bit & python 32bit In-Reply-To: <424b71ec0902060858k2cd19923ye0a25a4336dd0e82@mail.gmail.com> References: <424b71ec0902060858k2cd19923ye0a25a4336dd0e82@mail.gmail.com> Message-ID: Siddhartha: This seems to be a pyodbc question, and would be best answered on their discussion group. Try http://groups.google.com/group/pyodbc The SQL dbapi interfaces which ship with pywin32 are odbc and adodbapi. Nevertheless, your very long DSN string gives me pause. You might try going back in to your Control Panel->Administrative Tools->Data Sources (ODBC) and define a simpler DSN. The one I use most often is "Test". Make sure the administration tool can access your database by using its built in "test" button. -- Vernon On Fri, Feb 6, 2009 at 9:58 AM, siddhartha veedaluru < siddhartha.veedaluru at gmail.com> wrote: > Hi all, > > I trying to connect to MSSQl 2005 Database which is on a x64 bit machine. > i have installed 32bit python2.5 and pyodbc.pywin32-211 > i have created a odbc DSN. > When i'm using this DSN in the script it errors out saying > ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not > found and no default driver specified (0)') > > Here is my script > import pyodbc,sys,os > conString = "DSN=int2003r2-64bit;UID=sa;PWD=kbuilder" > try: > con = pyodbc.connect(conString) > except pyodbc.Error, erno: > mesg = "Error:Unable to establish connection to Database" > print mesg > print erno > sys.exit(1) > cur = con.cursor() > query = "select id from CLIENT where name = 'int2003r2-64bit'" > try: > cur.execute(query) > except pyodbc.Error, erno: > mesg = "Unable to execute %s query" % query > print mesg > sys.exit(1) > for row in cur: > clientId = row[0] > > Please Help. > Thanks > Sid > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jworld789 at yahoo.com Fri Feb 6 20:13:41 2009 From: jworld789 at yahoo.com (Jason Hilton) Date: Fri, 6 Feb 2009 11:13:41 -0800 (PST) Subject: [python-win32] LVM_GETITEMPOSITION Message-ID: <338803.69307.qm@web51709.mail.re2.yahoo.com> Okay, so I am new to python win32 development and I am trying to find the location of icons on the desktop. I understand that the desktop is just a listview control so theoretically I should be able to use this code- from commctrl import * from win32gui import * from ctypes import * class POINT(Structure): ???? _fields_=[('x',c_long),('y',c_long)] desk=1435653??? # Handle to the desktop. I just made this up for the example here. SendMessage(desk,LVM_GETITEMPOSITION,0,POINT()) I think this is supposed to return the point that the icon in index 0 is located at, but when I try to use this, explorer crashes. I have researched this online and found similar predicaments that other people have had where explorer crashed using GETITEMPOSITION, but those examples are in other programming languages that I can't read and don't understand, and I haven't found any examples in Python on how to overcome this problem, if indeed it is possible. Any help? -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Feb 6 21:55:34 2009 From: timr at probo.com (Tim Roberts) Date: Fri, 06 Feb 2009 12:55:34 -0800 Subject: [python-win32] LVM_GETITEMPOSITION In-Reply-To: <338803.69307.qm@web51709.mail.re2.yahoo.com> References: <338803.69307.qm@web51709.mail.re2.yahoo.com> Message-ID: <498CA3C6.5080605@probo.com> Jason Hilton wrote: > Okay, so I am new to python win32 development and I am trying to find > the location of icons on the desktop. I understand that the desktop is > just a listview control so theoretically I should be able to use this > code- > > from commctrl import * > from win32gui import * > from ctypes import * > > class POINT(Structure): > _fields_=[('x',c_long),('y',c_long)] > > desk=1435653 # Handle to the desktop. I just made this up for the > example here. > > SendMessage(desk,LVM_GETITEMPOSITION,0,POINT()) > > I think this is supposed to return the point that the icon in index 0 > is located at, but when I try to use this, explorer crashes. I have > researched this online and found similar predicaments that other > people have had where explorer crashed using GETITEMPOSITION, but > those examples are in other programming languages that I can't read > and don't understand, and I haven't found any examples in Python on > how to overcome this problem, if indeed it is possible. > > I assume you are getting the desktop list view handle by doing something like this: h1 = FindWindow( "progman", None ) h2 = FindWindowEx( h1, 0, "SHELLDLL_DefView", None ) h3 = FindWindowEx( h2, 0, "syslistview32", None ) There are several problems in front of you, one minor, one major. The minor problem is that the last parameter to LVM_GETITEMPOSITION needs to be a pointer to a POINT structure. In order to get information back, you'd need to pass a pointer to an existing object. pt = POINT() SendMessage( h3, LVM_GETITEMPOSITION, 0, pointer(pt) ) However, there is a much more difficult problem to solve. Remember that the desktop window is owned by a different process, and its window procedure is part of that process. With one specific exception, you can't pass pointers in a SendMessage or PostMessage call that is going to a different process. When the list view within Explorer gets your message, it thinks the address in the message is an address within its own process. It's going to overwrite some random data within Explorer. Your structure won't be touched, because Explorer can't write into your process. The solution to this is a very tricky piece of code that actually allocates a piece of memory in Explorer's process, then uses WriteProcessMemory and ReadProcessMemory to copy the data in and out. Here's the code in VB, but it's very easy to screw this up with disastrous results: http://www.vbforums.com/archive/index.php/t-546207.html -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From chaim at chaim.com Sat Feb 7 04:05:57 2009 From: chaim at chaim.com (Chaim Krause) Date: Fri, 06 Feb 2009 21:05:57 -0600 Subject: [python-win32] Looking for python-win32 version of EasyGUI Message-ID: <498CFA95.9010603@chaim.com> I have an very small application that uses a single multichoicebox from EasyGUI. Because of the limitations of tkinter, I cannot get a single exe file using py2exe. I was wondering if anybody had created something similar to EasyGUI, but using python-win32. The idea being that I could replace the multichoicebox from EasyGUI with one that uses the win32 API instead so that I could get a single exe from py2exe. Can anybody point me in the right direction where I might find such a thing? Thank you, Chaim From robin at reportlab.com Sat Feb 7 11:16:57 2009 From: robin at reportlab.com (Robin Becker) Date: Sat, 07 Feb 2009 10:16:57 +0000 Subject: [python-win32] Looking for python-win32 version of EasyGUI In-Reply-To: <498CFA95.9010603@chaim.com> References: <498CFA95.9010603@chaim.com> Message-ID: <498D5F99.6060807@jessikat.plus.net> Chaim Krause wrote: > I have an very small application that uses a single multichoicebox from > EasyGUI. Because of the limitations of tkinter, I cannot get a single > exe file using py2exe. > > I was wondering if anybody had created something similar to EasyGUI, but > using python-win32. The idea being that I could replace the > multichoicebox from EasyGUI with one that uses the win32 API instead so > that I could get a single exe from py2exe. > > Can anybody point me in the right direction where I might find such a > thing? > > Thank you, > Chaim ...... some info here might be of use http://ginstrom.com/scribbles/2008/02/26/python-gui-programming-platforms-for-windows/#Win32 -- Robin Becker From imageguy1206 at gmail.com Sat Feb 7 20:21:44 2009 From: imageguy1206 at gmail.com (geoff) Date: Sat, 7 Feb 2009 14:21:44 -0500 Subject: [python-win32] OT: MS Office Addin -- Guidance/Advice Message-ID: <3ee0b280902071121l295645b6me8bb9d785a622c1f@mail.gmail.com> Hello, I am sorry for troubling people on this list, however, I am hoping someone can steer me in the right direction. I would like to create an Addin for MS-Office that would allow me to store a copy of a document/email/spreadsheet in an external database. IOW, when I have the doc/email/xls open I have a button on the tool bar that allows me to specify some params and then the current active object is sent to the db. I have search thru MSDN, but can't find the "Here's how ya do it" entry. Thanks in advance. g. From theller at ctypes.org Sat Feb 7 22:55:19 2009 From: theller at ctypes.org (Thomas Heller) Date: Sat, 07 Feb 2009 22:55:19 +0100 Subject: [python-win32] Looking for python-win32 version of EasyGUI In-Reply-To: <498D5F99.6060807@jessikat.plus.net> References: <498CFA95.9010603@chaim.com> <498D5F99.6060807@jessikat.plus.net> Message-ID: Robin Becker schrieb: > Chaim Krause wrote: >> I have an very small application that uses a single multichoicebox from >> EasyGUI. Because of the limitations of tkinter, I cannot get a single >> exe file using py2exe. >> >> I was wondering if anybody had created something similar to EasyGUI, but >> using python-win32. The idea being that I could replace the >> multichoicebox from EasyGUI with one that uses the win32 API instead so >> that I could get a single exe from py2exe. >> >> Can anybody point me in the right direction where I might find such a >> thing? >> >> Thank you, >> Chaim > ...... > some info here might be of use > > http://ginstrom.com/scribbles/2008/02/26/python-gui-programming-platforms-for-windows/#Win32 Or this one, by Jimmy Retzlaff? http://www.averdevelopment.com/python/EasyDialogs.html Thomas From blade.eric at gmail.com Sat Feb 7 23:48:27 2009 From: blade.eric at gmail.com (Eric Blade) Date: Sat, 7 Feb 2009 17:48:27 -0500 Subject: [python-win32] reliability issues with ReadDirectoryChangesW Message-ID: <59ce684e0902071448s4c370df2v2dd511b5331714f7@mail.gmail.com> I am getting significantly unreliable results using ReadDirectoryChangesW, attempting to use a simplified version of the codes that had been presented to me in my last query for help.. It's kind of messy, but here's the relevant bits of code.. if os.name == 'nt': self.filehandlelist[site] = {} self.filehandlelist[site]['dir'] = dir self.filehandlelist[site]['handle'] = win32file.CreateFile(dir, 0x0001, win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, None, win32con.OPEN_EXISTING, win32con.FILE_FLAG_BACKUP_SEMANTICS | win32con.FILE_FLAG_OVERLAPPED, None) self.filehandlelist[site]['overlap'] = pywintypes.OVERLAPPED() self.filehandlelist[site]['overlap'].hEvent = win32event.CreateEvent(None, 0, 0, None) self.filehandlelist[site]['buffer'] = win32file.AllocateReadBuffer(1024) print "Add to filehandlelist: ", self.filehandlelist[site] .... if os.name == 'nt': for handle in self.filehandlelist: # print "check folder ", self.filehandlelist[handle] results = win32file.ReadDirectoryChangesW(self.filehandlelist[handle]['handle'], self.filehandlelist[handle]['buffer'], True, win32con.FILE_NOTIFY_CHANGE_FILE_NAME | win32con.FILE_NOTIFY_CHANGE_DIR_NAME | win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES | win32con.FILE_NOTIFY_CHANGE_SIZE | win32con.FILE_NOTIFY_CHANGE_LAST_WRITE | win32con.FILE_NOTIFY_CHANGE_SECURITY, self.filehandlelist[handle]['overlap']) if win32event.WaitForSingleObject(self.filehandlelist[handle]['overlap'].hEvent, 100) == win32event.WAIT_OBJECT_0: numbytes = win32file.GetOverlappedResult(self.filehandlelist[handle]['handle'], self.filehandlelist[handle]['overlap'], False) win32event.ResetEvent(self.filehandlelist[handle]['overlap'].hEvent) if numbytes == 0: continue for action, file in win32file.FILE_NOTIFY_INFORMATION(self.filehandlelist[handle]['buffer'], numbytes): full_filename = os.path.join(self.filehandlelist[handle]['dir'], file) print "file ", full_filename, "updated action ", action if full_filename not in self.filelist: self.addImportFile(full_filename, site) if action == 1 or action == 3: # created or updated self.import_file_dict(full_filename, self.filelist[full_filename][0], self.filelist[full_filename][1]) elif action == 2: # file deleted del self.filelist[full_filename] ... it feels like i'm doing something wrong here, but for the life of me, i can't seem to pinpoint it. -- Cheers, - Eric From ckkart at hoc.net Sun Feb 8 09:06:19 2009 From: ckkart at hoc.net (Christian K.) Date: Sun, 08 Feb 2009 09:06:19 +0100 Subject: [python-win32] mapi - writing to PR_BODY Message-ID: Hi, according to http://msdn.microsoft.com/en-us/library/cc839695.aspx writing to the PR_BODY property of a mapi message should be done more or less like the following: def TextToStream(mapi_object, text): prop_id = PR_BODY_A stream = mapi_object.OpenProperty(prop_id, pythoncom.IID_IStream, 0, mapi.MAPI_MODIFY) print stream.Stat(0) print stream.Write('papperlapapp\n'*10) mapi.RTFSync(mapi_object, mapi.RTF_SYNC_BODY_CHANGED|mapi.RTF_SYNC_RTF_CHANGED) stream.Commit(1) del stream # instead of calling Release, which I could not find write should return the number of bytes written but it returns None here. In case it makes a difference: I am not creating a new message rather than trying to modify the body of an existing one. I learned much from the spambayes project how to properly read message bodies but I cannot find more information on write access. Any pointers highly appreciated. Regards, Christian From mc at mclaveau.com Sun Feb 8 20:49:47 2009 From: mc at mclaveau.com (Michel Claveau) Date: Sun, 8 Feb 2009 20:49:47 +0100 Subject: [python-win32] OT: MS Office Addin -- Guidance/Advice In-Reply-To: <3ee0b280902071121l295645b6me8bb9d785a622c1f@mail.gmail.com> References: <3ee0b280902071121l295645b6me8bb9d785a622c1f@mail.gmail.com> Message-ID: <04C0FE80E93B44D18BEABC97D45F4D4E@MCI1330> Hi! Look for C:\Python26\Lib\site-packages\win32com\demos\excelAddin.py and C:\Python26\Lib\site-packages\win32com\demos\outlookAddin.py It's a goods exemples, and startpoints, for addin for Excel & Outlook. For Word, sorry, no addin possible. But you can make a button for a macro who will call Python, via COM. @-salutations -- Michel Claveau From mail at timgolden.me.uk Sun Feb 8 21:17:11 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 08 Feb 2009 20:17:11 +0000 Subject: [python-win32] reliability issues with ReadDirectoryChangesW In-Reply-To: <59ce684e0902071448s4c370df2v2dd511b5331714f7@mail.gmail.com> References: <59ce684e0902071448s4c370df2v2dd511b5331714f7@mail.gmail.com> Message-ID: <498F3DC7.7070705@timgolden.me.uk> Eric Blade wrote: > I am getting significantly unreliable results using > ReadDirectoryChangesW, attempting to use a simplified version of the > codes that had been presented to me in my last query for help.. Eric, can you say what results you *are* getting and in what way they're unreliable? I don't claim to have tested my own version of this exhaustively, but it seems to work in simple terms. (Sorry, your code was just so messed up between your email client and mine that I couldn't face putting it back together) TJG From mail at timgolden.me.uk Sun Feb 8 21:21:38 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 08 Feb 2009 20:21:38 +0000 Subject: [python-win32] reliability issues with ReadDirectoryChangesW In-Reply-To: <59ce684e0902071448s4c370df2v2dd511b5331714f7@mail.gmail.com> References: <59ce684e0902071448s4c370df2v2dd511b5331714f7@mail.gmail.com> Message-ID: <498F3ED2.8080000@timgolden.me.uk> Eric Blade wrote: [... snipped code ...] If it's possible, consider posting to something like pastebin or some other online snippets clipboard so we can see the whole code. It's even more difficult debugging something when you only have half the code! :) TJG From skippy.hammond at gmail.com Mon Feb 9 02:35:55 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 09 Feb 2009 12:35:55 +1100 Subject: [python-win32] mapi - writing to PR_BODY In-Reply-To: References: Message-ID: <498F887B.6050201@gmail.com> On 8/02/2009 7:06 PM, Christian K. wrote: > write should return the number of bytes written but it returns None > here. It appears Roger fixed this on 2007/08/07 and the fix was in builds 211 and 212. Cheers, Mark From chaim at chaim.com Mon Feb 9 04:34:32 2009 From: chaim at chaim.com (Chaim Krause) Date: Sun, 08 Feb 2009 21:34:32 -0600 Subject: [python-win32] Looking for python-win32 version of EasyGUI In-Reply-To: References: <498CFA95.9010603@chaim.com> <498D5F99.6060807@jessikat.plus.net> Message-ID: <498FA448.1010308@chaim.com> Thanks for the suggestions folks. I took a look at all of them, but none of them meant my requirements for a EasyGUI-like wrapper for dialog boxes using the win21 API. What I ended up doing was going with Pythoncard. It was simple enough for me to use that within one day I had ported my app to a Pythoncard application from its original form of a console application with one EasyGUI multiple choice dialog box. Thanks again for your suggestions. Chaim From apt.shansen at gmail.com Mon Feb 9 18:12:35 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 9 Feb 2009 09:12:35 -0800 Subject: [python-win32] COM with timeouts? Message-ID: <7a9c25c20902090912wc6028edid117bc729de80c60@mail.gmail.com> Hi all. I have an application that's controlling Word via COM, and have situations where I'd like to set a timeout on those operations. Word might throw up an error message for example which stalls everything until clicked. In such a case I'd rather just give up, go and kill Word and start over. My first thought was: why, I'll wrap the calls in a context manager that sets a SIGALRM. Then remembered Windows didn't support SIGALRM, and cried inside. Any tips on an approach to take to interrupt a COM call or set a timeout on it? Thanks in advance. --Stephen From blade.eric at gmail.com Mon Feb 9 21:39:10 2009 From: blade.eric at gmail.com (Eric Blade) Date: Mon, 9 Feb 2009 15:39:10 -0500 Subject: [python-win32] ReadDirectoryChangesW Message-ID: <59ce684e0902091239s86788b7m84f5828c3b6fd6b3@mail.gmail.com> > Eric Blade wrote: >> I am getting significantly unreliable results using >> ReadDirectoryChangesW, attempting to use a simplified version of the >> codes that had been presented to me in my last query for help.. > > Eric, can you say what results you *are* getting and in what > way they're unreliable? I don't claim to have tested my own > version of this exhaustively, but it seems to work in simple > terms. > > (Sorry, your code was just so messed up between your email > client and mine that I couldn't face putting it back together) In what way was it messed up? *strange* Here's the relevant bits, again: http://pastebin.ca/1331850 Sometimes I'm getting results as they happen, other times, I don't get a change notification until many minutes after it happens, sometimes, i never get it at all. From timr at probo.com Mon Feb 9 22:17:46 2009 From: timr at probo.com (Tim Roberts) Date: Mon, 09 Feb 2009 13:17:46 -0800 Subject: [python-win32] COM with timeouts? In-Reply-To: <7a9c25c20902090912wc6028edid117bc729de80c60@mail.gmail.com> References: <7a9c25c20902090912wc6028edid117bc729de80c60@mail.gmail.com> Message-ID: <49909D7A.8020700@probo.com> Stephen Hansen wrote: > Hi all. > > I have an application that's controlling Word via COM, and have > situations where I'd like to set a timeout on those operations. Word > might throw up an error message for example which stalls everything > until clicked. In such a case I'd rather just give up, go and kill > Word and start over. > > My first thought was: why, I'll wrap the calls in a context manager > that sets a SIGALRM. Then remembered Windows didn't support SIGALRM, > and cried inside. > > Any tips on an approach to take to interrupt a COM call or set a timeout on it? > There's no reliable way to do that. You could, of course, spin off a separate thread to simulate SIGALRM using time.sleep, but once you had done so, there's no good way to stop the thread that is blocked waiting for Word to respond. And if word has displayed a modal error box, it's not trivial to kill it in a clean way. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From apt.shansen at gmail.com Mon Feb 9 23:41:58 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 9 Feb 2009 14:41:58 -0800 Subject: [python-win32] COM with timeouts? In-Reply-To: <49909D7A.8020700@probo.com> References: <7a9c25c20902090912wc6028edid117bc729de80c60@mail.gmail.com> <49909D7A.8020700@probo.com> Message-ID: <7a9c25c20902091441q1dd5887av2f5055a8fcc67399@mail.gmail.com> >> Any tips on an approach to take to interrupt a COM call or set a timeout on it? >> > > There's no reliable way to do that. You could, of course, spin off a > separate thread to simulate SIGALRM using time.sleep, but once you had > done so, there's no good way to stop the thread that is blocked waiting > for Word to respond. And if word has displayed a modal error box, it's > not trivial to kill it in a clean way. Doh. I was hoping I had just missed a convenient timeout function. Killing word itself is no problem: in my scenario its okay to do so violently, as the reinitialization procedure goes through a lot of effort to clean up the newly started word instance. Soo, I'm going to try a subprocess approach. Launch a subprocess which will actually drive Word, and send messages to it in a non-blocking fashion; then I can just kill that process if the parent's timeout expires on any given action. Way more work then I was hoping to do, but hey :) Thanks. --S From skippy.hammond at gmail.com Tue Feb 10 01:15:28 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 10 Feb 2009 11:15:28 +1100 Subject: [python-win32] ReadDirectoryChangesW In-Reply-To: <59ce684e0902091239s86788b7m84f5828c3b6fd6b3@mail.gmail.com> References: <59ce684e0902091239s86788b7m84f5828c3b6fd6b3@mail.gmail.com> Message-ID: <4990C720.5040601@gmail.com> On 10/02/2009 7:39 AM, Eric Blade wrote: >> Eric Blade wrote: >>> I am getting significantly unreliable results using >>> ReadDirectoryChangesW, attempting to use a simplified version of the >>> codes that had been presented to me in my last query for help.. >> Eric, can you say what results you *are* getting and in what >> way they're unreliable? I don't claim to have tested my own >> version of this exhaustively, but it seems to work in simple >> terms. >> >> (Sorry, your code was just so messed up between your email >> client and mine that I couldn't face putting it back together) > > In what way was it messed up? *strange* > > Here's the relevant bits, again: > > http://pastebin.ca/1331850 > > Sometimes I'm getting results as they happen, other times, I don't get > a change notification until many minutes after it happens, sometimes, > i never get it at all. It would help if you can reduce this down to the smallest possible *complete* sample we can run and see the strangeness for ourselves... Cheers, Mark From skippy.hammond at gmail.com Tue Feb 10 01:18:19 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 10 Feb 2009 11:18:19 +1100 Subject: [python-win32] COM with timeouts? In-Reply-To: <7a9c25c20902090912wc6028edid117bc729de80c60@mail.gmail.com> References: <7a9c25c20902090912wc6028edid117bc729de80c60@mail.gmail.com> Message-ID: <4990C7CB.50603@gmail.com> On 10/02/2009 4:12 AM, Stephen Hansen wrote: > Hi all. > > I have an application that's controlling Word via COM, and have > situations where I'd like to set a timeout on those operations. Word > might throw up an error message for example which stalls everything > until clicked. In such a case I'd rather just give up, go and kill > Word and start over. If you kill the Word process, you could expect the COM RPC mechanism will then return from the blocked call with some exception. Cheers, Mark From apt.shansen at gmail.com Tue Feb 10 03:44:52 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 9 Feb 2009 18:44:52 -0800 Subject: [python-win32] COM with timeouts? In-Reply-To: <4990C7CB.50603@gmail.com> References: <7a9c25c20902090912wc6028edid117bc729de80c60@mail.gmail.com> <4990C7CB.50603@gmail.com> Message-ID: <7a9c25c20902091844x6e3a730m72562f640e3ee0f7@mail.gmail.com> On Mon, Feb 9, 2009 at 4:18 PM, Mark Hammond wrote: > If you kill the Word process, you could expect the COM RPC mechanism will > then return from the blocked call with some exception. ... Oh. Yes, that's brilliant. The thought never occurred to me to let the kill_word code itself serve as my sigalrm and interrupt the blocking call. I just "with timeout(token, 5): document.DoSomething" and have the timeout contextmanager add/remove pending cancellations from a thread that chain-sleeps waiting for any to run out when any are registered. Works just fine so far. Thanks. --S From vernondcole at gmail.com Tue Feb 10 17:15:12 2009 From: vernondcole at gmail.com (Vernon Cole) Date: Tue, 10 Feb 2009 09:15:12 -0700 Subject: [python-win32] Fwd: [DB-SIG] adodbapi return datetime In-Reply-To: References: Message-ID: This is a copy of a message I just sent to dbsig. I would like the opinions of this group as well. This is a poll: Should adodbapi be changed so that datetime.datetime is the default return type for SQL date-time columns? (The present implementation will default to mx.DateTime if present.) My feeling is "yes", because 1) the Python 3.0 version of pywin32 will return COM date-times as datetime.datetime 2) mx.DateTime is not (yet?) available on Python 3.0 nor IronPython 3) as William said, it IS weird to silently change when mxbase is loaded. But, I am worried about breaking existing code if I change the default. Your comments solicited... -- VC On Tue, Feb 10, 2009 at 8:49 AM, William Dode wrote: > On 10-02-2009, Vernon Cole wrote: > > > William: > > It has always seemed to me that the syntax you tried should work. Perhaps > > someday, some "real" Python guru will explain to me why sometimes it does > > not, and maybe even tell me how to fix it. Perhaps the module definition > is > > not done quite right, I dunno? Try adding an extra level of depth to your > > module reference, and I think you may find that it works. > > > adodbapi.adodbapi.dateconverter = > adodbapi.adodbapi.pythonDateTimeConverter() > > > > > Looks weird to me and I don't understand it, but try it. > > It works ! thanks you to answer so quickly. > > Do you plan to make datetime the default ? > > It's weird that with python >= 2.3 the behaviour will silently change if > we add mx package ! > > -- > William Dod? - http://flibuste.net > Informaticien Ind?pendant > > _______________________________________________ > DB-SIG maillist - DB-SIG at python.org > http://mail.python.org/mailman/listinfo/db-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed Feb 11 00:09:02 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 11 Feb 2009 10:09:02 +1100 Subject: [python-win32] Fwd: [DB-SIG] adodbapi return datetime In-Reply-To: References: Message-ID: <4992090E.7000907@gmail.com> On 11/02/2009 3:15 AM, Vernon Cole wrote: > My feeling is "yes", because > 1) the Python 3.0 version of pywin32 will return COM date-times as > datetime.datetime > 2) mx.DateTime is not (yet?) available on Python 3.0 nor IronPython > 3) as William said, it IS weird to silently change when mxbase is loaded. The fact it comes with Python itself is also a strong argument, but: > But, I am worried about breaking existing code if I change the default. I don't have any such code, so my opinion isn't that valid here. Just to be clear though, adodbapi has a documented way of changing what is returned, so people who want to continue relying on mxDateTime have a one-or-two line fix available, correct? Thanks, Mark From Dominick.Lauzon at MSCsoftware.com Wed Feb 11 23:50:55 2009 From: Dominick.Lauzon at MSCsoftware.com (Dominick Lauzon) Date: Wed, 11 Feb 2009 17:50:55 -0500 Subject: [python-win32] numpy and pylab on win64 ? Message-ID: <589DC3F5067BDD479AAAE54CE398166D7D3537@NAAAEX01.na.mscsoftware.com> Maybe not the right forum, but I am in the process of porting stuff developed originally on win32 to a win64 platform. One of the script used to call numpy and pylab. I cannot find 64bit specific installs for these but am wondering if installing the 32bit version would still work on my xp64 platform. Thanks Dominick Lauzon ing. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Feb 12 00:21:00 2009 From: timr at probo.com (Tim Roberts) Date: Wed, 11 Feb 2009 15:21:00 -0800 Subject: [python-win32] numpy and pylab on win64 ? In-Reply-To: <589DC3F5067BDD479AAAE54CE398166D7D3537@NAAAEX01.na.mscsoftware.com> References: <589DC3F5067BDD479AAAE54CE398166D7D3537@NAAAEX01.na.mscsoftware.com> Message-ID: <49935D5C.2030400@probo.com> Dominick Lauzon wrote: > > Maybe not the right forum, but I am in the process of porting stuff > developed originally on win32 to a win64 platform. > > > > One of the script used to call numpy and pylab. > > > > I cannot find 64bit specific installs for these but am wondering if > installing the 32bit version would still work on my xp64 platform. > If you install 32-bit Python, then the 32-bit add-ons continue to work just as they always have. If you install 64-bit Python, then you need 64-bit add-ons. Numpy, at least, uses C extensions. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Thu Feb 12 03:44:44 2009 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 12 Feb 2009 13:44:44 +1100 Subject: [python-win32] EOFError in gencache.py In-Reply-To: <49929580.1000905@salford.cz> References: <498A1964.2010606@volny.cz> <498A7DA5.5040007@gmail.com> <49929580.1000905@salford.cz> Message-ID: <032f01c98cbb$dfc12580$9f437080$@com.au> > My app consists of 2 scripts. The first one is an infinite loop which > calls periodically the second script. The first script does not work > with COM. The second script makes one instance of COM, calls some its > methods and ends. The first script waits until the second one finishes > its job so only one instance of COM exists in one process at any time. > I > choose this scenario because COM, which is another party's product, > includes small memory leak which prevents to run it 24x7. In this scenario, we would expect the dicts.dat file to be written when the script first runs and not updated until some new COM object is used or the generated files are removed. It would be interesting to know why that isn't the case (maybe setting dicts.dat to readonly might help see when it happens?) Cheers, Mark From mc at mclaveau.com Thu Feb 12 08:04:24 2009 From: mc at mclaveau.com (Michel Claveau) Date: Thu, 12 Feb 2009 08:04:24 +0100 Subject: [python-win32] Slow convert collection to list (search a fast way) Message-ID: Hi! I get a collection of (COM) objects: tobj = oie.prepartableau( #it's a JScript array of objects, returned by a JScript function via COM I convert (translate? transtype?) this collection to LIST: lobj = list(tobj) But it's (very) slow(*). I tried [i for i in tobj] ; I tried with iter ; with 'for' ; etc. All is slow. Who know a way for fast get the collection like LIST? Thanks in advance. -- Michel Claveau (*) slow: 0.7 seconds for len=1000 From timr at probo.com Thu Feb 12 08:11:15 2009 From: timr at probo.com (Tim Roberts) Date: Wed, 11 Feb 2009 23:11:15 -0800 Subject: [python-win32] Slow convert collection to list (search a fast way) Message-ID: <200902120711.n1C7BFU05497@probo.probo.com> You wrote: > >Hi! > >I get a collection of (COM) objects: > tobj = oie.prepartableau( #it's a JScript array of objects, returned >by a JScript function via COM >I convert (translate? transtype?) this collection to LIST: > lobj = list(tobj) >But it's (very) slow(*). I tried [i for i in tobj] ; I tried with iter ; >with 'for' ; etc. All is slow. >(*) slow: 0.7 seconds for len=1000 > >Who know a way for fast get the collection like LIST? You think 700 microseconds for a COM transaction is slow? Perhaps it is your expectations that need adjusting. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mc at mclaveau.com Thu Feb 12 08:58:35 2009 From: mc at mclaveau.com (Michel Claveau) Date: Thu, 12 Feb 2009 08:58:35 +0100 Subject: [python-win32] Slow convert collection to list (search a fastway) In-Reply-To: <200902120711.n1C7BFU05497@probo.probo.com> References: <200902120711.n1C7BFU05497@probo.probo.com> Message-ID: <511DE8731C0344B5875731E9BE7B6851@MCI1330> Re! > You think 700 microseconds for a COM transaction is slow? Perhaps it is > your expectations that need adjusting. When I get an array of data (for example, numbers), the (same) list conversion (len=1000) take 0.07 s But with array of object, it is ten times more slow (0.7 s). In my appli, I have table with 100 rows and 10 cols. But, if I go up 1000 rows and 20 cols, it will become a long way to obtain satisfaction... If there are no fast way for translate collection.objects to list of objects, I will change a big part of the architecture of my appli. Thanks for your answer, and zorry for my rotten english. @-salutations -- Michel Claveau From skippy.hammond at gmail.com Thu Feb 12 11:11:48 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 12 Feb 2009 21:11:48 +1100 Subject: [python-win32] Slow convert collection to list (search a fastway) In-Reply-To: <511DE8731C0344B5875731E9BE7B6851@MCI1330> References: <200902120711.n1C7BFU05497@probo.probo.com> <511DE8731C0344B5875731E9BE7B6851@MCI1330> Message-ID: <4993F5E4.7070601@gmail.com> On 12/02/2009 6:58 PM, Michel Claveau wrote: > Re! > >> You think 700 microseconds for a COM transaction is slow? Perhaps it >> is your expectations that need adjusting. > > When I get an array of data (for example, numbers), the (same) list > conversion (len=1000) take 0.07 s > But with array of object, it is ten times more slow (0.7 s). > In my appli, I have table with 100 rows and 10 cols. But, if I go up > 1000 rows and 20 cols, it will become a long way to obtain satisfaction... I'm afraid that I'm not too surprised creating a COM object is 10 times slower than creating a python integer object. Do you really need all these objects as IDispatch objects? Can you enumerate over them instead? It is quite likely enumeration isn't as efficient as it could be, but updating win32com's semnatics wrt iterators etc is something I'd be keen to work on post pywin32-213 - which may not help you much immediately though... Cheers, Mark From mc at mclaveau.com Thu Feb 12 11:37:13 2009 From: mc at mclaveau.com (Michel Claveau) Date: Thu, 12 Feb 2009 11:37:13 +0100 Subject: [python-win32] Slow convert collection to list (search a fastway) In-Reply-To: <4993F5E4.7070601@gmail.com> References: <200902120711.n1C7BFU05497@probo.probo.com> <511DE8731C0344B5875731E9BE7B6851@MCI1330> <4993F5E4.7070601@gmail.com> Message-ID: <96349F606099459883C60C601E097996@MCI1330> Re ! > ... win32com's semantics ... wrt ... iterators etc ... pywin32-213 OK. I will modifie (today) my (architecture) code. With definition (& usage) of class with "lazy treatment". The time will be consumed only for need (I hope my english translation will have been understandable). Thanks you, and nice day for all, in Universe. -- Michel Claveau From ckkart at hoc.net Thu Feb 12 16:35:24 2009 From: ckkart at hoc.net (Christian K.) Date: Thu, 12 Feb 2009 16:35:24 +0100 Subject: [python-win32] mapi - writing to PR_BODY In-Reply-To: <498F887B.6050201@gmail.com> References: <498F887B.6050201@gmail.com> Message-ID: Mark Hammond schrieb: > On 8/02/2009 7:06 PM, Christian K. wrote: >> write should return the number of bytes written but it returns None >> here. > > It appears Roger fixed this on 2007/08/07 and the fix was in builds 211 > and 212. I suppose I am using a recent build - where can I find the version information? In fact I am currently not concerned that write returns None but that the code snippet shown before does not change the mail body at all. And I had situations, where write indeed did return the number of bytes written, again without any change on the body. My understanding of mapi is very basic but this seems to have to do with the access method to the mail body, i.e. whether the body should be retrieved via GetProp or via streaming. In the end I would like to be able the mail body of each recieved mail, i.e. I catch the newmail event, read the mail body and want to write it back. If there are any other ideas how to achieve that, I would be grateful to hear about them. Christian From steven.pollack at fda.hhs.gov Thu Feb 12 19:59:01 2009 From: steven.pollack at fda.hhs.gov (Pollack, Steven K) Date: Thu, 12 Feb 2009 13:59:01 -0500 Subject: [python-win32] catching the "close" event Message-ID: <9483CC56B029B14094A5F63E501CA38E04637613@FMD3VS021.fda.gov> I am trying to write a python based glue to orchestrate interaction between Access, Excel and Outlook. I understand events reasonably well, can DispatchWithEvents an instance of excel and catch worksheet and file save related events. but can't figure out if there is an event I can catch associated with the "close" button (the little ole red x) that I can trap and or cancel before the application dies. I want to force a file save first. Also, it would be nice to know (for a newbie) how to search the archive to see if such a thing has already been asked. Steven K. Pollack, Ph.D. Director, Division of Chemistry and Materials Science Office of Science and Engineering Laboratories Center for Devices and Radiological Health Food and Drug Administration 10903 New Hampshire Avenue, Building 64, Room 4028 Silver Spring, Maryland 20903-0002 (301)-796-2476 (V) (301)-801-4228 (M) (301)-796-9924 (F) -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Thu Feb 12 21:57:18 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 13 Feb 2009 07:57:18 +1100 Subject: [python-win32] mapi - writing to PR_BODY In-Reply-To: References: <498F887B.6050201@gmail.com> Message-ID: <49948D2E.5090403@gmail.com> On 13/02/2009 2:35 AM, Christian K. wrote: > Mark Hammond schrieb: >> On 8/02/2009 7:06 PM, Christian K. wrote: >>> write should return the number of bytes written but it returns None >>> here. >> >> It appears Roger fixed this on 2007/08/07 and the fix was in builds >> 211 and 212. > > I suppose I am using a recent build - where can I find the version > information? Via "Add Remove Programs" is probably easiest. > In fact I am currently not concerned that write returns None but that > the code snippet shown before does not change the mail body at all. > > And I had situations, where write indeed did return the number of bytes > written, again without any change on the body. My understanding of mapi > is very basic but this seems to have to do with the access method to the > mail body, i.e. whether the body should be retrieved via GetProp or via > streaming. That seems strange - the Write method on that interface used to unconditionally return None and now it unconditionally returns an integer. > In the end I would like to be able the mail body of each recieved mail, > i.e. I catch the newmail event, read the mail body and want to write it > back. If there are any other ideas how to achieve that, I would be > grateful to hear about them. I'm afraid I'm missing the point then. You referenced SpamBayes and it fetches the body text of each new mail as it arrives - why is that scheme not working for you? Mark From skippy.hammond at gmail.com Thu Feb 12 21:59:16 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 13 Feb 2009 07:59:16 +1100 Subject: [python-win32] catching the "close" event In-Reply-To: <9483CC56B029B14094A5F63E501CA38E04637613@FMD3VS021.fda.gov> References: <9483CC56B029B14094A5F63E501CA38E04637613@FMD3VS021.fda.gov> Message-ID: <49948DA4.8060504@gmail.com> On 13/02/2009 5:59 AM, Pollack, Steven K wrote: > I am trying to write a python based glue to orchestrate interaction > between Access, Excel and Outlook. > > I understand events reasonably well, can DispatchWithEvents an instance > of excel and catch worksheet and file save related events. but can?t > figure out if there is an event I can catch associated with the ?close? > button (the little ole red x) that I can trap and or cancel before the > application dies. I want to force a file save first. Each application defines its own events - so I'm afraid this depends on exactly what object you are talking about. There is no generic mechanism triggered when a COM object, or its window is closed. Mark From ckkart at hoc.net Fri Feb 13 09:32:41 2009 From: ckkart at hoc.net (Christian K.) Date: Fri, 13 Feb 2009 09:32:41 +0100 Subject: [python-win32] mapi - writing to PR_BODY In-Reply-To: <49948D2E.5090403@gmail.com> References: <498F887B.6050201@gmail.com> <49948D2E.5090403@gmail.com> Message-ID: Mark Hammond wrote: > On 13/02/2009 2:35 AM, Christian K. wrote: >> Mark Hammond wrote: >> And I had situations, where write indeed did return the number of bytes >> written, again without any change on the body. My understanding of mapi >> is very basic but this seems to have to do with the access method to the >> mail body, i.e. whether the body should be retrieved via GetProp or via >> streaming. > > That seems strange - the Write method on that interface used to > unconditionally return None and now it unconditionally returns an integer. I will check that again. > > I'm afraid I'm missing the point then. You referenced SpamBayes and it > fetches the body text of each new mail as it arrives - why is that > scheme not working for you? Actually I am using the spambayes routines to read the body but I cannot find a way to write it back to the message. Writing e.g. the subject is much easier as I only have to call SetProps followed by SaveChanges. Christian From ckkart at hoc.net Fri Feb 13 14:56:34 2009 From: ckkart at hoc.net (Christian K.) Date: Fri, 13 Feb 2009 14:56:34 +0100 Subject: [python-win32] mapi - writing to PR_BODY In-Reply-To: <49948D2E.5090403@gmail.com> References: <498F887B.6050201@gmail.com> <49948D2E.5090403@gmail.com> Message-ID: Mark Hammond schrieb: > On 13/02/2009 2:35 AM, Christian K. wrote: >> Mark Hammond schrieb: tuations, where write indeed did return the number of bytes >> written, again without any change on the body. My understanding of mapi >> is very basic but this seems to have to do with the access method to the >> mail body, i.e. whether the body should be retrieved via GetProp or via >> streaming. > > That seems strange - the Write method on that interface used to > unconditionally return None and now it unconditionally returns an integer. You were right. I was mixing observations from two different machines, one of them has build 210, the other 212 installed. My mistake, sorry. So write seems to work as expected (reporting the right number of bytes) but I have no clue *where* the data is written to. The mail body stays completely unaffected. Any ideas? Christian From skippy.hammond at gmail.com Sat Feb 14 23:04:29 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sun, 15 Feb 2009 09:04:29 +1100 Subject: [python-win32] mapi - writing to PR_BODY In-Reply-To: References: <498F887B.6050201@gmail.com> <49948D2E.5090403@gmail.com> Message-ID: <49973FED.1070906@gmail.com> On 14/02/2009 12:56 AM, Christian K. wrote: > So write seems to work as expected (reporting the right number of bytes) > but I have no clue *where* the data is written to. The mail body stays > completely unaffected. I guess step 1 would be to see if you can re-read it - ie, is the data not getting there, or is Outlook etc simply ignoring it? If the latter; I can't remember the details, but isn't there a flag which indicates if PR_BODY, PR_BODY_HTML or some other rich-text related property is used? If also might be worth looking at the "Redemption" tool - IIRC, that tool gives you a nice raw internal view of such objects and may let you see what is going on a little better... Cheers, Mark From ckkart at hoc.net Sun Feb 15 11:58:35 2009 From: ckkart at hoc.net (Christian K.) Date: Sun, 15 Feb 2009 11:58:35 +0100 Subject: [python-win32] mapi - writing to PR_BODY In-Reply-To: <49973FED.1070906@gmail.com> References: <498F887B.6050201@gmail.com> <49948D2E.5090403@gmail.com> <49973FED.1070906@gmail.com> Message-ID: Mark Hammond schrieb: > On 14/02/2009 12:56 AM, Christian K. wrote: > >> So write seems to work as expected (reporting the right number of bytes) >> but I have no clue *where* the data is written to. The mail body stays >> completely unaffected. > > I guess step 1 would be to see if you can re-read it - ie, is the data > not getting there, or is Outlook etc simply ignoring it? Godd point and in fact the modified text is there when I re-read it. > If the latter; I can't remember the details, but isn't there a flag > which indicates if PR_BODY, PR_BODY_HTML or some other rich-text related > property is used? Right, spambayes is handling all those cases correctly and I think, that it should be possible to write the plain body and let outlook do an internal synchronization of the various formats. > If also might be worth looking at the "Redemption" tool - IIRC, that > tool gives you a nice raw internal view of such objects and may let you > see what is going on a little better... I am using outlookspy (by the same author as the redempion tool) to find out what is going on but had no luck so far. Christian From ckkart at hoc.net Sun Feb 15 22:06:18 2009 From: ckkart at hoc.net (Christian K.) Date: Sun, 15 Feb 2009 22:06:18 +0100 Subject: [python-win32] mapi - writing to PR_BODY In-Reply-To: References: Message-ID: Christian K. wrote: > def TextToStream(mapi_object, text): > prop_id = PR_BODY_A > stream = mapi_object.OpenProperty(prop_id, > pythoncom.IID_IStream, > 0, mapi.MAPI_MODIFY) > print stream.Stat(0) > print stream.Write('papperlapapp\n'*10) > mapi.RTFSync(mapi_object, > mapi.RTF_SYNC_BODY_CHANGED|mapi.RTF_SYNC_RTF_CHANGED) > stream.Commit(1) > del stream # instead of calling Release, which I could not find Found the solution. Partly a stupid mistake. I forgot to call SaveChanges, for my excuse: it is not mentioned in the article above. And the setting the PR_RTF_IN_SYNC to false is crucial to make outlook convert the plain text to RTF. mapi_object.SetProps([(PR_RTF_IN_SYNC, 0)]) mapi_object.SaveChanges() Thanks Mark for your help, Christian From mpkn2002 at yahoo.com Mon Feb 16 09:03:03 2009 From: mpkn2002 at yahoo.com (Payman Rowhani) Date: Mon, 16 Feb 2009 00:03:03 -0800 (PST) Subject: [python-win32] PyWin 32 variable instead of 'Nothing' in VB Message-ID: <774607.72655.qm@web51509.mail.re2.yahoo.com> We have a Visual Basic script that communicates with an application through com. We like to translate it to Python and use win32com.client instead. We have everything working, except for the use of "Nothing" in the VB script for a couple of its function calls. What is the replacement of "Nothing" in Python? Note that the generic "None" does not work. ? Thanks in advance, Payman -------------- next part -------------- An HTML attachment was scrubbed... URL: From boesen at xefion.com Mon Feb 16 10:28:41 2009 From: boesen at xefion.com (Thomas P. Boesen) Date: Mon, 16 Feb 2009 10:28:41 +0100 Subject: [python-win32] Released prototype Excel add-in making it easy to create Python add-ins Message-ID: <499931C9.3050705@xefion.com> Hi, I am thinking about creating an Excel add-in that makes it very easy to create Excel macros / add-ins using Python (IronPython) Any feedback about the idea will be greatly appreciated. I have made a prototype of this add-in available here: http://www.xefion.com/en/discoveryscript.html The add-in would be free, although not open-source. It takes quite a bit of ?plumbing? to get COM add-ins running within Excel. My add-in would look for Python scripts in a specific directory and automatically create Excel menu-items for all the scripts in that directory. Hence, to get started the user just has to create a one-line Python script and store this script in the designated folder, then he can run the script from Excel. There will be various other options, for example shared network locations with scripts and connecting Excel events (e.g. OpenDoc or SaveDoc) to scripts based on their names. Later versions might also work with other Office programs (e.g. Word). The download-page mentioned above contains a description of feature candidates. :-) Thomas P. Boesen From mhammond at skippinet.com.au Mon Feb 16 13:50:51 2009 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 16 Feb 2009 23:50:51 +1100 Subject: [python-win32] pywin32 build 213 released Message-ID: <001c01c99035$330e6e60$992b4b20$@com.au> Hi all, I'm extremely happy to announce the release of pywin32 build 213 - the first release of pywin32 with support for Python 3.x. This release has a large number of changes and should, in general, be considered BETA quality - please refer to the release notes below for details. The full change log is at https://sourceforge.net/project/shownotes.php?release_id=661475 Get it now via http://sourceforge.net/project/showfiles.php?group_id=78018&package_id=79063 &release_id=661475 Finally-ly... Mark Release Notes: -------------- This is the first release of pywin32 with support for Python 3.0. Both as a direct result of this, and given the opportunity, many modernizations and internal cleanups have been made. Many of the hacks necessary when Python didn't support unicode have been removed, and many old modules which also predate unicode (such as Pythonwin) have been dragged, sometimes kicking and screaming, into a modern era. While very few of these changes should be visible to users of the package, this build should be treated as BETA quality. While this build has many more unit tests than previous builds and no significant known problems exist, it is likely some corners will have regressions. Please test this build thoroughly before relying on it for production work. For Python 3.0 in particular, some details are subject to change in the future without regard for backwards compatibility. For example, if this build allows you to pass 'bytes' where only a string makes logical sense, we reserve the right to 'fix' this oversight. Obviously common-sense rules here though; we will not break sensible applications in the pursuit of purity. Please see the pywin32 documentation for more details on py3k support. Thanks to Roger Upole, without whom this huge effort wouldn't have even started yet, and to Jason R. Coombs and Vernon Cole for their help getting the win32timezone and adodbapi modules working on py3k. Enjoy! From p.f.moore at gmail.com Mon Feb 16 15:30:55 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 16 Feb 2009 14:30:55 +0000 Subject: [python-win32] Obtaining Outlook item properties from saved email file Message-ID: <79990c6b0902160630r1be1b6afm19d7486693b4afe4@mail.gmail.com> Sorry, this is only peripherally a Python issue, as the code I'm writing could just as easily be VBScript or any other language... But as I'm writing in Python, and this group is full of helpful and knowledgeable people... :-) I have a folder full of emails saved from Outlook (.msg extension). I want to extract from those files, the subject, sent/received date, author, etc. Getting the properties isn't hard once I have a CDO message object (or equivalent) to work with, but I've been unable to find any way of getting a message object when all I'm given is the filename of a ".msg" file in the filesystem. Can anybody suggest a way to do this, or point me at sample code? Once again, sorry for the mostly off-topic question, and thanks for any help. Paul. From mail at timgolden.me.uk Mon Feb 16 16:03:40 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 16 Feb 2009 15:03:40 +0000 Subject: [python-win32] Obtaining Outlook item properties from saved email file In-Reply-To: <79990c6b0902160630r1be1b6afm19d7486693b4afe4@mail.gmail.com> References: <79990c6b0902160630r1be1b6afm19d7486693b4afe4@mail.gmail.com> Message-ID: <4999804C.7050707@timgolden.me.uk> Paul Moore wrote: > Sorry, this is only peripherally a Python issue, as the code I'm > writing could just as easily be VBScript or any other language... But > as I'm writing in Python, and this group is full of helpful and > knowledgeable people... :-) > > I have a folder full of emails saved from Outlook (.msg extension). I > want to extract from those files, the subject, sent/received date, > author, etc. Getting the properties isn't hard once I have a CDO > message object (or equivalent) to work with, but I've been unable to > find any way of getting a message object when all I'm given is the > filename of a ".msg" file in the filesystem. > > Can anybody suggest a way to do this, or point me at sample code? They're structured storage and a bit opaque. In principle this (very sketchy and untested) code should get you started: import pythoncom from win32com import storagecon filename = r"c:\temp\outlook.msg" print pythoncom.StgIsStorageFile (filename) flags = storagecon.STGM_READ | storagecon.STGM_SHARE_EXCLUSIVE storage = pythoncom.StgOpenStorage (filename, None, flags) for data in storage.EnumElements (): if data[1] == 2: print data[0] stream = storage.OpenStream (data[0], None, flags) print repr (stream.Read (data[2])) # # ... and now you've got an IStream interface which # you can read etc. # There are some stream names listed here: http://www.msusenet.com/archive/topic.php/t-288764.html TJG From mail at timgolden.me.uk Mon Feb 16 16:07:43 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 16 Feb 2009 15:07:43 +0000 Subject: [python-win32] PyWin 32 variable instead of 'Nothing' in VB In-Reply-To: <774607.72655.qm@web51509.mail.re2.yahoo.com> References: <774607.72655.qm@web51509.mail.re2.yahoo.com> Message-ID: <4999813F.5000908@timgolden.me.uk> Payman Rowhani wrote: > We have a Visual Basic script that communicates with an application through com. We like to translate it to Python and use win32com.client instead. We have everything working, except for the use of "Nothing" in the VB script for a couple of its function calls. What is the replacement of "Nothing" in Python? Note that the generic "None" does not work. I *think* you can use pythoncom.Empty TJG From p.f.moore at gmail.com Mon Feb 16 16:35:57 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 16 Feb 2009 15:35:57 +0000 Subject: [python-win32] Obtaining Outlook item properties from saved email file In-Reply-To: <4999804C.7050707@timgolden.me.uk> References: <79990c6b0902160630r1be1b6afm19d7486693b4afe4@mail.gmail.com> <4999804C.7050707@timgolden.me.uk> Message-ID: <79990c6b0902160735h1c1aeff1xb5220d2d80479753@mail.gmail.com> 2009/2/16 Tim Golden : > They're structured storage and a bit opaque. In principle > this (very sketchy and untested) code should get you started: Thanks, that's a good start. Actually, your mention of the IStream interface below reminds me, I'm fairly sure I saw somewhere a mention of a CDO method to load a message from a stream, so that's probably what I need (plus your code below). I'll go rummaging and see what I can find. Thanks! Paul. From p.f.moore at gmail.com Mon Feb 16 17:20:56 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 16 Feb 2009 16:20:56 +0000 Subject: [python-win32] Obtaining Outlook item properties from saved email file In-Reply-To: <79990c6b0902160735h1c1aeff1xb5220d2d80479753@mail.gmail.com> References: <79990c6b0902160630r1be1b6afm19d7486693b4afe4@mail.gmail.com> <4999804C.7050707@timgolden.me.uk> <79990c6b0902160735h1c1aeff1xb5220d2d80479753@mail.gmail.com> Message-ID: <79990c6b0902160820g25ce2b42o38120f13abba9665@mail.gmail.com> 2009/2/16 Paul Moore : > 2009/2/16 Tim Golden : >> They're structured storage and a bit opaque. In principle >> this (very sketchy and untested) code should get you started: > > Thanks, that's a good start. Actually, your mention of the IStream > interface below reminds me, I'm fairly sure I saw somewhere a mention > of a CDO method to load a message from a stream, so that's probably > what I need (plus your code below). > > I'll go rummaging and see what I can find. Thanks! For reference, what I came up with is import sys from win32com.client import Dispatch filename = sys.argv[1] stm = Dispatch("ADODB.Stream") stm.Open() stm.LoadFromFile(filename) msg = Dispatch("CDO.Message") msg.DataSource.OpenObject(stm, "_Stream") print repr(msg.From) print repr(msg.Subject) #print repr(msg.TextBody) which is essentially what gets recommended in various places on the web. Ironically, it's not using structured storage, but ADO streams, for whatever the difference implies. One minor problem - it doesn't work for me (:-)) I suspect this might be to do with subtle issues around the version of Outlook we use (2003) and whether I save the file as "Outlook Message Format" or "Outlook Message Format - Unicode". I say this, because these issues gave us compatibility problems a while ago, which we never tracked down but which "went away" somewhere in a series of patches/updates. So it may be I'm hitting an old CDO library, or something. Sigh. It's stuff like this that makes me end up doing stuff by hand whenever I try scripting Outlook :-( I'll report back on what (if anything) I find - if only for the archives. Paul. From davidanthonypowell at gmail.com Tue Feb 17 07:51:06 2009 From: davidanthonypowell at gmail.com (David Powell) Date: Tue, 17 Feb 2009 17:51:06 +1100 Subject: [python-win32] Problem with COM return value in python, but works fine in VB Message-ID: <4f8149830902162251k107887bdq70dfefda469f3c77@mail.gmail.com> Hello, I am trying to automate the commercial software "CST Microwave Studio" using win32com, on a 32 bit windows XP machine. The program has a reasonably well documented COM interface, and for example I am able to run the following .vbs script, which shows the expected behaviour of opening a new project and doesn't return any error messages: Set app = CreateObject ("CSTStudio.Application") Set mws = app.NewMWS However, vbscript is far too primitive for what I want to do, so I have translated this code to python using win32com: import win32com.client cst = win32com.client.Dispatch("CSTStudio.Application") cst.NewMWS() This results in the following error output: Traceback (most recent call last): File "C:\Documents and Settings\dap124\Desktop\cst_com.py", line 19, in cst.NewMWS() File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 508, in __getattr__ return self._get_good_object_(ret) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 301, in _get_good_object_ return self._get_good_single_object_(ob) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 289, in _get_good_single_obj ect_ return self._wrap_dispatch_(ob, userName, ReturnCLSID) File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 125, in _wrap_dispatch_ return Dispatch(ob, userName, returnCLSID,None) File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 96, in Dispatch return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx) File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 43, in __WrapDispatch return dynamic.Dispatch(dispatch, userName, WrapperClass, typeinfo, clsctx=clsctx) File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 121, in Dispatch typecomp = typeinfo.GetTypeComp() AttributeError: 'NoneType' object has no attribute 'GetTypeComp' >>> This seems to happen regardless of which version of pywin32 I use, or whether I run it from ipython, or the normal python console. It does actually perform the desired action of opening a new project in the CST program, and it seems that the error has something to do with the returned value which I need for further communication over the COM interface. I also tried using the comtypes package, which results in the following code: Set app = CreateObject ("CSTStudio.Application") Set mws = app.NewMWS This results in the following error output: Traceback (most recent call last): File "C:\Documents and Settings\dap124\Desktop\cst_com.py", line 23, in cst.NewMWS() File "C:\Python25\Lib\site-packages\comtypes\client\dynamic.py", line 95, in __getattr__ result = self._comobj.Invoke(dispid, _invkind=flags) File "C:\Python25\Lib\site-packages\comtypes\automation.py", line 699, in Invoke return result._get_value(dynamic=True) File "C:\Python25\Lib\site-packages\comtypes\automation.py", line 349, in _get_value return Dispatch(ptr) File "C:\Python25\Lib\site-packages\comtypes\client\dynamic.py", line 28, in Dispatch tinfo = obj.GetTypeInfo(0) File "C:\Python25\Lib\site-packages\comtypes\automation.py", line 599, in GetTypeInfo return result.QueryInterface(comtypes.typeinfo.ITypeInfo) File "C:\Python25\Lib\site-packages\comtypes\__init__.py", line 1069, in QueryInterface self.__com_QueryInterface(byref(iid), byref(p)) ValueError: NULL COM pointer access >>> Does anyone have any suggestions as to why python is failing here? I appreciate that it is hard to know what a closed source program is doing with it's interface, but if anyone understands anything from the above error messages which may help me, then I would be most appreciative regards David From neta.shaer at intel.com Tue Feb 17 08:17:37 2009 From: neta.shaer at intel.com (Shaer, Neta) Date: Tue, 17 Feb 2009 09:17:37 +0200 Subject: [python-win32] passing 'small' integers as 64 bit integers to COM functions Message-ID: <08D365F074934A4D970C60E2E6986DA93315E0E3@hasmsx502.ger.corp.intel.com> Hello, I'm using python 2.5 on windows (32 bit). I'm using some COM object from python. One of the functions in this COM objects expects VARIANT and operate according to the type of this VARIANT. The thing is that it does one thing if the VARIANT type is VT_UI4 (32 bit integer) and a different thing for VARIANT of type VT_UI8 (64 bit integer). The python code that calls this function 'knows' what should be the type of the VARIANT. and in certain cases, the type of the VARIANT should be VT_UI8 (64 bit), though the actual value of the variable is small (i.e. can be contained in 32 bit). But in these cases python will automatically set the type of this variant to VT_UI4 and this will cause the COM function to do the wrong thing (and eventually fail). Is there any way to 'force' python to pass this VARIANT as VT_UI8 though its value is very small? Thanks a lot, Neta. --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed Feb 18 00:55:53 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 18 Feb 2009 10:55:53 +1100 Subject: [python-win32] passing 'small' integers as 64 bit integers to COM functions In-Reply-To: <08D365F074934A4D970C60E2E6986DA93315E0E3@hasmsx502.ger.corp.intel.com> References: <08D365F074934A4D970C60E2E6986DA93315E0E3@hasmsx502.ger.corp.intel.com> Message-ID: <499B4E89.2030303@gmail.com> On 17/02/2009 6:17 PM, Shaer, Neta wrote: > Hello, > > I?m using python 2.5 on windows (32 bit). > > I'm using some COM object from python. > One of the functions in this COM objects expects VARIANT and operate > according to the type of this VARIANT. > The thing is that it does one thing if the VARIANT type is VT_UI4 (32 > bit integer) and a different thing for VARIANT of type VT_UI8 (64 bit > integer). > The python code that calls this function 'knows' what should be the type > of the VARIANT. and in certain cases, the type of the VARIANT should be > VT_UI8 (64 bit), though the actual value of the variable is small (i.e. > can be contained in 32 bit). But in these cases python will > automatically set the type of this variant to VT_UI4 and this will cause > the COM function to do the wrong thing (and eventually fail). > Is there any way to 'force' python to pass this VARIANT as VT_UI8 though > its value is very small? No - infact pywin32 doesn't support VT_UI8 at all - but it will use VT_I8 only when the value doesn't fit in 32 bits. Note that MS documents *both* VT_I8 and VT_UI8 as being an invalid type in a variant: from WTypes.h: * VARENUM usage key, * * * [V] - may appear in a VARIANT * * [T] - may appear in a TYPEDESC * * [P] - may appear in an OLE property set * * [S] - may appear in a Safe Array ... * VT_I1 [V][T][P][s] signed char * VT_UI1 [V][T][P][S] unsigned char * VT_UI2 [V][T][P][S] unsigned short * VT_UI4 [V][T][P][S] unsigned long * VT_I8 [T][P] signed 64-bit int * VT_UI8 [T][P] unsigned 64-bit int So it would appear our support for even VT_I8 is suspect. To make matters less clear, we only support VT_I8 when *creating* a variant - we do not attempt to unpack VT_I8 or VT_UI8 from an incoming variant at all - in general we only support those explicitly declared by MS to be valid in variants (although there is almost no risk in accepting unsupported types on the way in that I can see) BTW: it wouldn't be hard to argue that the COM object in question is insane - that the size of the integer passed shouldn't impact how it operates - but I guess it is what it is... Cheers, Mark From vinaya at adobe.com Wed Feb 18 01:25:21 2009 From: vinaya at adobe.com (Vinay Anantharaman) Date: Tue, 17 Feb 2009 16:25:21 -0800 Subject: [python-win32] Error with VixCom operation; TypeError: The VARIANT type is unknown (0x00000015) Message-ID: Hi, I am trying to translate an error into text by using a library function in vix com: http://www.vmware.com/products/beta/vmware_server/vix_api/ReferenceGuide/lang/com/functions/GetErrorText.html My code is as follows: vixLib = win32com.client.gencache.EnsureDispatch('VixCom.VixLib') vixLib.GetErrorText(4, None) Instead of getting some explanation that a file was not found I get an exception: File "C:\Users\vinaya\AppData\Local\Temp\gen_py\2.4\7A474EE3-0062-4239-AE91-134AC9BD5FD3x0x1x0.py", line 1316, in GetErrorText , locale) TypeError: The VARIANT type is unknown (0x00000015) The code in that function is: def GetErrorText(self, err=defaultNamedNotOptArg, locale=defaultNamedNotOptArg): """method GetErrorText""" # Result is a Unicode object - return as-is for this version of Python return self._oleobj_.InvokeTypes(2, LCID, 1, (8, 0), ((21, 1), (8, 1)),err , locale) I'm not really sure what to do. Instead of using the library I can create a small script to take the error codes from the HTML documentation and convert it into a dictionary. But that is a hassle to maintain. Thanks, Vinay Anantharaman From timr at probo.com Wed Feb 18 01:40:13 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 17 Feb 2009 16:40:13 -0800 Subject: [python-win32] Error with VixCom operation; TypeError: The VARIANT type is unknown (0x00000015) In-Reply-To: References: Message-ID: <499B58ED.8050902@probo.com> Vinay Anantharaman wrote: > Hi, > > I am trying to translate an error into text by using a library function in vix com: > http://www.vmware.com/products/beta/vmware_server/vix_api/ReferenceGuide/lang/com/functions/GetErrorText.html > > My code is as follows: > vixLib = win32com.client.gencache.EnsureDispatch('VixCom.VixLib') > vixLib.GetErrorText(4, None) > > Instead of getting some explanation that a file was not found I get an exception: > File "C:\Users\vinaya\AppData\Local\Temp\gen_py\2.4\7A474EE3-0062-4239-AE91-134AC9BD5FD3x0x1x0.py", line 1316, in GetErrorText > , locale) > TypeError: The VARIANT type is unknown (0x00000015) > It's ironic that you posted this the same day as the other recent COM question, because it is exactly the same problem. VARIANT type 0x15 is VT_UI8 -- a 64-bit integer. It's kind of loony for an API to use a 64-bit integer as an error number, but that's what they're doing. As Mark said, pywin32 doesn't support VT_UI8 at all. There may be a hacky way to do this with comtypes. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From greg.ewing at canterbury.ac.nz Wed Feb 18 04:18:12 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 18 Feb 2009 16:18:12 +1300 Subject: [python-win32] Error with VixCom operation; TypeError: The VARIANT type is unknown (0x00000015) In-Reply-To: <499B58ED.8050902@probo.com> References: <499B58ED.8050902@probo.com> Message-ID: <499B7DF4.6060504@canterbury.ac.nz> Tim Roberts wrote: > It's kind of loony for an API to use a > 64-bit integer as an error number, but that's what they're doing. This is Windows, remember. There are large numbers of things that can go wrong. -- Greg From blade.eric at gmail.com Wed Feb 18 12:56:03 2009 From: blade.eric at gmail.com (Eric Blade) Date: Wed, 18 Feb 2009 06:56:03 -0500 Subject: [python-win32] ReadDirectoryChangesW Message-ID: <59ce684e0902180356l1925712ei74766fa6899f7623@mail.gmail.com> hi all.. sorry, i haven't been able to get back here, we've had a bunch of issues in life (work, car death, children, etc) and i haven't been able to spend a lot of time working on this .. was there anything obvious that i'm doing with the Windows calls? that's the only place that I can figure out that might be causing the issue, is either (a) the system call itself is unreliable (b) python's version is unreliable or most likely (c) i'm calling something incorrectly, or expecting/processing the results incorrectly i've been trying to get a standalone version of the code to work, but i can't seem to get anything that doesn't just spew errors, so far. but, then, i've only had about 15 minutes since my last message to dink around with it .. so, i'm going to try to mess with it some more in what little time i do find, and hope maybe someone glances at it, and goes "like duh, it's right here." :D http://pastebin.ca/1331850 -- Cheers, - Eric From theller at ctypes.org Thu Feb 19 22:29:42 2009 From: theller at ctypes.org (Thomas Heller) Date: Thu, 19 Feb 2009 22:29:42 +0100 Subject: [python-win32] Error with VixCom operation; TypeError: The VARIANT type is unknown (0x00000015) In-Reply-To: <499B58ED.8050902@probo.com> References: <499B58ED.8050902@probo.com> Message-ID: Tim Roberts schrieb: > Vinay Anantharaman wrote: >> Hi, >> >> I am trying to translate an error into text by using a library function in vix com: >> http://www.vmware.com/products/beta/vmware_server/vix_api/ReferenceGuide/lang/com/functions/GetErrorText.html >> >> My code is as follows: >> vixLib = win32com.client.gencache.EnsureDispatch('VixCom.VixLib') >> vixLib.GetErrorText(4, None) >> >> Instead of getting some explanation that a file was not found I get an exception: >> File "C:\Users\vinaya\AppData\Local\Temp\gen_py\2.4\7A474EE3-0062-4239-AE91-134AC9BD5FD3x0x1x0.py", line 1316, in GetErrorText >> , locale) >> TypeError: The VARIANT type is unknown (0x00000015) >> > > It's ironic that you posted this the same day as the other recent COM > question, because it is exactly the same problem. VARIANT type 0x15 is > VT_UI8 -- a 64-bit integer. It's kind of loony for an API to use a > 64-bit integer as an error number, but that's what they're doing. > > As Mark said, pywin32 doesn't support VT_UI8 at all. There may be a > hacky way to do this with comtypes. I don't see anything hacky here; but ymmv: c:\sf\comtypes>py25 Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from comtypes.client import CreateObject >>> d = CreateObject("VixCom.VixLib") # Generating comtypes.gen._7A474EE3_0062_4239_AE91_134AC9BD5FD3_0_1_0 # Generating comtypes.gen._00020430_0000_0000_C000_000000000046_0_2_0 # Generating comtypes.gen.stdole # Generating comtypes.gen.VixCOM >>> from comtypes.gen import VixCOM >>> d.GetErrorText(4, None) Traceback (most recent call last): File "", line 1, in _ctypes.COMError: (-2147417851, 'Ausnahmefehler des Servers.', (None, None, None, 0, None)) >>> d.Connect(1, VixCOM.VIX_SERVICEPROVIDER_VMWARE_SERVER, "", 0, "", "", 0, None, None) >>> d.GetErrorText(4, None) u'A file was not found' >>> The first d.GetErrorText call fails because not all libraries are loaded when Connect has not yet been executed; according to this thread: http://communities.vmware.com/message/650022 -- Thanks, Thomas From contact at tejerodgers.com Fri Feb 20 22:10:38 2009 From: contact at tejerodgers.com (=?iso-8859-1?Q?Te-j=E9_Rodgers?=) Date: Fri, 20 Feb 2009 17:10:38 -0400 Subject: [python-win32] Accessing Interfaces Message-ID: <000001c9939f$af9fac10$0edf0430$@com> I don?t know if I?m in the right place. Basically I?m doing some messing about in the Windows API which has been going fine so far, but then I noticed most of the newer APIs require interfaces, like this one: http://msdn.microsoft.com/en-us/library/dd368183(VS.85).aspx. I?d like to know how I would be able to wrap and use those from Python. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Feb 20 22:38:04 2009 From: timr at probo.com (Tim Roberts) Date: Fri, 20 Feb 2009 13:38:04 -0800 Subject: [python-win32] Accessing Interfaces In-Reply-To: <000001c9939f$af9fac10$0edf0430$@com> References: <000001c9939f$af9fac10$0edf0430$@com> Message-ID: <499F22BC.4050907@probo.com> Te-j? Rodgers wrote: > > I don?t know if I?m in the right place. Basically I?m doing some > messing about in the Windows API which has been going fine so far, but > then I noticed most of the newer APIs require interfaces, like this > one: http://msdn.microsoft.com/en-us/library/dd368183(VS.85).aspx > . > > > > I?d like to know how I would be able to wrap and use those from Python. > PyWin32 has always supported COM interfaces, as long as they support late binding (meaning IDispatch). These DirectWrite interfaces are still in beta (they are Win 7 only), so I seriously doubt anyone has played with them enough to know whether they do IDispatch. If they don't, it's always (well, almost always) possible to handle these with ctypes and comtypes. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Feb 20 23:56:38 2009 From: timr at probo.com (Tim Roberts) Date: Fri, 20 Feb 2009 14:56:38 -0800 Subject: [python-win32] Accessing Interfaces In-Reply-To: <000e01c993aa$5ded83a0$19c88ae0$@com> References: <000001c9939f$af9fac10$0edf0430$@com> <499F22BC.4050907@probo.com> <000e01c993aa$5ded83a0$19c88ae0$@com> Message-ID: <499F3526.4090807@probo.com> Te-j? Rodgers wrote: > Could you point me to an example of how to use COM interfaces with pywin32? I've skimmed the documentation but it seems to be geared at someone who already knows what he's doing. > It's not really all that complicated, in general, because PyWin32 automatically generates "wrapper" classes to hide the ugly details. Here's a quick example of how to use COM to open up Word, make it visible, and enter a few characters of text. You can even type this at the interactive prompt to watch the progress: import win32com.client word = win32com.client.Dispatch( "Word.Application" ) word.Visible = 1 word.Selection.TypeText( Text="abc" ) "word" in that code is a COM object. As you can see, once you HAVE the object, you just treat it like a Python object. Pythoncom takes care of the mapping. However, in the case of DirectWrite, things are a little more complicated, because you can't use the normal win32com Dispatch mechanism to create the object. You have to use DWriteCreateFactory. And because it's only in Windows 7, DWriteCreateFactory is not in any of the pywin32 wrappers yet. So, if you really need to do this with Python, you will end up using ctypes to call DWriteCreateFactory, and ctypes/comtypes to call the member functions. Are you sure you want to do this? ;) Until someone writes a wrapper layer, it would probably be more productive for you to use C++. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From contact at tejerodgers.com Sat Feb 21 00:20:24 2009 From: contact at tejerodgers.com (=?utf-8?Q?Te-j=C3=A9_Rodgers?=) Date: Fri, 20 Feb 2009 19:20:24 -0400 Subject: [python-win32] Accessing Interfaces In-Reply-To: <499F3526.4090807@probo.com> References: <000001c9939f$af9fac10$0edf0430$@com> <499F22BC.4050907@probo.com> <000e01c993aa$5ded83a0$19c88ae0$@com> <499F3526.4090807@probo.com> Message-ID: <000001c993b1$d1829420$7487bc60$@com> I think you may be right, but I always dread working with C++. Thanks for the help anyway. -----Original Message----- From: Tim Roberts [mailto:timr at probo.com] Sent: Friday, February 20, 2009 6:57 PM To: Python-Win32 List Subject: Re: [python-win32] Accessing Interfaces Te-j? Rodgers wrote: > Could you point me to an example of how to use COM interfaces with pywin32? I've skimmed the documentation but it seems to be geared at someone who already knows what he's doing. > It's not really all that complicated, in general, because PyWin32 automatically generates "wrapper" classes to hide the ugly details. Here's a quick example of how to use COM to open up Word, make it visible, and enter a few characters of text. You can even type this at the interactive prompt to watch the progress: import win32com.client word = win32com.client.Dispatch( "Word.Application" ) word.Visible = 1 word.Selection.TypeText( Text="abc" ) "word" in that code is a COM object. As you can see, once you HAVE the object, you just treat it like a Python object. Pythoncom takes care of the mapping. However, in the case of DirectWrite, things are a little more complicated, because you can't use the normal win32com Dispatch mechanism to create the object. You have to use DWriteCreateFactory. And because it's only in Windows 7, DWriteCreateFactory is not in any of the pywin32 wrappers yet. So, if you really need to do this with Python, you will end up using ctypes to call DWriteCreateFactory, and ctypes/comtypes to call the member functions. Are you sure you want to do this? ;) Until someone writes a wrapper layer, it would probably be more productive for you to use C++. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From rdahlstrom at directedge.com Sat Feb 21 00:27:55 2009 From: rdahlstrom at directedge.com (Dahlstrom, Roger) Date: Fri, 20 Feb 2009 18:27:55 -0500 Subject: [python-win32] Accessing Interfaces In-Reply-To: <000001c993b1$d1829420$7487bc60$@com> References: <000001c9939f$af9fac10$0edf0430$@com> <499F22BC.4050907@probo.com> <000e01c993aa$5ded83a0$19c88ae0$@com> <499F3526.4090807@probo.com> <000001c993b1$d1829420$7487bc60$@com> Message-ID: <70D9B06B9E99EE4E98E4893703ADA14111CC132F3A@EXCHANGE1.global.knight.com> That would be Python. -----Original Message----- From: python-win32-bounces+rdahlstrom=directedge.com at python.org [mailto:python-win32-bounces+rdahlstrom=directedge.com at python.org] On Behalf Of Te-j? Rodgers Sent: Friday, February 20, 2009 6:20 PM To: python-win32 at python.org Subject: Re: [python-win32] Accessing Interfaces I think you may be right, but I always dread working with C++. Thanks for the help anyway. -----Original Message----- From: Tim Roberts [mailto:timr at probo.com] Sent: Friday, February 20, 2009 6:57 PM To: Python-Win32 List Subject: Re: [python-win32] Accessing Interfaces Te-j? Rodgers wrote: > Could you point me to an example of how to use COM interfaces with pywin32? I've skimmed the documentation but it seems to be geared at someone who already knows what he's doing. > It's not really all that complicated, in general, because PyWin32 automatically generates "wrapper" classes to hide the ugly details. Here's a quick example of how to use COM to open up Word, make it visible, and enter a few characters of text. You can even type this at the interactive prompt to watch the progress: import win32com.client word = win32com.client.Dispatch( "Word.Application" ) word.Visible = 1 word.Selection.TypeText( Text="abc" ) "word" in that code is a COM object. As you can see, once you HAVE the object, you just treat it like a Python object. Pythoncom takes care of the mapping. However, in the case of DirectWrite, things are a little more complicated, because you can't use the normal win32com Dispatch mechanism to create the object. You have to use DWriteCreateFactory. And because it's only in Windows 7, DWriteCreateFactory is not in any of the pywin32 wrappers yet. So, if you really need to do this with Python, you will end up using ctypes to call DWriteCreateFactory, and ctypes/comtypes to call the member functions. Are you sure you want to do this? ;) Until someone writes a wrapper layer, it would probably be more productive for you to use C++. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From venutaurus539 at gmail.com Mon Feb 23 05:14:45 2009 From: venutaurus539 at gmail.com (venu madhav) Date: Mon, 23 Feb 2009 09:44:45 +0530 Subject: [python-win32] Help required in opening a remote file in python. Message-ID: Hello all, I am writing an application where I need to open a shared file on a remote machine using python script. I tried using the following function: f = urllib.open("\\remote_machine\\folder1\\file1.doc") I also tried using class urllib.FancyURLopener(...) but didn't work. Can some one help me in this regard. Thank you in advance, Venu -------------- next part -------------- An HTML attachment was scrubbed... URL: From gerdusvanzyl at gmail.com Mon Feb 23 07:43:31 2009 From: gerdusvanzyl at gmail.com (Gerdus van Zyl) Date: Mon, 23 Feb 2009 08:43:31 +0200 Subject: [python-win32] Help required in opening a remote file in python. In-Reply-To: References: Message-ID: <91882ea90902222243y23676b47ycc6977009145a58e@mail.gmail.com> Try using the normal file access functions, eg: open("file","r"), etc. ~G On Mon, Feb 23, 2009 at 6:14 AM, venu madhav wrote: > Hello all, I am writing an application where I need to open a shared file on > a remote machine using python script. I tried using the following function: > f = urllib.open("\\remote_machine\\folder1\\file1.doc") I also tried using > class urllib.FancyURLopener(...) but didn't work. Can some one help me in > this regard. Thank you in advance, Venu > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > From Andrew.MacIntyre at acma.gov.au Mon Feb 23 08:45:03 2009 From: Andrew.MacIntyre at acma.gov.au (Andrew MacIntyre) Date: Mon, 23 Feb 2009 18:45:03 +1100 Subject: [python-win32] Help required in opening a remote file in python. [SEC=PERSONAL] In-Reply-To: References: Message-ID: <7B01D7143C4AD54899EA079D4557562AFEF5E5@ACT01EXC02.internal.govt> > Hello all, I am writing an application where I need to open a shared > file on a remote machine using python script. I tried using the > following function: f = > urllib.open("\\remote_machine\\folder1\\file1.doc") I also tried using > class urllib.FancyURLopener(...) but didn't work. > Can some one help me in this regard. Thank you in advance, Venu If it's a shared file on a Windows network (which I'm inferring), provided you have the necessary access permissions, use open("\\\\remote_machine\\share\\folder\\file", "r") ^^^^ Note that UNC names do require a double backslash to start... Its often easier to read as open(r"\\remote_machine\share\folder\file", "r") If you really must open it via urllib, then try urllib.open("file://remote_machine/share/folder/file") -------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre National Licensing and Allocations Branch tel: +61 2 6219 5356 Inputs to Industry Division fax: +61 2 6253 3277 Australian Communications & Media Authority email: andrew.macintyre at acma.gov.au If you have received this email in error, please notify the sender immediately and erase all copies of the email and any attachments to it. The information contained in this email and any attachments may be private, confidential and legally privileged or the subject of copyright. If you are not the addressee it may be illegal to review, disclose, use, forward, or distribute this email and/or its contents. Unless otherwise specified, the information in the email and any attachments is intended as a guide only and should not be relied upon as legal or technical advice or regarded as a substitute for legal or technical advice in individual cases. Opinions contained in this email or any of its attachments do not necessarily reflect the opinions of ACMA. From rdahlstrom at directedge.com Mon Feb 23 12:56:16 2009 From: rdahlstrom at directedge.com (Dahlstrom, Roger) Date: Mon, 23 Feb 2009 06:56:16 -0500 Subject: [python-win32] Help required in opening a remote file in python. In-Reply-To: References: Message-ID: <70D9B06B9E99EE4E98E4893703ADA14111CC132F5B@EXCHANGE1.global.knight.com> It would be much easier for us to help if we could see your code, and the error you receive when you try to run it. ________________________________ From: python-win32-bounces+rdahlstrom=directedge.com at python.org [mailto:python-win32-bounces+rdahlstrom=directedge.com at python.org] On Behalf Of venu madhav Sent: Sunday, February 22, 2009 11:15 PM To: Python-Win32 List Subject: [python-win32] Help required in opening a remote file in python. Hello all, I am writing an application where I need to open a shared file on a remote machine using python script. I tried using the following function: f = urllib.open("\\remote_machine\\folder1\\file1.doc") I also tried using class urllib.FancyURLopener(...) but didn't work. Can some one help me in this regard. Thank you in advance, Venu -------------- next part -------------- An HTML attachment was scrubbed... URL: From venutaurus539 at gmail.com Mon Feb 23 14:54:36 2009 From: venutaurus539 at gmail.com (venu madhav) Date: Mon, 23 Feb 2009 19:24:36 +0530 Subject: [python-win32] Problem in finding the attributes of file with name in non english characters. Message-ID: Hi all, I am trying to find the attributes of afile whose name has non english characters one like given below. When I try to run my python scirpt, it fails giving out an error filename must be in string or UNICODE. When i try to copy the name of the file as a strinig, it (KOMODO IDE) is not allowing me to save the script saying that it cannot convert some of the characters in the current encoding which is Western European(CP-1252). 0010testUnicode_???????????????????? !#$%&'()+,-. 0123456789;=@ABCD.txt.txt Hope some one could help me in this regard. Thank you in advance, Venu Madhav -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Mon Feb 23 15:31:26 2009 From: vernondcole at gmail.com (Vernon Cole) Date: Mon, 23 Feb 2009 07:31:26 -0700 Subject: [python-win32] Help required in opening a remote file in python. In-Reply-To: <91882ea90902222243y23676b47ycc6977009145a58e@mail.gmail.com> References: <91882ea90902222243y23676b47ycc6977009145a58e@mail.gmail.com> Message-ID: Yes, if you are normal Windows shared files, you should be using normal file access functions. But your file name is incorrectly formatted. The name of the remote computer must have TWO leading backslashes, which is Windows' cue that you want a remote file. Python will convert forward slashes ("/") into the backslashes ("\") which windows requires, so you can do it three different ways. You can: 1) use slashes, and let python convert: >>> f=open("//remote_machine/folder1/file1.doc", "r") 2) use backslash escapes doubled, so you type four to get two: >>> f=open("\\\\remote_machine\\folder1\\file1.doc", "r") 3) use a python "raw" string which eliminates backslash escapes entirely so that you can type the string as windows will see it (note the letter "r" before first quote): >>> f=open( r"\\remote_machine\folder1\file1.doc", "r") -- Vernon Cole On Sun, Feb 22, 2009 at 11:43 PM, Gerdus van Zyl wrote: > Try using the normal file access functions, eg: open("file","r"), etc. > > ~G > > On Mon, Feb 23, 2009 at 6:14 AM, venu madhav > wrote: > > Hello all, I am writing an application where I need to open a shared file > on > > a remote machine using python script. I tried using the following > function: > > f = urllib.open("\\remote_machine\\folder1\\file1.doc") I also tried > using > > class urllib.FancyURLopener(...) but didn't work. Can some one help me in > > this regard. Thank you in advance, Venu > > > > _______________________________________________ > > python-win32 mailing list > > python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Tue Feb 24 00:44:04 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 24 Feb 2009 10:44:04 +1100 Subject: [python-win32] pywin32 build 213 released In-Reply-To: <001c01c99035$330e6e60$992b4b20$@com.au> References: <001c01c99035$330e6e60$992b4b20$@com.au> Message-ID: <49A334C4.50207@gmail.com> On 16/02/2009 11:50 PM, Mark Hammond wrote: > Hi all, > I'm extremely happy to announce the release of pywin32 build 213 - the > first release of pywin32 with support for Python 3.x. > > This release has a large number of changes and should, in general, be > considered BETA quality ... I'm not sure if my BETA warning has put people off from trying it, but I believe there hasn't been a single report of a regression in this build :) So if I did put you off, please give it a go... Cheers, Mark From jesus at aguillon.com Tue Feb 24 01:37:43 2009 From: jesus at aguillon.com (Jesus Aguillon) Date: Mon, 23 Feb 2009 16:37:43 -0800 Subject: [python-win32] pywin32 build 213 released In-Reply-To: <49A334C4.50207@gmail.com> References: <001c01c99035$330e6e60$992b4b20$@com.au> <49A334C4.50207@gmail.com> Message-ID: It did for me :) But now I'll give it a go! On Mon, Feb 23, 2009 at 3:44 PM, Mark Hammond wrote: > On 16/02/2009 11:50 PM, Mark Hammond wrote: > >> Hi all, >> I'm extremely happy to announce the release of pywin32 build 213 - the >> first release of pywin32 with support for Python 3.x. >> >> This release has a large number of changes and should, in general, be >> considered BETA quality ... >> > > I'm not sure if my BETA warning has put people off from trying it, but I > believe there hasn't been a single report of a regression in this build :) > > So if I did put you off, please give it a go... > > Cheers, > > Mark > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- But the fact that some geniuses were laughed at does not imply that all who are laughed at are geniuses. They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown. - Carl Sagan -------------- next part -------------- An HTML attachment was scrubbed... URL: From venutaurus539 at gmail.com Tue Feb 24 04:28:29 2009 From: venutaurus539 at gmail.com (venu madhav) Date: Tue, 24 Feb 2009 08:58:29 +0530 Subject: [python-win32] opening files with names in non-english characters. In-Reply-To: <50697b2c0902231002k28b4f2dfs4b4bbf38e569511f@mail.gmail.com> References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> <50697b2c0902231002k28b4f2dfs4b4bbf38e569511f@mail.gmail.com> Message-ID: Hello, First of all thanks for your response. I've written a function as shown below to recurse a directory and return a file based on the value of n. I am calling this fucntion from my main code to catch that filename. The folder which it recurses through contains a folder having files with unicode names (as an example i've given earlier. ----------------------------------------------------------------------------- def findFile(dir_path): for name in os.listdir(dir_path): full_path = os.path.join(dir_path, name) print full_path if os.path.isdir(full_path): findFile(full_path) else: n = n - 1 if(n ==0): return full_path -------------------------------------------------------------------------------------------------- The problem is in the return statement. In the function when I tried to print the file name, it is printing properly but the receiving variable is not getting populated with the file name. The below code (1st statement) shows the value of the full_path variable while the control is at the return statement. The second statement is in the main code from where the function call has been made. Once the control has reached the main procedure after executing the findFile procedure, the third statement gives the status of file variable which has type as NoneType and value as None. Now when I try to check if the path exists, it fails giving the below trace back. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder\0003testUnicode_??I?NOK?????U???UU?a??????ic?e?e??idnok?????u???uu.txt.txt ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ file = findFile(fpath) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- file NoneType None ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- This is the final trace back: Traceback (most recent call last): File "C:\RecallStubFopen.py", line 268, in if os.path.exists(file): File "C:\Python26\lib\genericpath.py", line 18, in exists st = os.stat(path) TypeError: coercing to Unicode: need string or buffer, NoneType found --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Please ask if you need any further information. Thank you, Venu On Mon, Feb 23, 2009 at 11:32 PM, Chris Rebert wrote: > On Mon, Feb 23, 2009 at 5:51 AM, venutaurus539 at gmail.com > wrote: > > Hi all, > > I am trying to find the attributes of afile whose name has > > non english characters one like given below. When I try to run my > > python scirpt, it fails giving out an error filename must be in string > > or UNICODE. When i try to copy the name of the file as a strinig, it > > (KOMODO IDE) is not allowing me to save the script saying that it > > cannot convert some of the characters in the current encoding which is > > Western European(CP-1252). > > > > 0010testUnicode_???????????????????? !#$%&'()+,-. > > 0123456789;=@ABCD.txt.txt > > (1) How are you entering or retrieving that filename? > (2) Please provide the exact error and Traceback you're getting. > > Cheers, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From metolone+gmane at gmail.com Tue Feb 24 05:52:49 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Mon, 23 Feb 2009 20:52:49 -0800 Subject: [python-win32] pywin32 build 213 released References: <001c01c99035$330e6e60$992b4b20$@com.au> <49A334C4.50207@gmail.com> Message-ID: "Mark Hammond" wrote in message news:49A334C4.50207 at gmail.com... > On 16/02/2009 11:50 PM, Mark Hammond wrote: >> Hi all, >> I'm extremely happy to announce the release of pywin32 build 213 - the >> first release of pywin32 with support for Python 3.x. >> >> This release has a large number of changes and should, in general, be >> considered BETA quality ... > > I'm not sure if my BETA warning has put people off from trying it, but I > believe there hasn't been a single report of a regression in this build :) > > So if I did put you off, please give it a go... > > Cheers, > > Mark I'm using it, and love the Unicode support. It still has a problem with backspacing over non-ascii characters such as Chinese in the editor, by deleting byte-at-a-time instead of character-at-a-time. It will throw exceptions in the interpreter window as the bytes are backspaced over. It works fine in the interpreter window. I filed a bug and found and posted an update that works for me, but may not be the best solution. I'm not familiar with Scintilla. I also noticed that the default encoding for saves is latin1 in both 2.x and 3.x versions. Shouldn't it be ascii for 2.x and utf8 for 3.x if a #coding declaration isn't present? I like that the editor recognizes the #coding line and saves in the requested encoding. -Mark From gerdusvanzyl at gmail.com Tue Feb 24 08:19:17 2009 From: gerdusvanzyl at gmail.com (Gerdus van Zyl) Date: Tue, 24 Feb 2009 09:19:17 +0200 Subject: [python-win32] opening files with names in non-english characters. In-Reply-To: References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> <50697b2c0902231002k28b4f2dfs4b4bbf38e569511f@mail.gmail.com> Message-ID: <91882ea90902232319l7421b12v34f3ac824211bf0b@mail.gmail.com> I see a couple of problems with your code: 1. where is n first given a value and what is it total file count, etc? also you decrement the value, do you want the last file in the directory or something? 2. The if os.path.isdir(full_path): .. findFile(full_path) part doesn't return or handle the value so it's not useful so far i can see. So you either need to "return findFile(full_path) " or "value = findFile(full_path)" 3. I am not sure of your usage of n, the way i do similiar things is to build a list and then just get the item i want by index or slicing. ~g On Tue, Feb 24, 2009 at 5:28 AM, venu madhav wrote: > Hello, > ?? ? ? ?First of all thanks for your response. I've written a function as > shown below to recurse a directory and return a file based on the value of > n. I am calling this fucntion from my main code to catch that filename. The > folder which it recurses through contains a folder having files with unicode > names (as an example i've given earlier. > ----------------------------------------------------------------------------- > def findFile(dir_path): > ?? ?for name in os.listdir(dir_path): > ?? ? ? ?full_path = os.path.join(dir_path, name) > ?? ? ? ?print full_path > ?? ? ? ?if os.path.isdir(full_path): > ?? ? ? ? ? ?findFile(full_path) > ?? ? ? ?else: > ?? ? ? ? ? ?n = n - 1 > ?? ? ? ? ? ?if(n ==0): > ?? ? ? ? ? ? ? ?return full_path > -------------------------------------------------------------------------------------------------- > ?? ? ? ? ? ? ? ? ? ?The problem is in the return statement. In the function > when I tried to print the file name, it is printing properly but the > receiving variable is not getting populated with the file name. The below > code (1st statement) shows the value of the full_path variable while the > control is at the return statement. The second statement is in the main code > from where the function call has been made. > Once the control has reached the main procedure after executing the findFile > procedure, the third statement gives the status of file variable which has > type as NoneType and value as None. Now when I try to check if the path > exists, it fails giving the below trace back. > ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder\0003testUnicode_??I?NOK?????U???UU?a??????ic?e?e??idnok?????u???uu.txt.txt > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ > file = findFile(fpath) > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > file > NoneType > None > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > This is the final trace back: > Traceback (most recent call last): > ??File "C:\RecallStubFopen.py", line 268, in > ?? ?if os.path.exists(file): > ??File "C:\Python26\lib\genericpath.py", line 18, in exists > ?? ?st = os.stat(path) > TypeError: coercing to Unicode: need string or buffer, NoneType found > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > Please ask if you need any further information. > > Thank you, > Venu > > > > > > > > On Mon, Feb 23, 2009 at 11:32 PM, Chris Rebert wrote: >> >> On Mon, Feb 23, 2009 at 5:51 AM, venutaurus539 at gmail.com >> wrote: >> > Hi all, >> > ? ? ? ? ?I am trying to find the attributes of afile whose name has >> > non english characters one like given below. When I try to run my >> > python scirpt, it fails giving out an error filename must be in string >> > or UNICODE. When i try to copy the name of the file as a strinig, it >> > (KOMODO IDE) is not allowing me to save the script saying that it >> > cannot convert some of the characters in the current encoding which is >> > Western European(CP-1252). >> > >> > 0010testUnicode_???????????????????? !#$%&'()+,-. >> > 0123456789;=@ABCD.txt.txt >> >> (1) How are you entering or retrieving that filename? >> (2) Please provide the exact error and Traceback you're getting. >> >> Cheers, >> Chris >> >> -- >> Follow the path of the Iguana... >> http://rebertia.com > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > From venutaurus539 at gmail.com Tue Feb 24 08:27:31 2009 From: venutaurus539 at gmail.com (venu madhav) Date: Tue, 24 Feb 2009 12:57:31 +0530 Subject: [python-win32] opening files with names in non-english characters. In-Reply-To: <91882ea90902232319l7421b12v34f3ac824211bf0b@mail.gmail.com> References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> <50697b2c0902231002k28b4f2dfs4b4bbf38e569511f@mail.gmail.com> <91882ea90902232319l7421b12v34f3ac824211bf0b@mail.gmail.com> Message-ID: Hello, The value of n is initialized in the main procedure which calls it. Basically I am trying to find the n'th file in the directory(can be in its sub directories too). As I've given the previous mail itself file = findFile(path) invokes that function.When the path is a directory it just recurses into it. And coming to your idea of storing all the items in a list can't be used here because my folder contain thousands of files and storing them in a list would eat up my memory. Thanks for your suggestions, Venu On Tue, Feb 24, 2009 at 12:49 PM, Gerdus van Zyl wrote: > I see a couple of problems with your code: > > 1. where is n first given a value and what is it total file count, > etc? also you decrement the value, do you want the last file in the > directory or something? > 2. The if os.path.isdir(full_path): .. findFile(full_path) part > doesn't return or handle the value so it's not useful so far i can > see. So you either need to "return findFile(full_path) " or "value = > findFile(full_path)" > 3. I am not sure of your usage of n, the way i do similiar things is > to build a list and then just get the item i want by index or slicing. > > ~g > > On Tue, Feb 24, 2009 at 5:28 AM, venu madhav > wrote: > > Hello, > > First of all thanks for your response. I've written a function as > > shown below to recurse a directory and return a file based on the value > of > > n. I am calling this fucntion from my main code to catch that filename. > The > > folder which it recurses through contains a folder having files with > unicode > > names (as an example i've given earlier. > > > ----------------------------------------------------------------------------- > > def findFile(dir_path): > > for name in os.listdir(dir_path): > > full_path = os.path.join(dir_path, name) > > print full_path > > if os.path.isdir(full_path): > > findFile(full_path) > > else: > > n = n - 1 > > if(n ==0): > > return full_path > > > -------------------------------------------------------------------------------------------------- > > The problem is in the return statement. In the > function > > when I tried to print the file name, it is printing properly but the > > receiving variable is not getting populated with the file name. The below > > code (1st statement) shows the value of the full_path variable while the > > control is at the return statement. The second statement is in the main > code > > from where the function call has been made. > > Once the control has reached the main procedure after executing the > findFile > > procedure, the third statement gives the status of file variable which > has > > type as NoneType and value as None. Now when I try to check if the path > > exists, it fails giving the below trace back. > > > ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > > E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder\0003testUnicode_??I?NOK?????U???UU?a??????ic?e?e??idnok?????u???uu.txt.txt > > > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ > > file = findFile(fpath) > > > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > file > > NoneType > > None > > > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > This is the final trace back: > > Traceback (most recent call last): > > File "C:\RecallStubFopen.py", line 268, in > > if os.path.exists(file): > > File "C:\Python26\lib\genericpath.py", line 18, in exists > > st = os.stat(path) > > TypeError: coercing to Unicode: need string or buffer, NoneType found > > > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > Please ask if you need any further information. > > > > Thank you, > > Venu > > > > > > > > > > > > > > > > On Mon, Feb 23, 2009 at 11:32 PM, Chris Rebert > wrote: > >> > >> On Mon, Feb 23, 2009 at 5:51 AM, venutaurus539 at gmail.com > >> wrote: > >> > Hi all, > >> > I am trying to find the attributes of afile whose name has > >> > non english characters one like given below. When I try to run my > >> > python scirpt, it fails giving out an error filename must be in string > >> > or UNICODE. When i try to copy the name of the file as a strinig, it > >> > (KOMODO IDE) is not allowing me to save the script saying that it > >> > cannot convert some of the characters in the current encoding which is > >> > Western European(CP-1252). > >> > > >> > 0010testUnicode_???????????????????? !#$%&'()+,-. > >> > 0123456789;=@ABCD.txt.txt > >> > >> (1) How are you entering or retrieving that filename? > >> (2) Please provide the exact error and Traceback you're getting. > >> > >> Cheers, > >> Chris > >> > >> -- > >> Follow the path of the Iguana... > >> http://rebertia.com > > > > > > _______________________________________________ > > python-win32 mailing list > > python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gerdusvanzyl at gmail.com Tue Feb 24 08:39:59 2009 From: gerdusvanzyl at gmail.com (Gerdus van Zyl) Date: Tue, 24 Feb 2009 09:39:59 +0200 Subject: [python-win32] opening files with names in non-english characters. In-Reply-To: References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> <50697b2c0902231002k28b4f2dfs4b4bbf38e569511f@mail.gmail.com> <91882ea90902232319l7421b12v34f3ac824211bf0b@mail.gmail.com> Message-ID: <91882ea90902232339u4d476d46ra3c356dec1303e12@mail.gmail.com> ok, I understand better now, some more points. You need to handle the case that it doesn't find the file after the for loop, one source of a None return. also as mentioned in point 2 when recursing you need to return the result so: if os.path.isdir(full_path): findFile(full_path) becomes if os.path.isdir(full_path): return findFile(full_path) Another thing you need to test is I don't know if you will always receive files and folders in the same order which means that the nth file won't be consistent. On Tue, Feb 24, 2009 at 9:27 AM, venu madhav wrote: > Hello, > ?? ? ? ?The value of n is initialized in the main procedure which calls it. > Basically I am trying to find the n'th file in the directory(can be in its > sub directories too). As I've given the previous mail itself > file = findFile(path) > ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? invokes that function.When the path is a > directory it just recurses into it. And coming to your idea of storing all > the items in a list can't be used here because my folder contain thousands > of files and storing them in a list would eat up my memory. > Thanks for your suggestions, > Venu > On Tue, Feb 24, 2009 at 12:49 PM, Gerdus van Zyl > wrote: >> >> I see a couple of problems with your code: >> >> 1. where is n first given a value and what is it total file count, >> etc? also you decrement the value, do you want the last file in the >> directory or something? >> 2. The if os.path.isdir(full_path): .. findFile(full_path) part >> doesn't return or handle the value so it's not useful so far i can >> see. So you either need to "return findFile(full_path) " or "value = >> findFile(full_path)" >> 3. I am not sure of your usage of n, the way i do similiar things is >> to build a list and then just get the item i want by index or slicing. >> >> ~g >> >> On Tue, Feb 24, 2009 at 5:28 AM, venu madhav >> wrote: >> > Hello, >> > ?? ? ? ?First of all thanks for your response. I've written a function >> > as >> > shown below to recurse a directory and return a file based on the value >> > of >> > n. I am calling this fucntion from my main code to catch that filename. >> > The >> > folder which it recurses through contains a folder having files with >> > unicode >> > names (as an example i've given earlier. >> > >> > ----------------------------------------------------------------------------- >> > def findFile(dir_path): >> > ?? ?for name in os.listdir(dir_path): >> > ?? ? ? ?full_path = os.path.join(dir_path, name) >> > ?? ? ? ?print full_path >> > ?? ? ? ?if os.path.isdir(full_path): >> > ?? ? ? ? ? ?findFile(full_path) >> > ?? ? ? ?else: >> > ?? ? ? ? ? ?n = n - 1 >> > ?? ? ? ? ? ?if(n ==0): >> > ?? ? ? ? ? ? ? ?return full_path >> > >> > -------------------------------------------------------------------------------------------------- >> > ?? ? ? ? ? ? ? ? ? ?The problem is in the return statement. In the >> > function >> > when I tried to print the file name, it is printing properly but the >> > receiving variable is not getting populated with the file name. The >> > below >> > code (1st statement) shows the value of the full_path variable while the >> > control is at the return statement. The second statement is in the main >> > code >> > from where the function call has been made. >> > Once the control has reached the main procedure after executing the >> > findFile >> > procedure, the third statement gives the status of file variable which >> > has >> > type as NoneType and value as None. Now when I try to check if the path >> > exists, it fails giving the below trace back. >> > >> > ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- >> > >> > E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder\0003testUnicode_??I?NOK?????U???UU?a??????ic?e?e??idnok?????u???uu.txt.txt >> > >> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ >> > file = findFile(fpath) >> > >> > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- >> > file >> > NoneType >> > None >> > >> > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- >> > This is the final trace back: >> > Traceback (most recent call last): >> > ??File "C:\RecallStubFopen.py", line 268, in >> > ?? ?if os.path.exists(file): >> > ??File "C:\Python26\lib\genericpath.py", line 18, in exists >> > ?? ?st = os.stat(path) >> > TypeError: coercing to Unicode: need string or buffer, NoneType found >> > >> > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- >> > Please ask if you need any further information. >> > >> > Thank you, >> > Venu >> > >> > >> > >> > >> > >> > >> > >> > On Mon, Feb 23, 2009 at 11:32 PM, Chris Rebert >> > wrote: >> >> >> >> On Mon, Feb 23, 2009 at 5:51 AM, venutaurus539 at gmail.com >> >> wrote: >> >> > Hi all, >> >> > ? ? ? ? ?I am trying to find the attributes of afile whose name has >> >> > non english characters one like given below. When I try to run my >> >> > python scirpt, it fails giving out an error filename must be in >> >> > string >> >> > or UNICODE. When i try to copy the name of the file as a strinig, it >> >> > (KOMODO IDE) is not allowing me to save the script saying that it >> >> > cannot convert some of the characters in the current encoding which >> >> > is >> >> > Western European(CP-1252). >> >> > >> >> > 0010testUnicode_???????????????????? !#$%&'()+,-. >> >> > 0123456789;=@ABCD.txt.txt >> >> >> >> (1) How are you entering or retrieving that filename? >> >> (2) Please provide the exact error and Traceback you're getting. >> >> >> >> Cheers, >> >> Chris >> >> >> >> -- >> >> Follow the path of the Iguana... >> >> http://rebertia.com >> > >> > >> > _______________________________________________ >> > python-win32 mailing list >> > python-win32 at python.org >> > http://mail.python.org/mailman/listinfo/python-win32 >> > >> > > > From venutaurus539 at gmail.com Tue Feb 24 08:55:23 2009 From: venutaurus539 at gmail.com (venu madhav) Date: Tue, 24 Feb 2009 13:25:23 +0530 Subject: [python-win32] opening files with names in non-english characters. In-Reply-To: <91882ea90902232339u4d476d46ra3c356dec1303e12@mail.gmail.com> References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> <50697b2c0902231002k28b4f2dfs4b4bbf38e569511f@mail.gmail.com> <91882ea90902232319l7421b12v34f3ac824211bf0b@mail.gmail.com> <91882ea90902232339u4d476d46ra3c356dec1303e12@mail.gmail.com> Message-ID: Thank you very much for your timely replies. They were really helpful in making my work easier. But the main issue which I am facing is that if the file has name has some Unicode charactes (Arabic, Russian etc), this python interpreter is failing to detect those and inturn returning "???" in place of those characters. As a result I am unable to proceed further. The main problem is python by default uses ascii encoding and since the characters are in Unicode it fails. But I also tried changing the default encoding to Unicode in site.py scirpt (where the setdefaultencoding function is defined) but of no use. THank you once again, Venu On Tue, Feb 24, 2009 at 1:09 PM, Gerdus van Zyl wrote: > ok, I understand better now, some more points. > > You need to handle the case that it doesn't find the file after the > for loop, one source of a None return. > > also as mentioned in point 2 when recursing you need to return the result > so: > if os.path.isdir(full_path): > findFile(full_path) > becomes > if os.path.isdir(full_path): > return findFile(full_path) > > Another thing you need to test is I don't know if you will always > receive files and folders in the same order which means that the nth > file won't be consistent. > > On Tue, Feb 24, 2009 at 9:27 AM, venu madhav > wrote: > > Hello, > > The value of n is initialized in the main procedure which calls > it. > > Basically I am trying to find the n'th file in the directory(can be in > its > > sub directories too). As I've given the previous mail itself > > file = findFile(path) > > invokes that function.When the path is a > > directory it just recurses into it. And coming to your idea of storing > all > > the items in a list can't be used here because my folder contain > thousands > > of files and storing them in a list would eat up my memory. > > Thanks for your suggestions, > > Venu > > On Tue, Feb 24, 2009 at 12:49 PM, Gerdus van Zyl > > > wrote: > >> > >> I see a couple of problems with your code: > >> > >> 1. where is n first given a value and what is it total file count, > >> etc? also you decrement the value, do you want the last file in the > >> directory or something? > >> 2. The if os.path.isdir(full_path): .. findFile(full_path) part > >> doesn't return or handle the value so it's not useful so far i can > >> see. So you either need to "return findFile(full_path) " or "value = > >> findFile(full_path)" > >> 3. I am not sure of your usage of n, the way i do similiar things is > >> to build a list and then just get the item i want by index or slicing. > >> > >> ~g > >> > >> On Tue, Feb 24, 2009 at 5:28 AM, venu madhav > >> wrote: > >> > Hello, > >> > First of all thanks for your response. I've written a function > >> > as > >> > shown below to recurse a directory and return a file based on the > value > >> > of > >> > n. I am calling this fucntion from my main code to catch that > filename. > >> > The > >> > folder which it recurses through contains a folder having files with > >> > unicode > >> > names (as an example i've given earlier. > >> > > >> > > ----------------------------------------------------------------------------- > >> > def findFile(dir_path): > >> > for name in os.listdir(dir_path): > >> > full_path = os.path.join(dir_path, name) > >> > print full_path > >> > if os.path.isdir(full_path): > >> > findFile(full_path) > >> > else: > >> > n = n - 1 > >> > if(n ==0): > >> > return full_path > >> > > >> > > -------------------------------------------------------------------------------------------------- > >> > The problem is in the return statement. In the > >> > function > >> > when I tried to print the file name, it is printing properly but the > >> > receiving variable is not getting populated with the file name. The > >> > below > >> > code (1st statement) shows the value of the full_path variable while > the > >> > control is at the return statement. The second statement is in the > main > >> > code > >> > from where the function call has been made. > >> > Once the control has reached the main procedure after executing the > >> > findFile > >> > procedure, the third statement gives the status of file variable which > >> > has > >> > type as NoneType and value as None. Now when I try to check if the > path > >> > exists, it fails giving the below trace back. > >> > > >> > > ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > >> > > >> > > E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder\0003testUnicode_??I?NOK?????U???UU?a??????ic?e?e??idnok?????u???uu.txt.txt > >> > > >> > > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ > >> > file = findFile(fpath) > >> > > >> > > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > >> > file > >> > NoneType > >> > None > >> > > >> > > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > >> > This is the final trace back: > >> > Traceback (most recent call last): > >> > File "C:\RecallStubFopen.py", line 268, in > >> > if os.path.exists(file): > >> > File "C:\Python26\lib\genericpath.py", line 18, in exists > >> > st = os.stat(path) > >> > TypeError: coercing to Unicode: need string or buffer, NoneType found > >> > > >> > > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > >> > Please ask if you need any further information. > >> > > >> > Thank you, > >> > Venu > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > On Mon, Feb 23, 2009 at 11:32 PM, Chris Rebert > >> > wrote: > >> >> > >> >> On Mon, Feb 23, 2009 at 5:51 AM, venutaurus539 at gmail.com > >> >> wrote: > >> >> > Hi all, > >> >> > I am trying to find the attributes of afile whose name has > >> >> > non english characters one like given below. When I try to run my > >> >> > python scirpt, it fails giving out an error filename must be in > >> >> > string > >> >> > or UNICODE. When i try to copy the name of the file as a strinig, > it > >> >> > (KOMODO IDE) is not allowing me to save the script saying that it > >> >> > cannot convert some of the characters in the current encoding which > >> >> > is > >> >> > Western European(CP-1252). > >> >> > > >> >> > 0010testUnicode_???????????????????? !#$%&'()+,-. > >> >> > 0123456789;=@ABCD.txt.txt > >> >> > >> >> (1) How are you entering or retrieving that filename? > >> >> (2) Please provide the exact error and Traceback you're getting. > >> >> > >> >> Cheers, > >> >> Chris > >> >> > >> >> -- > >> >> Follow the path of the Iguana... > >> >> http://rebertia.com > >> > > >> > > >> > _______________________________________________ > >> > python-win32 mailing list > >> > python-win32 at python.org > >> > http://mail.python.org/mailman/listinfo/python-win32 > >> > > >> > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.berning at denviso.de Tue Feb 24 11:24:17 2009 From: ulrich.berning at denviso.de (Ulrich Berning) Date: Tue, 24 Feb 2009 11:24:17 +0100 Subject: [python-win32] opening files with names in non-english characters. In-Reply-To: References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> <50697b2c0902231002k28b4f2dfs4b4bbf38e569511f@mail.gmail.com> Message-ID: <49A3CAD1.1010500@denviso.de> venu madhav wrote: > Hello, > First of all thanks for your response. I've written a function > as shown below to recurse a directory and return a file based on the > value of n. I am calling this fucntion from my main code to catch that > filename. The folder which it recurses through contains a folder > having files with unicode names (as an example i've given earlier. > ----------------------------------------------------------------------------- > def findFile(dir_path): > for name in os.listdir(dir_path): > full_path = os.path.join(dir_path, name) > print full_path > if os.path.isdir(full_path): > findFile(full_path) > else: > n = n - 1 > if(n ==0): > return full_path > -------------------------------------------------------------------------------------------------- Because os.listdir() returns the list in arbitrary order (depends on platform and/or filesystem type), it is pretty useless to get the n'th file of a directory. With every call of your function, the n'th file may be a different one. Never rely on the order of items returned by os.listdir(). Ulli From vernondcole at gmail.com Tue Feb 24 22:30:34 2009 From: vernondcole at gmail.com (Vernon Cole) Date: Tue, 24 Feb 2009 14:30:34 -0700 Subject: [python-win32] opening files with names in non-english characters. In-Reply-To: <49A3CAD1.1010500@denviso.de> References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> <50697b2c0902231002k28b4f2dfs4b4bbf38e569511f@mail.gmail.com> <49A3CAD1.1010500@denviso.de> Message-ID: 1) Comparing the time it would take to walk a directory tree thousands of times, with the storage it would take to store thousands of file names, I think you would be much better of to store the list. Buy another memory chip if needed. 2) I suspect that Python is NOT returning question mark characters. Windows (or KIMODO) is probably failing to display some characters that Python is returning. Try using >>> print repr(yourFileNameObjectHere) to see what is really in that object. You cannot expect your display to have the glyph for every arbitrary unicode code point, so repr() will display it with backslash escapes so that you can tell what is there. 3) The documentation for "os.listdir(path)" says: "Changed in version 2.3: On Windows NT/2k/XP and Unix, if path is a Unicode object, the result will be a list of Unicode objects." Make sure that your path argument is a unicode object. myPath = unicode(someStringObject) or myPath = u'somePath' -- Vernon Cole From timr at probo.com Tue Feb 24 22:46:47 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 24 Feb 2009 13:46:47 -0800 Subject: [python-win32] opening files with names in non-english characters. In-Reply-To: References: <5b6a03dc-0393-46e6-bff0-c36669a67340@w34g2000yqm.googlegroups.com> <50697b2c0902231002k28b4f2dfs4b4bbf38e569511f@mail.gmail.com> <49A3CAD1.1010500@denviso.de> Message-ID: <49A46AC7.9050509@probo.com> Vernon Cole wrote: > 2) I suspect that Python is NOT returning question mark characters. > Windows (or KIMODO) is probably failing to display some characters > that Python is returning. Actually, you're wrong here. The Windows API is returning the file names in Unicode. The "os.listdir" function wants to return an 8-bit string, so it converts the Unicode names using some encoding, which can probably be predicted. Characters which do not exist in that encoding are changed to ? by the decode error process. So, by the time os.listdir returns, the file names really DO have "?" characters in them. > to see what is really in that object. You cannot expect your display > to have the glyph for every arbitrary unicode code point, so repr() > will display it with backslash escapes so that you can tell what is > there. > Yes, but in that case, you'll get an error when you try to print it, not just "?" characters. > 3) The documentation for "os.listdir(path)" says: "Changed in version > 2.3: On Windows NT/2k/XP and Unix, if path is a Unicode object, the > result will be a list of Unicode objects." Make sure that your path > argument is a unicode object. > THIS is the solution to his problem. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From venutaurus539 at gmail.com Wed Feb 25 08:40:22 2009 From: venutaurus539 at gmail.com (venu madhav) Date: Wed, 25 Feb 2009 13:10:22 +0530 Subject: [python-win32] Problem in identifying an archived file in Windows Message-ID: Hello all, I am writing an application which has to identify the archived files in a given directory.I've tried using the function i = win32api.GetFileAttributes (full_path) to obtain the attributes.But am unable to identify based on the value it returns as it is returning 5152, 13856 etc for different files but all of them are archived. Is there any way to come to a conclusion using these numbers about whether a file is archived or not. Thanks in advance, Venu -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Feb 25 09:19:19 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 25 Feb 2009 06:19:19 -0200 Subject: [python-win32] Problem in identifying an archived file in Windows References: Message-ID: En Wed, 25 Feb 2009 05:40:22 -0200, venu madhav escribi?: > I am writing an application which has to identify the > archived files in a given directory.I've tried using the function > i = win32api.GetFileAttributes (full_path) > > to obtain the attributes.But am unable to identify based on the value > it returns as it is returning 5152, 13856 etc for different files but > all of them are archived. Is there any way to come to a conclusion > using these numbers about whether a file is archived or not. So you're using the pywin32 package. It comes with a help file (PyWin32.chm), you can open it right from the menu: Start, All Programs, Python XX, Python for Windows documentation. Go to the GetFileAttributes topic. It says "The return value is a combination of the win32con.FILE_ATTRIBUTE_* constants". Ok, which constants? Let Python tell us: py> import win32con py> [name for name in dir(win32con) if name.startswith("FILE_ATTRIBUTE_")] ['FILE_ATTRIBUTE_ARCHIVE', 'FILE_ATTRIBUTE_ATOMIC_WRITE', 'FILE_ATTRIBUTE_COMPRESSED', 'FILE_ATTRIBUTE_DIRECTORY', 'FILE_ATTRIBUTE_HIDDEN', 'FILE_ATTRIBUTE_NORMAL', 'FILE_ATTRIBUTE_READONLY','FILE_ATTRIBUTE_SYSTEM', 'FILE_ATTRIBUTE_TEMPORARY', 'FILE_ATTRIBUTE_XACTION_WRITE'] What do they mean? The best source is the Microsoft site. There is a very convenient link in the help topic: "Search for GetFileAttributes at msdn, google or google groups." Click on msdn, the first result is You apparently are looking for FILE_ATTRIBUTE_ARCHIVE. -- Gabriel Genellina From le.dahut at laposte.net Wed Feb 25 11:54:51 2009 From: le.dahut at laposte.net (le dahut) Date: Wed, 25 Feb 2009 11:54:51 +0100 Subject: [python-win32] NT service and login prompt In-Reply-To: <48E22C76.2090908@laposte.net> References: <48E22C76.2090908@laposte.net> Message-ID: <49A5237B.8010008@laposte.net> After some investigations, I finally found a solution : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ServiceGroupOrder:List In this list you can add your proper group, assign your service to the group. Windows will start services by group following the order they appear in "List". To make the service start before logon screen : * activate "SyncForegroundPolicy" to make windows wait for the network to be up before showing logon screen * put a new group "mygroup" in ServiceGroupOrder:List, the correct place seems to be between : NetworkProvider mygroup RemoteValidation * configure service to be member of "mygroup" : 'sc config myservice group= mygroup' (note the space between equal sign and "mygroup") Beside to that it is necessary to use self.ReportServiceStatus(win32service.SERVICE_START_PENDING) and self.ReportServiceStatus(win32service.SERVICE_RUNNING) at the correct place otherwise windows will think service has started while in fact it has not finished to. Hope this helps, I spend a couple of hours to find this solution, it is not well documented on msdn. Maybe this for search engine : wait service start logon screen login screen wait NT service le dahut wrote : > > Hello, > Is it possible to tell windows to wait a python service has started > before the login prompt is displayed ? > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > From bba at inbox.com Wed Feb 25 16:29:25 2009 From: bba at inbox.com (Ben) Date: Wed, 25 Feb 2009 07:29:25 -0800 Subject: [python-win32] Unreliable results with Winreg & WMI Message-ID: <531EB6D09E2.0000036Fbba@inbox.com> Hello I have generally been getting better results using winreg than using WMI, but even Winreg (or config problems on our server) are causing me problems. For example I'd use this code to find out if a certain security update is installed across all our servers: def KB958644(OS, servername): HKLM_remote = _winreg.ConnectRegistry (r"\\%s" % servername, _winreg.HKEY_LOCAL_MACHINE) KEY_PATH = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\KB958644" ValueName = 'InstallDate' hKeyRemote = _winreg.OpenKey (HKLM_remote, KEY_PATH, 0, _winreg.KEY_READ) value, type = _winreg.QueryValueEx (hKeyRemote, ValueName) print 'KB958644: ', value return value Now on some servers, this works, and returns the date when the update was installed. But on others it would return: WindowsError: [Error 2] The system cannot find the file specified When I look at the servers where it failed, I find the patch is installed and the registry key the script was looking for is there. It is all Server 2003 on the same domain. What could the problem be? Thanks ____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails From bba at inbox.com Wed Feb 25 17:24:00 2009 From: bba at inbox.com (Ben) Date: Wed, 25 Feb 2009 08:24:00 -0800 Subject: [python-win32] Unreliable results with Winreg & WMI In-Reply-To: <531EB6D09E2.0000036Fbba@inbox.com> Message-ID: <5398BA2E95C.0000042Dbba@inbox.com> > I have generally been getting better results using winreg than using WMI, > but even Winreg (or config problems on our server) are causing me > problems. For example I'd use this code to find out if a certain > I'm beginning to think this is because of 32 vs 64 bit, because the server running the script is 32-bit, and (I haven't checked all), but it seems that it works on 32 bit servers but not 64-bit ones. Is this possible, and if so, is there any way around the problem? From bborcic at gmail.com Wed Feb 25 17:56:25 2009 From: bborcic at gmail.com (Boris Borcic) Date: Wed, 25 Feb 2009 17:56:25 +0100 Subject: [python-win32] import win32traceutil - stopped working, any lights ? Message-ID: Hello, I just moved a python ISAPI between servers, the code works fine except that "import win32traceutil" doesn't work any more for the ISAPI. On the other hand, "import win32traceutil" in a small test program run either from the pythonwin environment or with python.exe, works all right : the pywin "Python Trace Collector" tool shows all printed messages. Any idea for rectifying this would be welcome. Pythonwin version : 2.5.4 Possibly relevant : the move was made in the simplest possible manner, by installing the current (2.5.4) ActivePython for the major version (2.5) on the target machine and simply copying files not included in the distribution, even though the ActivePython on the source machine was in fact 2.5.1, this on the basis of the idea that binary compatibility is guaranteed between minor versions. Could this be a (the) mistake ? Thanks in advance for any help, Boris Borcic From timr at probo.com Wed Feb 25 19:17:16 2009 From: timr at probo.com (Tim Roberts) Date: Wed, 25 Feb 2009 10:17:16 -0800 Subject: [python-win32] Unreliable results with Winreg & WMI In-Reply-To: <5398BA2E95C.0000042Dbba@inbox.com> References: <5398BA2E95C.0000042Dbba@inbox.com> Message-ID: <49A58B2C.8040000@probo.com> Ben wrote: >> I have generally been getting better results using winreg than using WMI, >> but even Winreg (or config problems on our server) are causing me >> problems. For example I'd use this code to find out if a certain >> >> > > I'm beginning to think this is because of 32 vs 64 bit, because the server running the > script is 32-bit, and (I haven't checked all), but it seems that it works on 32 bit > servers but not 64-bit ones. Is this possible, and if so, is there any way around the > problem? > Absolutely. In one of the stupidest moves Microsoft has made in the last decade, they implemented an incredibly bizarre scheme called "registry redirection" and "file system redirection" which redirects registry and file system requests for a 32-bit process running on Win64. For example, if a 32-bit process tries to open \Windows\System32\xxx.xxx, it will instead open \Windows\SysWow64\xxx.xxx. The same thing happens to many keys within HKEY_LOCAL_MACHINE. They apparently felt we were all too STUPID to correctly handle the 32-to-64 transition, even though we all managed to handle the exact same issues during the 16-to-32 transition 15 years ago. You can suppress this redirection by calling RegDisableReflectionKey for the key you want to talk to. I do not know if this is exposed in _winreg. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Wed Feb 25 19:19:31 2009 From: timr at probo.com (Tim Roberts) Date: Wed, 25 Feb 2009 10:19:31 -0800 Subject: [python-win32] Unreliable results with Winreg & WMI In-Reply-To: <49A58B2C.8040000@probo.com> References: <5398BA2E95C.0000042Dbba@inbox.com> <49A58B2C.8040000@probo.com> Message-ID: <49A58BB3.9070200@probo.com> Tim Roberts wrote: > Ben wrote: > >>> I have generally been getting better results using winreg than using WMI, >>> but even Winreg (or config problems on our server) are causing me >>> problems. For example I'd use this code to find out if a certain >>> >>> >>> >> I'm beginning to think this is because of 32 vs 64 bit, because the server running the >> script is 32-bit, and (I haven't checked all), but it seems that it works on 32 bit >> servers but not 64-bit ones. Is this possible, and if so, is there any way around the >> problem? >> >> > > Absolutely. In one of the stupidest moves Microsoft has made in the > last decade, they implemented an incredibly bizarre scheme called > "registry redirection" and "file system redirection" which redirects > registry and file system requests for a 32-bit process running on > Win64. For example, if a 32-bit process tries to open > \Windows\System32\xxx.xxx, it will instead open > \Windows\SysWow64\xxx.xxx. The same thing happens to many keys within > HKEY_LOCAL_MACHINE. They apparently felt we were all too STUPID to > correctly handle the 32-to-64 transition, even though we all managed to > handle the exact same issues during the 16-to-32 transition 15 years ago. > > You can suppress this redirection by calling RegDisableReflectionKey for > the key you want to talk to. I do not know if this is exposed in _winreg. > Whoops, I just noticed you're doing this on remote machines. RegDisableReflectionKey doesn't work for that. Instead, when you call OpenKey, you should be able to add KEY_WOW64_64KEY to your flags. That's 0x100. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From skippy.hammond at gmail.com Wed Feb 25 23:51:54 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 26 Feb 2009 09:51:54 +1100 Subject: [python-win32] import win32traceutil - stopped working, any lights ? In-Reply-To: References: Message-ID: <49A5CB8A.5050005@gmail.com> On 26/02/2009 3:56 AM, Boris Borcic wrote: > Hello, > > I just moved a python ISAPI between servers, the code works fine except > that "import win32traceutil" doesn't work any more for the ISAPI. > > On the other hand, "import win32traceutil" in a small test program run > either from the pythonwin environment or with python.exe, works all > right : the pywin "Python Trace Collector" tool shows all printed messages. > > Any idea for rectifying this would be welcome. > > Pythonwin version : 2.5.4 > > Possibly relevant : the move was made in the simplest possible manner, > by installing the current (2.5.4) ActivePython for the major version > (2.5) on the target machine and simply copying files not included in the > distribution, even though the ActivePython on the source machine was in > fact 2.5.1, this on the basis of the idea that binary compatibility is > guaranteed between minor versions. Could this be a (the) mistake ? I believe that build 212 had a problem with win32traceutil, introduced trying to get things working on Vista. Build 213 should have that fixed, but on Vista it may be necessary to either (a) run win32traceutil as an admin or (b) ensure IIS has already imported win32traceutil before starting the reader process. Unfortunately I'm not sure what builds of ActivePython correspond to real pywin32 builds... Cheers, Mark From trentm at activestate.com Thu Feb 26 00:00:55 2009 From: trentm at activestate.com (Trent Mick) Date: Wed, 25 Feb 2009 15:00:55 -0800 Subject: [python-win32] import win32traceutil - stopped working, any lights ? In-Reply-To: <49A5CB8A.5050005@gmail.com> References: <49A5CB8A.5050005@gmail.com> Message-ID: <49A5CDA7.2000707@activestate.com> Mark Hammond wrote: > I believe that build 212 had a problem with win32traceutil, introduced > trying to get things working on Vista. Build 213 should have that > fixed, but on Vista it may be necessary to either (a) run win32traceutil > as an admin or (b) ensure IIS has already imported win32traceutil before > starting the reader process. > > Unfortunately I'm not sure what builds of ActivePython correspond to > real pywin32 builds... ActivePython 2.5.4.3 is built with PyWin32 211.1 (from CVS sources as of 2008-06-24). IOW, time for a update. Trent -- Trent Mick trentm at activestate.com From bborcic at gmail.com Thu Feb 26 13:01:11 2009 From: bborcic at gmail.com (Boris Borcic) Date: Thu, 26 Feb 2009 13:01:11 +0100 Subject: [python-win32] import win32traceutil - stopped working, any lights ? In-Reply-To: <49A5CB8A.5050005@gmail.com> References: <49A5CB8A.5050005@gmail.com> Message-ID: Mark Hammond wrote: > On 26/02/2009 3:56 AM, Boris Borcic wrote: >> Hello, >> >> I just moved a python ISAPI between servers, the code works fine except >> that "import win32traceutil" doesn't work any more for the ISAPI. ... >> Any idea for rectifying this would be welcome. >> >> Pythonwin version : 2.5.4 ... > I believe that build 212 had a problem with win32traceutil, introduced > trying to get things working on Vista. Build 213 should have that > fixed, ... Well, thank you, based on your answer and Trent's to make it work I simply installed over the Activestate's distrib, a pywin210 installer (210 being the build used in my working source installation). Could have gone 213 but anyway the intention is to migrate to python 2.6 together with latest versions of libs, so 210 is good enough for the immediate need of continuous service. (os is windows server 2003 btw). Cheers, BB