Exemplo n.º 1
0
 def PCDataBase_OnCastFrom(CleObj, SourceData):
     from pchain import pydata
     rawdata = pydata.UnWrap(SourceData)
     rawclass = pydata.UnWrap(CleObj)
     if rawdata == None or rawclass == None:  #not python data or not python class
         databuf = SourceData.GetDataBuf()
         newdata = CleObj._New()
         newdata.SetDataBuf(databuf)
         return newdata
     else:
         #create new class instance with old class's value
         newrawdata = rawclass(rawdata.value())
         newdata = newrawdata.Wrap()
         return newdata
Exemplo n.º 2
0
 def PCDataBase_OnDefineSubType(CleObj, SubTypeName):
     from pchain import pydata
     import libstarpy
     SrvGroup = libstarpy._GetSrvGroup(0)
     Service = SrvGroup._GetService("", "")
     rawclass = pydata.UnWrap(CleObj)
     #using name space of parent class
     StarNameSpace = Service.StarObjectSpace.FindSpace(CleObj)
     if rawclass == None:
         subclass_cle = CleObj.CreateType(SubTypeName)
         if StarNameSpace == None:
             pass
         else:
             StarNameSpace.SetObject(subclass_cle)
         return subclass_cle
     else:
         if StarNameSpace == None:
             pass
         else:
             subclass_cle = StarNameSpace.GetObject(SubTypeName)
             if subclass_cle == None:
                 pass
             else:
                 return subclass_cle
         subclass = pydata.DefineSubType_WithSpace(rawclass, SubTypeName,
                                                   StarNameSpace)
         subclass_cle = subclass.Wrap()
         return subclass_cle
Exemplo n.º 3
0
 def _to_pydata(cls, returnval):
     if returnval == None:
         return None
     from pchain import pydata
     from pchain.pydata import PCPyDataClass
     val = pydata.UnWrap(returnval)
     if isinstance(val, PCPyDataClass) == True:
         return val
     else:
         return returnval
Exemplo n.º 4
0
 def _to_pydatatype(cls, returnval):
     if returnval == None:
         return None
     from pchain import pydata
     from pchain.pydata import PCPyDataClass
     val = pydata.UnWrap(returnval)
     import libstarpy
     if val == None or type(val) == libstarpy.ObjectClass:
         return returnval
     if val == PCPyDataClass or issubclass(val, PCPyDataClass) == True:
         return val
     else:
         return returnval
Exemplo n.º 5
0
 def cleproc_Execute(SelfObj, Realm, Cell, Runner):
     from pchain import pydata
     pythonobj = UnWrap(SelfObj)
     in1 = SelfObj.InputToParaPkg()
     SrvGroup = libstarpy._GetSrvGroup(0)
     pythonobj.Context = {
         'SelfObj': SelfObj,
         'Realm': Realm,
         'Cell': Cell,
         'Runner': Runner
     }
     para = []
     for item in in1._Iterator():
         if type(item
                 ) == libstarpy.ObjectClass and PCDataBaseClass._IsInst(
                     item) and item.HasDataTypeClass():
             para.append(pydata.UnWrap(item))
         else:
             if SrvGroup._IsParaPkg(item) == True:
                 subitem = []
                 for ii in item._Iterator():
                     if type(
                             ii
                     ) == libstarpy.ObjectClass and PCDataBaseClass._IsInst(
                             ii) and ii.HasDataTypeClass():
                         subitem.append(pydata.UnWrap(ii))
                     else:
                         subitem.append(ii)
                 para.append(tuple(subitem))
             else:
                 para.append(item)
     #call class function
     result = pythonobj.Execute(*para)
     if isinstance(result, tuple):
         if len(result) == 3 and type(result[0]) == int and type(
                 result[1]) == int:
             if result[1] < 0:
                 SelfObj.RejectInput(None)
             else:
                 if result[1] > 0:
                     SelfObj.AcceptInput(None)
         else:
             isresultvalid = True
             for item in result:
                 if isinstance(item, PCPyDataClass):
                     pass
                 else:
                     isresultvalid = False
             if isresultvalid == False:
                 raise Exception(
                     'result from proc ' +
                     pythonobj.__class__.__name__ +
                     ' must be tuple (returnvalue,processinput,result)')
             else:
                 SelfObj.AcceptInput(None)
                 result = (0, 1, result)
     else:
         if isinstance(result, PCPyDataClass):
             SelfObj.AcceptInput(None)
             result = (0, 1, result)
         else:
             if result == None:
                 SelfObj.AcceptInput(None)
                 result = (0, 1, result)
             else:
                 raise Exception(
                     'result from proc ' +
                     pythonobj.__class__.__name__ +
                     ' must be tuple (returnvalue,processinput,result)')
     if result[0] < 0:
         return -1
     else:
         _processresult(SelfObj, tp.__name__, result[2], libstarpy,
                        PCPyDataClass)
     if result[0] == 0 or result[0] == 1 or result[0] == 2 or result[
             0] == 3:
         return result[0]
     else:
         return SelfObj.Continue(result[0] - 4)
