diff --git a/kallithea/controllers/api/__init__.py b/kallithea/controllers/api/__init__.py --- a/kallithea/controllers/api/__init__.py +++ b/kallithea/controllers/api/__init__.py @@ -226,12 +226,12 @@ class JSONRPCController(TGController): if isinstance(raw_response, HTTPError): self._error = str(raw_response) except JSONRPCError as e: - self._error = unicode(e) + self._error = str(e) except Exception as e: log.error('Encountered unhandled exception: %s', traceback.format_exc(),) json_exc = JSONRPCError('Internal server error') - self._error = unicode(json_exc) + self._error = str(json_exc) if self._error is not None: raw_response = None diff --git a/kallithea/lib/celerylib/__init__.py b/kallithea/lib/celerylib/__init__.py --- a/kallithea/lib/celerylib/__init__.py +++ b/kallithea/lib/celerylib/__init__.py @@ -95,7 +95,7 @@ def __get_lockkey(func, *fargs, **fkwarg func_name = str(func.__name__) if hasattr(func, '__name__') else str(func) lockkey = 'task_%s.lock' % \ - md5(safe_bytes(func_name + '-' + '-'.join(unicode(x) for x in params))).hexdigest() + md5(safe_bytes(func_name + '-' + '-'.join(str(x) for x in params))).hexdigest() return lockkey diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -460,11 +460,11 @@ def flash(message, category, logf=None): assert category in ('error', 'success', 'warning'), category if hasattr(message, '__html__'): # render to HTML for storing in cookie - safe_message = unicode(message) + safe_message = str(message) else: # Apply str - the message might be an exception with __str__ # Escape, so we can trust the result without further escaping, without any risk of injection - safe_message = html_escape(unicode(message)) + safe_message = html_escape(str(message)) if logf is None: logf = log.info if category == 'success': diff --git a/kallithea/lib/recaptcha.py b/kallithea/lib/recaptcha.py --- a/kallithea/lib/recaptcha.py +++ b/kallithea/lib/recaptcha.py @@ -26,7 +26,7 @@ def submit(g_recaptcha_response, private return RecaptchaResponse(is_valid=False, error_code='incorrect-captcha-sol') def encode_if_necessary(s): - if isinstance(s, unicode): + if isinstance(s, str): return s.encode('utf-8') return s diff --git a/kallithea/lib/utils2.py b/kallithea/lib/utils2.py --- a/kallithea/lib/utils2.py +++ b/kallithea/lib/utils2.py @@ -179,8 +179,8 @@ def age(prevdate, show_short_version=Fal :param prevdate: datetime object :param show_short_version: if it should approximate the date and return a shorter string - :rtype: unicode - :returns: unicode words describing age + :rtype: str + :returns: str words describing age """ now = now or datetime.datetime.now() order = ['year', 'month', 'day', 'hour', 'minute', 'second'] @@ -278,7 +278,7 @@ def uri_filter(uri): Removes user:password from given url string :param uri: - :rtype: unicode + :rtype: str :returns: filtered list of strings """ if not uri: diff --git a/kallithea/lib/vcs/backends/base.py b/kallithea/lib/vcs/backends/base.py --- a/kallithea/lib/vcs/backends/base.py +++ b/kallithea/lib/vcs/backends/base.py @@ -342,10 +342,10 @@ class BaseChangeset(object): combined list of ``Node`` objects ``author`` - author of the changeset, as unicode + author of the changeset, as str ``message`` - message of the changeset, as unicode + message of the changeset, as str ``parents`` list of parent changesets diff --git a/kallithea/lib/vcs/backends/hg/repository.py b/kallithea/lib/vcs/backends/hg/repository.py --- a/kallithea/lib/vcs/backends/hg/repository.py +++ b/kallithea/lib/vcs/backends/hg/repository.py @@ -428,7 +428,7 @@ class MercurialRepository(BaseRepository if revision in [-1, None]: revision = b'tip' - elif isinstance(revision, unicode): + elif isinstance(revision, str): revision = safe_bytes(revision) try: diff --git a/kallithea/lib/vcs/subprocessio.py b/kallithea/lib/vcs/subprocessio.py --- a/kallithea/lib/vcs/subprocessio.py +++ b/kallithea/lib/vcs/subprocessio.py @@ -286,7 +286,7 @@ class SubprocessIOChunker(object): - We are multithreaded. Writing in and reading out, err are all sep threads. - We support concurrent (in and out) stream processing. - - The output is not a stream. It's a queue of read string (bytes, not unicode) + - The output is not a stream. It's a queue of read string (bytes, not str) chunks. The object behaves as an iterable. You can "for chunk in obj:" us. - We are non-blocking in more respects than communicate() (reading from subprocess out pauses when internal buffer is full, but diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -205,7 +205,7 @@ class Setting(Base, BaseDbModel): @validates('_app_settings_value') def validate_settings_value(self, key, val): - assert isinstance(val, unicode) + assert isinstance(val, str) return val @hybrid_property diff --git a/kallithea/model/gist.py b/kallithea/model/gist.py --- a/kallithea/model/gist.py +++ b/kallithea/model/gist.py @@ -125,7 +125,7 @@ class GistModel(object): Session().flush() # make database assign gist.gist_id if gist_type == Gist.GIST_PUBLIC: # use DB ID for easy to use GIST ID - gist.gist_access_id = unicode(gist.gist_id) + gist.gist_access_id = str(gist.gist_id) log.debug('Creating new %s GIST repo %s', gist_type, gist.gist_access_id) repo = RepoModel()._create_filesystem_repo( diff --git a/kallithea/model/notification.py b/kallithea/model/notification.py --- a/kallithea/model/notification.py +++ b/kallithea/model/notification.py @@ -184,7 +184,7 @@ class EmailNotificationModel(object): bracket_tags = [] status_change = kwargs.get('status_change') if status_change: - bracket_tags.append(unicode(status_change)) # apply unicode to evaluate LazyString before .join + bracket_tags.append(str(status_change)) # apply str to evaluate LazyString before .join if kwargs.get('closing_pr'): bracket_tags.append(_('Closing')) if bracket_tags: diff --git a/kallithea/tests/vcs/test_git.py b/kallithea/tests/vcs/test_git.py --- a/kallithea/tests/vcs/test_git.py +++ b/kallithea/tests/vcs/test_git.py @@ -588,13 +588,13 @@ class TestGitChangeset(object): 'vcs/nodes.py'] assert set(changed) == set([f.path for f in chset.changed]) - def test_commit_message_is_unicode(self): + def test_commit_message_is_str(self): for cs in self.repo: - assert isinstance(cs.message, unicode) + assert isinstance(cs.message, str) - def test_changeset_author_is_unicode(self): + def test_changeset_author_is_str(self): for cs in self.repo: - assert isinstance(cs.author, unicode) + assert isinstance(cs.author, str) def test_repo_files_content_is_bytes(self): changeset = self.repo.get_changeset() diff --git a/kallithea/tests/vcs/test_hg.py b/kallithea/tests/vcs/test_hg.py --- a/kallithea/tests/vcs/test_hg.py +++ b/kallithea/tests/vcs/test_hg.py @@ -535,13 +535,13 @@ class TestMercurialChangeset(object): # but it would be one of ``removed`` (changeset's attribute) assert path in [rf.path for rf in chset.removed] - def test_commit_message_is_unicode(self): + def test_commit_message_is_str(self): for cm in self.repo: - assert isinstance(cm.message, unicode) + assert isinstance(cm.message, str) - def test_changeset_author_is_unicode(self): + def test_changeset_author_is_str(self): for cm in self.repo: - assert isinstance(cm.author, unicode) + assert isinstance(cm.author, str) def test_repo_files_content_is_bytes(self): test_changeset = self.repo.get_changeset(100) diff --git a/kallithea/tests/vcs/test_inmemchangesets.py b/kallithea/tests/vcs/test_inmemchangesets.py --- a/kallithea/tests/vcs/test_inmemchangesets.py +++ b/kallithea/tests/vcs/test_inmemchangesets.py @@ -37,7 +37,7 @@ class InMemoryChangesetTestMixin(_Backen for node in to_add: self.imc.add(node) message = u'Added: %s' % ', '.join((node.path for node in self.nodes)) - author = unicode(self.__class__) + author = str(self.__class__) changeset = self.imc.commit(message=message, author=author) newtip = self.repo.get_changeset() @@ -59,7 +59,7 @@ class InMemoryChangesetTestMixin(_Backen for node in self.nodes] self.imc.add(*to_add) message = u'Added: %s' % ', '.join((node.path for node in self.nodes)) - author = unicode(self.__class__) + author = str(self.__class__) changeset = self.imc.commit(message=message, author=author) newtip = self.repo.get_changeset() @@ -109,7 +109,7 @@ class InMemoryChangesetTestMixin(_Backen for node in to_add: self.imc.add(node) message = u'Added: %s' % ', '.join((node.path for node in self.nodes)) - author = unicode(self.__class__) + author = str(self.__class__) changeset = self.imc.commit(message=message, author=author) newtip = self.repo.get_changeset() @@ -134,7 +134,7 @@ class InMemoryChangesetTestMixin(_Backen def test_check_integrity_raise_already_exist(self): node = FileNode('foobar', content='baz') self.imc.add(node) - self.imc.commit(message=u'Added foobar', author=unicode(self)) + self.imc.commit(message=u'Added foobar', author=str(self)) self.imc.add(node) with pytest.raises(NodeAlreadyExistsError): self.imc.commit(message='new message', @@ -189,7 +189,7 @@ class InMemoryChangesetTestMixin(_Backen def test_check_integrity_change_raise_node_does_not_exist(self): node = FileNode('foobar', content='baz') self.imc.add(node) - self.imc.commit(message=u'Added foobar', author=unicode(self)) + self.imc.commit(message=u'Added foobar', author=str(self)) node = FileNode('not-foobar', content='') self.imc.change(node) with pytest.raises(NodeDoesNotExistError): @@ -198,7 +198,7 @@ class InMemoryChangesetTestMixin(_Backen def test_change_raise_node_already_changed(self): node = FileNode('foobar', content='baz') self.imc.add(node) - self.imc.commit(message=u'Added foobar', author=unicode(self)) + self.imc.commit(message=u'Added foobar', author=str(self)) node = FileNode('foobar', content='more baz') self.imc.change(node) with pytest.raises(NodeAlreadyChangedError): @@ -212,13 +212,13 @@ class InMemoryChangesetTestMixin(_Backen with pytest.raises(NodeNotChangedError): self.imc.commit( message=u'Trying to mark node as changed without touching it', - author=unicode(self) + author=str(self), ) def test_change_raise_node_already_removed(self): node = FileNode('foobar', content='baz') self.imc.add(node) - self.imc.commit(message=u'Added foobar', author=unicode(self)) + self.imc.commit(message=u'Added foobar', author=str(self)) self.imc.remove(FileNode('foobar')) with pytest.raises(NodeAlreadyRemovedError): self.imc.change(node) @@ -230,7 +230,7 @@ class InMemoryChangesetTestMixin(_Backen node = self.nodes[0] assert node.content == tip.get_node(node.path).content self.imc.remove(node) - self.imc.commit(message=u'Removed %s' % node.path, author=unicode(self)) + self.imc.commit(message=u'Removed %s' % node.path, author=str(self)) newtip = self.repo.get_changeset() assert tip != newtip @@ -253,7 +253,7 @@ class InMemoryChangesetTestMixin(_Backen with pytest.raises(NodeDoesNotExistError): self.imc.commit( message='Trying to remove node at empty repository', - author=str(self) + author=str(self), ) def test_check_integrity_remove_raise_node_does_not_exist(self): @@ -264,7 +264,7 @@ class InMemoryChangesetTestMixin(_Backen with pytest.raises(NodeDoesNotExistError): self.imc.commit( message=u'Trying to remove not existing node', - author=unicode(self) + author=str(self), ) def test_remove_raise_node_already_removed(self):