Use proper encoding on compat_str construction when necessary

This commit is contained in:
Sergey M․ 2015-12-20 06:29:36 +06:00
parent 8e60dc7526
commit c0384f221e
2 changed files with 11 additions and 10 deletions

View file

@ -47,6 +47,7 @@
DEFAULT_OUTTMPL, DEFAULT_OUTTMPL,
determine_ext, determine_ext,
DownloadError, DownloadError,
encode_compat_str,
encodeFilename, encodeFilename,
error_to_str, error_to_str,
ExtractorError, ExtractorError,
@ -496,7 +497,7 @@ def trouble(self, message=None, tb=None):
tb = '' tb = ''
if hasattr(sys.exc_info()[1], 'exc_info') and sys.exc_info()[1].exc_info[0]: if hasattr(sys.exc_info()[1], 'exc_info') and sys.exc_info()[1].exc_info[0]:
tb += ''.join(traceback.format_exception(*sys.exc_info()[1].exc_info)) tb += ''.join(traceback.format_exception(*sys.exc_info()[1].exc_info))
tb += compat_str(traceback.format_exc()) tb += encode_compat_str(traceback.format_exc())
else: else:
tb_data = traceback.format_list(traceback.extract_stack()) tb_data = traceback.format_list(traceback.extract_stack())
tb = ''.join(tb_data) tb = ''.join(tb_data)
@ -682,7 +683,7 @@ def extract_info(self, url, download=True, ie_key=None, extra_info={},
raise raise
except Exception as e: except Exception as e:
if self.params.get('ignoreerrors', False): if self.params.get('ignoreerrors', False):
self.report_error(error_to_str(e), tb=compat_str(traceback.format_exc())) self.report_error(error_to_str(e), tb=encode_compat_str(traceback.format_exc()))
break break
else: else:
raise raise

View file

@ -9,7 +9,7 @@
import sys import sys
from zipimport import zipimporter from zipimport import zipimporter
from .compat import compat_str from .utils import encode_compat_str
from .version import __version__ from .version import __version__
@ -61,7 +61,7 @@ def update_self(to_screen, verbose, opener):
newversion = opener.open(VERSION_URL).read().decode('utf-8').strip() newversion = opener.open(VERSION_URL).read().decode('utf-8').strip()
except Exception: except Exception:
if verbose: if verbose:
to_screen(compat_str(traceback.format_exc())) to_screen(encode_compat_str(traceback.format_exc()))
to_screen('ERROR: can\'t find the current version. Please try again later.') to_screen('ERROR: can\'t find the current version. Please try again later.')
return return
if newversion == __version__: if newversion == __version__:
@ -74,7 +74,7 @@ def update_self(to_screen, verbose, opener):
versions_info = json.loads(versions_info) versions_info = json.loads(versions_info)
except Exception: except Exception:
if verbose: if verbose:
to_screen(compat_str(traceback.format_exc())) to_screen(encode_compat_str(traceback.format_exc()))
to_screen('ERROR: can\'t obtain versions info. Please try again later.') to_screen('ERROR: can\'t obtain versions info. Please try again later.')
return return
if 'signature' not in versions_info: if 'signature' not in versions_info:
@ -123,7 +123,7 @@ def version_tuple(version_str):
urlh.close() urlh.close()
except (IOError, OSError): except (IOError, OSError):
if verbose: if verbose:
to_screen(compat_str(traceback.format_exc())) to_screen(encode_compat_str(traceback.format_exc()))
to_screen('ERROR: unable to download latest version') to_screen('ERROR: unable to download latest version')
return return
@ -137,7 +137,7 @@ def version_tuple(version_str):
outf.write(newcontent) outf.write(newcontent)
except (IOError, OSError): except (IOError, OSError):
if verbose: if verbose:
to_screen(compat_str(traceback.format_exc())) to_screen(encode_compat_str(traceback.format_exc()))
to_screen('ERROR: unable to write the new version') to_screen('ERROR: unable to write the new version')
return return
@ -157,7 +157,7 @@ def version_tuple(version_str):
return # Do not show premature success messages return # Do not show premature success messages
except (IOError, OSError): except (IOError, OSError):
if verbose: if verbose:
to_screen(compat_str(traceback.format_exc())) to_screen(encode_compat_str(traceback.format_exc()))
to_screen('ERROR: unable to overwrite current version') to_screen('ERROR: unable to overwrite current version')
return return
@ -169,7 +169,7 @@ def version_tuple(version_str):
urlh.close() urlh.close()
except (IOError, OSError): except (IOError, OSError):
if verbose: if verbose:
to_screen(compat_str(traceback.format_exc())) to_screen(encode_compat_str(traceback.format_exc()))
to_screen('ERROR: unable to download latest version') to_screen('ERROR: unable to download latest version')
return return
@ -183,7 +183,7 @@ def version_tuple(version_str):
outf.write(newcontent) outf.write(newcontent)
except (IOError, OSError): except (IOError, OSError):
if verbose: if verbose:
to_screen(compat_str(traceback.format_exc())) to_screen(encode_compat_str(traceback.format_exc()))
to_screen('ERROR: unable to overwrite current version') to_screen('ERROR: unable to overwrite current version')
return return