Exemplo n.º 6
0
    def call(cls, *args):
        # call execute? no
        import libstarpy
        import inspect
        from pchain import pydata
        from pchain.pydata import PCPyDataClass
        SrvGroup = libstarpy._GetSrvGroup(0)
        Service = SrvGroup._GetService("", "")

        newin = []
        for item in args:

            if type(item) == libstarpy.ObjectClass:
                if PCDataBaseClass._IsInst(item) == True:
                    rawitem = pydata.UnWrap(item)
                    if rawitem == None:
                        rawitem = item
                else:
                    if item._HasRawContext() == True:
                        rawitem = item._GetRawObject()
                        if isinstance(rawitem, PCPyDataClass) == True:
                            pass
                        else:
                            rawitem = item
                    else:
                        rawitem = item
            else:
                rawitem = item
            if isinstance(rawitem, PCPyDataClass):
                newin.append(rawitem.Wrap())
            else:
                if type(rawitem
                        ) == libstarpy.ObjectClass and PCDataBaseClass._IsInst(
                            rawitem) == True:
                    newin.append(rawitem)
                else:
                    if rawitem == None:
                        newin.append(rawitem)
                    else:
                        raise Exception(
                            'call ' + cls.__name__ +
                            ' failed, input args must be cle object or instance of PCPyDataClass'
                        )
        #
        self_cleobj = cls.GetType()
        result = Service.PCRealmBase.RunProc(newin,
                                             self_cleobj.GetOutputType(),
                                             self_cleobj)
        if result._Number == 0:  #failed
            raise Exception('call ' + cls.__name__ +
                            ' failed, RunProc function returns false')
            return None
        else:
            ReturnValue = result
            if SrvGroup._IsParaPkg(ReturnValue) == False:
                if isinstance(ReturnValue, PCPyDataClass):
                    return ReturnValue
                else:
                    if type(ReturnValue) == libstarpy.ObjectClass:
                        if PCDataBaseClass._IsInst(
                                ReturnValue) and ReturnValue.HasDataTypeClass(
                                ):
                            return pydata.UnWrap(ReturnValue)
                        else:
                            return ReturnValue
                    else:
                        if ReturnValue == None:
                            return ReturnValue
                        else:
                            raise Exception(
                                'call ' + cls.__name__ +
                                ' failed, output must be None, or cle object or instance of PCPyDataClass'
                            )
            else:
                if ReturnValue._Number == 0:
                    return None
                else:
                    returntuple = []
                    for item in ReturnValue._Iterator():
                        if isinstance(item, PCPyDataClass):
                            returntuple.append(item)
                        else:
                            if type(item) == libstarpy.ObjectClass:
                                if PCDataBaseClass._IsInst(
                                        item) and item.HasDataTypeClass():
                                    returntuple.append(pydata.UnWrap(item))
                                else:
                                    returntuple.append(item)
                            else:
                                if item == None:
                                    returntuple.append(item)
                                else:
                                    raise Exception(
                                        'call ' + cls.__name__ +
                                        ' failed, output must be None, or cle object or instance of PCPyDataClass'
                                    )
                    if len(returntuple) == 1:
                        return returntuple[0]
                    else:
                        return tuple(returntuple)
Exemplo n.º 7
0
def OnException(SelfObj, level, Info):
    if level == 0 or level == 6:
        pass
    else:
        print(Info)


realm.SetRealmStub(realmstub)

from pchain import loader

#load package first

proc_str = r'''{"PackageInfo":[{"PackageName":"grab_url_img_package","PackageVersion":"1.0.0","PackageUrl":"http://127.0.0.1/grab_url_img_package.1.0.0.zip"}],"ObjectList":[{"Type":"PCProcChain","PCProcBase":[{"ClassName":"grab_url_img_package.DownloadHtmlProc","ObjectID":"7de8b486-22aa-42c1-b3da-f2a899133d0c","InputQueue":[{"RequestNumber":1,"DataBaseName":"grab_url_img_package.UrlClass"}],"OutputQueue":[{"DataBaseName":"grab_url_img_package.HtmlClass"}],"Type":"PCProc"},{"ClassName":"grab_url_img_package.ParseImageUrlProc","ObjectID":"12d8dbdb-fe9e-46b6-9080-3be1fa1bbf41","InputQueue":[{"RequestNumber":1,"DataBaseName":"grab_url_img_package.HtmlClass"}],"OutputQueue":[{"DataBaseName":"grab_url_img_package.ImageUrlClass"}],"Type":"PCProc"},{"ClassName":"grab_url_img_package.DownloadImageProc","ObjectID":"48bc33b7-d41e-45f9-93e5-7ac1edeccb24","InputQueue":[{"RequestNumber":1,"DataBaseName":"grab_url_img_package.ImageUrlClass"}],"OutputQueue":[{"DataBaseName":"grab_url_img_package.ImageClass"}],"Type":"PCProc"}]}]}'''
pkg = Service._ServiceGroup._NewParaPkg()
pkg._FromJSon(proc_str)
print(loader.loadobjectpackage(pkg))

print('load package   ', str(Service.grab_url_img_package))
print(Service.grab_url_img_package.DownloadHtmlProc)

#restore object
loadobjects = realm.LoadObject(pkg, False)

#call process
UrlClass = pydata.UnWrap(Service.UrlClass)
result = realm.RunProc(UrlClass('http://www.srplab.com/en/index.html'), None,
                       loadobjects[0])
print(result)

pchain.cleterm()
Exemplo n.º 8
0
@realmstub._RegScriptProc_P('OnException')
def OnException(SelfObj, level, Info):
    if level == 0 or level == 6:
        pass
    else:
        print(Info)


realm.SetRealmStub(realmstub)

procs = realm.BuildProcChain(grab_url_img_package.ImageClass,
                             grab_url_img_package.UrlClass)
parapkg = Service._ServiceGroup._NewParaPkg()
realm.SaveObject(parapkg, procs[1])

proc_str = parapkg._ToJSon()
print(proc_str)

print(procs[1].GetTag())
print(procs[1].GetTagLabel())

UrlClass = pydata.UnWrap(grab_url_img_package.UrlClass)
result = realm.RunString(UrlClass('http://www.srplab.com/en/index.html'), None,
                         proc_str)
print(result)

print(realmstub.GetPerformanceData(False))
print(realm.FindSystemPackage(UrlClass))
print(realmstub.FindSystemPackage(UrlClass))

pchain.cleterm()