python类ascii()的实例源码

textpad.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
textpad.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
menu_textpad_mod.py 文件源码 项目:aws-ec2rescue-linux 作者: awslabs 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            # Possible reference before assignment fix
            oldch = None
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
textpad.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
textpad.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
textpad.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
textpad.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
textpad.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
vi_editor.py 文件源码 项目:ci_edit 作者: google 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def setTextBuffer(self, textBuffer):
    app.controller.Controller.setTextBuffer(self, textBuffer)
    normalCommandSet = {
      ord('^'): textBuffer.cursorStartOfLine,
      ord('$'): textBuffer.cursorEndOfLine,
      ord('h'): textBuffer.cursorLeft,
      ord('i'): self.switchToCommandSetInsert,
      ord('j'): textBuffer.cursorDown,
      ord('k'): textBuffer.cursorUp,
      ord('l'): textBuffer.cursorRight,
    }
    self.commandSet = normalCommandSet
    self.commandSet_Insert = {
      curses.ascii.ESC: self.switchToCommandSetNormal,
    }
    self.commandDefault = self.textBuffer.insertPrintable
textpad.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
edit.py 文件源码 项目:notex 作者: adiultra 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def CTRL(key):
    return curses.ascii.ctrl(key)
edit.py 文件源码 项目:notex 作者: adiultra 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def keys_init_noedit(self):
        """Define methods for each key for non-editing mode.

        """
        self.keys = {
            curses.ascii.ETX:               self.close,
            curses.KEY_DOWN:                self.down_noedit,
            CTRL('n'):                      self.down_noedit,
            'j':                            self.down_noedit,
            curses.KEY_F1:                  self.help,
            curses.KEY_NPAGE:               self.page_down,
            'J':                            self.page_down,
            CTRL('f'):                      self.page_up,
            curses.KEY_PPAGE:               self.page_up,
            'K':                            self.page_up,
            CTRL('b'):                      self.page_up,
            CTRL('x'):                      self.quit,
            curses.KEY_F2:                  self.quit,
            curses.KEY_F3:                  self.quit_nosave,
            curses.ascii.ESC:               self.quit_nosave,
            curses.KEY_RESIZE:              self.resize,
            -1:                             self.resize,
            curses.KEY_UP:                  self.up_noedit,
            CTRL('p'):                      self.up_noedit,
            'k':                            self.up_noedit,
        }
textpad.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
textpad.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
pyStationInfoEdit.py 文件源码 项目:Parallel.GAMIT 作者: demiangomez 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, win, insert_mode=False, text=''):
        Textbox.__init__(self, win, insert_mode)

        for chr in text:
            if chr == '\n':
                Textbox.do_command(self, curses.ascii.NL)
            else:
                Textbox.do_command(self, chr)
textpad.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
textpad.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
test_menu_item.py 文件源码 项目:aws-ec2rescue-linux 作者: awslabs 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_menu_textentryitem__eot_deletion(self):
        """Test that the input_caller returns the expected string value."""
        curses.initscr()
        curses.ungetch("\n")
        curses.ungetch("a")
        curses.ungetch(curses.ascii.EOT)
        curses.ungetch(curses.ascii.EOT)
        curses.ungetch(curses.KEY_LEFT)
        curses.ungetch(curses.ascii.EOT)
        curses.ungetch(curses.KEY_LEFT)
        curses.ungetch("a")
        curses.ungetch("a")
        self.textentryitem()
        self.assertEqual(self.textentryitem.get_value(), "a")
test_menu_item.py 文件源码 项目:aws-ec2rescue-linux 作者: awslabs 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_menu_textentryitem__ascii_bel(self):
        """Test that the input_caller returns the expected string value."""
        curses.initscr()
        curses.ungetch("\n")
        curses.ungetch(curses.ascii.BEL)
        # BEL is a non-printable character so the return value should be an empty string
        self.textentryitem()
        self.assertEqual(self.textentryitem.get_value(), "")
