def codec_lookup(encoding, default='utf-8'):
 if (not encoding):
  return codecs.lookup(default)
 try:
  info = codecs.lookup(encoding)
 except (LookupError, TypeError):
  return codecs.lookup(default)
 try:
  if (not info._is_text_encoding):
   return codecs.lookup(default)
 except AttributeError:
  pass
 if (info.name == 'undefined'):
  return codecs.lookup(default)
 return info

def codec_lookup ( encoding , default = 'utf-8' ) : if ( not encoding ) : return codecs . lookup ( default ) try : info = codecs . lookup ( encoding ) except ( LookupError , TypeError ) : return codecs . lookup ( default ) try : if ( not info . _is_text_encoding ) : return codecs . lookup ( default ) except AttributeError : pass if ( info . name == 'undefined' ) : return codecs . lookup ( default ) return info
safely lookup a codec and ignore non-text codecs .