当前位置: 首页>>代码示例>>Python>>正文


Python History.append方法代码示例

本文整理汇总了Python中history.History.append方法的典型用法代码示例。如果您正苦于以下问题:Python History.append方法的具体用法?Python History.append怎么用?Python History.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在history.History的用法示例。


在下文中一共展示了History.append方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import append [as 别名]
class Shell:

  def __init__(self):
    self.builtins = Builtins(self)
    self.completion = Completion(self)
    self.history = History()
    self.javascript = Javascript()
    self.log = Log()
    self.prompt = Prompt()

  def execute(self, command):
    self.log.append(str(self.prompt) + command)
    self.history.append(command)

    if command:
      # execute builtins command
      try:
        self.builtins.execute(command.strip())
      except self.builtins.UnknownCommandError as e:
        self.log.append('websh: command not found: {0}'.format(e.command))
      except Exception as e:
        print 'Error in builtins: {0}'.format(e)

    return json.dumps({'javascript': str(self.javascript),
                       'log': str(self.log),
                       'prompt': str(self.prompt)})

  def template(self):
    # read template file
    file = open('data/template.html', 'r')
    template = string.Template(file.read())
    file.close()

    return template.substitute(log = str(self.log),
                               prompt = str(self.prompt))
开发者ID:Desintegr,项目名称:websh,代码行数:37,代码来源:shell.py

示例2: testSaveHistory

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import append [as 别名]
    def testSaveHistory(self):
        file = tempfile.mktemp()

        h = History(self.console, file)
        h.append("a")
        h.append("b")
        h.append("c")
        h.saveHistory()

        f = open(file)
        self.assertEquals("a", f.readline()[:-1])
        self.assertEquals("b", f.readline()[:-1])
        self.assertEquals("c", f.readline()[:-1])
开发者ID:cureHsu,项目名称:android-ssl-bypass,代码行数:15,代码来源:history_test_case.py

示例3: testHistoryUp

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import append [as 别名]
    def testHistoryUp(self):
        h = History(self.console)
        h.append("one")
        h.append("two")
        h.append("three")

        h.historyUp()
        self.assertEquals("three", self.console.text)

        h.historyUp()
        self.assertEquals("two", self.console.text)

        h.historyUp()
        self.assertEquals("one", self.console.text)

        # history doesn't roll, just stops at the last item
        h.historyUp()
        self.assertEquals("one", self.console.text)
开发者ID:baowuji,项目名称:quickpalm.future,代码行数:20,代码来源:history_test_case.py

示例4: run

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import append [as 别名]
def run(args, setup=None):
    if not setup:
        setup = import_module(args.setup)

    runtime = MLPalRuntime()
    runtime.data_source = setup.DataSource(args)
    runtime.spec = setup.LearningSpec()
    runtime.config = args

    history = History(id=args.history_id)
    runtime.info = history.new()
    runtime.info['config'] = runtime.config.__repr__()
    runtime.info['started_at'] = str(datetime.now())

    task = args.task
    task_function = getattr(sys.modules[__name__], 'run_%s' % task)
    task_function(runtime)

    runtime.info['finished_at'] = str(datetime.now())
    history.append(runtime.info)
开发者ID:eliasdorneles,项目名称:mlpal,代码行数:22,代码来源:runner.py

示例5: testHistoryDown

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import append [as 别名]
    def testHistoryDown(self):
        h = History(self.console)
        h.append("one")
        h.append("two")
        h.append("three")

        h.historyUp()
        h.historyUp()
        
        h.historyUp()
        self.assertEquals("one", self.console.text)

        h.historyDown()
        self.assertEquals("two", self.console.text)

        h.historyDown()
        self.assertEquals("three", self.console.text)

        h.historyDown()
        self.assertEquals("", self.console.text)

        # History doesn't wrap
        h.historyDown()
        self.assertEquals("", self.console.text)
开发者ID:baowuji,项目名称:quickpalm.future,代码行数:26,代码来源:history_test_case.py

示例6: testSkipEmpty

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import append [as 别名]
    def testSkipEmpty(self):
        h = History(self.console)
        h.append("")
        self.assert_(len(h.history) == 0)

        h.append("\n")
        self.assert_(len(h.history) == 0)

        h.append(None)
        self.assert_(len(h.history) == 0)
