r"""
    >>> encode_unicode_codepoints("a") == 'a'
    True
    >>> ascii = ''.join(chr(i) for i in range(0x80))
    >>> encode_unicode_codepoints(ascii) == ascii
    True
    >>> encode_unicode_codepoints('\u4e16\u754c') == '\\u4e16\\u754c'
    True
329377
def encode_unicode_codepoints(str):
    
    """
    codepoint_format = '\\u{0:04x}'.format

    def codepoint(m):
        return codepoint_format(ord(m.group(0)))

    return re.sub('[^\x00-\x7f]', codepoint, str)
335010
def _ostaunicode(src):
    # type: (str) -> bytes
    '''
    
    '''
    if have_py_3:
        bytename = src
    else:
        bytename = src.decode('utf-8')  # type: ignore

    try:
        enc = bytename.encode('latin-1')
        encbyte = b'\x08'
    except (UnicodeEncodeError, UnicodeDecodeError):
        enc = bytename.encode('utf-16_be')
        encbyte = b'\x10'
    return encbyte + enc
94982
def uriencode(uristring, safe='', encoding='utf-8', errors='strict'):
    """"""
    if not isinstance(uristring, bytes):
        uristring = uristring.encode(encoding, errors)
    if not isinstance(safe, bytes):
        safe = safe.encode('ascii')
    try:
        encoded = _encoded[safe]
    except KeyError:
        encoded = _encoded[b''][:]
        for i in _tointseq(safe):
            encoded[i] = _fromint(i)
        _encoded[safe] = encoded
    return b''.join(map(encoded.__getitem__, _tointseq(uristring)))
337622
def encode_unicode(f):
    
    @wraps(f)
    def wrapped(obj, error):

        def _encode(value):
            """Helper encoding unicode strings into binary utf-8"""
            if isinstance(value, unicode):  # noqa: F821
                return value.encode('utf-8')
            return value

        error = copy(error)
        error.document_path = _encode(error.document_path)
        error.schema_path = _encode(error.schema_path)
        error.constraint = _encode(error.constraint)
        error.value = _encode(error.value)
        error.info = _encode(error.info)
        return f(obj, error)

    return wrapped if PYTHON_VERSION < 3 else f
470584
public function ucs2Encode($codePoints)
    {
        $outStr = '';
        foreach ($codePoints as $v) {
            if( 0x10000 <= $v && $v <= 0x10FFFF) {
                $v -= 0x10000;
                $w1 = 0xD800 | ($v >> 10);
                $w2 = 0xDC00 | ($v & 0x03FF);
                $outStr .= chr(0xFF & ($w1 >> 8)) . chr(0xFF & $w1);
                $outStr .= chr(0xFF & ($w2 >> 8)) . chr(0xFF & $w2);
            }else{
                $outStr .= chr(0xFF & ($v >> 8)) . chr(0xFF & $v);
            }
        }
        return $outStr;
    }
107125
def unicode2encode(text, charmap):
    '''
    
    '''
    if isinstance(text, (list, tuple)):
        unitxt = ''
        for line in text:
            for val,key in charmap.items():
                if key in line:
                    line = line.replace(key, val)
                # end of if val in text:
            unitxt += line
        # end of for line in text:
        return unitxt
    elif isinstance(text, str):
        for val,key in charmap.items():
            if key in text:
                text = text.replace(key, val)
        return text
885687
def _unicode(self):
        ''''''

        return u'\n'.join ([ u''.join(c) for c in self.w ])
522677
def encode(value, encoding='utf-8', encoding_errors='strict'):
    
    if isinstance(value, bytes):
        return value
    if not isinstance(value, basestring):
        value = str(value)
    if isinstance(value, unicode):
        value = value.encode(encoding, encoding_errors)
    return value
909164
public static String encodeIllegalCharacters(String uri) {
        StringBuilder result = new StringBuilder();
        int length = uri.length();
        for (int i = 0; i < length; i++) {
            char character = uri.charAt(i);
            if (character == '%') {
                // Encode invalid escape sequences
                if (i >= length - 2 || !isHex(uri.charAt(i + 1)) || !isHex(uri.charAt(i + 2))) {
                    result.append("%25");
                } else {
                    result.append('%');
                }
            } else {
                int j = (int) character;
                if (j >= CONVERSION_TABLE_SIZE || j < 0) {
                    result.append(encode(character));
                } else {
                    result.append(CONVERSION_TABLE[j]);
                }
            }
        }
        return result.toString();
    }
