示例#1
0
def object2id(obj):
    """Convert object to string that can be used as an identifier.

    Generator objects that were never activated get a generic name...
        >>> def producer():
        ...     yield 1
        >>> gobject = GeneratorObject(producer())
        >>> object2id(gobject)
        'generator'

    ...but if we have a matching definition, the name is based on it.
        >>> definition = Function('producer', is_generator=True)
        >>> gobject.activate(definition, {}, definition)
        >>> object2id(gobject)
        'producer_instance'

    Accepts only SerializedObjects as arguments.
        >>> object2id(42)
        Traceback (most recent call last):
          ...
        TypeError: object2id() should be called with a SerializedObject argument, not 42
    """
    assert_argument_type(obj, SerializedObject)
    if isinstance(obj, GeneratorObject) and obj.is_activated():
        return "%s_instance" % obj.definition.name
    else:
        return obj.human_readable_id
示例#2
0
    def remove_call_from_call_graph(self, call_to_remove):
        assert_argument_type(call_to_remove, Call)

        def remove(calls):
            try:
                calls.remove(call_to_remove)
                return True
            except ValueError:
                for call in calls:
                    if remove(call.subcalls):
                        return True

        remove(self.call_graph)
示例#3
0
文件: store.py 项目: goulu/pythoscope
 def activate(self, generator, args, callable):
     assert_argument_type(generator, (Function, Method))
     assert_argument_type(callable, (Function, UserObject))
     if self.is_activated():
         raise ValueError("This generator has already been activated.")
     if not generator.is_generator:
         raise TypeError("Tried to activate GeneratorObject with %r as a generator definition." % generator)
     self.definition = generator
     self.args = args
     # Finally register this GeneratorObject with its callable context
     # (which will be a Function or an UserObject). This has to be
     # done only once for each GeneratorObject.
     callable.add_call(self)
示例#4
0
 def activate(self, generator, args, callable):
     assert_argument_type(generator, (Function, Method))
     assert_argument_type(callable, (Function, UserObject))
     if self.is_activated():
         raise ValueError("This generator has already been activated.")
     if not generator.is_generator:
         raise TypeError(
             "Tried to activate GeneratorObject with %r as a generator definition."
             % generator)
     self.definition = generator
     self.args = args
     # Finally register this GeneratorObject with its callable context
     # (which will be a Function or an UserObject). This has to be
     # done only once for each GeneratorObject.
     callable.add_call(self)
示例#5
0
 def add_call(self, call):
     assert_argument_type(call, self.calls_type)
     self.calls.append(call)
示例#6
0
def generator_object_yields(gobject):
    assert_argument_type(gobject, (GeneratorObject, MethodCallContext))
    return [c.output for c in gobject.calls]
示例#7
0
def generator_object_yields(gobject):
    assert_argument_type(gobject, (GeneratorObject, MethodCallContext))
    return [c.output for c in gobject.calls]
示例#8
0
文件: store.py 项目: goulu/pythoscope
 def add_call(self, call):
     assert_argument_type(call, self.calls_type)
     self.calls.append(call)
示例#9
0
def generator_object_yields(gobject):
    assert_argument_type(gobject, GeneratorObject)
    return [c.output for c in gobject.calls]
示例#10
0
def generator_object_exception(gobject):
    assert_argument_type(gobject, GeneratorObject)
    for call in gobject.calls:
        if call.raised_exception():
            return call.exception