本文整理汇总了Python中new.instance函数的典型用法代码示例。如果您正苦于以下问题:Python instance函数的具体用法?Python instance怎么用?Python instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了instance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rule
def rule(self):
if self.subNodes is not None:
extension = new.instance(pmml.Extension)
extension.tag = "Extension"
extension.attrib = {"name": "gain", "value": self.bestGain}
extension.children = []
output = new.instance(pmml.CompoundRule)
output.tag = "CompoundRule"
output.attrib = {}
output.children = [extension, self.pmmlTrue]
output.predicateIndex = 1
for subNode, var, cat, val in zip(self.subNodes, self.cutVar, self.cutCat, self.cutVal):
node = subNode.rule()
predicate = new.instance(pmml.SimplePredicate)
predicate.tag = "SimplePredicate"
if val is None:
predicate.attrib = {"field": var, "operator": "equal", "value": cat}
else:
predicate.attrib = {"field": var, "operator": "greaterThan" if cat else "lessOrEqual", "value": val}
predicate.children = []
node[node.predicateIndex] = predicate
output.children.append(node)
else:
output = new.instance(pmml.SimpleRule)
output.tag = "SimpleRule"
output.attrib = {"score": self.score}
output.children = [self.pmmlTrue]
output.predicateIndex = 0
return output
示例2: _unjelly_instance
def _unjelly_instance(self, rest):
clz = self.unjelly(rest[0])
if type(clz) is not types.ClassType:
raise InsecureJelly("Instance found with non-class class.")
if hasattr(clz, "__setstate__"):
inst = instance(clz, {})
state = self.unjelly(rest[1])
inst.__setstate__(state)
else:
state = self.unjelly(rest[1])
inst = instance(clz, state)
if hasattr(clz, 'postUnjelly'):
self.postCallbacks.append(inst.postUnjelly)
return inst
示例3: get_class
def get_class(kls, attrs):
parts = __name__.split('.')
module = "%s.%s" % (".".join(parts[:-1]), kls)
m = importlib.import_module(module)
m = getattr(m, kls.title())
m = new.instance(m, attrs)
return m
示例4: _simplePredicate
def _simplePredicate(self, field, value, operator):
p = new.instance(pmml.SimplePredicate)
p.tag = "SimplePredicate"
p.children = []
p.attrib = dict(field=field, value=value, operator=operator)
p.post_validate()
return p
示例5: evaluate
def evaluate(self):
classe = _RpcUtils.class_for_name(self.serviceIntfName)
if self.serviceMethodName not in classe.__dict__:
raise _RpcException(__err_msg__["met.nf"] % (self.serviceIntfName, self.serviceMethodName))
serialization = {}
methods = []
_RpcUtils.multi_inherit_serialization(classe, serialization, methods)
if len(serialization) > 0:
if self.serviceMethodName in serialization:
self.returnType = serialization[self.serviceMethodName]
else:
raise _RpcException(__err_msg__["ser.met.nf"] % (self.serviceIntfName, self.serviceMethodName))
else:
raise _RpcException(__err_msg__["ser.nf"] % (self.serviceIntfName))
instance = new.instance(classe)
method = getattr(instance, self.serviceMethodName)
RpcHandler.ctx.serviceInstance = instance
RpcHandler.ctx.methodInstance = method
RpcHandler._callInterceptors("beforeEvaluate")
val = method.__call__(*self.parameterValues)
RpcHandler.ctx.responseObject = val
RpcHandler._callInterceptors("afterEvaluate")
return val
示例6: __new
def __new(cls, C):
try:
import new
return new.instance(C)
except:
pass
return Exception.__new__(C)
示例7: __deepcopy__
def __deepcopy__(self, memo={}):
output = new.instance(self.__class__)
output.__dict__ = copy.deepcopy(self.__dict__, memo)
if "repr" in output.__dict__:
del output.__dict__["repr"]
memo[id(self)] = output
return output
示例8: falseSimplePredicate
def falseSimplePredicate(self):
output = new.instance(pmml.SimplePredicate)
output.tag = "SimplePredicate"
output.attrib = {"field": self.name, "operator": "lessOrEqual", "value": self.value}
output.children = []
output.needsValue = False
return output
示例9: __copy__
def __copy__(self):
obj = new.instance(self.__class__, self.__dict__)
obj.distutils_vars = obj.distutils_vars.clone(obj._environment_hook)
obj.command_vars = obj.command_vars.clone(obj._environment_hook)
obj.flag_vars = obj.flag_vars.clone(obj._environment_hook)
obj.executables = obj.executables.copy()
return obj
示例10: getNewInstance
def getNewInstance(fullClassName, searchPath=['./']):
"""@return: an instance of the fullClassName class WITHOUT the C{__init__} method having been called"""
# Was original, then modified with parts of
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/223972
parts = fullClassName.split('.')
className = parts.pop()
moduleName = parts.pop()
package = '.'.join(parts)
try:
module = sys.modules[package + '.' + moduleName]
except KeyError:
if len(parts) > 0:
module = __import__(package + "." + moduleName, globals(), locals(), [''])
else:
module = __import__(moduleName, globals(), locals())
function = getattr(module, className)
if not callable(function):
raise ImportError(fullFuncError)
return new.instance(function)
示例11: load
def load(cls, filename):
f = open(filename)
data = cPickle.load(f)
f.close()
obj = new.instance(cls, data)
obj.verbose = False
return obj
示例12: _new
def _new(S, name, args, kwargs):
# can only call _new if we have a matching class to instantiate
if not S._class: raise RuntimeError, "instances of this type not available"
# check that it isn't already there!
try:
getinst(S._path, name)
raise RuntimeError, "tried to create an instance that already exists"
except NoSuchObject: pass # we *expect* this
# construct the new object. Do *not* call __init__ yet!
newobj = new.instance(S._class, {})
# Call Object.__setup__ to do required object setup, eg. set object
# name.
fullname = S._path + '%' + name
Object.__setup__(newobj, fullname, name)
# Call the real __init__ if it's there
if hasattr(newobj, '__init__'):
apply(newobj.__init__, args, kwargs)
# Remember to cache the new instance!
ocache[fullname] = newobj
return newobj
示例13: recv_packet
def recv_packet(self, block=True):
buf = self.recv_buf
packet = self.recv_pkt
while True:
if self.recv_ready():
break
if packet.parse(buf) == -1:
return -1
# TODO: callbacks
if packet.event == packet.EVENT_NONE:
if block:
self.net_recv()
else:
return None
elif packet.event == packet.EVENT_READY:
#print 'body ready'
pass
elif packet.event == packet.EVENT_CHUNK:
#print 'chunk', repr(packet.chunk_body)
packet.body += packet.chunk_body
elif packet.event == packet.EVENT_HEAD:
#print 'head ready'
pass
if packet.get_header('Connection').lower() == 'keep-alive':
#print 'keep-alive'
self.keep_alive = True
else:
#print 'not keep-alive'
self.keep_alive = False
self.recv_pkt = new.instance(self.recv_pkt.__class__)
self.recv_pkt.__init__()
return packet
示例14: getRandomStruct
def getRandomStruct(typeCode, compRef):
'''
Helper function
'''
structDef = getDefinition(typeCode.id())
try:
return getKnownBaciType(structDef._get_id())
except:
pass
#determine which namespace the struct is in...
#changes 'IDL:alma/someMod/.../struct:1.0" to
# [ 'someMod', ...,'struct' ]
nameHierarchy = structDef._get_id().split(':')[1].split('/')[1:]
#Just the 'struct' part...
structName = nameHierarchy.pop()
moduleName = nameHierarchy.pop(0)
LOGGER.logTrace("module=" + moduleName
+ "; hierarchy=" + str(nameHierarchy)
+ "; struct=" + structName)
#import the top module
tGlobals = {}
tLocals = {}
#module object where the struct is contained
container = __import__(moduleName, tGlobals, tLocals, [])
if container == None:
msg = "import of module \'" + moduleName + "\' failed"
LOGGER.logCritical(msg)
raise CORBA.NO_IMPLEMENT(msg)
# Now navigate down the nested hierarchy of objects
for h in nameHierarchy:
previousContainer = container
container = container.__dict__.get(h)
if container == None:
msg = "Name \'" + h + "\' not found in " + str( previousContainer)
LOGGER.logCritical(msg)
raise CORBA.NO_IMPLEMENT(msg)
#class object for the struct
tClass = container.__dict__.get(structName)
if tClass == None:
msg = "Could not get structure \'" + structName + "\' from " \
+ str(container)
LOGGER.logCritical(msg)
raise CORBA.NO_IMPLEMENT(msg)
#create an instance of the struct using a kooky Python mechanism.
retVal = instance(tClass)
#populate the fields of the struct using the IFR
for member in structDef._get_members():
LOGGER.logTrace("Adding a member variable for: " +
str(member.name))
retVal.__dict__[member.name] = getRandomValue(member.type_def._get_type(),
compRef)
return retVal
示例15: accept
def accept(self):
sock, addr = self.sock.accept()
link = new.instance(self.__class__)
link.__init__(sock)
link.role = LINK_ROLE_ACCEPT
link.parent = self
link.remote_addr = "%s:%d" % sock.getpeername()
return link