python cmd第3子级未退出

2024-04-16 14:04:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在处理来自这个recipyhttp://code.activestate.com/recipes/280500/的一些代码
我从github用户jochem code获得的EPP代码(仅导入):Python EPP(只是为了澄清,我没有自己创建EPP代码)

我补充道

def do_A_register(self, args):
    i = A_register()
    i.cmdloop()

这让我想到: (编辑:格式搞砸了)

class A_register(cmd.Cmd):
   prompt = "(A register) "
   def do_handles(self, args):
       # Goto sub command
       i = A_registerHandles()
       i.prompt = self.prompt[:-1]+'-> handles $ '
       i.cmdloop()

   def do_domain(self, args):
       # Goto sub command
       pass

   def do_exit(self, args):
       return True

   def do_EOF(self, args):
       return self.do_exit(args)

如果我退出或者在这个子菜单中使用crtl-D,我返回1级,这是我想要的,但是如果我返回1级到句柄(2级),我就不能返回1级(0级是shell)

第三级代码是

class A_registerHandles(cmd.Cmd):
config = {
    'host': 'epp.a_registar.com',
    'port': 700,
    'user': '<username>',
    'pass': '<password>',
    'handle': '<defaultHandle>',
}

def do_handleAvailable(self, args):
    print "Give handle:",
    handle = raw_input().strip()
    self.epp = EPP(**self.config)
    self.contact = Contact(self.epp, handle)
    canCreate = self.contact.available()
    if bool(canCreate):
        print "Handle %s is free to use." % handle
    else:
        print "Handle %s is in use!" % handle

def do_handleInfo(self, args):
    print "Give handle: ",
    handle = raw_input().strip()
    self.epp = EPP(**self.config)
    self.contact = Contact(self.epp, handle)
    handleInfo = self.contact.info()

def do_exit(self, args):
    return True

def do_EOF(self, args):
    return self.do_exit(args)

所以我想知道如何从2级回到1级(或者3级回到2级或者4级回到3级,你明白我的意思了)

我创建了一个从2级返回到1级,而不是从3级返回到2级的工作示例。 由于长度问题,我将代码添加到pastebinhttp://pastebin.com/qjF4LPXZ

我正在运行的python版本:

Python 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] on linux2

Thnx的任何回应。 保罗。你知道吗


Tags: 代码selfcomregisterreturndefexitargs