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
  1. import sys
  2. import os
  3. import time
  4. import socket
  5. import ip
  6. import icmp
  7. import errno
  8. import logging
  9. log = logging.getLogger("zen.Ping")

  10. from twisted.internet import reactor, defer
  11. from twisted.spread import pb

  12. class PermissionError(Exception):
  13.     """Not permitted to access resource."""

  14. class IpConflict(Exception):
  15.     """Pinging two jobs simultaneously with different hostnames but the same IP"""

  16. class PingJob(pb.Copyable, pb.RemoteCopy):
  17.     """
  18.     Class representing a single target to be pinged.
  19.     """
  20.     def __init__(self, ipaddr, hostname="", status=0, unused_cycle=60):
  21.         self.parent = False
  22.         self.ipaddr = ipaddr
  23.         self.hostname = hostname
  24.         self.status = status
  25.         self.reset()


  26.     def reset(self):
  27.         self.deferred = defer.Deferred()
  28.         self.rrt = 0
  29.         self.start = 0
  30.         self.sent = 0
  31.         self.message = ""
  32.         self.severity = 5
  33.         self.inprocess = False
  34.         self.pathcheck = 0
  35.         self.eventState = 0


  36.     def checkpath(self):
  37.         if self.parent:
  38.             return self.parent.checkpath()   

  39.     def routerpj(self):
  40.         if self.parent:
  41.             return self.parent.routerpj()

  42. pb.setUnjellyableForClass(PingJob, PingJob)
复制代码
from twisted.spread import pb
pb.setUnjellyableForClass(PingJob, PingJob)



setUnjellyableForClass是什么意识,什么作用啊,看英文不大懂
  1. def setUnjellyableForClass(classname, unjellyable):
  2.     """
  3.     Set which local class will represent a remote type.

  4.     If you have written a Copyable class that you expect your client to be
  5.     receiving, write a local "copy" class to represent it, then call::

  6.         jellier.setUnjellyableForClass('module.package.Class', MyCopier).

  7.     Call this at the module level immediately after its class
  8.     definition. MyCopier should be a subclass of RemoteCopy.

  9.     The classname may be a special tag returned by
  10.     'Copyable.getTypeToCopyFor' rather than an actual classname.

  11.     This call is also for cached classes, since there will be no
  12.     overlap.  The rules are the same.
  13.     """

  14.     global unjellyableRegistry
  15.     classname = _maybeClass(classname)
  16.     unjellyableRegistry[classname] = unjellyable
  17.     globalSecurity.allowTypes(classname)
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2