154938
def python_to_ucn(uni_char, as_bytes=False):
    
    ucn = uni_char.encode('unicode_escape').decode('latin1')
    ucn = text_type(ucn).replace('\\', '').upper().lstrip('U')
    if len(ucn) > int(4):
        # get rid of the zeroes that Python uses to pad 32 byte UCNs
        ucn = ucn.lstrip("0")
    ucn = "U+" + ucn.upper()

    if as_bytes:
        ucn = ucn.encode('latin1')

    return ucn
594507
def u2s(self,u):
		""""""

		try:
			return u.encode('utf-8',errors='ignore')
		except (UnicodeDecodeError,AttributeError) as e:
			try:
				return str(u)
			except UnicodeEncodeError:
				return unicode(u).encode('utf-8',errors='ignore')
1126458
def enc(x, codec='ascii'):
    """"""
    x = x.replace('&', '&amp;').replace('>', '&gt;').replace('<', '&lt;').replace('"', '&quot;')
    return x.encode(codec, 'xmlcharrefreplace')
1312095
def convert_unicode_character_to_ascii_repr(match_obj):
    
    match = match_obj.group(0)
    code_point = ord(match)

    hex_repr = hex(code_point)
    hex_code_point = hex_repr[2:]

    hex_value = hex_code_point.zfill(6).upper()

    return '<U+{}>'.format(hex_value)
714624
function encode(data, ch) {
        if (!self.utfMouse) {
          if (ch === 255) return data.push(0);
          if (ch > 127) ch = 127;
          data.push(ch);
        } else {
          if (ch === 2047) return data.push(0);
          if (ch < 127) {
            data.push(ch);
          } else {
            if (ch > 2047) ch = 2047;
            data.push(0xC0 | (ch >> 6));
            data.push(0x80 | (ch & 0x3F));
          }
        }
      }
320278
def encode_alphanumeric(self):
        
        #Convert the string to upper case
        self.data = self.data.upper()

        #Change the data such that it uses a QR code ascii table
        ascii = []
        for char in self.data:
            if isinstance(char, int):
                ascii.append(tables.ascii_codes[chr(char)])
            else:
                ascii.append(tables.ascii_codes[char])
        
        #Now perform the algorithm that will make the ascii into bit fields
        with io.StringIO() as buf:
            for (a,b) in self.grouper(2, ascii):
                if b is not None:
                    buf.write(self.binary_string((45*a)+b, 11))
                else:
                    #This occurs when there is an odd number
                    #of characters in the data
                    buf.write(self.binary_string(a, 6))

            #Return the binary string
            return buf.getvalue()
612231
def to_unicode_repr( _letter ):
    
    # Python 2-3 compatible
    return u"u'"+ u"".join( [ u"\\u%04x"%ord(l) for l in _letter ] ) + u"'"
303963
def ucharcopy(t, s, i)
    n = s.length - i
    raise Utf8Error if n < 1

    c0 = s[i].ord

    # 1-byte, 7-bit sequence?
    if c0 < Utagx
      t.putc(c0)
      return 1
    end

    raise Utf8Error if c0 < Utag2 # unexpected continuation byte?

    raise Utf8Error if n < 2 # need continuation byte
    c1 = s[i+1].ord
    raise Utf8Error if c1 < Utagx || Utag2 <= c1

    # 2-byte, 11-bit sequence?
    if c0 < Utag3
      raise Utf8Error if ((c0&Umask2)<<6 | (c1&Umaskx)) <= Uchar1max
      t.putc(c0)
      t.putc(c1)
      return 2
    end

    # need second continuation byte
    raise Utf8Error if n < 3

    c2 = s[i+2].ord
    raise Utf8Error if c2 < Utagx || Utag2 <= c2

    # 3-byte, 16-bit sequence?
    if c0 < Utag4
      u = (c0&Umask3)<<12 | (c1&Umaskx)<<6 | (c2&Umaskx)
      raise Utf8Error if u <= Uchar2max
      t.putc(c0)
      t.putc(c1)
      t.putc(c2)
      return 3
    end

    # need third continuation byte
    raise Utf8Error if n < 4
    c3 = s[i+3].ord
    raise Utf8Error if c3 < Utagx || Utag2 <= c3

    # 4-byte, 21-bit sequence?
    if c0 < Utag5
      u = (c0&Umask4)<<18 | (c1&Umaskx)<<12 | (c2&Umaskx)<<6 | (c3&Umaskx)
      raise Utf8Error if u <= Uchar3max
      t.putc(c0)
      t.putc(c1)
      t.putc(c2)
      t.putc(c3)
      return 4
    end

    raise Utf8Error
  rescue Utf8Error
    t.write(Ustrerr)
    return 1
  end