From ada323f4c2a2f8198f4fe74f8e6ff5ade2dfbf9c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 16 2017 09:23:52 +0000 Subject: Raise a PagureEncodingException when none of the encoding guessed worked In pagure.doc_utils.convert_readme() we try guessing the encoding of the file, then we iterate over all these encoding and try to decode the file in it. If all the encoding fails, we raise an exception, it used to be a generic PagureException, it will now be a PagureEncodingException inheriting from both PagureExpception and ValueError --- diff --git a/pagure/docs_server.py b/pagure/docs_server.py index 42ee168..bc17900 100644 --- a/pagure/docs_server.py +++ b/pagure/docs_server.py @@ -114,7 +114,7 @@ def __get_tree_and_content(repo_obj, commit, path): try: content, safe = pagure.doc_utils.convert_readme( blob_obj.data, ext) - except pagure.exceptions.PagureException: + except pagure.exceptions.PagureEncodingException: safe = False content = blob_obj.data else: diff --git a/pagure/exceptions.py b/pagure/exceptions.py index 6892623..d4e7a1a 100644 --- a/pagure/exceptions.py +++ b/pagure/exceptions.py @@ -87,3 +87,10 @@ class NoCorrespondingPR(PagureException): class InvalidObjectException(PagureException): ''' Exception raised when a given object is not what was expected. ''' pass + + +class PagureEncodingException(PagureException, ValueError): + ''' Exception raised none of the encoding guessed could be applied to + the content examined + ''' + pass diff --git a/pagure/lib/encoding_utils.py b/pagure/lib/encoding_utils.py index 550de58..70569d6 100644 --- a/pagure/lib/encoding_utils.py +++ b/pagure/lib/encoding_utils.py @@ -127,7 +127,7 @@ def guess_encoding(data): return encoding.encoding except UnicodeDecodeError: pass - raise PagureException('No encoding could be guessed for this file') + raise PagureEncodingException('No encoding could be guessed for this file') def decode(data):