home *** CD-ROM | disk | FTP | other *** search
/ Freelog 116 / FreelogNo116-JuilletSeptembre2013.iso / GestionFichiers / metamorphose / metamorphose2_0.8.2_setup.exe / metamorphose2.exe / cmd.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2011-01-12  |  8KB  |  321 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import string
  5. __all__ = [
  6.     'Cmd']
  7. PROMPT = '(Cmd) '
  8. IDENTCHARS = string.ascii_letters + string.digits + '_'
  9.  
  10. class Cmd:
  11.     prompt = PROMPT
  12.     identchars = IDENTCHARS
  13.     ruler = '='
  14.     lastcmd = ''
  15.     intro = None
  16.     doc_leader = ''
  17.     doc_header = 'Documented commands (type help <topic>):'
  18.     misc_header = 'Miscellaneous help topics:'
  19.     undoc_header = 'Undocumented commands:'
  20.     nohelp = '*** No help on %s'
  21.     use_rawinput = 1
  22.     
  23.     def __init__(self, completekey = 'tab', stdin = None, stdout = None):
  24.         import sys as sys
  25.         if stdin is not None:
  26.             self.stdin = stdin
  27.         else:
  28.             self.stdin = sys.stdin
  29.         if stdout is not None:
  30.             self.stdout = stdout
  31.         else:
  32.             self.stdout = sys.stdout
  33.         self.cmdqueue = []
  34.         self.completekey = completekey
  35.  
  36.     
  37.     def cmdloop(self, intro = None):
  38.         self.preloop()
  39.         if self.use_rawinput and self.completekey:
  40.             
  41.             try:
  42.                 import readline as readline
  43.                 self.old_completer = readline.get_completer()
  44.                 readline.set_completer(self.complete)
  45.                 readline.parse_and_bind(self.completekey + ': complete')
  46.             except ImportError:
  47.                 pass
  48.             except:
  49.                 None<EXCEPTION MATCH>ImportError
  50.             
  51.  
  52.         None<EXCEPTION MATCH>ImportError
  53.         
  54.         try:
  55.             if intro is not None:
  56.                 self.intro = intro
  57.             
  58.             if self.intro:
  59.                 self.stdout.write(str(self.intro) + '\n')
  60.             
  61.             stop = None
  62.             while not stop:
  63.                 None if self.cmdqueue else None<EXCEPTION MATCH>EOFError
  64.                 self.stdout.write(self.prompt)
  65.                 self.stdout.flush()
  66.                 line = self.stdin.readline()
  67.                 if not len(line):
  68.                     line = 'EOF'
  69.                 else:
  70.                     line = line[:-1]
  71.                 line = self.precmd(line)
  72.                 stop = self.onecmd(line)
  73.                 stop = self.postcmd(stop, line)
  74.             self.postloop()
  75.         finally:
  76.             if self.use_rawinput and self.completekey:
  77.                 
  78.                 try:
  79.                     import readline as readline
  80.                     readline.set_completer(self.old_completer)
  81.                 except ImportError:
  82.                     pass
  83.                 except:
  84.                     None<EXCEPTION MATCH>ImportError
  85.                 
  86.  
  87.  
  88.  
  89.     
  90.     def precmd(self, line):
  91.         return line
  92.  
  93.     
  94.     def postcmd(self, stop, line):
  95.         return stop
  96.  
  97.     
  98.     def preloop(self):
  99.         pass
  100.  
  101.     
  102.     def postloop(self):
  103.         pass
  104.  
  105.     
  106.     def parseline(self, line):
  107.         line = line.strip()
  108.         if not line:
  109.             return (None, None, line)
  110.         None if line[0] == '?' else hasattr(self, 'do_shell')
  111.         i = 0
  112.         n = len(line)
  113.         while i < n and line[i] in self.identchars:
  114.             i = i + 1
  115.         cmd = line[:i]
  116.         arg = line[i:].strip()
  117.         return (cmd, arg, line)
  118.  
  119.     
  120.     def onecmd(self, line):
  121.         (cmd, arg, line) = self.parseline(line)
  122.         if not line:
  123.             return self.emptyline()
  124.         if cmd is None:
  125.             return self.default(line)
  126.         self.lastcmd = line
  127.         if cmd == '':
  128.             return self.default(line)
  129.         
  130.         try:
  131.             func = getattr(self, 'do_' + cmd)
  132.         except AttributeError:
  133.             cmd == ''
  134.             cmd == ''
  135.             cmd is None
  136.             return self.default(line)
  137.             line
  138.  
  139.         return func(arg)
  140.  
  141.     
  142.     def emptyline(self):
  143.         if self.lastcmd:
  144.             return self.onecmd(self.lastcmd)
  145.  
  146.     
  147.     def default(self, line):
  148.         self.stdout.write('*** Unknown syntax: %s\n' % line)
  149.  
  150.     
  151.     def completedefault(self, *ignored):
  152.         return []
  153.  
  154.     
  155.     def completenames(self, text, *ignored):
  156.         dotext = 'do_' + text
  157.         return _[1]
  158.  
  159.     
  160.     def complete(self, text, state):
  161.         if state == 0:
  162.             import readline
  163.             origline = readline.get_line_buffer()
  164.             line = origline.lstrip()
  165.             stripped = len(origline) - len(line)
  166.             begidx = readline.get_begidx() - stripped
  167.             endidx = readline.get_endidx() - stripped
  168.             if begidx > 0:
  169.                 (cmd, args, foo) = self.parseline(line)
  170.             None if cmd == '' else None<EXCEPTION MATCH>AttributeError
  171.             compfunc = self.completenames
  172.             self.completion_matches = compfunc(text, line, begidx, endidx)
  173.         
  174.         
  175.         try:
  176.             return self.completion_matches[state]
  177.         except IndexError:
  178.             return None
  179.  
  180.  
  181.     
  182.     def get_names(self):
  183.         names = []
  184.         classes = [
  185.             self.__class__]
  186.         while classes:
  187.             aclass = classes.pop(0)
  188.             if aclass.__bases__:
  189.                 classes = classes + list(aclass.__bases__)
  190.             
  191.             names = names + dir(aclass)
  192.         return names
  193.  
  194.     
  195.     def complete_help(self, *args):
  196.         return self.completenames(*args)
  197.  
  198.     
  199.     def do_help(self, arg):
  200.         if arg:
  201.             
  202.             try:
  203.                 func = getattr(self, 'help_' + arg)
  204.             except AttributeError:
  205.                 
  206.                 try:
  207.                     doc = getattr(self, 'do_' + arg).__doc__
  208.                     if doc:
  209.                         self.stdout.write('%s\n' % str(doc))
  210.                         return None
  211.                 except AttributeError:
  212.                     pass
  213.  
  214.                 self.stdout.write('%s\n' % str(self.nohelp % (arg,)))
  215.                 return None
  216.  
  217.             func()
  218.         else:
  219.             names = self.get_names()
  220.             cmds_doc = []
  221.             cmds_undoc = []
  222.             help = { }
  223.             for name in names:
  224.                 if name[:5] == 'help_':
  225.                     help[name[5:]] = 1
  226.                     continue
  227.             
  228.             names.sort()
  229.             prevname = ''
  230.             for name in names:
  231.                 if name[:3] == 'do_':
  232.                     if name == prevname:
  233.                         continue
  234.                     
  235.                     prevname = name
  236.                     cmd = name[3:]
  237.                     if cmd in help:
  238.                         cmds_doc.append(cmd)
  239.                         del help[cmd]
  240.                     elif getattr(self, name).__doc__:
  241.                         cmds_doc.append(cmd)
  242.                     else:
  243.                         cmds_undoc.append(cmd)
  244.                 cmd in help
  245.             
  246.             self.stdout.write('%s\n' % str(self.doc_leader))
  247.             self.print_topics(self.doc_header, cmds_doc, 15, 80)
  248.             self.print_topics(self.misc_header, help.keys(), 15, 80)
  249.             self.print_topics(self.undoc_header, cmds_undoc, 15, 80)
  250.  
  251.     
  252.     def print_topics(self, header, cmds, cmdlen, maxcol):
  253.         if cmds:
  254.             self.stdout.write('%s\n' % str(header))
  255.             if self.ruler:
  256.                 self.stdout.write('%s\n' % str(self.ruler * len(header)))
  257.             
  258.             self.columnize(cmds, maxcol - 1)
  259.             self.stdout.write('\n')
  260.         
  261.  
  262.     
  263.     def columnize(self, list, displaywidth = 80):
  264.         if not list:
  265.             self.stdout.write('<empty>\n')
  266.             return None
  267.         nonstrings = _[1]
  268.         if nonstrings:
  269.             raise TypeError, 'list[i] not a string for i in %s' % ', '.join(map(str, nonstrings))
  270.         nonstrings
  271.         size = len(list)
  272.         if size == 1:
  273.             self.stdout.write('%s\n' % str(list[0]))
  274.             return None
  275.         for nrows in range(1, len(list)):
  276.             ncols = (size + nrows - 1) // nrows
  277.             colwidths = []
  278.             totwidth = -2
  279.             for col in range(ncols):
  280.                 colwidth = 0
  281.                 for row in range(nrows):
  282.                     i = row + nrows * col
  283.                     x = list[i]
  284.                     colwidth = max(colwidth, len(x))
  285.                 
  286.                 colwidths.append(colwidth)
  287.                 totwidth += colwidth + 2
  288.                 if totwidth > displaywidth:
  289.                     break
  290.                     continue
  291.                 [] if i >= size else []
  292.             
  293.             if totwidth <= displaywidth:
  294.                 break
  295.                 continue
  296.             list
  297.         else:
  298.             nrows = len(list)
  299.             ncols = 1
  300.             colwidths = [
  301.                 0]
  302.         for row in range(nrows):
  303.             texts = []
  304.             for col in range(ncols):
  305.                 i = row + nrows * col
  306.                 if i >= size:
  307.                     x = ''
  308.                 else:
  309.                     x = list[i]
  310.                 texts.append(x)
  311.             
  312.             while texts and not texts[-1]:
  313.                 del texts[-1]
  314.             for col in range(len(texts)):
  315.                 texts[col] = texts[col].ljust(colwidths[col])
  316.             
  317.             self.stdout.write('%s\n' % str('  '.join(texts)))
  318.         
  319.  
  320.  
  321.