Advertisement
Guest User

Untitled

a guest
Jul 1st, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1.     ## Given an input object that is a function, generate a string of the
  2.     # form
  3.     # "__pyrelFunctionPointer__:object ID:function name".
  4.     def makeFunctionString(self, obj):
  5.         # The im_self field on functions contains the object the function
  6.         # is bound to.
  7.         obj = key.im_self
  8.         if not hasattr(obj, 'id'):
  9.             # We can only serialize functions if they are bound to objects
  10.             # that we are also serializing.
  11.             raise RuntimeError("Tried to serialize a function bound to an object with no ID: %s" % str(obj))
  12.         boundId = obj.id
  13.         if boundId not in self.objectToId:
  14.             # Unrecognized object ID.             raise RuntimeError("Tried to serialize a function bound to object with unknown ID %s" % boundID)
  15.         ## The __name__ field is the function's name in string form.
  16.         funcName = obj.__name__
  17.         return "__pyrelFunctionPointer:%s:%s" % (boundId, funcName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement