Have you tried: >> headerObj.name = "value" and >> headerObj.SetAttribute('name', 'value') or >> headerObj.Attribute['name'] = 'value'
Just an idea :) Matthew Sherborne ----- Original Message ----- From: "Anesh Madapoosi" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, January 29, 2002 1:42 PM Subject: how to call 'overloaded' COM methods Hi, I am trying to invoke some calls on com objects, and I am getting weird errors. The calls seem a little strange to me (overloaded functions or something like that) and I was wondering if anyone can help. The interface is defined here http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmrm/ht m/headerattribute.asp If I use the python command line, here is what I get >>> headerObj = win32com.client.Dispatch("Wmrmobjs.WMRMHeader") >>> headerObj.Attribute("name") = "value" Traceback (SyntaxError: can't assign to function call As I need this to be run as an asp, I seem to be getting different errors there. I get a 500 as the response and on the win32traceutil I see a TypeError as shown below. Thanks. Anesh. Object with win32trace dispatcher created (object=None) in _InvokeEx_ with SetScriptSite 0 1 (<PyIActiveScriptSite at 0x2469884 with obj at 0x1491f34>,) None None in <win32com.axscript.client.pyscript.PyScript instance at 024E2ACC>._QueryInterface_ with unsupported IID IActiveScriptProperty(unregistered) ({4954E0D0-FBC7-11D1-8410-006008C3FBFC}) in _InvokeEx_ with InitNew 0 1 () None None in _InvokeEx_ with GetScriptDispatch 0 1 (None,) None None in <win32com.axscript.client.pyscript.PyScript instance at 024E2ACC>._QueryInterface_ with unsupported IID <Unregistered interface> ({1D044690-8923-11D0-ABD2-00A0C911E8B2}) in _InvokeEx_ with AddNamedItem 0 1 ('Response', 66) None None in _InvokeEx_ with AddNamedItem 0 1 ('Request', 66) None None in _InvokeEx_ with AddNamedItem 0 1 ('Server', 66) None None in _InvokeEx_ with AddNamedItem 0 1 ('Session', 66) None None in _InvokeEx_ with AddNamedItem 0 1 ('Application', 66) None None in _InvokeEx_ with AddNamedItem 0 1 ('ObjectContext', 66) None None in _InvokeEx_ with AddNamedItem 0 1 ('ASPGLOBALTLB', 74) None None in _InvokeEx_ with ParseScriptText 0 1 ('def getkeys():\r\n\timport cPickle\r\n\treturn cPickle.loads(str(Application("keys")))\r\ndef write(msg):\r\n\tResponse.Write(msg)\r\ndef getuser():\r\n\treturn Session("user")\r\ndef getuserid():\r\n\treturn int(Session("userid"))\r\ndef getdbconnstr():\r\n\treturn Application("dbconnstr")\r\ndef getroot():\r\n\treturn Application(\'inputfilesroot\')\r\ndef getdisplaypath(path):\r\n\troot = getroot()\r\n\tif (path.startswith(root)):\r\n\t\tpath = path[len(root)+1:]\r\n\treturn "\\"" + path + "\\""\r\ndef getinputpath():\r\n\timport os.path\r\n\tuserpath = os.path.join(getroot(), getuser())\r\n\treturn userpath\r\ndef getoutputpath():\r\n\timport os.path\r\n\treturn os.path.join(getinputpath(), "protected")\r\ndef getlogpath():\r\n\timport os.path\r\n\treturn os.path.join(getinputpath(), "logs")\r\ndef getfilelist():\r\n\timport os\r\n\timport os.path\r\n\tinputpath = getinputpath()\r\n\tif (not os.path.isdir(inputpath)):\r\n\t\tos.makedirs(inputpath)\r\n\tallfiles = os.listdir(inputpath)\r\n\tfilelist = []\r\n\tfor file in allfiles:\r\n\t\tif (os.path.isfile(os.path.join(inputpath, file))):\r\n\t\t\tfilelist.append(file)\r\n\tfilelist.sort()\r\n\treturn filelist\r\ndef mkdir(dir):\r\n\timport os\r\n\timport os.path\r\n\tif (not os.path.isdir(dir)):\r\n\t\tos.makedirs(dir)\r\ndef getformparam(paramname):\r\n\tparam = Request.Form(paramname)\r\n\tif (param == None):\r\n\t\treturn None\r\n\tparam = str(param)\r\n\tparam = param.strip()\r\n\t# ok this "None" test sucks, but I don\'t know why\r\n\t# its returning "None" instead of None\r\n\tif (len(param)==0 or param == "None"):\r\n\t\treturn None\r\n\telse:\r\n\t\treturn str(param)\r\ndef fieldIsValid(field):\r\n\tif (field != None and field != "" and field != "None"):\r\n\t\treturn 1\r\n\telse:\r\n\t\treturn 0\r\ndef verifysession():\r\n\tuser = getuser()\r\n\tif (not fieldIsValid(user)):\r\n\t\tResponse.Redirect("Login.asp")\r\ndef getdata(keys=\'\'):\r\n\t\'\'\'\r\n\tpossible ways to call this function:\r\n\tvalue=getdata(\'key\')\r\n\tdict=getdata((\'key1\',\'key2 \')) #get subset\r\n\tdict=getdata() #return everything\r\n\tIt assumes you don\'t have the same key for\r\n\tGET and POST methods\r\n\t\'\'\'\r\n\timport types\r\n\tkey_type=type(keys)\r\n\td_data={} #initialize dictionary\r\n\tif keys==\'\': #if they don\'t supply keys then return everything\r\n\t\tfor key in Request.Form:\r\n\t\t\td_data[key]=Request.Form(key)\r\n\t\tfor key in Request.QueryString:\r\n\t\t\td_data[key]=Request.QueryString(key)\r\n\t \treturn d_data\r\n\telif key_type == types.StringType: #if they provide a single string\r\n\t\tvalue=Request.Form(keys)\r\n\t\tif (value != \'None\') and (str(value) == \'None\'):\r\n\t\t\treturn Request.QueryString(keys)\r\n\t\telse:\r\n\t\t\treturn value\r\n\t#if they provide a list then return a dictionary with all the key/values\r\n\telif key_type == types.TupleType or key_type == types.ListType:\r\n\t\tfor key in keys:\r\n\t\t\tvalue=Request.Form(key)\r\n\t\t\t#now check if the data was empty, if so look at QueryString\r\n\t\t\tif (value != \'None\') and (str(value) == \'None\'):\r\n\t\t\t\tvalue=Request.QueryString(key)\r\n\t\t\tdata[key]= value\r\n\t\treturn d_data\r\nverifysession()\r\nResponse.Expires = 0\r\nfrom DBLib import DBLicense\r\nfrom DBConn import DBConn\r\nfrom DRMConfig import ASPConfig\r\nimport os.path\r\nimport sys\r\nimport win32traceutil\r\nimport pythoncom\r\nclass ProtectLog:\r\n\tdef __init__(self):\r\n\t\tself.filename = self.findFileName("protectlog.txt")\r\n\t\tself.file = None\r\n\t\tself.file = open(self.filename, "a+")\r\n\tdef __del__(self):\r\n\t\tif (self.file != None):\r\n\t\t\tself.file.close()\r\n\tdef findFileName(self, filename):\r\n\t\toutputpath = getlogpath()\r\n\t\tmkdir(outputpath)\r\n\t\toutputfile = os.path.join(outputpath, filename)\r\n\t\tidx = 1\r\n\t\twhile (os.path.exists(outputfile)):\r\n\t\t\t(root, ext) = os.path.splitext(os.path.basename(filename))\r\n\t\t\toutputfile = root + "-" + str(idx) + ext\r\n\t\t\toutputfile = os.path.join(outputpath, outputfile)\r\n\t\t\tidx = idx + 1\r\n\t\treturn outputfile\r\n\tdef write(self, msg):\r\n\t\tself.file.write(msg)\r\n\t\tself.file.write("\\r\\n")\r\n\t def condwrite(self, msg, var):\r\n\t\tif (var != None):\r\n\t\t\tself.write(msg + var)\r\n\tdef writeToResponse(self):\r\n\t\t# the write function here is not this classes\' write()\r\n\t\twrite("Displaying protect log: " + self.filename + "<br>")\r\n\t\twrite("<br>")\r\n\t\tself.file.close()\r\n\t\tself.file = None\r\n\t\tlines = open(self.filename, "r").readlines()\r\n\t\tfor line in lines:\r\n\t\t\twrite(line + "<br>")\r\ndef doprotect():\r\n\t# set up output path\r\n\toutputpath = getoutputpath()\r\n\tmkdir(outputpath)\r\n\taspConfig = ASPConfig(Server, Application)\r\n\tdebug = aspConfig.debug\r\n\t# set up input path\r\n\tinputpath = getinputpath()\r\n\tkeys = getkeys()\r\n\tsigning_key_id = keys["default"]\r\n\t(pubkey, privkey) = keys[signing_key_id]\r\n\tsiteurl = Application(\'siteurl\')\r\n\tfilelist = getfilelist()\r\n\tfor file in filelist:\r\n\t\t# set up input path\r\n\t\tinputfile = os.path.join(inputpath, file)\r\n\t\toutputfile = os.path.join(outputpath, file)\r\n\t\tlog.write("Input File: " + inputfile)\r\n\t\tlog.write("Output File: " + outputfile)\r\n\t\tkeygen = Server.CreateObject("Wmrmobjs.WMRMKeys")\r\n\t\tseed = keygen.GenerateSeed()\r\n\t\t# create a dblicense and populate it\r\n\t\tdbLicense = DBLicense()\r\n\t\tdbLicense.license_key_id = keygen.GenerateKeyID()\r\n\t\tdbLicense.creator_id = getuserid()\r\n\t\t# skip creation date\r\n\t\t# skip modified date\r\n\t\tdbLicense.key_seed_value = seed\r\n\t\tdbLicense.signing_key_id = signing_key_id\r\n\t\tdbLicense.zformat_id = keygen.GenerateKeyID()\r\n\t\tdbLicense.date_available = getformparam("availdate")\r\n\t\tdbLicense.date_expire = getformparam("expiredate")\r\n\t\tdbLicense.num_plays_limit = getformparam("allowedplays")\r\n\t\tif (dbLicense.num_plays_limit == None):\r\n\t\t\tdbLicense.num_plays_limit = 0\r\n\t\tdbLicense.license_term = -1\r\n\t\t# log the content id\r\n\t\tlog.write("Content ID: " + dbLicense.zformat_id)\r\n\t\t# log the protection settings (if the values exist)\r\n\t\tlog.condwrite("Availability Date: ", getformparam("availdate"))\r\n\t\tlog.condwrite("Expiration Date: ", getformparam("expiredate"))\r\n\t\tlog.condwrite("Allowed Plays: ", getformparam("allowedplays"))\r\n\t\t# create license key\r\n\t\tkeygen.seed = dbLicense.key_seed_value\r\n\t\tkeygen.KeyId = dbLicense.license_key_id\r\n\t\tkey = keygen.GenerateKey()\r\n\t\t# create header\r\n\t\theaderObj = Server.CreateObject("Wmrmobjs.WMRMHeader")\r\n\t\tdebug(dir(headerObj))\ r\n\t\theaderObj.KeyID = dbLicense.license_key_id\r\n\t\theaderObj.ContentID = dbLicense.zformat_id\r\n\t\theaderObj.LicenseAcqURL = siteurl\r\n\t\t#headerObj.IndividualizedVersion = "2.2"\r\n\t\ttry:\r\n\t\t\tname = pythoncom.Unicode(\'Author\')\r\n\t\t\theaderObj.Attribute("name") = "value"\r\n\t\texcept:\r\n\t\t\t#debug("exception %s %s" % (sys.exc_info()[0], sys.exc_info()[1]))\r\n\t\t\tprint "exception"\r\n\t\theaderObj.SetCheckSum(key)\r\n\t\theaderObj.Sign(priv key)\r\n\t\theader = headerObj.Header\r\n\t\t#header.Attribute("RID") = getformparam("allowedplays")\r\n\t\t# TODO: do we want to support v1 keys/urls?\r\n\t\t# protect the file\r\n\t\tprotector = Server.CreateObject("Wmrmobjs.WMRMProtect")\r\n\t\tprotector.Header = header\r\n\t\tprotector.Key = key\r\n\t\tprotector.V1KeyID = dbLicense.license_key_id\r\n\t\tprotector.InputFile = inputfile\r\n\t\tprotector.ProtectFile(outputfile)\r\n\t\taspConfig = ASPConfig(Server, Application)\r\n\t\t# save the dbLicense object\r\n\t\tfoo = DBConn(aspConfig)\r\n\t\tdbLicense.save(foo)\r\n\t\t# put in into a file so that it can be imported into the bizapp\r\n\t\tdbLicense.writeToFile(os.path.join(outputpath, file + ".drminfo"))\r\n\t\t# done with this file. write an empty line\r\n\t\tlog.write("")\r\n\t# delete the input files\r\n\t##for file in filelist:\r\n\t##\tinputfile = os.path.join(inputpath, file)\r\n\t##\tos.remove(inputfile)\r\n\t##\tlog.write("Removed input file: " + inputfile)\r\nlog = ProtectLog()\r\ndoprotect()\r\npagetitle = "Kontiki DRM Protection Utility"\r\nResponse.WriteBlock(0)\r\nResponse.Write(pagetitle)\r\nRespo nse.WriteBlock(1)\r\nResponse.Write(pagetitle)\r\nResponse.WriteBlock(2) \r\nResponse.Write(getdisplaypath(getoutputpath()))\r\nResponse.WriteBlo ck(3)\r\nResponse.Write(getdisplaypath(log.filename))\r\nResponse.WriteB lock(4)\r\n', None, None, '</SCRIPT>', 0, 1, 192, 0) None None in _InvokeEx_ with GetScriptDispatch 0 1 (None,) None None in _InvokeEx_ with AddNamedItem 0 1 ('ScriptingNamespace', 10) None None in _InvokeEx_ with SetScriptState 0 1 (1,) None None Traceback (most recent call last): File "C:\Python21\win32comext\axscript\client\error.py", line 86, in __BuildFromException self._BuildFromSyntaxError(site, value, tb) File "C:\Python21\win32comext\axscript\client\error.py", line 104, in _BuildFromSyntaxError self.colno = offset - 1 TypeError: unsupported operand type(s) for - Traceback (most recent call last): File "C:\Python21\win32com\server\dispatcher.py", line 58, in _InvokeEx_ return self.policy._InvokeEx_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python21\win32com\server\policy.py", line 321, in _InvokeEx_ return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider) File "C:\Python21\win32com\server\policy.py", line 509, in _invokeex_ return apply(func, args) File "C:\Python21\win32comext\axscript\client\framework.py", line 553, in SetScriptState self.ExecutePendingScripts() File "C:\Python21\win32comext\axscript\client\framework.py", line 674, in ExecutePendingScripts self.DoExecutePendingScripts() File "C:\Python21\win32comext\axscript\client\pyscript.py", line 277, in DoExecutePendingScripts if self.CompileInScriptedSection(codeBlock, "exec"): File "C:\Python21\win32comext\axscript\client\framework.py", line 807, in CompileInScriptedSection self.HandleException(codeBlock) File "C:\Python21\win32comext\axscript\client\framework.py", line 855, in HandleException codeBlock, exc_type, exc_value, exc_traceback) File "C:\Python21\win32comext\axscript\client\error.py", line 78, in __init__ self.__BuildFromException(site, exc_type, exc_value, exc_traceback) File "C:\Python21\win32comext\axscript\client\error.py", line 92, in __BuildFromException raise sys.exc_info() TypeError in _InvokeEx_ with SetScriptState 0 1 (0,) None None in _InvokeEx_ with Close 0 1 () None None _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/activepython _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/activepython