本文整理汇总了Python中pyreadline.unicode_helper.ensure_unicode函数的典型用法代码示例。如果您正苦于以下问题:Python ensure_unicode函数的具体用法?Python ensure_unicode怎么用?Python ensure_unicode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ensure_unicode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: write_plain
def write_plain(self, text, attr=None):
u"""write text at current cursor position."""
text = ensure_unicode(text)
log(u'write("%s", %s)' % (text, attr))
if attr is None:
attr = self.attr
junk = DWORD(0)
self.SetConsoleTextAttribute(self.hout, attr)
for short_chunk in split_block(chunk):
self.WriteConsoleW(self.hout, ensure_unicode(short_chunk), len(short_chunk), byref(junk), None)
return len(text)
开发者ID:chensunn,项目名称:PortableJekyll,代码行数:11,代码来源:console.py
示例2: _get_completions
def _get_completions(self):
"""Return a list of possible completions for the string ending at the point.
Also set begidx and endidx in the process."""
completions = []
self.begidx = self.l_buffer.point
self.endidx = self.l_buffer.point
buf=self.l_buffer.line_buffer
if self.completer:
# get the string to complete
while self.begidx > 0:
self.begidx -= 1
if buf[self.begidx] in self.completer_delims:
self.begidx += 1
break
text = ensure_str(''.join(buf[self.begidx:self.endidx]))
log('complete text="%s"' % ensure_unicode(text))
i = 0
while 1:
try:
r = self.completer(ensure_unicode(text), i)
except IndexError:
break
except TypeError:
break
i += 1
if r is None:
break
elif r and r not in completions:
completions.append(r)
else:
pass
log('text completions=<%s>' % list(map(ensure_unicode, completions)))
if (self.complete_filesystem == "on") and not completions:
# get the filename to complete
while self.begidx > 0:
self.begidx -= 1
if buf[self.begidx] in ' \t\n':
self.begidx += 1
break
text = ensure_str(''.join(buf[self.begidx:self.endidx]))
log('file complete text="%s"' % ensure_unicode(text))
completions = list(map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'.encode('ascii'))))
if self.mark_directories == 'on':
mc = []
for f in completions:
if os.path.isdir(f):
mc.append(f + os.sep)
else:
mc.append(f)
completions = mc
log('fnames=<%s>' % list(map(ensure_unicode, completions)))
return completions
开发者ID:ainfosec,项目名称:pyreadline,代码行数:52,代码来源:basemode.py
示例3: _get_completions
def _get_completions(self):
"""Return a list of possible completions for the string ending at the point.
Also set begidx and endidx in the process."""
completions = []
self.begidx = self.l_buffer.point
self.endidx = self.l_buffer.point
buf=self.l_buffer.line_buffer
if self.completer:
# get the string to complete
while self.begidx > 0:
self.begidx -= 1
if buf[self.begidx] in self.completer_delims:
self.begidx += 1
break
text = ensure_str(u''.join(buf[self.begidx:self.endidx]))
log(u'complete text="%s"' % ensure_unicode(text))
i = 0
while 1:
try:
r = ensure_unicode(self.completer(text, i))
except:
break
i += 1
if r and r not in completions:
completions.append(r)
else:
break
log(u'text completions=<%s>' % map(ensure_unicode, completions))
if not completions:
# get the filename to complete
while self.begidx > 0:
self.begidx -= 1
if buf[self.begidx] in u' \t\n':
self.begidx += 1
break
text = ensure_str(u''.join(buf[self.begidx:self.endidx]))
log(u'file complete text="%s"' % ensure_unicode(text))
completions = map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'))
if self.mark_directories == u'on':
mc = []
for f in completions:
if os.path.isdir(f):
mc.append(f + os.sep)
else:
mc.append(f)
completions = mc
log(u'fnames=<%s>' % map(ensure_unicode, completions))
return completions
开发者ID:fboender,项目名称:mcplayeredit,代码行数:48,代码来源:basemode.py
示例4: parse_history_from_string
def parse_history_from_string(self, string=None):
'''Create a readline history from a string.
Each history item must be separated by a newline character (\n)'''
if not string:
return
for line in string.split("\n"):
self.add_history(ensure_unicode(line.rstrip()))
开发者ID:ainfosec,项目名称:pyreadline,代码行数:7,代码来源:history.py
示例5: add_item
def add_item(self, line, force=False):
# Kludge. pyreadline is a pain in the ass.
from pyreadline import lineobj
from pyreadline.unicode_helper import ensure_unicode
line = ensure_unicode(line.rstrip())
readline.add_history(lineobj.ReadLineTextBuffer(line))
开发者ID:AppScale,项目名称:appscale,代码行数:7,代码来源:history.py
示例6: check_key
def check_key():
if msvcrt is None:
return False
else:
if msvcrt.kbhit():
q = ensure_unicode(msvcrt.getch())
return q
return ""
开发者ID:AgainstTheCurrent,项目名称:pyreadline,代码行数:8,代码来源:logserver.py
示例7: _readline_from_keyboard
def _readline_from_keyboard(self):
c = self.console
def nop(e):
pass
while 1:
self._update_line()
lbuf = self.l_buffer
log_sock("point:%d mark:%d selection_mark:%d" % (lbuf.point, lbuf.mark, lbuf.selection_mark))
try:
event = c.getkeypress()
log_sock(u">>%s" % event)
except KeyboardInterrupt:
from pyreadline.keysyms.common import KeyPress
from pyreadline.console.event import Event
event = Event(0, 0)
event.char = "c"
event.keyinfo = KeyPress("c", shift=False, control=True, meta=False, keyname=None)
log_sock("KBDIRQ")
if self.allow_ctrl_c:
now = time.time()
if (now - self.ctrl_c_timeout) < self.ctrl_c_tap_time_interval:
raise
else:
self.ctrl_c_timeout = now
pass
else:
raise
if self.next_meta:
self.next_meta = False
control, meta, shift, code = event.keyinfo
event.keyinfo = (control, True, shift, code)
# Process exit keys. Only exit on empty line
keyinfo = event.keyinfo.tuple()
if keyinfo in self.exit_dispatch:
if lineobj.EndOfLine(self.l_buffer) == 0:
raise EOFError
if len(keyinfo[-1]) > 1:
default = nop
else:
default = self.self_insert
dispatch_func = self.key_dispatch.get(keyinfo, default)
log("readline from keyboard:%s,%s" % (keyinfo, dispatch_func))
log_sock((u"%s|%s" % (ensure_unicode(format(keyinfo)), dispatch_func.__name__)), "bound_function")
r = None
if dispatch_func:
r = dispatch_func(event)
self._keylog(dispatch_func, self.l_buffer)
self.l_buffer.push_undo()
self.previous_func = dispatch_func
if r:
self._update_line()
break
开发者ID:HBPSP8Repo,项目名称:exareme,代码行数:57,代码来源:emacs.py
示例8: write_plain
def write_plain(self, text, attr=None):
'''write text at current cursor position.'''
log('write("%s", %s)' %(text,attr))
if attr is None:
attr = self.attr
n = c_int(0)
self.SetConsoleTextAttribute(self.hout, attr)
self.WriteConsoleW(self.hout, ensure_unicode(chunk), len(chunk), byref(junk), None)
return len(text)
开发者ID:Aha00a,项目名称:play1,代码行数:9,代码来源:console.py
示例9: write_scrolling
def write_scrolling(self, text, attr=None):
'''write text at current cursor position while watching for scrolling.
If the window scrolls because you are at the bottom of the screen
buffer, all positions that you are storing will be shifted by the
scroll amount. For example, I remember the cursor position of the
prompt so that I can redraw the line but if the window scrolls,
the remembered position is off.
This variant of write tries to keep track of the cursor position
so that it will know when the screen buffer is scrolled. It
returns the number of lines that the buffer scrolled.
'''
text = ensure_unicode(text)
x, y = self.pos()
w, h = self.size()
scroll = 0 # the result
# split the string into ordinary characters and funny characters
chunks = self.motion_char_re.split(text)
for chunk in chunks:
n = self.write_color(chunk, attr)
if len(chunk) == 1: # the funny characters will be alone
if chunk[0] == '\n': # newline
x = 0
y += 1
elif chunk[0] == '\r': # carriage return
x = 0
elif chunk[0] == '\t': # tab
x = 8 * (int(x / 8) + 1)
if x > w: # newline
x -= w
y += 1
elif chunk[0] == '\007': # bell
pass
elif chunk[0] == '\010':
x -= 1
if x < 0:
y -= 1 # backed up 1 line
else: # ordinary character
x += 1
if x == w: # wrap
x = 0
y += 1
if y == h: # scroll
scroll += 1
y = h - 1
else: # chunk of ordinary characters
x += n
l = int(x / w) # lines we advanced
x = x % w # new x value
y += l
if y >= h: # scroll
scroll += y - h + 1
y = h - 1
return scroll
开发者ID:0x0mar,项目名称:OWASP-ZSC,代码行数:56,代码来源:console.py
示例10: GetClipboardText
def GetClipboardText():
text = u""
if OpenClipboard(0):
hClipMem = GetClipboardData(CF_TEXT)
if hClipMem:
GlobalLock.restype = c_char_p
text = GlobalLock(hClipMem)
GlobalUnlock(hClipMem)
CloseClipboard()
return ensure_unicode(text)
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:10,代码来源:win32_clipboard.py
示例11: write_color
def write_color(self, text, attr=None):
text = ensure_unicode(text)
n,res= self.ansiwriter.write_color(text,attr)
junk = c_int(0)
for attr,chunk in res:
log(unicode(attr))
log(unicode(chunk))
self.SetConsoleTextAttribute(self.hout, attr.winattr)
self.WriteConsoleW(self.hout, chunk, len(chunk), byref(junk), None)
return n
开发者ID:Aha00a,项目名称:play1,代码行数:10,代码来源:console.py
示例12: read_history_file
def read_history_file(self, filename=None):
'''Load a readline history file.'''
if filename is None:
filename = self.history_filename
try:
for line in open(filename, 'r'):
self.add_history(lineobj.ReadLineTextBuffer(ensure_unicode(line.rstrip())))
except IOError:
self.history = []
self.history_cursor = 0
开发者ID:willbr,项目名称:pyreadline,代码行数:10,代码来源:history.py
示例13: write_color
def write_color(self, text, attr=None):
text = ensure_unicode(text)
n, res = self.ansiwriter.write_color(text, attr)
junk = DWORD(0)
for attr, chunk in res:
log(u"console.attr:%s" % unicode(attr))
log(u"console.chunk:%s" % unicode(chunk))
self.SetConsoleTextAttribute(self.hout, attr.winattr)
for short_chunk in split_block(chunk):
self.WriteConsoleW(self.hout, short_chunk, len(short_chunk), byref(junk), None)
return n
开发者ID:chensunn,项目名称:PortableJekyll,代码行数:11,代码来源:console.py
示例14: add_history
def add_history(self, line):
'''Append a line to the history buffer, as if it was the last line typed.'''
line = ensure_unicode(line)
if not hasattr(line, "get_line_text"):
line = lineobj.ReadLineTextBuffer(line)
if not line.get_line_text():
pass
elif len(self.history) > 0 and self.history[-1].get_line_text() == line.get_line_text():
pass
else:
self.history.append(line)
self.history_cursor = len(self.history)
开发者ID:ainfosec,项目名称:pyreadline,代码行数:12,代码来源:history.py
示例15: SetClipboardText
def SetClipboardText(text):
buffer = create_unicode_buffer(ensure_unicode(text))
bufferSize = sizeof(buffer)
hGlobalMem = GlobalAlloc(c_int(GHND), c_int(bufferSize))
GlobalLock.restype = c_void_p
lpGlobalMem = GlobalLock(c_int(hGlobalMem))
memcpy(lpGlobalMem, addressof(buffer), c_int(bufferSize))
GlobalUnlock(c_int(hGlobalMem))
if OpenClipboard(0):
EmptyClipboard()
SetClipboardData(c_int(CF_UNICODETEXT), c_int(hGlobalMem))
CloseClipboard()
开发者ID:GeeksXtreme,项目名称:csr2f,代码行数:12,代码来源:win32_clipboard.py
示例16: get
def get(self):
'''Get next event from queue.'''
inputHookFunc = c_int.from_address(self.inputHookPtr).value
Cevent = INPUT_RECORD()
count = c_int(0)
while 1:
if inputHookFunc:
call_function(inputHookFunc, ())
status = self.ReadConsoleInputW(self.hin, byref(Cevent), 1, byref(count))
if status and count.value == 1:
e = event(self, Cevent)
log_sock(ensure_unicode(e.keyinfo),"keypress")
return e
开发者ID:Aha00a,项目名称:play1,代码行数:14,代码来源:console.py
示例17: SetClipboardText
def SetClipboardText(text):
buffer = create_unicode_buffer(ensure_unicode(text))
bufferSize = sizeof(buffer)
hGlobalMem = GlobalAlloc(GHND, c_size_t(bufferSize))
GlobalLock.restype = c_void_p
lpGlobalMem = GlobalLock(hGlobalMem)
_strncpy(cast(lpGlobalMem, c_wchar_p),
cast(addressof(buffer), c_wchar_p),
c_size_t(bufferSize))
GlobalUnlock(c_int(hGlobalMem))
if OpenClipboard(0):
EmptyClipboard()
SetClipboardData(CF_UNICODETEXT, hGlobalMem)
CloseClipboard()
开发者ID:0x0mar,项目名称:OWASP-ZSC,代码行数:14,代码来源:win32_clipboard.py
示例18: add_history
def add_history(self, line):
'''Append a line to the history buffer, as if it was the last line typed.
Empty lines are skipped.
Repeated line, i.e. line equal to the last one is skipped as well
modified history nformation is discarded
'''
line = ensure_unicode(line)
log('add_history line="%s" currentlen is %d' % (line.get_line_text(), len(self.history)))
if not hasattr(line, "get_line_text"):
line = lineobj.ReadLineTextBuffer(line)
else:
line.end_of_line()
if not line.get_line_text():
if len(self.history) > 0 and len(self.history[-1].get_line_text()) == 0:
self.history = self.history[:-1]
pass
elif len(self.history) > 0 and self.history[-1].get_line_text() == line.get_line_text():
pass
elif len(self.history) > 0 and len(self.history[-1].get_line_text()) == 0:
self.history[-1] = line
else:
self.history.append(line)
self.history_cursor = len(self.history)
self.clear_modified_history()
开发者ID:mishagr,项目名称:pyreadline,代码行数:24,代码来源:history.py
示例19: read_history_file
def read_history_file(self, filename=None):
u'''Load a readline history file. The default filename is ~/.history.'''
if filename is None:
filename = self.mode._history.history_filename
log(u"read_history_file from %s"%ensure_unicode(filename))
self.mode._history.read_history_file(filename)
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:6,代码来源:rlmain.py
示例20: write
def write(self, text):
text = ensure_unicode(text)
log('write("%s")' % text)
return self.write_color(text)
开发者ID:0x0mar,项目名称:OWASP-ZSC,代码行数:4,代码来源:console.py
注:本文中的pyreadline.unicode_helper.ensure_unicode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论