Messenger.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. """Undocumented Module"""
  2. __all__ = ['Messenger']
  3. from PythonUtil import *
  4. from direct.directnotify import DirectNotifyGlobal
  5. import types
  6. from libpandaexpress import ConfigVariableBool
  7. # If using the Toontown ActiveX launcher, this must be set true.
  8. # Also, Panda must be compiled with SIMPLE_THREADS or no HAVE_THREADS
  9. # at all. In the normal Panda case, this should be set false.
  10. if ConfigVariableBool('delay-messenger-lock', False).getValue():
  11. class Lock:
  12. """ This is a cheesy delayed implementation of Lock, designed to
  13. support the Toontown ActiveX launch, which must import Messenger
  14. before it has downloaded the rest of Panda. Note that this
  15. cheesy lock isn't thread-safe if the application starts any
  16. threads before acquiring the Messenger lock the first time.
  17. (However, it's mostly thread-safe if Panda is compiled with
  18. SIMPLE_THREADS.) """
  19. notify = DirectNotifyGlobal.directNotify.newCategory("Messenger.Lock")
  20. def __init__(self):
  21. self.locked = 0
  22. def acquire(self):
  23. # Before we download Panda, we can't use any threading
  24. # interfaces. So don't, until we observe that we have some
  25. # actual contention on the lock.
  26. if self.locked:
  27. # We have contention.
  28. return self.__getLock()
  29. # This relies on the fact that any individual Python statement
  30. # is atomic.
  31. self.locked += 1
  32. if self.locked > 1:
  33. # Whoops, we have contention.
  34. self.locked -= 1
  35. return self.__getLock()
  36. def release(self):
  37. if self.locked:
  38. # Still using the old, cheesy lock.
  39. self.locked -= 1
  40. return
  41. # The new lock must have been put in place.
  42. self.release = self.lock.release
  43. return self.lock.release()
  44. def __getLock(self):
  45. # Now that we've started Panda, it's safe to import the Mutex
  46. # class, which becomes our actual lock.
  47. # From now on, this lock will be used.
  48. self.notify.info("Acquiring Panda lock for the first time.")
  49. from pandac.PandaModules import Thread, Mutex
  50. self.__dict__.setdefault('lock', Mutex('Messenger'))
  51. self.lock.acquire()
  52. self.acquire = self.lock.acquire
  53. # Wait for the cheesy lock to be released before we return.
  54. self.notify.info("Waiting for cheesy lock to be released.")
  55. while self.locked:
  56. Thread.forceYield()
  57. self.notify.info("Got cheesy lock.")
  58. # We return with the lock acquired.
  59. else:
  60. # In the normal case, there's no reason not to import all of
  61. # libpanda right away, and so we can just use Lock directly. This
  62. # is perfectly thread-safe.
  63. from direct.stdpy.threading import Lock
  64. class Messenger:
  65. notify = DirectNotifyGlobal.directNotify.newCategory("Messenger")
  66. def __init__(self):
  67. """
  68. One is keyed off the event name. It has the following structure:
  69. {event1: {object1: [method, extraArgs, persistent],
  70. object2: [method, extraArgs, persistent]},
  71. event2: {object1: [method, extraArgs, persistent],
  72. object2: [method, extraArgs, persistent]}}
  73. This dictionary allow for efficient callbacks when the messenger
  74. hears an event.
  75. A second dictionary remembers which objects are accepting which
  76. events. This allows for efficient ignoreAll commands.
  77. Or, for an example with more real data:
  78. {'mouseDown': {avatar: [avatar.jump, [2.0], 1]}}
  79. """
  80. # eventName->objMsgrId->callbackInfo
  81. self.__callbacks = {}
  82. # objMsgrId->set(eventName)
  83. self.__objectEvents = {}
  84. self._messengerIdGen = 0
  85. # objMsgrId->listenerObject
  86. self._id2object = {}
  87. # A mapping of taskChain -> eventList, used for sending events
  88. # across task chains (and therefore across threads).
  89. self._eventQueuesByTaskChain = {}
  90. # This protects the data structures within this object from
  91. # multithreaded access.
  92. self.lock = Lock()
  93. if __debug__:
  94. self.__isWatching=0
  95. self.__watching={}
  96. # I'd like this to be in the __debug__, but I fear that someone will
  97. # want this in a release build. If you're sure that that will not be
  98. # then please remove this comment and put the quiet/verbose stuff
  99. # under __debug__.
  100. self.quieting={"NewFrame":1,
  101. "avatarMoving":1,
  102. "event-loop-done":1,
  103. 'collisionLoopFinished':1,
  104. } # see def quiet()
  105. def _getMessengerId(self, object):
  106. # TODO: allocate this id in DirectObject.__init__ and get derived
  107. # classes to call down (speed optimization, assuming objects
  108. # accept/ignore more than once over their lifetime)
  109. # get unique messenger id for this object
  110. # assumes lock is held.
  111. if not hasattr(object, '_MSGRmessengerId'):
  112. object._MSGRmessengerId = (object.__class__.__name__, self._messengerIdGen)
  113. self._messengerIdGen += 1
  114. return object._MSGRmessengerId
  115. def _storeObject(self, object):
  116. # store reference-counted reference to object in case we need to
  117. # retrieve it later. assumes lock is held.
  118. id = self._getMessengerId(object)
  119. if id not in self._id2object:
  120. self._id2object[id] = [1, object]
  121. else:
  122. self._id2object[id][0] += 1
  123. def _getObject(self, id):
  124. return self._id2object[id][1]
  125. def _getObjects(self):
  126. self.lock.acquire()
  127. try:
  128. objs = []
  129. for refCount, obj in self._id2object.itervalues():
  130. objs.append(obj)
  131. return objs
  132. finally:
  133. self.lock.release()
  134. def _getNumListeners(self, event):
  135. return len(self.__callbacks.get(event, {}))
  136. def _getEvents(self):
  137. return self.__callbacks.keys()
  138. def _releaseObject(self, object):
  139. # assumes lock is held.
  140. id = self._getMessengerId(object)
  141. if id in self._id2object:
  142. record = self._id2object[id]
  143. record[0] -= 1
  144. if record[0] <= 0:
  145. del self._id2object[id]
  146. def accept(self, event, object, method, extraArgs=[], persistent=1):
  147. """ accept(self, string, DirectObject, Function, List, Boolean)
  148. Make this object accept this event. When the event is
  149. sent (using Messenger.send or from C++), method will be executed,
  150. optionally passing in extraArgs.
  151. If the persistent flag is set, it will continue to respond
  152. to this event, otherwise it will respond only once.
  153. """
  154. notifyDebug = Messenger.notify.getDebug()
  155. if notifyDebug:
  156. Messenger.notify.debug(
  157. "object: %s (%s)\n accepting: %s\n method: %s\n extraArgs: %s\n persistent: %s" %
  158. (safeRepr(object), self._getMessengerId(object), event, safeRepr(method),
  159. safeRepr(extraArgs), persistent))
  160. # Make sure that the method is callable
  161. assert hasattr(method, '__call__'), (
  162. "method not callable in accept (ignoring): %s %s"%
  163. (safeRepr(method), safeRepr(extraArgs)))
  164. # Make sure extraArgs is a list or tuple
  165. if not (isinstance(extraArgs, list) or isinstance(extraArgs, tuple) or isinstance(extraArgs, set)):
  166. raise TypeError, "A list is required as extraArgs argument"
  167. self.lock.acquire()
  168. try:
  169. acceptorDict = self.__callbacks.setdefault(event, {})
  170. id = self._getMessengerId(object)
  171. # Make sure we are not inadvertently overwriting an existing event
  172. # on this particular object.
  173. if id in acceptorDict:
  174. # TODO: we're replacing the existing callback. should this be an error?
  175. if notifyDebug:
  176. oldMethod = acceptorDict[id][0]
  177. if oldMethod == method:
  178. self.notify.warning(
  179. "object: %s was already accepting: \"%s\" with same callback: %s()" %
  180. (object.__class__.__name__, safeRepr(event), method.__name__))
  181. else:
  182. self.notify.warning(
  183. "object: %s accept: \"%s\" new callback: %s() supplanting old callback: %s()" %
  184. (object.__class__.__name__, safeRepr(event), method.__name__, oldMethod.__name__))
  185. acceptorDict[id] = [method, extraArgs, persistent]
  186. # Remember that this object is listening for this event
  187. eventDict = self.__objectEvents.setdefault(id, {})
  188. if event not in eventDict:
  189. self._storeObject(object)
  190. eventDict[event] = None
  191. finally:
  192. self.lock.release()
  193. def ignore(self, event, object):
  194. """ ignore(self, string, DirectObject)
  195. Make this object no longer respond to this event.
  196. It is safe to call even if it was not already accepting
  197. """
  198. if Messenger.notify.getDebug():
  199. Messenger.notify.debug(
  200. safeRepr(object) + ' (%s)\n now ignoring: ' % (self._getMessengerId(object), ) + safeRepr(event))
  201. self.lock.acquire()
  202. try:
  203. id = self._getMessengerId(object)
  204. # Find the dictionary of all the objects accepting this event
  205. acceptorDict = self.__callbacks.get(event)
  206. # If this object is there, delete it from the dictionary
  207. if acceptorDict and id in acceptorDict:
  208. del acceptorDict[id]
  209. # If this dictionary is now empty, remove the event
  210. # entry from the Messenger alltogether
  211. if (len(acceptorDict) == 0):
  212. del self.__callbacks[event]
  213. # This object is no longer listening for this event
  214. eventDict = self.__objectEvents.get(id)
  215. if eventDict and event in eventDict:
  216. del eventDict[event]
  217. if (len(eventDict) == 0):
  218. del self.__objectEvents[id]
  219. self._releaseObject(object)
  220. finally:
  221. self.lock.release()
  222. def ignoreAll(self, object):
  223. """
  224. Make this object no longer respond to any events it was accepting
  225. Useful for cleanup
  226. """
  227. if Messenger.notify.getDebug():
  228. Messenger.notify.debug(
  229. safeRepr(object) + ' (%s)\n now ignoring all events' % (self._getMessengerId(object), ))
  230. self.lock.acquire()
  231. try:
  232. id = self._getMessengerId(object)
  233. # Get the list of events this object is listening to
  234. eventDict = self.__objectEvents.get(id)
  235. if eventDict:
  236. for event in eventDict.keys():
  237. # Find the dictionary of all the objects accepting this event
  238. acceptorDict = self.__callbacks.get(event)
  239. # If this object is there, delete it from the dictionary
  240. if acceptorDict and id in acceptorDict:
  241. del acceptorDict[id]
  242. # If this dictionary is now empty, remove the event
  243. # entry from the Messenger alltogether
  244. if (len(acceptorDict) == 0):
  245. del self.__callbacks[event]
  246. self._releaseObject(object)
  247. del self.__objectEvents[id]
  248. finally:
  249. self.lock.release()
  250. def getAllAccepting(self, object):
  251. """
  252. Returns the list of all events accepted by the indicated object.
  253. """
  254. self.lock.acquire()
  255. try:
  256. id = self._getMessengerId(object)
  257. # Get the list of events this object is listening to
  258. eventDict = self.__objectEvents.get(id)
  259. if eventDict:
  260. return eventDict.keys()
  261. return []
  262. finally:
  263. self.lock.release()
  264. def isAccepting(self, event, object):
  265. """ isAccepting(self, string, DirectOject)
  266. Is this object accepting this event?
  267. """
  268. self.lock.acquire()
  269. try:
  270. acceptorDict = self.__callbacks.get(event)
  271. id = self._getMessengerId(object)
  272. if acceptorDict and id in acceptorDict:
  273. # Found it, return true
  274. return 1
  275. # If we looked in both dictionaries and made it here
  276. # that object must not be accepting that event.
  277. return 0
  278. finally:
  279. self.lock.release()
  280. def whoAccepts(self, event):
  281. """
  282. Return objects accepting the given event
  283. """
  284. return self.__callbacks.get(event)
  285. def isIgnoring(self, event, object):
  286. """ isIgnorning(self, string, DirectObject)
  287. Is this object ignoring this event?
  288. """
  289. return (not self.isAccepting(event, object))
  290. def send(self, event, sentArgs=[], taskChain = None):
  291. """
  292. Send this event, optionally passing in arguments
  293. event is usually a string.
  294. sentArgs is a list of any data that you want passed along to the
  295. handlers listening to this event.
  296. If taskChain is not None, it is the name of the task chain
  297. which should receive the event. If taskChain is None, the
  298. event is handled immediately. Setting a non-None taskChain
  299. will defer the event (possibly till next frame or even later)
  300. and create a new, temporary task within the named taskChain,
  301. but this is the only way to send an event across threads.
  302. """
  303. if Messenger.notify.getDebug() and not self.quieting.get(event):
  304. assert Messenger.notify.debug(
  305. 'sent event: %s sentArgs = %s, taskChain = %s' % (
  306. event, sentArgs, taskChain))
  307. self.lock.acquire()
  308. try:
  309. foundWatch=0
  310. if __debug__:
  311. if self.__isWatching:
  312. for i in self.__watching.keys():
  313. if str(event).find(i) >= 0:
  314. foundWatch=1
  315. break
  316. acceptorDict = self.__callbacks.get(event)
  317. if not acceptorDict:
  318. if __debug__:
  319. if foundWatch:
  320. print "Messenger: \"%s\" was sent, but no function in Python listened."%(event,)
  321. return
  322. if taskChain:
  323. # Queue the event onto the indicated task chain.
  324. from direct.task.TaskManagerGlobal import taskMgr
  325. queue = self._eventQueuesByTaskChain.setdefault(taskChain, [])
  326. queue.append((acceptorDict, event, sentArgs, foundWatch))
  327. if len(queue) == 1:
  328. # If this is the first (only) item on the queue,
  329. # spawn the task to empty it.
  330. taskMgr.add(self.__taskChainDispatch, name = 'Messenger-%s' % (taskChain),
  331. extraArgs = [taskChain], taskChain = taskChain,
  332. appendTask = True)
  333. else:
  334. # Handle the event immediately.
  335. self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
  336. finally:
  337. self.lock.release()
  338. def __taskChainDispatch(self, taskChain, task):
  339. """ This task is spawned each time an event is sent across
  340. task chains. Its job is to empty the task events on the queue
  341. for this particular task chain. This guarantees that events
  342. are still delivered in the same order they were sent. """
  343. while True:
  344. eventTuple = None
  345. self.lock.acquire()
  346. try:
  347. queue = self._eventQueuesByTaskChain.get(taskChain, None)
  348. if queue:
  349. eventTuple = queue[0]
  350. del queue[0]
  351. if not queue:
  352. # The queue is empty, we're done.
  353. if queue is not None:
  354. del self._eventQueuesByTaskChain[taskChain]
  355. if not eventTuple:
  356. # No event; we're done.
  357. return task.done
  358. self.__dispatch(*eventTuple)
  359. finally:
  360. self.lock.release()
  361. return task.done
  362. def __dispatch(self, acceptorDict, event, sentArgs, foundWatch):
  363. for id in acceptorDict.keys():
  364. # We have to make this apparently redundant check, because
  365. # it is possible that one object removes its own hooks
  366. # in response to a handler called by a previous object.
  367. #
  368. # NOTE: there is no danger of skipping over objects due to
  369. # modifications to acceptorDict, since the for..in above
  370. # iterates over a list of objects that is created once at
  371. # the start
  372. callInfo = acceptorDict.get(id)
  373. if callInfo:
  374. method, extraArgs, persistent = callInfo
  375. # If this object was only accepting this event once,
  376. # remove it from the dictionary
  377. if not persistent:
  378. # This object is no longer listening for this event
  379. eventDict = self.__objectEvents.get(id)
  380. if eventDict and event in eventDict:
  381. del eventDict[event]
  382. if (len(eventDict) == 0):
  383. del self.__objectEvents[id]
  384. self._releaseObject(self._getObject(id))
  385. del acceptorDict[id]
  386. # If the dictionary at this event is now empty, remove
  387. # the event entry from the Messenger altogether
  388. if (event in self.__callbacks \
  389. and (len(self.__callbacks[event]) == 0)):
  390. del self.__callbacks[event]
  391. if __debug__:
  392. if foundWatch:
  393. print "Messenger: \"%s\" --> %s%s"%(
  394. event,
  395. self.__methodRepr(method),
  396. tuple(extraArgs + sentArgs))
  397. #print "Messenger: \"%s\" --> %s%s"%(
  398. # event,
  399. # self.__methodRepr(method),
  400. # tuple(extraArgs + sentArgs))
  401. # It is important to make the actual call here, after
  402. # we have cleaned up the accept hook, because the
  403. # method itself might call accept() or acceptOnce()
  404. # again.
  405. assert hasattr(method, '__call__')
  406. # Release the lock temporarily while we call the method.
  407. self.lock.release()
  408. try:
  409. method (*(extraArgs + sentArgs))
  410. finally:
  411. self.lock.acquire()
  412. def clear(self):
  413. """
  414. Start fresh with a clear dict
  415. """
  416. self.lock.acquire()
  417. try:
  418. self.__callbacks.clear()
  419. self.__objectEvents.clear()
  420. self._id2object.clear()
  421. finally:
  422. self.lock.release()
  423. def isEmpty(self):
  424. return (len(self.__callbacks) == 0)
  425. def getEvents(self):
  426. return self.__callbacks.keys()
  427. def replaceMethod(self, oldMethod, newFunction):
  428. """
  429. This is only used by Finder.py - the module that lets
  430. you redefine functions with Control-c-Control-v
  431. """
  432. import new
  433. retFlag = 0
  434. for entry in self.__callbacks.items():
  435. event, objectDict = entry
  436. for objectEntry in objectDict.items():
  437. object, params = objectEntry
  438. method = params[0]
  439. if (type(method) == types.MethodType):
  440. function = method.im_func
  441. else:
  442. function = method
  443. #print ('function: ' + repr(function) + '\n' +
  444. # 'method: ' + repr(method) + '\n' +
  445. # 'oldMethod: ' + repr(oldMethod) + '\n' +
  446. # 'newFunction: ' + repr(newFunction) + '\n')
  447. if (function == oldMethod):
  448. newMethod = new.instancemethod(
  449. newFunction, method.im_self, method.im_class)
  450. params[0] = newMethod
  451. # Found it retrun true
  452. retFlag += 1
  453. # didn't find that method, return false
  454. return retFlag
  455. def toggleVerbose(self):
  456. isVerbose = 1 - Messenger.notify.getDebug()
  457. Messenger.notify.setDebug(isVerbose)
  458. if isVerbose:
  459. print "Verbose mode true. quiet list = %s"%(
  460. self.quieting.keys(),)
  461. if __debug__:
  462. def watch(self, needle):
  463. """
  464. return a matching event (needle) if found (in haystack).
  465. This is primarily a debugging tool.
  466. This is intended for debugging use only.
  467. This function is not defined if python is ran with -O (optimize).
  468. See Also: unwatch
  469. """
  470. if not self.__watching.get(needle):
  471. self.__isWatching += 1
  472. self.__watching[needle]=1
  473. def unwatch(self, needle):
  474. """
  475. return a matching event (needle) if found (in haystack).
  476. This is primarily a debugging tool.
  477. This is intended for debugging use only.
  478. This function is not defined if python is ran with -O (optimize).
  479. See Also: watch
  480. """
  481. if self.__watching.get(needle):
  482. self.__isWatching -= 1
  483. del self.__watching[needle]
  484. def quiet(self, message):
  485. """
  486. When verbose mode is on, don't spam the output with messages
  487. marked as quiet.
  488. This is primarily a debugging tool.
  489. This is intended for debugging use only.
  490. This function is not defined if python is ran with -O (optimize).
  491. See Also: unquiet
  492. """
  493. if not self.quieting.get(message):
  494. self.quieting[message]=1
  495. def unquiet(self, message):
  496. """
  497. Remove a message from the list of messages that are not reported
  498. in verbose mode.
  499. This is primarily a debugging tool.
  500. This is intended for debugging use only.
  501. This function is not defined if python is ran with -O (optimize).
  502. See Also: quiet
  503. """
  504. if self.quieting.get(message):
  505. del self.quieting[message]
  506. def find(self, needle):
  507. """
  508. return a matching event (needle) if found (in haystack).
  509. This is primarily a debugging tool.
  510. """
  511. keys = self.__callbacks.keys()
  512. keys.sort()
  513. for event in keys:
  514. if repr(event).find(needle) >= 0:
  515. print self.__eventRepr(event),
  516. return {event: self.__callbacks[event]}
  517. def findAll(self, needle, limit=None):
  518. """
  519. return a dict of events (needle) if found (in haystack).
  520. limit may be None or an integer (e.g. 1).
  521. This is primarily a debugging tool.
  522. """
  523. matches = {}
  524. keys = self.__callbacks.keys()
  525. keys.sort()
  526. for event in keys:
  527. if repr(event).find(needle) >= 0:
  528. print self.__eventRepr(event),
  529. matches[event] = self.__callbacks[event]
  530. # if the limit is not None, decrement and
  531. # check for break:
  532. if limit > 0:
  533. limit -= 1
  534. if limit == 0:
  535. break
  536. return matches
  537. def __methodRepr(self, method):
  538. """
  539. return string version of class.method or method.
  540. """
  541. if (type(method) == types.MethodType):
  542. functionName = method.im_class.__name__ + '.' + \
  543. method.im_func.__name__
  544. else:
  545. functionName = method.__name__
  546. return functionName
  547. def __eventRepr(self, event):
  548. """
  549. Compact version of event, acceptor pairs
  550. """
  551. str = event.ljust(32) + '\t'
  552. acceptorDict = self.__callbacks[event]
  553. for key, (method, extraArgs, persistent) in acceptorDict.items():
  554. str = str + self.__methodRepr(method) + ' '
  555. str = str + '\n'
  556. return str
  557. def __repr__(self):
  558. """
  559. Compact version of event, acceptor pairs
  560. """
  561. str = "The messenger is currently handling:\n" + "="*64 + "\n"
  562. keys = self.__callbacks.keys()
  563. keys.sort()
  564. for event in keys:
  565. str += self.__eventRepr(event)
  566. # Print out the object: event dictionary too
  567. str += "="*64 + "\n"
  568. for key, eventDict in self.__objectEvents.items():
  569. object = self._getObject(key)
  570. str += "%s:\n" % repr(object)
  571. for event in eventDict.keys():
  572. str += " %s\n" % repr(event)
  573. str += "="*64 + "\n" + "End of messenger info.\n"
  574. return str
  575. def detailedRepr(self):
  576. """
  577. Print out the table in a detailed readable format
  578. """
  579. import types
  580. str = 'Messenger\n'
  581. str = str + '='*50 + '\n'
  582. keys = self.__callbacks.keys()
  583. keys.sort()
  584. for event in keys:
  585. acceptorDict = self.__callbacks[event]
  586. str = str + 'Event: ' + event + '\n'
  587. for key in acceptorDict.keys():
  588. function, extraArgs, persistent = acceptorDict[key]
  589. object = self._getObject(key)
  590. if (type(object) == types.InstanceType):
  591. className = object.__class__.__name__
  592. else:
  593. className = "Not a class"
  594. functionName = function.__name__
  595. str = (str + '\t' +
  596. 'Acceptor: ' + className + ' instance' + '\n\t' +
  597. 'Function name:' + functionName + '\n\t' +
  598. 'Extra Args: ' + repr(extraArgs) + '\n\t' +
  599. 'Persistent: ' + repr(persistent) + '\n')
  600. # If this is a class method, get its actual function
  601. if (type(function) == types.MethodType):
  602. str = (str + '\t' +
  603. 'Method: ' + repr(function) + '\n\t' +
  604. 'Function: ' + repr(function.im_func) + '\n')
  605. else:
  606. str = (str + '\t' +
  607. 'Function: ' + repr(function) + '\n')
  608. str = str + '='*50 + '\n'
  609. return str