403Webshell
Server IP : 123.56.80.60  /  Your IP : 216.73.216.78
Web Server : Apache/2.4.54 (Win32) OpenSSL/1.1.1s PHP/7.4.33 mod_fcgid/2.3.10-dev
System : Windows NT iZhx3sob14hnz7Z 10.0 build 14393 (Windows Server 2016) i586
User : SYSTEM ( 0)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/Program Files/python/Lib/site-packages/win32com/test/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : C:/Program Files/python/Lib/site-packages/win32com/test/policySemantics.py
import win32com.server.util
import win32com.client
import pythoncom
import winerror
import win32com.test.util

import unittest

class Error(Exception):
    pass

# An object representing a list of numbers
class PythonSemanticClass:
    _public_methods_ = ["In"]  # DISPIDs are allocated.
    _dispid_to_func_ = { 10: 'Add', 11:'Remove'} # DISPIDs specified by the object.
    def __init__(self):
        self.list = []
    def _NewEnum(self):
        return win32com.server.util.NewEnum(self.list)
    def _value_(self):
        # should return an array.
        return self.list
    def _Evaluate(self):
        # return the sum
        return sum(self.list)
    def In(self, value):
        return value in self.list
    def Add(self, value):
        self.list.append(value)
    def Remove(self, value):
        self.list.remove(value)

def DispExTest(ob):
    if not __debug__: print("WARNING: Tests dressed up as assertions are being skipped!")
    assert ob.GetDispID("Add", 0)==10, "Policy did not honour the dispid"
# Not impl
#       assert ob.GetMemberName(10, 0)=="add", "Policy did not give me the correct function for the dispid"
    assert ob.GetDispID("Remove", 0)==11, "Policy did not honour the dispid"
    assert ob.GetDispID("In", 0)==1000, "Allocated dispid unexpected value"
    assert ob.GetDispID("_NewEnum", 0)==pythoncom.DISPID_NEWENUM, "_NewEnum() got unexpected DISPID"
    dispids = []
    dispid = -1
    while 1:
        try:
            dispid = ob.GetNextDispID(0, dispid)
            dispids.append(dispid)
        except pythoncom.com_error as xxx_todo_changeme:
            (hr, desc, exc, arg) = xxx_todo_changeme.args
            assert hr==winerror.S_FALSE, "Bad result at end of enum"
            break
    dispids.sort()
    if dispids != [pythoncom.DISPID_EVALUATE, pythoncom.DISPID_NEWENUM, 10, 11, 1000]:
        raise Error("Got back the wrong dispids: %s" % dispids)

def SemanticTest(ob):
    # First just check our object "generally" as expected.
    ob.Add(1)
    ob.Add(2)
    ob.Add(3)
    # invoke _value_
    if ob() != (1,2,3):
        raise Error("Bad result - got %s" % (repr(ob())))

    dispob = ob._oleobj_

    rc = dispob.Invoke(pythoncom.DISPID_EVALUATE, 0, pythoncom.DISPATCH_METHOD|pythoncom.DISPATCH_PROPERTYGET, 1)
    if rc != 6:
        raise Error("Evaluate returned %d" % rc)


class Tester(win32com.test.util.TestCase):
    def setUp(self):
        debug=0
        import win32com.server.dispatcher
        if debug:
            dispatcher=win32com.server.dispatcher.DefaultDebugDispatcher
        else:
            dispatcher=None
        disp = win32com.server.util.wrap(PythonSemanticClass(), useDispatcher=dispatcher)
        self.ob = win32com.client.Dispatch(disp)
    def tearDown(self):
        self.ob = None
    def testSemantics(self):
        SemanticTest(self.ob)
    def testIDispatchEx(self):
        dispexob = self.ob._oleobj_.QueryInterface(pythoncom.IID_IDispatchEx)
        DispExTest(dispexob)

if __name__=='__main__':
    unittest.main()

Youez - 2016 - github.com/yon3zu
LinuXploit