Changeset - 287b5f1cb40a
[Not reviewed]
default
0 6 0
Mads Kiilerich - 6 years ago 2019-12-16 00:02:34
mads@kiilerich.com
Grafted from: 26b6d73775ab
py3: only use safe_str for string conversion - not for arbitrary __str__ invocation

Usually, we actually just want unicode string, and it is better to just unicode().
6 files changed with 12 insertions and 13 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/api/__init__.py
Show inline comments
 
@@ -226,12 +226,12 @@ class JSONRPCController(TGController):
 
            if isinstance(raw_response, HTTPError):
 
                self._error = str(raw_response)
 
        except JSONRPCError as e:
 
            self._error = safe_str(e)
 
            self._error = unicode(e)
 
        except Exception as e:
 
            log.error('Encountered unhandled exception: %s',
 
                      traceback.format_exc(),)
 
            json_exc = JSONRPCError('Internal server error')
 
            self._error = safe_str(json_exc)
 
            self._error = unicode(json_exc)
 

	
 
        if self._error is not None:
 
            raw_response = None
kallithea/controllers/changelog.py
Show inline comments
 
@@ -67,7 +67,7 @@ class ChangelogController(BaseRepoContro
 
            h.flash(_('There are no changesets yet'), category='error')
 
        except RepositoryError as e:
 
            log.error(traceback.format_exc())
 
            h.flash(safe_str(e), category='error')
 
            h.flash(unicode(e), category='error')
 
        raise HTTPBadRequest()
 

	
 
    @LoginRequired(allow_default_user=True)
 
@@ -111,7 +111,7 @@ class ChangelogController(BaseRepoContro
 
                        cs = self.__get_cs(revision, repo_name)
 
                        collection = cs.get_file_history(f_path)
 
                    except RepositoryError as e:
 
                        h.flash(safe_str(e), category='warning')
 
                        h.flash(unicode(e), category='warning')
 
                        raise HTTPFound(location=h.url('changelog_home', repo_name=repo_name))
 
            else:
 
                collection = c.db_repo_scm_instance.get_changesets(start=0, end=revision,
 
@@ -125,11 +125,11 @@ class ChangelogController(BaseRepoContro
 
            c.cs_comments = c.db_repo.get_comments(page_revisions)
 
            c.cs_statuses = c.db_repo.statuses(page_revisions)
 
        except EmptyRepositoryError as e:
 
            h.flash(safe_str(e), category='warning')
 
            h.flash(unicode(e), category='warning')
 
            raise HTTPFound(location=url('summary_home', repo_name=c.repo_name))
 
        except (RepositoryError, ChangesetDoesNotExistError, Exception) as e:
 
            log.error(traceback.format_exc())
 
            h.flash(safe_str(e), category='error')
 
            h.flash(unicode(e), category='error')
 
            raise HTTPFound(location=url('changelog_home', repo_name=c.repo_name))
 

	
 
        c.branch_name = branch_name
kallithea/controllers/files.py
Show inline comments
 
@@ -90,7 +90,7 @@ class FilesController(BaseRepoController
 
            h.flash(msg, category='error')
 
            raise HTTPNotFound()
 
        except RepositoryError as e:
 
            h.flash(safe_str(e), category='error')
 
            h.flash(unicode(e), category='error')
 
            raise HTTPNotFound()
 

	
 
    def __get_filenode(self, cs, path):
 
@@ -110,7 +110,7 @@ class FilesController(BaseRepoController
 
            h.flash(msg, category='error')
 
            raise HTTPNotFound()
 
        except RepositoryError as e:
 
            h.flash(safe_str(e), category='error')
 
            h.flash(unicode(e), category='error')
 
            raise HTTPNotFound()
 

	
 
        return file_node
 
@@ -175,7 +175,7 @@ class FilesController(BaseRepoController
 
            else:
 
                c.authors = c.file_history = []
 
        except RepositoryError as e:
 
            h.flash(safe_str(e), category='error')
 
            h.flash(unicode(e), category='error')
 
            raise HTTPNotFound()
 

	
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
kallithea/controllers/summary.py
Show inline comments
 
@@ -108,7 +108,7 @@ class SummaryController(BaseRepoControll
 
        try:
 
            collection = c.db_repo_scm_instance.get_changesets(reverse=True)
 
        except EmptyRepositoryError as e:
 
            h.flash(safe_str(e), category='warning')
 
            h.flash(unicode(e), category='warning')
 
            collection = []
 
        c.cs_pagination = Page(collection, page=p, items_per_page=size)
 
        page_revisions = [x.raw_id for x in list(c.cs_pagination)]
kallithea/lib/base.py
Show inline comments
 
@@ -603,7 +603,7 @@ class BaseRepoController(BaseController)
 
            raise webob.exc.HTTPNotFound()
 
        except RepositoryError as e:
 
            log.error(traceback.format_exc())
 
            h.flash(safe_str(e), category='error')
 
            h.flash(unicode(e), category='error')
 
            raise webob.exc.HTTPBadRequest()
 

	
 

	
kallithea/lib/vcs/utils/__init__.py
Show inline comments
 
@@ -106,8 +106,7 @@ def safe_str(s):
 
    if isinstance(s, str):
 
        return s
 

	
 
    if not isinstance(s, unicode):
 
        return str(s)
 
    assert isinstance(s, unicode), s  # don't use safe_str to coerce non-strings
 

	
 
    from kallithea.lib.vcs.conf import settings
 
    for enc in settings.DEFAULT_ENCODINGS:
0 comments (0 inline, 0 general)