Decode from specified encoding.

    ``encoding`` defaults to the preferred encoding.
    ``errors`` defaults to the preferred error handler.
199760
def decode(string, encoding=None, errors=None):
    
    if encoding is None:
        encoding = getpreferredencoding()
    if errors is None:
        errors = getpreferrederrors()
    return string.decode(encoding, errors)
723655
public EncodingPredictor.DecodeResult receiveErrorString(int len) throws IOException {
    if (!pgInput.ensureBytes(len)) {
      throw new EOFException();
    }

    EncodingPredictor.DecodeResult res;
    try {
      String value = encoding.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
      // no autodetect warning as the message was converted on its own
      res = new EncodingPredictor.DecodeResult(value, null);
    } catch (IOException e) {
      res = EncodingPredictor.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
      if (res == null) {
        Encoding enc = Encoding.defaultEncoding();
        String value = enc.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
        res = new EncodingPredictor.DecodeResult(value, enc.name());
      }
    }
    pgInput.skip(len);
    return res;
  }
1366832
def _decode(self, data):
        
        if self.encoding:
            data = data.decode(self.encoding, 'replace')
        return data
129203
def _ensure_decoded(s):
    
    if isinstance(s, (np.bytes_, bytes)):
        s = s.decode(pd.get_option('display.encoding'))
    return s
928225
def deep_encode(s, encoding='utf-8', errors='strict'):
    """"""
    # encoding defaults to the default encoding. errors may be given to set
    # a different error handling scheme. Default is 'strict' meaning
    # that encoding errors raise
    # a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
    # 'xmlcharrefreplace' as well as any other name registered with
    # codecs.register_error that can handle UnicodeEncodeErrors.
    s = deep_encode(s)
    if sys.version_info.major < 3 and isinstance(s, unicode):
        return s.encode(encoding, errors)
    if isinstance(s, (list, tuple)):
        return [deep_encode(i, encoding=encoding, errors=errors) for i in s]
    if isinstance(s, dict):
        return dict([
            (
                deep_encode(key, encoding=encoding, errors=errors),
                deep_encode(s[key], encoding=encoding, errors=errors)
            ) for key in s
        ])
        # new_dict = {}
        # for key in s:
        #     new_dict[
        #         to_encode(key, encoding=encoding, errors=errors)
        #     ] = to_encode(s[key], encoding=encoding, errors=errors)
        # return new_dict
    return s
1053795
def decode(self, encoded):
        
        if self.enforce_reversible:
            self.enforce_reversible = False
            if self.encode(self.decode(encoded)) != encoded:
                raise ValueError('Decoding is not reversible for "%s"' % encoded)
            self.enforce_reversible = True

        return encoded
801647
def decode_if_bytes(obj, mode=True):
    """"""
    if mode is True:
        mode = unicode_errors_default
    if isinstance(obj, bytes):
        return obj.decode("utf-8", errors=mode)
    return obj
232350
def _decode(self, infile, encoding):
        
        if isinstance(infile, string_types):
            # can't be unicode
            # NOTE: Could raise a ``UnicodeDecodeError``
            return infile.decode(encoding).splitlines(True)
        for i, line in enumerate(infile):
            # NOTE: The isinstance test here handles mixed lists of unicode/string
            # NOTE: But the decode will break on any non-string values
            # NOTE: Or could raise a ``UnicodeDecodeError``
            if PY3K:
                if not isinstance(line, str):
                    infile[i] = line.decode(encoding)
            else:
                if not isinstance(line, unicode):
                    infile[i] = line.decode(encoding)
        return infile
835338
def _decode_data(self, data, charset):
        

        try:
            return smart_unicode(data, charset)
        except UnicodeDecodeError:
            raise errors.BadRequest('wrong charset')
1091345
def try_decoding(data, encoding):
    ''''''
    try:
        data.decode(encoding, 'strict')
    except UnicodeError:
        # Data under 16 bytes is very unlikely to be truncated
        if len(data) > 16:
            for trim in (1, 2, 3):
                trimmed_data = data[:-trim]
                if trimmed_data:
                    try:
                        trimmed_data.decode(encoding, 'strict')
                    except UnicodeError:
                        continue
                    else:
                        return True
        return False
    else:
        return True
574758
def decode_html(html, default_encoding=DEFAULT_ENCODING, encoding=None, errors=DEFAULT_ENC_ERRORS):
    
    if isinstance(html, unicode):
        return html

    if encoding:
        return html.decode(encoding, errors)

    match = CHARSET_META_TAG_PATTERN.search(html)
    if match:
        declared_encoding = match.group(1).decode("ASCII")
        # proceed unknown encoding as if it wasn't found at all
        with ignored(LookupError):
            return html.decode(declared_encoding, errors)

    # unknown encoding
    try:
        # try UTF-8 first
        return html.decode("utf8")
    except UnicodeDecodeError:
        # try lucky with default encoding
        try:
            return html.decode(default_encoding, errors)
        except UnicodeDecodeError as e:
            raise JustextError("Unable to decode the HTML to Unicode: " + unicode(e))
1148710
def default_encoder(obj):
    
    if isinstance(obj, bytes):
        return json.dumps(bytes_to_str(obj),
                          ensure_ascii=False).encode("utf-8")
    else:
        return json.dumps(obj, ensure_ascii=False).encode("utf-8")
672202
def decode_return(codec="ascii"):
    """"""

    def outer(f):
        def wrap(*args, **kwargs):
            res = f(*args, **kwargs)
            if res is not None:
                return res.decode(codec)
            return res
        return wrap
    return outer
1031170
def nts(s, encoding, errors):
    
    p = s.find(b"\0")
    if p != -1:
        s = s[:p]
    return s.decode(encoding, errors)
390888
def _decode(self, s):
        ''' '''
        if self.decoder is not None:
            return self.decoder.decode(s)
        else:
            raise TypeError("This screen was constructed with encoding=None, "
                            "so it does not handle bytes.")
794870
def _decode(value):
        
        if value.isdigit():
            return int(value)
        if isinstance(value, bytes):
            return value.decode('utf-8')
        else:
            return value
381232
def _decode(self, obj):
        
        if self.decode_responses and isinstance(obj, bytes):
            try:
                return obj.decode(self.encoding)
            except UnicodeDecodeError:
                return obj
        return obj