本文整理匯總了Python中builtins.chr方法的典型用法代碼示例。如果您正苦於以下問題:Python builtins.chr方法的具體用法?Python builtins.chr怎麽用?Python builtins.chr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類builtins
的用法示例。
在下文中一共展示了builtins.chr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: chr
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def chr(val):
"""
Patched Version of builtins.chr, to work with narrow python builds
In those versions, the function unichr does not work with inputs >0x10000
This seems to be a problem usually on older windows builds.
:param val: integer value of character
:return: character
"""
try:
return builtins.chr(val)
except ValueError as e:
if "(narrow Python build)" in str(e):
return struct.pack('i', val).decode('utf-32')
else:
raise e
示例2: encode_string
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def encode_string(string):
"""Encode a string so that non printables are escaped.
Returns unicode string.
e.g. b"hello\x88xdr" -> "hello\x88xdr"
"""
byte_string = SmartStr(string)
result = []
for c in byte_string:
c = my_ord(c)
if c > 127 or c < 32:
result.extend("\\x%02x" % c)
else:
result.append(chr(c))
return "".join(result)
示例3: urn_from_member_name
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def urn_from_member_name(member, base_urn, version):
"""Returns a URN object from a zip file's member name."""
member = utils.SmartUnicode(member)
if version != pyaff4.version.basic_zip:
if version.isLessThanOrEqual(1, 0):
# Remove %xx escapes.
member = re.sub(
"%(..)", lambda x: chr(int("0x" + x.group(1), 0)),
member)
elif version.equals(1,1):
member = member.replace(" ", "%20")
# This is an absolute URN.
if urllib.parse.urlparse(member).scheme == "aff4":
result = member
else:
# Relative member becomes relative to the volume's URN.
result = base_urn.Append(member, quote=False)
return rdfvalue.URN(result)
示例4: update
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def update(self, reseed):
"""
Update that trail!
:param reseed: Whether we are in the normal reseed cycle or not.
"""
if self._clear:
for i in range(0, 3):
self._screen.print_at(" ",
self._x,
self._screen.start_line + self._y + i)
self._maybe_reseed(reseed)
else:
for i in range(0, 3):
self._screen.print_at(chr(randint(32, 126)),
self._x,
self._screen.start_line + self._y + i,
Screen.COLOUR_GREEN)
for i in range(4, 6):
self._screen.print_at(chr(randint(32, 126)),
self._x,
self._screen.start_line + self._y + i,
Screen.COLOUR_GREEN,
Screen.A_BOLD)
self._maybe_reseed(reseed)
示例5: test_putch_and_getch
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def test_putch_and_getch(self):
"""
Check deprecated features still work.
"""
def internal_checks(screen):
for x in range(screen.width):
for y in range(15):
char = randint(0, 255)
fg = randint(0, Screen.COLOUR_WHITE)
bg = randint(0, Screen.COLOUR_WHITE)
attr = randint(0, Screen.A_UNDERLINE)
screen.putch(chr(char), x, y, fg, attr, bg)
char2, fg2, attr2, bg2 = screen.getch(x, y)
self.assertEqual(char, char2)
self.assertEqual(fg, fg2)
self.assertEqual(attr, attr2)
self.assertEqual(bg, bg2)
Screen.wrapper(internal_checks, height=15)
示例6: test_ctrl
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def test_ctrl(self):
"""
Check that ctrl returns the right values.
"""
# Check standard alphabetical range
for i, char in enumerate(range(ord('@'), ord('Z'))):
self.assertEqual(Screen.ctrl(char), i)
self.assertEqual(Screen.ctrl(chr(char)), i)
self.assertEqual(Screen.ctrl(chr(char).lower()), i)
# Check last few options - which mostly aren't actually returned in
# Linux and so probably only of limited value, but what the heck!
for i, char in enumerate(["[", "\\", "]", "^", "_"]):
self.assertEqual(Screen.ctrl(char), i + 27)
# Check other things return None - pick boundaries for checks.
for char in ["?", "`", "\x7f"]:
self.assertIsNone(Screen.ctrl(char))
示例7: test_stars
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def test_stars(self):
"""
Check that Stars works.
"""
# Check that Stars randomly updates the Screen every frame.
screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
canvas = Canvas(screen, 10, 40, 0, 0)
effect = Stars(canvas, 100)
effect.reset()
self.assert_blank(canvas)
my_buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)]
for i in range(10):
effect.update(i)
self.assertTrue(self.check_canvas(
canvas,
my_buffer,
lambda value: self.assertIn(chr(value[0]), " .+x*")))
# Check there is no stop frame by default.
self.assertEqual(effect.stop_frame, 0)
# This effect should ignore events.
event = object()
self.assertEqual(event, effect.process_event(event))
示例8: test_stars_pattern
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def test_stars_pattern(self):
"""
Check that Stars custom pattern value works.
"""
# Check that Stars randomly updates the Screen every frame.
screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
canvas = Canvas(screen, 10, 40, 0, 0)
effect = Stars(canvas, 100, "TESTTESTTEST")
effect.reset()
my_buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)]
for i in range(10):
effect.update(i)
self.assertTrue(self.check_canvas(
canvas,
my_buffer,
lambda value: self.assertIn(chr(value[0]), " TES")))
示例9: test_snow
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def test_snow(self):
"""
Check that Snow works.
"""
# Check that Snow randomly updates the Screen every 3rd frame.
screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
canvas = Canvas(screen, 10, 40, 0, 0)
effect = Snow(canvas)
effect.reset()
self.assert_blank(canvas)
my_buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)]
for i in range(10):
effect.update(i)
self.assertEqual(self.check_canvas(
canvas,
my_buffer,
lambda value: self.assertIn(chr(value[0]), ".+* ,;#@")),
i % 3 == 0)
# Check there is no stop frame by default.
self.assertEqual(effect.stop_frame, 0)
# This effect should ignore events.
event = object()
self.assertEqual(event, effect.process_event(event))
示例10: get_text_to_type
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def get_text_to_type():
"""Return text to type."""
chars = []
chars_to_type_count = random.randint(1, MAX_CHARS_TO_TYPE)
meta_chars = [
'|', '&', ';', '(', ')', '<', '>', ' ', '\t', ',', '\'', '"', '`', '[',
']', '{', '}'
]
for _ in range(chars_to_type_count):
char_code = random.randint(32, 126)
char = chr(char_code)
if char in meta_chars:
continue
chars.append(char)
return ''.join(chars)
示例11: refresh
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def refresh(self):
"""
Refresh the screen.
"""
# Scroll the screen as required to minimize redrawing.
if self._last_start_line != self._start_line:
self._scroll(self._start_line - self._last_start_line)
if self._start_line > self._last_start_line:
self._buffer.invalidate(self._last_start_line + self.height, self._start_line + self.height)
else:
self._buffer.invalidate(self._start_line, self._last_start_line)
self._last_start_line = self._start_line
# Now draw any deltas to the scrolled screen. Note that CJK character sets sometimes
# use double-width characters, so don't try to draw the next character if we hit one.
for y, x in self._buffer.deltas(self._last_start_line, self.height):
new_cell = self._buffer.get(x, y)
self._change_colours(new_cell[1], new_cell[2], new_cell[3])
self._print_at(chr(new_cell[0]), x, y - self._last_start_line, new_cell[4])
# Resynch for next refresh.
self._buffer.sync()
示例12: jhexdecode
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def jhexdecode(t):
r = re.sub(r'_\d+x\w+x(\d+)', 'var_' + r'\1', t)
r = re.sub(r'_\d+x\w+', 'var_0', r)
def to_hx(c):
h = int("%s" % c.groups(0), 16)
if 19 < h < 160:
return chr(h)
else:
return ""
r = re.sub(r'(?:\\|)x(\w{2})', to_hx, r).replace('var ', '')
f = eval(scrapertools.find_single_match(r, '\s*var_0\s*=\s*([^;]+);'))
for i, v in enumerate(f):
r = r.replace('[[var_0[%s]]' % i, "." + f[i])
r = r.replace(':var_0[%s]' % i, ":\"" + f[i] + "\"")
r = r.replace(' var_0[%s]' % i, " \"" + f[i] + "\"")
r = r.replace('(var_0[%s]' % i, "(\"" + f[i] + "\"")
r = r.replace('[var_0[%s]]' % i, "." + f[i])
if v == "": r = r.replace('var_0[%s]' % i, '""')
r = re.sub(r':(function.*?\})', r":'\g<1>'", r)
r = re.sub(r':(var[^,]+),', r":'\g<1>',", r)
return r
示例13: argument_names
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def argument_names(args):
"""Give arguments alpha-numeric names.
>>> names = argument_names(range(100))
>>> [names[i] for i in range(0,100,26)]
[u'?a', u'?a1', u'?a2', u'?a3']
>>> [names[i] for i in range(1,100,26)]
[u'?b', u'?b1', u'?b2', u'?b3']
"""
# Argument naming scheme: integer -> `?[a-z]` with potentially a number if
# there more than 26 arguments.
name = {}
for i, arg in enumerate(args):
c = i // 26 if i >= 26 else ''
name[arg] = '?%s%s' % (chr(97+(i % 26)), c)
return name
示例14: hexdump
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def hexdump(data):
def _cut(sequence, size):
for i in range(0, len(sequence), size):
yield sequence[i:i+size]
def _hex(sequence):
return ['{0:02x}'.format(b) for b in sequence]
def _chr(sequence):
return [chr(b) if 32 <= b <= 126 else '.' for b in sequence]
raw_data = map(ord, data)
hexpanel = [' '.join(line) for line in _cut(_hex(raw_data), 16)]
chrpanel = [''.join(line) for line in _cut(_chr(raw_data), 16)]
hexpanel[-1] = hexpanel[-1] + (chr(32) * (47 - len(hexpanel[-1])))
chrpanel[-1] = chrpanel[-1] + (chr(32) * (16 - len(chrpanel[-1])))
return '\n'.join('{} {}'.format(h, c) for h, c in zip(hexpanel, chrpanel))
示例15: cp437
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import chr [as 別名]
def cp437(self, c):
return chr(self.cp437ToUnicode[c])