def __call__(self): if self.model.classname is None: raise Incomplete(u"Incomplete class definition.") ret = list() for decorator in self.model.filtereditems(IDecorator): ret.append(decorator()) name = self.model.classname level = self.model.nodelevel bases = self.model.bases indent = level * 4 * u" " base_str = u"class %s(" % name rclass = u"%s%s" % (indent, base_str) if not bases: bases = ["object"] if len(bases) > 1 and "object" in bases: bases.remove("object") rargs = self.render_arguments(level, len(name) + 7, bases) rclass = u"%s%s):\n" % (rclass, rargs) ret.append(rclass) values = [val for val in self.model.values() if not IDecorator.providedBy(val)] # case ``pass`` was parsed for class body if len(values) == 1 and IBlock.providedBy(values[0]) and values[0].text == u"pass": values = list() self._calcpostlf(values) if not values: ret.append(u"%s pass\n" % indent) valuecount = len(values) for i in range(valuecount): if i == 0 and not IDocstring.providedBy(values[i]): ret.append("\n") ret.append(values[i]()) ret += [u"\n" for i in range(self.model.postlf)] return u"".join(ret)
def __call__(self): if self.model.functionname is None: raise Incomplete(u"Incomplete function definition.") showNotImplemented = True ret = list() for decorator in self.model.filtereditems(IDecorator): ret.append(decorator()) name = self.model.functionname level = self.model.nodelevel args, kwargs = self.model.extract_arguments() indent = level * 4 * u" " base_str = u"def %s(" % name rfunc = u"%s%s" % (indent, base_str) parent = self.model.__parent__ # XXX: to be tested, if the deactivation of the next 2 lines doesnt # break -> # if not IClass.providedBy(parent) and u'self' in args: # args = args[1:] if IClass.providedBy(parent): # add self to methods, but only if the class is not an interface try: isInterface = token(str(parent.uuid), False, isInterface=False).isInterface except ComponentLookupError: isInterface = False if not isInterface and not u"self" in args: args = [u"self"] + args else: # interface methods are empty on purpose showNotImplemented = False rargs = self.render_arguments(level, len(name) + 5, args, kwargs) rfunc = u"%s%s):\n" % (rfunc, rargs) ret.append(rfunc) values = [val for val in self.model.values() if not IDecorator.providedBy(val)] for child in values: child.postlf = 0 ret.append(child()) if not values: if showNotImplemented: ret.append(u'%s raise NotImplementedError("stub generated by AGX.")\n' % indent) else: ret.append(u"%s pass\n" % indent) ret += [u"\n" for i in range(self.model.postlf)] return u"".join(ret)
def __call__(self): if self.model.functionname is None: raise Incomplete, u"Incomplete function definition." showNotImplemented=True ret = list() for decorator in self.model.filtereditems(IDecorator): ret.append(decorator()) name = self.model.functionname level = self.model.nodelevel args, kwargs = self.model.extract_arguments() indent = level * 4 * u' ' base_str = u'def %s(' % name rfunc = u'%s%s' % (indent, base_str) parent=self.model.__parent__ if not IClass.providedBy(parent) and u'self' in args: args = args[1:] if IClass.providedBy(parent): #add self to methods, but only if the class is not an interface try: isInterface=token(str(parent.uuid),False,isInterface=False).isInterface except ComponentLookupError: isInterface=False if not isInterface and not u'self' in args: args = [u'self'] + args else: showNotImplemented=False #interface methods are empty on purpose rargs = self.render_arguments(level, len(name) + 5, args, kwargs) rfunc = u'%s%s):\n' % (rfunc, rargs) ret.append(rfunc) values = [val for val in self.model.values() \ if not IDecorator.providedBy(val)] for child in values: child.postlf = 0 ret.append(child()) if not values: if showNotImplemented: ret.append(u'%s raise NotImplementedError, "stub generated by AGX."\n' % indent) else: ret.append(u'%s pass\n' % indent) ret += [u'\n' for i in range(self.model.postlf)] return u''.join(ret)
def __call__(self): if self.model.classname is None: raise Incomplete, u"Incomplete class definition." ret = list() for decorator in self.model.filtereditems(IDecorator): ret.append(decorator()) name = self.model.classname level = self.model.nodelevel bases = self.model.bases indent = level * 4 * u' ' base_str = u'class %s(' % name rclass = u'%s%s' % (indent, base_str) if not bases: bases = ['object'] if len(bases) > 1 and 'object' in bases: bases.remove('object') rargs = self.render_arguments(level, len(name) + 7, bases) rclass = u'%s%s):\n' % (rclass, rargs) ret.append(rclass) values = [val for val in self.model.values() \ if not IDecorator.providedBy(val)] # case ``pass`` was parsed for class body if len(values) == 1 \ and IBlock.providedBy(values[0]) \ and values[0].text == u'pass': values = list() self._calcpostlf(values) if not values: ret.append(u'%s pass\n' % indent) valuecount = len(values) for i in range(valuecount): if i == 0 and not IDocstring.providedBy(values[i]): ret.append('\n') ret.append(values[i]()) ret += [u'\n' for i in range(self.model.postlf)] return u''.join(ret)