Esempio n. 1
0
 def raw_input(self, *args):
     line = InteractiveConsole.raw_input(self, *args)
     if line == EDIT_CMD:
         fd, tmpfl = mkstemp()
         os.write(fd, '\n'.join(self.last_buffer))
         os.close(fd)
         os.system('%s %s' % (EDITOR, tmpfl))
         line = open(tmpfl).read()
         os.unlink(tmpfl)
         tmpfl = ''
     return line
Esempio n. 2
0
 def raw_input(self, *args):
     line = InteractiveConsole.raw_input(self, *args)
     if line == EDIT_CMD:
         fd, tmpfl = mkstemp('.py')
         os.write(fd, b'\n'.join(self.last_buffer))
         os.close(fd)
         os.system('%s %s' % (EDITOR, tmpfl))
         line = open(tmpfl).read()
         os.unlink(tmpfl)
         tmpfl = ''
         lines = line.split( '\n' )
         for i in range(len(lines) - 1): self.push( lines[i] )
         line = lines[-1]
     return line
Esempio n. 3
0
 def raw_input(self, *args):
     """Read the input and delegate if necessary.
     """
     line = InteractiveConsole.raw_input(self, *args)
     if line == config['HELP_CMD']:
         print(cyan(self.__doc__).format(**config))
         line = ''
     elif line.startswith(config['EDIT_CMD']):
         line = self.process_edit_cmd(line.strip(config['EDIT_CMD']))
     elif line.startswith(config['SH_EXEC']):
         line = self.process_sh_cmd(line.strip(config['SH_EXEC']))
     elif line.startswith(config['LIST_CMD']):
         # - strip off the possible tab-completed '('
         line = line.rstrip(config['LIST_CMD'] + '(')
         line = self.process_list_cmd(line.strip(config['LIST_CMD']))
     elif line.endswith(config['DOC_CMD']):
         if line.endswith(config['DOC_CMD'] * 2):
             # search for line in online docs
             # - strip off the '??' and the possible tab-completed
             # '(' or '.' and replace inner '.' with '+' to create the
             # query search string
             line = line.rstrip(config['DOC_CMD'] + '.(').replace('.', '+')
             webbrowser.open(config['DOC_URL'].format(sys=sys, term=line))
             line = ''
         else:
             line = line.rstrip(config['DOC_CMD'] + '.(')
             if not line:
                 line = 'dir()'
             elif keyword.iskeyword(line):
                 line = 'help("{}")'.format(line)
             else:
                 line = 'print({}.__doc__)'.format(line)
     elif line.startswith(self.tab) or self._indent:
         if line.strip():
             # if non empty line with an indent, check if the indent
             # level has been changed
             leading_space = line[:line.index(line.lstrip()[0])]
             if self._indent != leading_space:
                 # indent level changed, update self._indent
                 self._indent = leading_space
         else:
             # - empty line, decrease indent
             self._indent = self._indent[:-len(self.tab)]
             line = self._indent
     elif line.startswith('%'):
         self.writeline('Y U NO LIKE ME?')
         return line
     return line or ''
Esempio n. 4
0
 def raw_input(self, *args):
     line = InteractiveConsole.raw_input(self, *args)
     if line == EDIT_CMD:
         fd, tmpfl = mkstemp('.py')
         os.write(fd, b'\n'.join(self.last_buffer))
         os.close(fd)
         # I use MacVim's updated vim, but you can also use
         # EDITOR in the first variable of the line below.
         os.system('%s %s' % (MAC_VIM, tmpfl))
         line = open(tmpfl).read()
         os.unlink(tmpfl)
         tmpfl = ''
         lines = line.split('\n')
         for i in range(len(lines) - 1):
             self.push(lines[i])
         line = lines[-1]
     return line
Esempio n. 5
0
 def raw_input(self, *args):
     # Think about reimplementing raw_input for automatically adding spaces
     # appropriately. Maybe even backspace to previous line?
     line = InteractiveConsole.raw_input(self, *args)
     if line in ['quit', 'exit']:
         sys.exit()
         return ''
     if line == EDIT_CMD:
         fd, tmpfl = mkstemp('.py')
         os.write(fd, b'\n'.join(self.last_buffer))
         os.close(fd)
         os.system('%s %s' % (EDITOR, tmpfl))
         line = open(tmpfl).read()
         os.unlink(tmpfl)
         tmpfl = ''
         lines = line.split('\n')
         for i in range(len(lines) - 1):
             self.push(lines[i])
         line = lines[-1]
     return line
