Thread: [pywin32-checkins] pywin32/com/win32comext/bits/test test_bits.py, 1.1.2.2, 1.1.2.3
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-02-07 07:58:36
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/bits/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29206 Modified Files: Tag: sidnei-bits test_bits.py Log Message: fix line ends. Index: test_bits.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/bits/test/Attic/test_bits.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test_bits.py 6 Feb 2008 09:10:25 -0000 1.1.2.2 --- test_bits.py 7 Feb 2008 07:58:40 -0000 1.1.2.3 *************** *** 1,83 **** ! import win32com.server.policy ! import pythoncom, sys, os, time, win32api, win32event, tempfile ! from win32com.bits import bits ! ! TIMEOUT = 200 # ms ! StopEvent = win32event.CreateEvent(None, 0, 0, None) ! ! job_name = 'bits-pywin32-test' ! states = dict([(val, (name.split('_')[-1])) ! for name, val in vars(bits).items() ! if name.startswith('BG_JOB_STATE_')]) ! ! bcm = pythoncom.CoCreateInstance(bits.CLSID_BackgroundCopyManager, ! None, ! pythoncom.CLSCTX_LOCAL_SERVER, ! bits.IID_IBackgroundCopyManager) ! ! class BackgroundJobCallback(win32com.server.policy.DesignatedWrapPolicy): ! _com_interfaces_ = [bits.IID_IBackgroundCopyCallback] ! _public_methods_ = ["JobTransferred", "JobError", "JobModification"] ! ! def __init__(self): ! self._wrap_(self) ! ! def JobTransferred(self, job): ! print 'Job Transferred', job ! job.Complete() ! win32event.SetEvent(StopEvent) # exit msg pump ! ! def JobError(self, job, error): ! print 'Job Error', job, error ! f = error.GetFile() ! print 'While downloading', f.GetRemoteName() ! print 'To', f.GetLocalName() ! print 'The following error happened:' ! print error.GetErrorDescription(0) ! if f.GetRemoteName().endswith('missing-favicon.ico'): ! print 'Changing to point to correct file' ! f2 = f.QueryInterface(bits.IID_IBackgroundCopyFile2) ! f2.SetRemoteName(r'http://www.python.org/favicon.ico') ! job.Resume() ! else: ! job.Cancel() ! ! def JobModification(self, job, reserved): ! print 'Job Modification', job, states.get(job.GetState()) ! ! job = bcm.CreateJob(job_name, bits.BG_JOB_TYPE_DOWNLOAD) ! print job ! ! job.SetNotifyInterface(pythoncom.WrapObject(BackgroundJobCallback(), bits.IID_IBackgroundCopyCallback, pythoncom.IID_IUnknown)) ! job.SetNotifyFlags(bits.BG_NOTIFY_JOB_TRANSFERRED | ! bits.BG_NOTIFY_JOB_ERROR | ! bits.BG_NOTIFY_JOB_MODIFICATION) ! ! job.AddFile(r'http://www.python.org/favicon.ico', os.path.join(tempfile.gettempdir(), 'bits-favicon.ico')) ! job.AddFile(r'http://www.non-existing.domain/missing-favicon.ico', os.path.join(tempfile.gettempdir(), 'bits-missing-favicon.ico')) ! ! # job.Suspend() ! ! enum = job.EnumFiles() ! while True: ! files = enum.Next() ! if not files: ! break ! for f in files: ! print 'Downloading', f.GetRemoteName() ! print 'To', f.GetLocalName() ! ! job.Resume() ! ! while True: ! rc = win32event.MsgWaitForMultipleObjects( ! (StopEvent,), ! 0, ! TIMEOUT, ! win32event.QS_ALLEVENTS) ! ! if rc == win32event.WAIT_OBJECT_0: ! break ! elif rc == win32event.WAIT_OBJECT_0+1: ! if pythoncom.PumpWaitingMessages(): ! break # wm_quit --- 1,83 ---- ! import win32com.server.policy ! import pythoncom, sys, os, time, win32api, win32event, tempfile ! from win32com.bits import bits ! ! TIMEOUT = 200 # ms ! StopEvent = win32event.CreateEvent(None, 0, 0, None) ! ! job_name = 'bits-pywin32-test' ! states = dict([(val, (name.split('_')[-1])) ! for name, val in vars(bits).items() ! if name.startswith('BG_JOB_STATE_')]) ! ! bcm = pythoncom.CoCreateInstance(bits.CLSID_BackgroundCopyManager, ! None, ! pythoncom.CLSCTX_LOCAL_SERVER, ! bits.IID_IBackgroundCopyManager) ! ! class BackgroundJobCallback(win32com.server.policy.DesignatedWrapPolicy): ! _com_interfaces_ = [bits.IID_IBackgroundCopyCallback] ! _public_methods_ = ["JobTransferred", "JobError", "JobModification"] ! ! def __init__(self): ! self._wrap_(self) ! ! def JobTransferred(self, job): ! print 'Job Transferred', job ! job.Complete() ! win32event.SetEvent(StopEvent) # exit msg pump ! ! def JobError(self, job, error): ! print 'Job Error', job, error ! f = error.GetFile() ! print 'While downloading', f.GetRemoteName() ! print 'To', f.GetLocalName() ! print 'The following error happened:' ! print error.GetErrorDescription(0) ! if f.GetRemoteName().endswith('missing-favicon.ico'): ! print 'Changing to point to correct file' ! f2 = f.QueryInterface(bits.IID_IBackgroundCopyFile2) ! f2.SetRemoteName(r'http://www.python.org/favicon.ico') ! job.Resume() ! else: ! job.Cancel() ! ! def JobModification(self, job, reserved): ! print 'Job Modification', job, states.get(job.GetState()) ! ! job = bcm.CreateJob(job_name, bits.BG_JOB_TYPE_DOWNLOAD) ! print job ! ! job.SetNotifyInterface(pythoncom.WrapObject(BackgroundJobCallback(), bits.IID_IBackgroundCopyCallback, pythoncom.IID_IUnknown)) ! job.SetNotifyFlags(bits.BG_NOTIFY_JOB_TRANSFERRED | ! bits.BG_NOTIFY_JOB_ERROR | ! bits.BG_NOTIFY_JOB_MODIFICATION) ! ! job.AddFile(r'http://www.python.org/favicon.ico', os.path.join(tempfile.gettempdir(), 'bits-favicon.ico')) ! job.AddFile(r'http://www.non-existing.domain/missing-favicon.ico', os.path.join(tempfile.gettempdir(), 'bits-missing-favicon.ico')) ! ! # job.Suspend() ! ! enum = job.EnumFiles() ! while True: ! files = enum.Next() ! if not files: ! break ! for f in files: ! print 'Downloading', f.GetRemoteName() ! print 'To', f.GetLocalName() ! ! job.Resume() ! ! while True: ! rc = win32event.MsgWaitForMultipleObjects( ! (StopEvent,), ! 0, ! TIMEOUT, ! win32event.QS_ALLEVENTS) ! ! if rc == win32event.WAIT_OBJECT_0: ! break ! elif rc == win32event.WAIT_OBJECT_0+1: ! if pythoncom.PumpWaitingMessages(): ! break # wm_quit |