Chinaunix
标题:
twisted.spread 中pb.setUnjellyableForClass怎么用
[打印本页]
作者:
307183927
时间:
2011-09-07 09:25
标题:
twisted.spread 中pb.setUnjellyableForClass怎么用
本帖最后由 307183927 于 2011-09-07 09:32 编辑
部分代码zenoss-api_2.5.0\api\Products.ZenStatus.zenstatus-module.html
import sys
import os
import time
import socket
import ip
import icmp
import errno
import logging
log = logging.getLogger("zen.Ping")
from twisted.internet import reactor, defer
from twisted.spread import pb
class PermissionError(Exception):
"""Not permitted to access resource."""
class IpConflict(Exception):
"""Pinging two jobs simultaneously with different hostnames but the same IP"""
class PingJob(pb.Copyable, pb.RemoteCopy):
"""
Class representing a single target to be pinged.
"""
def __init__(self, ipaddr, hostname="", status=0, unused_cycle=60):
self.parent = False
self.ipaddr = ipaddr
self.hostname = hostname
self.status = status
self.reset()
def reset(self):
self.deferred = defer.Deferred()
self.rrt = 0
self.start = 0
self.sent = 0
self.message = ""
self.severity = 5
self.inprocess = False
self.pathcheck = 0
self.eventState = 0
def checkpath(self):
if self.parent:
return self.parent.checkpath()
def routerpj(self):
if self.parent:
return self.parent.routerpj()
pb.setUnjellyableForClass(PingJob, PingJob)
复制代码
from twisted.spread import pb
pb.setUnjellyableForClass(PingJob, PingJob)
setUnjellyableForClass是什么意识,什么作用啊,看英文不大懂
def setUnjellyableForClass(classname, unjellyable):
"""
Set which local class will represent a remote type.
If you have written a Copyable class that you expect your client to be
receiving, write a local "copy" class to represent it, then call::
jellier.setUnjellyableForClass('module.package.Class', MyCopier).
Call this at the module level immediately after its class
definition. MyCopier should be a subclass of RemoteCopy.
The classname may be a special tag returned by
'Copyable.getTypeToCopyFor' rather than an actual classname.
This call is also for cached classes, since there will be no
overlap. The rules are the same.
"""
global unjellyableRegistry
classname = _maybeClass(classname)
unjellyableRegistry[classname] = unjellyable
globalSecurity.allowTypes(classname)
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2