Esempio n. 6
0
 def raw_input(self, *args):
     """Read the input and delegate if necessary.
     """
     line = InteractiveConsole.raw_input(self, *args)
     if line == self.HELP_CMD:
         print(HELP)
         line = ''
     elif line == self.EDIT_CMD:
         line = self._process_edit_cmd()
     elif line.startswith(self.SH_EXEC):
         line = self._process_sh_cmd(line.strip(self.SH_EXEC))
     elif line.endswith(self.DOC_CMD):
         line = line.strip(self.DOC_CMD + '.(')
         if not line:
             line = 'dir()'
         elif keyword.iskeyword(line):
             line = 'help("{}")'.format(line)
         else:
             line = 'print({}.__doc__)'.format(line)
     return line
Esempio n. 7
0
 def raw_input(self, *args):
     """Read the input and delegate if necessary.
     """
     line = InteractiveConsole.raw_input(self, *args)
     if line == self.HELP_CMD:
         print(HELP)
         line = ''
     elif line == self.EDIT_CMD:
         line = self._process_edit_cmd()
     elif line.startswith(self.SH_EXEC):
         line = self._process_sh_cmd(line.strip(self.SH_EXEC))
     elif line.endswith(self.DOC_CMD):
         if line.endswith(self.DOC_CMD * 2):
             # search for line in online docs
             # - strip off the '??' and the possible tab-completed
             # '(' or '.' and split the dotted name for better search
             # query string
             line = line.rstrip(self.DOC_CMD + '.(').replace('.', '+')
             webbrowser.open(self.DOC_URL.format(sys=sys, term=line))
             line = ''
         else:
             line = line.rstrip(self.DOC_CMD + '.(')
             if not line:
                 line = 'dir()'
             elif keyword.iskeyword(line):
                 line = 'help("{}")'.format(line)
             else:
                 line = 'print({}.__doc__)'.format(line)
     elif line.startswith(self.tab) or self._indent:
         if line.strip():
             # if non empty line with an indent, check if the indent
             # level has been changed
             leading_space = line[:line.index(line.lstrip()[0])]
             if self._indent != leading_space:
                 self._indent = leading_space
         else:
             self._indent = self._indent[:-len(self.tab)]
             line = ''
     return line
Esempio n. 8
0
    def raw_input(self, *args, **kw):
        try:
            r = InteractiveConsole.raw_input(self, *args, **kw)
            for encoding in (getattr(sys.stdin, 'encoding', None),
                             sys.getdefaultencoding(), 'utf-8', 'latin-1'):
                if encoding:
                    try:
                        return r.decode(encoding)
                    except (UnicodeError, AttributeError):
                        pass
                    return r
        except EOFError:
            self.write(os.linesep)
            session = self.locals.get("session")
            if (session is not None and
                session.new or
                session.dirty or
                session.deleted):

                r = raw_input("Do you wish to commit your database changes? [Y/n]")
                if not r.lower().startswith("n"):
                    self.push("session.commit()")
            raise
Esempio n. 9
0
	def raw_input(self, *args):
		line = InteractiveConsole.raw_input(self, *args)
		if line == self.CLEAR:
			line = self.clear()
		elif re.search(self.DOC_RE, line):
			line = self.print_docstring(line)
		elif re.search(self.EDIT_HISTORY_RE, line):
			try:
				_, last = line.split()
				line = self.edithistory(int(last))
			except:
				line = self.edithistory()
		elif re.search(self.PPRINT_ATTR_RE, line):
			obj = line.split(' ')[1]
			line = self.pprint_attr(obj)
		elif line == self.EDIT_CMD:
			line = self.editcmd()
		elif line == self.REPEAT:
			line = self.repeat_last_cmd()
		elif line == self.PPRINT:
			line = self.pprint_last_cmd()
		elif line == self.EXIT:
			sys.exit()
		return line
Esempio n. 10
0
 def raw_input(self, *args, **kwargs):
     ret = InteractiveConsole.raw_input(self, *args, **kwargs)
     self.commands.append(ret + '\n')
     if ret.strip() == 'exit()':
         raise EOFError()
     return ret
Esempio n. 11
0
 def raw_input(self, prompt):
     line = InteractiveConsole.raw_input(self, prompt=self.client.prompt)
     return "rpc.execute('%s')" % line.replace("'", r"\'")
Esempio n. 12
0
    def raw_input(self, prompt=""):
        if self.needed > 0.01:
            prompt = "[%.2fs]\n%s" % (self.needed, prompt)
            self.needed = 0.0

        return InteractiveConsole.raw_input(self, prompt)
Esempio n. 13
0
 def raw_input(self, prompt):
     line = InteractiveConsole.raw_input(self, prompt)
     if not isinstance(line, unicode):
         line = line.decode(ENCODING)
     return line
Esempio n. 14
0
		def raw_input(self, *args):
			line = InteractiveConsole.raw_input(self, *args)
		
			return line
Esempio n. 15
0
 def raw_input(self, prompt=""):
     return InteractiveConsole.raw_input(self, self.prompt())