menu_textpad_mod.py 文件源码 项目:aws-ec2rescue-linux 作者: awslabs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last + 1)
                break
            elif last == 0:
                break
            last -= 1
        return last
menu_textpad_mod.py 文件源码 项目:aws-ec2rescue-linux 作者: awslabs 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def gather(self):
        """Collect and return the contents of the window."""
        result = ""
        for y in range(self.maxy + 1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx + 1):
                if self.stripspaces and x > stop:
                    break
                result += chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result += "\n"
        return result
textpad.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
textpad.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
screen.py 文件源码 项目:sciibo 作者: fdev 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_key(self):
        code = self.win.getch()
        if code > 0:
            # Accept newline and carriage return as enter key
            if code == curses.ascii.NL or code == curses.ascii.CR:
                code = curses.KEY_ENTER

            # Accept newline and carriage return as enter key
            if code == curses.ascii.BS:
                code = curses.KEY_BACKSPACE

            return code
input.py 文件源码 项目:sciibo 作者: fdev 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def on_key(self, ch):
        x = self.pos

        # ascii 32-126 (inclusive)
        if curses.ascii.isprint(ch):
            if len(self.value) < self.max_length:
                self.value = self.value[:x] + chr(ch) + self.value[x:]
                self.pos += 1

        elif ch == curses.KEY_LEFT:
            if x > 0:
                self.pos -= 1

        elif ch == curses.KEY_RIGHT:
            if x < len(self.value):
                self.pos += 1

        elif ch == curses.KEY_BACKSPACE:
            if x > 0:
                self.value = self.value[:x - 1] + self.value[x:]
                self.pos -= 1

        elif ch == curses.KEY_DC:
            if x < len(self.value):
                self.value = self.value[:x] + self.value[x + 1:]

        elif ch == curses.KEY_HOME:
            self.pos = 0

        elif ch == curses.KEY_END:
            self.pos = len(self.value)

        else:
            return False

        self.update()
        return True
playfield.py 文件源码 项目:sciibo 作者: fdev 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def on_key(self, ch):
        if not self.active:
            return

        if self.selected:
            if ch in (curses.ascii.ESC, curses.KEY_BACKSPACE):
                self.cancel_selection()

            elif ch == curses.KEY_LEFT:
                if self.selection > 0 and self.selection < 4 or self.selection > 4:
                    self.set_selection(self.selection - 1)

            elif ch == curses.KEY_RIGHT:
                if self.selection < 3 or self.selection > 3 and self.selection < 7:
                    self.set_selection(self.selection + 1)

            elif ch == curses.KEY_UP:
                if self.selection > 3:
                    self.set_selection(self.selection - 4)

            elif ch == curses.KEY_DOWN:
                if self.selection < 4 and self.selected_source == 'hand':
                    self.set_selection(self.selection + 4)

            elif ch in (curses.KEY_ENTER, curses.ascii.SP):
                self.confirm_selection()

        else:
            if ch == curses.KEY_LEFT:
                if self.selection > 0:
                    self.set_selection(self.selection - 1)

            elif ch == curses.KEY_RIGHT:
                if self.selection + 1 < len(self.selectable_sources):
                    self.set_selection(self.selection + 1)

            elif ch in (curses.KEY_ENTER, curses.ascii.SP):
                self.confirm_selection()
textpad.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
textpad.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
game.py 文件源码 项目:wpm 作者: cslarsen 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def is_escape(self, key):
        if len(key) == 1:
            return ord(key) == curses.ascii.ESC
        return False
game.py 文件源码 项目:wpm 作者: cslarsen 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def is_backspace(self, key):
        if len(key) > 1:
            return key == "KEY_BACKSPACE"
        elif ord(key) in (curses.ascii.BS, curses.ascii.DEL):
            return True
        return False


问题


面经


文章

微信
公众号

扫码关注公众号