Python future.builtins.chr() Examples

The following are 30 code examples of future.builtins.chr(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module future.builtins , or try the search function .
Example #1
Source File: quoprimime.py    From verge3d-blender-addon with GNU General Public License v3.0 6 votes vote down vote up
def unquote(s):
    """Turn a string in the form =AB to the ASCII character with value 0xab"""
    return chr(int(s[1:3], 16)) 
Example #2
Source File: test_urllib.py    From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 6 votes vote down vote up
def test_unquoting(self):
        # Make sure unquoting of all ASCII values works
        escape_list = []
        for num in range(128):
            given = hexescape(chr(num))
            expect = chr(num)
            result = urllib_parse.unquote(given)
            self.assertEqual(expect, result,
                             "using unquote(): %r != %r" % (expect, result))
            result = urllib_parse.unquote_plus(given)
            self.assertEqual(expect, result,
                             "using unquote_plus(): %r != %r" %
                             (expect, result))
            escape_list.append(given)
        escape_string = ''.join(escape_list)
        del escape_list
        result = urllib_parse.unquote(escape_string)
        self.assertEqual(result.count('%'), 1,
                         "using unquote(): not all characters escaped: "
                         "%s" % result)
        self.assertRaises((TypeError, AttributeError), urllib_parse.unquote, None)
        self.assertRaises((TypeError, AttributeError), urllib_parse.unquote, ())
        with support.check_warnings(('', BytesWarning), quiet=True):
            self.assertRaises((TypeError, AttributeError), urllib_parse.unquote, bytes(b'')) 
Example #3
Source File: scrollstring.py    From musicbox with MIT License 6 votes vote down vote up
def truelen(string):
    """
    It appears one Asian character takes two spots, but __len__
    counts it as three, so this function counts the dispalyed
    length of the string.

    >>> truelen('abc')
    3
    >>> truelen('你好')
    4
    >>> truelen('1二3')
    4
    >>> truelen('')
    0
    """
    return len(string) + sum(1 for c in string if c > chr(127)) 
Example #4
Source File: dammit.py    From Tautulli with GNU General Public License v3.0 6 votes vote down vote up
def _populate_class_variables():
        lookup = {}
        reverse_lookup = {}
        characters_for_re = []

        # &apos is an XHTML entity and an HTML 5, but not an HTML 4
        # entity. We don't want to use it, but we want to recognize it on the way in.
        #
        # TODO: Ideally we would be able to recognize all HTML 5 named
        # entities, but that's a little tricky.
        extra = [(39, 'apos')]
        for codepoint, name in list(codepoint2name.items()) + extra:
            character = chr(codepoint)
            if codepoint not in (34, 39):
                # There's no point in turning the quotation mark into
                # " or the single quote into ', unless it
                # happens within an attribute value, which is handled
                # elsewhere.
                characters_for_re.append(character)
                lookup[character] = name
            # But we do want to recognize those entities on the way in and
            # convert them to Unicode characters.
            reverse_lookup[name] = character
        re_definition = "[%s]" % "".join(characters_for_re)
        return lookup, reverse_lookup, re.compile(re_definition) 
Example #5
Source File: quoprimime.py    From misp42splunk with GNU Lesser General Public License v3.0 6 votes vote down vote up
def unquote(s):
    """Turn a string in the form =AB to the ASCII character with value 0xab"""
    return chr(int(s[1:3], 16)) 
Example #6
Source File: quoprimime.py    From blackmamba with MIT License 5 votes vote down vote up
def _max_append(L, s, maxlen, extra=''):
    if not isinstance(s, str):
        s = chr(s)
    if not L:
        L.append(s.lstrip())
    elif len(L[-1]) + len(s) <= maxlen:
        L[-1] += extra + s
    else:
        L.append(s.lstrip()) 
Example #7
Source File: parse.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def __missing__(self, b):
        # Handle a cache miss. Store quoted string in cache and return.
        res = chr(b) if b in self.safe else '%{0:02X}'.format(b)
        self[b] = res
        return res 
Example #8
Source File: quoprimime.py    From blackmamba with MIT License 5 votes vote down vote up
def unquote(s):
    """Turn a string in the form =AB to the ASCII character with value 0xab"""
    return chr(int(s[1:3], 16)) 
Example #9
Source File: _encoded_words.py    From blackmamba with MIT License 5 votes vote down vote up
def __missing__(self, key):
        if key in self.safe:
            self[key] = chr(key)
        else:
            self[key] = "={:02X}".format(key)
        return self[key] 
Example #10
Source File: parse.py    From blackmamba with MIT License 5 votes vote down vote up
def __missing__(self, b):
        # Handle a cache miss. Store quoted string in cache and return.
        res = chr(b) if b in self.safe else '%{0:02X}'.format(b)
        self[b] = res
        return res 
Example #11
Source File: quoprimime.py    From gimp-plugin-export-layers with GNU General Public License v3.0 5 votes vote down vote up
def header_check(octet):
    """Return True if the octet should be escaped with header quopri."""
    return chr(octet) != _QUOPRI_HEADER_MAP[octet] 
Example #12
Source File: quoprimime.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def unquote(s):
    """Turn a string in the form =AB to the ASCII character with value 0xab"""
    return chr(int(s[1:3], 16)) 
Example #13
Source File: parse.py    From arissploit with GNU General Public License v3.0 5 votes vote down vote up
def __missing__(self, b):
        # Handle a cache miss. Store quoted string in cache and return.
        res = chr(b) if b in self.safe else '%{0:02X}'.format(b)
        self[b] = res
        return res 
Example #14
Source File: quoprimime.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def header_check(octet):
    """Return True if the octet should be escaped with header quopri."""
    return chr(octet) != _QUOPRI_HEADER_MAP[octet] 
Example #15
Source File: quoprimime.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def body_check(octet):
    """Return True if the octet should be escaped with body quopri."""
    return chr(octet) != _QUOPRI_BODY_MAP[octet] 
Example #16
Source File: quoprimime.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def _max_append(L, s, maxlen, extra=''):
    if not isinstance(s, str):
        s = chr(s)
    if not L:
        L.append(s.lstrip())
    elif len(L[-1]) + len(s) <= maxlen:
        L[-1] += extra + s
    else:
        L.append(s.lstrip()) 
Example #17
Source File: quoprimime.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def header_check(octet):
    """Return True if the octet should be escaped with header quopri."""
    return chr(octet) != _QUOPRI_HEADER_MAP[octet] 
Example #18
Source File: quoprimime.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def _max_append(L, s, maxlen, extra=''):
    if not isinstance(s, str):
        s = chr(s)
    if not L:
        L.append(s.lstrip())
    elif len(L[-1]) + len(s) <= maxlen:
        L[-1] += extra + s
    else:
        L.append(s.lstrip()) 
Example #19
Source File: quoprimime.py    From blackmamba with MIT License 5 votes vote down vote up
def body_check(octet):
    """Return True if the octet should be escaped with body quopri."""
    return chr(octet) != _QUOPRI_BODY_MAP[octet] 
Example #20
Source File: quoprimime.py    From blackmamba with MIT License 5 votes vote down vote up
def header_check(octet):
    """Return True if the octet should be escaped with header quopri."""
    return chr(octet) != _QUOPRI_HEADER_MAP[octet] 
Example #21
Source File: quoprimime.py    From gimp-plugin-export-layers with GNU General Public License v3.0 5 votes vote down vote up
def _max_append(L, s, maxlen, extra=''):
    if not isinstance(s, str):
        s = chr(s)
    if not L:
        L.append(s.lstrip())
    elif len(L[-1]) + len(s) <= maxlen:
        L[-1] += extra + s
    else:
        L.append(s.lstrip()) 
Example #22
Source File: _encoded_words.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def __missing__(self, key):
        if key in self.safe:
            self[key] = chr(key)
        else:
            self[key] = "={:02X}".format(key)
        return self[key] 
Example #23
Source File: quoprimime.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def unquote(s):
    """Turn a string in the form =AB to the ASCII character with value 0xab"""
    return chr(int(s[1:3], 16)) 
Example #24
Source File: quoprimime.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def _max_append(L, s, maxlen, extra=''):
    if not isinstance(s, str):
        s = chr(s)
    if not L:
        L.append(s.lstrip())
    elif len(L[-1]) + len(s) <= maxlen:
        L[-1] += extra + s
    else:
        L.append(s.lstrip()) 
Example #25
Source File: quoprimime.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def body_check(octet):
    """Return True if the octet should be escaped with body quopri."""
    return chr(octet) != _QUOPRI_BODY_MAP[octet] 
Example #26
Source File: quoprimime.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def header_check(octet):
    """Return True if the octet should be escaped with header quopri."""
    return chr(octet) != _QUOPRI_HEADER_MAP[octet] 
Example #27
Source File: parse.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __missing__(self, b):
        # Handle a cache miss. Store quoted string in cache and return.
        res = chr(b) if b in self.safe else '%{0:02X}'.format(b)
        self[b] = res
        return res 
Example #28
Source File: _encoded_words.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __missing__(self, key):
        if key in self.safe:
            self[key] = chr(key)
        else:
            self[key] = "={:02X}".format(key)
        return self[key] 
Example #29
Source File: quoprimime.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def unquote(s):
    """Turn a string in the form =AB to the ASCII character with value 0xab"""
    return chr(int(s[1:3], 16)) 
Example #30
Source File: quoprimime.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _max_append(L, s, maxlen, extra=''):
    if not isinstance(s, str):
        s = chr(s)
    if not L:
        L.append(s.lstrip())
    elif len(L[-1]) + len(s) <= maxlen:
        L[-1] += extra + s
    else:
        L.append(s.lstrip())