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


Python builtins.chr方法代码示例

本文整理汇总了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 
开发者ID:amimo,项目名称:dcc,代码行数:19,代码来源:mutf8.py

示例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) 
开发者ID:google,项目名称:rekall,代码行数:18,代码来源:utils.py

示例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) 
开发者ID:aff4,项目名称:pyaff4,代码行数:23,代码来源:escaping.py

示例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) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:27,代码来源:effects.py

示例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) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:21,代码来源:test_screen.py

示例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)) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:20,代码来源:test_screen.py

示例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)) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:26,代码来源:test_effects.py

示例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"))) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:18,代码来源:test_effects.py

示例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)) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:27,代码来源:test_effects.py

示例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) 
开发者ID:google,项目名称:clusterfuzz,代码行数:20,代码来源:gestures.py

示例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() 
开发者ID:QData,项目名称:deepWordBug,代码行数:24,代码来源:screen.py

示例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 
开发者ID:alfa-addon,项目名称:addon,代码行数:23,代码来源:hdfull.py

示例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 
开发者ID:hltcoe,项目名称:PredPatt,代码行数:21,代码来源:patt.py

示例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)) 
开发者ID:base4sistemas,项目名称:pyescpos,代码行数:19,代码来源:helpers.py

示例15: cp437

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import chr [as 别名]
def cp437(self, c):
        return chr(self.cp437ToUnicode[c]) 
开发者ID:amimo,项目名称:dcc,代码行数:4,代码来源:ViewMode.py


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