开发者ID:baowuji,项目名称:quickpalm.future,代码行数:12,代码来源:history_test_case.py

示例7: testSkipEmpty

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import append [as 别名]
    def testSkipEmpty(self):
        h = History(self.console, tempfile.mktemp())
        size = len(h.history)
        h.append("")
        self.assert_(len(h.history) == size)

        h.append("\n")
        self.assert_(len(h.history) == size)

        h.append(None)
        self.assert_(len(h.history) == size)
开发者ID:cureHsu,项目名称:android-ssl-bypass,代码行数:13,代码来源:history_test_case.py

示例8: testSkipDuplicates

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import append [as 别名]
    def testSkipDuplicates(self):
       h = History(self.console)
       h.append("one")
       h.append("one")
       h.append("two")
       h.append("two")
       h.append("three")
       h.append("three")

       h.historyUp()
       self.assertEquals("three", self.console.text)

       h.historyUp()
       self.assertEquals("two", self.console.text)

       h.historyUp()
       self.assertEquals("one", self.console.text)
开发者ID:baowuji,项目名称:quickpalm.future,代码行数:19,代码来源:history_test_case.py

示例9: Console

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import append [as 别名]
class Console(object):
    PS1 = '>>> '
    PS2 = '... '

    def __init__(self, extender, namespace=None):
        self.extender = extender
        self.callbacks = extender.callbacks
        self.helpers = extender.helpers

        self._locals = dict(Burp=extender, items=[])
        self._buffer = []
        self.history = History(self)

        if namespace is not None:
            self._locals.update(namespace)

        self.interp = JythonInterpreter(self, self._locals)

        self.textpane = JTextPane(keyTyped=self.keyTyped,
                                  keyPressed=self.keyPressed)

        self.textpane.setFont(Font('Monospaced', Font.PLAIN, 11))
        self.callbacks.customizeUiComponent(self.textpane)

        self.initKeyMap()

        self.document.remove(0, self.document.getLength())
        self.write('Burp Extender Jython Shell', prefix='')
        self.write(self.PS1)

        self.textpane.requestFocus()
        self.callbacks.getStdout().write('Interactive interpreter ready...\n')

    @property
    def document(self):
        return self.textpane.document

    def resetbuffer(self):
        self._buffer = []

    def keyTyped(self, event=None):
        if not self.inLastLine():
            event.consume()

    def keyPressed(self, event):
        if event.keyCode in (KeyEvent.VK_BACK_SPACE, KeyEvent.VK_LEFT):
            self.backspaceListener(event)

    def getText(self):
        start, end = self.__getLastLineOffsets()
        text = self.document.getText(start, end - start)
        return text.rstrip()

    def insertText(self, data):
        position = self.textpane.getCaretPosition()
        self.textpane.select(position, position)
        self.textpane.replaceSelection(data)
        self.textpane.setCaretPosition(position + len(data))

    def replaceText(self, data):
        start, end = self.__getLastLineOffsets()
        self.textpane.select(start, end)
        self.textpane.replaceSelection(data)
        self.textpane.setCaretPosition(start + len(data))

    def write(self, data, color=Color.black, prefix='\n'):
        style = SimpleAttributeSet()

        if color is not None:
            style.addAttribute(StyleConstants.Foreground, color)

        self.document.insertString(self.document.getLength(), prefix + data, style)
        self.textpane.caretPosition = self.document.getLength()

    def enterAction(self, event=None):
        text = self.getText()
        self._buffer.append(text)
        source = '\n'.join(self._buffer)
        more = self.interp.runsource(source)

        if more:
            self.write(self.PS2, color=Color.black)
        else:
            self.resetbuffer()
            self.write(self.PS1)

        self.history.append(text)

    def deleteAction(self, event=None):
        if self.inLastLine():
            if self.textpane.getSelectedText():
                self.document.remove(self.textpane.getSelectionStart(),
                     self.textpane.getSelectionEnd() - self.textpane.getSelectionStart())

            elif self.textpane.getCaretPosition() < self.document.getLength():
                self.document.remove(self.textpane.getCaretPosition(), 1)

    def deleteEndLineAction(self, event=None):
        if self.inLastLine():
            position = self.textpane.getCaretPosition()
#.........这里部分代码省略.........
开发者ID:mwielgoszewski,项目名称:burp-jython-tab,代码行数:103,代码来源:console.py


注:本文中的history.History.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。