本文整理汇总了Python中pyreadline.unicode_helper.ensure_str函数的典型用法代码示例。如果您正苦于以下问题:Python ensure_str函数的具体用法?Python ensure_str怎么用?Python ensure_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ensure_str函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: log_sock
def log_sock(s, event_type=None):
if sock_silent:
pass
else:
if event_type is None:
logsocket.sendto(ensure_str(s), (host, port))
elif event_type in show_event:
logsocket.sendto(ensure_str(s), (host, port))
else:
pass
开发者ID:eclettica,项目名称:play1,代码行数:10,代码来源:logger.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(''.join(buf[self.begidx:self.endidx]))
log('complete text="%s"' % 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('text completions=%s' % completions)
if 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"' % text)
completions = map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'))
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' % completions)
return completions
开发者ID:Aha00a,项目名称:play1,代码行数:50,代码来源:basemode.py
示例4: __init__
def __init__(self):
self.history = []
self._history_length = 100
self._history_cursor = 0
self.history_filename = os.path.expanduser(ensure_str('~/.history')) #Cannot expand unicode strings correctly on python2.4
self.lastcommand = None
self.query = ""
self.last_search_for = ""
开发者ID:ainfosec,项目名称:pyreadline,代码行数:8,代码来源:history.py
示例5: write_history_file
def write_history_file(self, filename=None):
"""Save a readline history file."""
if filename is None:
filename = self.history_filename
fp = open(filename, "wb")
for line in self.history[-self.history_length :]:
fp.write(ensure_str(line.get_line_text()))
fp.write("\n")
fp.close()
开发者ID:NZubia,项目名称:coffee_Service_System_Play_And_Angularjs-,代码行数:9,代码来源:history.py
示例6: write_history_file
def write_history_file(self, filename = None):
'''Save a readline history file.'''
if filename is None:
filename = self.history_filename
fp = open(filename, 'wb')
for line in self.history[-self.history_length:]:
fp.write(ensure_str(line.get_line_text()))
fp.write('\n'.encode('ascii'))
fp.close()
开发者ID:willbr,项目名称:pyreadline,代码行数:9,代码来源:history.py
示例7: 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.
'''
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(ensure_str(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:willbr,项目名称:pyreadline,代码行数:55,代码来源:console.py
示例8: scroll
def scroll(self, rect, dx, dy, attr=None, fill=" "):
u"""Scroll a rectangle."""
if attr is None:
attr = self.attr
x0, y0, x1, y1 = rect
source = SMALL_RECT(x0, y0, x1 - 1, y1 - 1)
dest = self.fixcoord(x0 + dx, y0 + dy)
style = CHAR_INFO()
style.Char.AsciiChar = ensure_str(fill[0])
style.Attributes = attr
return self.ScrollConsoleScreenBufferW(self.hout, byref(source), byref(source), dest, byref(style))
开发者ID:chensunn,项目名称:PortableJekyll,代码行数:12,代码来源:console.py
示例9: SetClipboardText
def SetClipboardText(text):
buffer = c_buffer(ensure_str(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_TEXT), c_int(hGlobalMem))
CloseClipboard()
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:12,代码来源:win32_clipboard.py
示例10: hook_wrapper_23
def hook_wrapper_23(stdin, stdout, prompt):
'''Wrap a Python readline so it behaves like GNU readline.'''
try:
# call the Python hook
res = ensure_str(readline_hook(prompt))
# make sure it returned the right sort of thing
if res and not isinstance(res, bytes):
raise TypeError('readline must return a string.')
except KeyboardInterrupt:
# GNU readline returns 0 on keyboard interrupt
return 0
except EOFError:
# It returns an empty string on EOF
res = ensure_str('')
except:
print('Readline internal error', file=sys.stderr)
traceback.print_exc()
res = ensure_str('\n')
# we have to make a copy because the caller expects to free the result
n = len(res)
p = Console.PyMem_Malloc(n + 1)
_strncpy(cast(p, c_char_p), res, n + 1)
return p
开发者ID:0x0mar,项目名称:OWASP-ZSC,代码行数:23,代码来源:console.py
示例11: hook_wrapper
def hook_wrapper(prompt):
'''Wrap a Python readline so it behaves like GNU readline.'''
try:
# call the Python hook
res = ensure_str(readline_hook(prompt))
# make sure it returned the right sort of thing
if res and not isinstance(res, str):
raise TypeError, 'readline must return a string.'
except KeyboardInterrupt:
# GNU readline returns 0 on keyboard interrupt
return 0
except EOFError:
# It returns an empty string on EOF
res = ''
except:
print >>sys.stderr, 'Readline internal error'
traceback.print_exc()
res = '\n'
# we have to make a copy because the caller expects to free the result
p = cdll.msvcrt._strdup(res)
return p
开发者ID:Aha00a,项目名称:play1,代码行数:21,代码来源:console.py
示例12: get_current_completed_word
def get_current_completed_word(self):
"""Return a current word_between completion separators"""
begidx = self.l_buffer.point
endidx = self.l_buffer.point
buf=self.l_buffer.line_buffer
l = len(buf)
if l == 0:
return ""
# if we immediately after the symbol go one character back
if begidx == l or buf[begidx] in self.completer_delims:
begidx -= 1
# find the beginning of the word
while begidx > 0:
if buf[begidx] in self.completer_delims:
begidx += 1
break
begidx -= 1
# find the end of the word
while endidx < l:
if buf[endidx] in self.completer_delims:
break
endidx += 1
text = ensure_str(u''.join(buf[begidx:endidx]))
return text
开发者ID:minersoft,项目名称:miner,代码行数:24,代码来源:basemode.py
示例13: sethistoryfilename
def sethistoryfilename(filename):
self.mode._history.history_filename = os.path.expanduser(
ensure_str(filename))
开发者ID:CodeMaxx,项目名称:OWASP-ZSC-API,代码行数:3,代码来源:rlmain.py
示例14: write_color
def write_color(self, text, attr=None):
text = ensure_str(text)
junk = DWORD(0)
self.WriteFile(self.hout, text, len(text), byref(junk), None)
return len(text)
开发者ID:0x0mar,项目名称:OWASP-ZSC,代码行数:5,代码来源:console.py
示例15: log
def log(s):
s = ensure_str(s)
pyreadline_logger.debug(s)
开发者ID:0x0mar,项目名称:OWASP-ZSC,代码行数:3,代码来源:logger.py
示例16: write
def write(self, s):
self.logsocket.sendto(ensure_str(s), (host, port))
开发者ID:0x0mar,项目名称:OWASP-ZSC,代码行数:2,代码来源:logger.py
示例17: log
def log(s):
s = ensure_str(s)
root_logger.debug(s)
开发者ID:fboender,项目名称:mcplayeredit,代码行数:3,代码来源:logger.py
示例18: log
def log(s):
if _logfile:
s = ensure_str(s)
print >> _logfile, s
_logfile.flush()
开发者ID:eclettica,项目名称:play1,代码行数:5,代码来源:logger.py
示例19: read_inputrc
def read_inputrc(self, #in 2.4 we cannot call expanduser with unicode string
inputrcpath=os.path.expanduser(ensure_str("~/pyreadlineconfig.ini"))):
modes = dict([(x.mode, x) for x in self.editingmodes])
mode = self.editingmodes[0].mode
def setmode(name):
self.mode = modes[name]
def bind_key(key, name):
import types
if callable(name):
modes[mode]._bind_key(key, types.MethodType(name, modes[mode]))
elif hasattr(modes[mode], name):
modes[mode]._bind_key(key, getattr(modes[mode], name))
else:
print("Trying to bind unknown command '%s' to key '%s'" %
(name, key))
def un_bind_key(key):
keyinfo = make_KeyPress_from_keydescr(key).tuple()
if keyinfo in modes[mode].key_dispatch:
del modes[mode].key_dispatch[keyinfo]
def bind_exit_key(key):
modes[mode]._bind_exit_key(key)
def un_bind_exit_key(key):
keyinfo = make_KeyPress_from_keydescr(key).tuple()
if keyinfo in modes[mode].exit_dispatch:
del modes[mode].exit_dispatch[keyinfo]
def setkill_ring_to_clipboard(killring):
import pyreadline.lineeditor.lineobj
pyreadline.lineeditor.lineobj.kill_ring_to_clipboard = killring
def sethistoryfilename(filename):
self.mode._history.history_filename = os.path.expanduser(
ensure_str(filename))
def setbellstyle(mode):
self.bell_style = mode
def disable_readline(mode):
self.disable_readline = mode
def sethistorylength(length):
self.mode._history.history_length = int(length)
def allow_ctrl_c(mode):
log("allow_ctrl_c:%s:%s" % (self.allow_ctrl_c, mode))
self.allow_ctrl_c = mode
def setbellstyle(mode):
self.bell_style = mode
def show_all_if_ambiguous(mode):
self.mode.show_all_if_ambiguous = mode
def ctrl_c_tap_time_interval(mode):
self.ctrl_c_tap_time_interval = mode
def mark_directories(mode):
self.mode.mark_directories = mode
def completer_delims(delims):
self.mode.completer_delims = delims
def complete_filesystem(delims):
self.mode.complete_filesystem = delims.lower()
def enable_ipython_paste_for_paths(boolean):
self.mode.enable_ipython_paste_for_paths = boolean
def debug_output(
on, filename="pyreadline_debug_log.txt"): #Not implemented yet
if on in ["on", "on_nologfile"]:
self.debug = True
if on == "on":
logger.start_file_log(filename)
logger.start_socket_log()
logger.log("STARTING LOG")
elif on == "on_nologfile":
logger.start_socket_log()
logger.log("STARTING LOG")
else:
logger.log("STOPING LOG")
logger.stop_file_log()
logger.stop_socket_log()
_color_trtable = {"black": 0,
"darkred": 4,
"darkgreen": 2,
"darkyellow": 6,
"darkblue": 1,
"darkmagenta": 5,
"darkcyan": 3,
"gray": 7,
"red": 4 + 8,
"green": 2 + 8,
#.........这里部分代码省略.........
开发者ID:CodeMaxx,项目名称:OWASP-ZSC-API,代码行数:101,代码来源:rlmain.py
注:本文中的pyreadline.unicode_helper.ensure_str函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论